From 90e16be3aebfaf70304fb6f923056e59e7b22db5 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 5 Mar 2021 09:58:36 +0100 Subject: [PATCH] tape: improve PoolWriter logging Log reason why we allocate a new media set. --- src/api2/tape/backup.rs | 2 +- src/tape/media_pool.rs | 34 +++++++++++++++++++--------------- src/tape/pool_writer.rs | 13 +++++++++++-- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index 2f9f03d0..2fa4f352 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -295,7 +295,7 @@ fn backup_worker( let pool = MediaPool::with_config(status_path, &pool_config, changer_name)?; - let mut pool_writer = PoolWriter::new(pool, &setup.drive)?; + let mut pool_writer = PoolWriter::new(pool, &setup.drive, worker)?; let mut group_list = BackupInfo::list_backup_groups(&datastore.base_path())?; diff --git a/src/tape/media_pool.rs b/src/tape/media_pool.rs index 93605457..4e712be2 100644 --- a/src/tape/media_pool.rs +++ b/src/tape/media_pool.rs @@ -99,6 +99,11 @@ impl MediaPool { self.force_media_availability = true; } + /// Returns the Uuid of the current media set + pub fn current_media_set(&self) -> &Uuid { + self.current_media_set.uuid() + } + /// Creates a new instance using the media pool configuration pub fn with_config( state_path: &Path, @@ -230,27 +235,27 @@ impl MediaPool { /// /// Note: We also call this in list_media to compute correct media /// status, so this must not change persistent/saved state. - pub fn start_write_session(&mut self, current_time: i64) -> Result<(), Error> { + /// + /// Returns the reason why we started a new media set (if we do) + pub fn start_write_session(&mut self, current_time: i64) -> Result, Error> { - let mut create_new_set = match self.current_set_usable() { - Err(err) => { - eprintln!("unable to use current media set - {}", err); - true - } - Ok(usable) => !usable, + let mut create_new_set = match self.current_set_usable() { + Err(err) => { + Some(err.to_string()) + } + Ok(_) => None, }; - if !create_new_set { - + if create_new_set.is_none() { match &self.media_set_policy { MediaSetPolicy::AlwaysCreate => { - create_new_set = true; + create_new_set = Some(String::from("policy is AlwaysCreate")); } MediaSetPolicy::CreateAt(event) => { if let Some(set_start_time) = self.inventory.media_set_start_time(&self.current_media_set.uuid()) { if let Ok(Some(alloc_time)) = compute_next_event(event, set_start_time as i64, false) { - if current_time >= alloc_time { - create_new_set = true; + if current_time >= alloc_time { + create_new_set = Some(String::from("policy CreateAt event triggered")); } } } @@ -259,13 +264,12 @@ impl MediaPool { } } - if create_new_set { + if create_new_set.is_some() { let media_set = MediaSet::new(); - eprintln!("starting new media set {}", media_set.uuid()); self.current_media_set = media_set; } - Ok(()) + Ok(create_new_set) } /// List media in current media set diff --git a/src/tape/pool_writer.rs b/src/tape/pool_writer.rs index 149c1913..a0a54576 100644 --- a/src/tape/pool_writer.rs +++ b/src/tape/pool_writer.rs @@ -68,11 +68,20 @@ pub struct PoolWriter { impl PoolWriter { - pub fn new(mut pool: MediaPool, drive_name: &str) -> Result { + pub fn new(mut pool: MediaPool, drive_name: &str, worker: &WorkerTask) -> Result { let current_time = proxmox::tools::time::epoch_i64(); - pool.start_write_session(current_time)?; + let new_media_set_reason = pool.start_write_session(current_time)?; + if let Some(reason) = new_media_set_reason { + task_log!( + worker, + "starting new media set - reason: {}", + reason, + ); + } + + task_log!(worker, "media set uuid: {}", pool.current_media_set()); let mut media_set_catalog = MediaSetCatalog::new();