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();