]> git.proxmox.com Git - proxmox-backup.git/commitdiff
tape: improve PoolWriter logging
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 5 Mar 2021 08:58:36 +0000 (09:58 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 5 Mar 2021 08:59:38 +0000 (09:59 +0100)
Log reason why we allocate a new media set.

src/api2/tape/backup.rs
src/tape/media_pool.rs
src/tape/pool_writer.rs

index 2f9f03d0e28736df6769e246d255a4d8b6ea8e29..2fa4f3523a996431d252e7db102489d7f12d38d4 100644 (file)
@@ -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())?;
 
index 936054572bf8eb1aa703c7b94f4c743bf5353289..4e712be200090d5f876d59c3ff7a0caa61d9b8af 100644 (file)
@@ -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> {
-
-        let mut create_new_set = match self.current_set_usable() {
-            Err(err) => {
-                eprintln!("unable to use current media set - {}", err);
-                true
-            }
-            Ok(usable) => !usable,
+    ///
+    /// Returns the reason why we started a new media set (if we do)
+    pub fn start_write_session(&mut self, current_time: i64) -> Result<Option<String>, Error> {
+
+         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
index 149c19135bf3d52973fbcfa6fed7565e72179f11..a0a54576e265bfc841727a213cffa128d3eff079 100644 (file)
@@ -68,11 +68,20 @@ pub struct PoolWriter {
 
 impl PoolWriter {
 
-    pub fn new(mut pool: MediaPool, drive_name: &str) -> Result<Self, Error> {
+    pub fn new(mut pool: MediaPool, drive_name: &str, worker: &WorkerTask) -> Result<Self, Error> {
 
         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();