[pbs-devel] [PATCH proxmox-backup v2 3/7] tape: pool_writer: finish the catalog when its done

Dominik Csapak d.csapak at proxmox.com
Thu Jul 22 15:41:02 CEST 2021


by adding a 'finish' method to the pool writer itself which must
be called before its dropped

and when the catalog gets moved into the read_only section of
the catalog set

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/api2/tape/backup.rs             |  2 +-
 src/tape/pool_writer/catalog_set.rs |  3 ++-
 src/tape/pool_writer/mod.rs         | 15 +++++++++++++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs
index 8119482f..45ee4bad 100644
--- a/src/api2/tape/backup.rs
+++ b/src/api2/tape/backup.rs
@@ -520,7 +520,7 @@ fn backup_worker(
         }
     }
 
-    pool_writer.commit()?;
+    pool_writer.finish()?;
 
     if need_catalog {
         task_log!(worker, "append media catalog");
diff --git a/src/tape/pool_writer/catalog_set.rs b/src/tape/pool_writer/catalog_set.rs
index d5903413..da39b659 100644
--- a/src/tape/pool_writer/catalog_set.rs
+++ b/src/tape/pool_writer/catalog_set.rs
@@ -58,7 +58,8 @@ impl CatalogSet {
     pub fn append_catalog(&mut self, new_catalog: MediaCatalog) -> Result<(), Error> {
 
         // append current catalog to read-only set
-        if let Some(catalog) = self.catalog.take() {
+        if let Some(mut catalog) = self.catalog.take() {
+            catalog.finish()?;
             self.media_set_catalog.append_catalog(catalog)?;
         }
 
diff --git a/src/tape/pool_writer/mod.rs b/src/tape/pool_writer/mod.rs
index 6f887c60..dc908ce5 100644
--- a/src/tape/pool_writer/mod.rs
+++ b/src/tape/pool_writer/mod.rs
@@ -186,8 +186,7 @@ impl PoolWriter {
 
     /// commit changes to tape and catalog
     ///
-    /// This is done automatically during a backupsession, but needs to
-    /// be called explicitly before dropping the PoolWriter
+    /// This is done automatically during a backupsession
     pub fn commit(&mut self) -> Result<(), Error> {
          if let Some(PoolWriterState {ref mut drive, .. }) = self.status {
             drive.sync()?; // sync all data to the tape
@@ -196,6 +195,18 @@ impl PoolWriter {
         Ok(())
     }
 
+    /// commit changes to tape and finished catalog
+    ///
+    /// this needs be called before the PoolWriter is dropped
+    pub fn finish(&mut self) -> Result<(), Error> {
+        self.commit()?;
+        let mut catalog_set = self.catalog_set.lock().unwrap();
+        if let Some(ref mut catalog) = catalog_set.catalog {
+            catalog.finish()?;
+        }
+        Ok(())
+    }
+
     /// Load a writable media into the drive
     pub fn load_writable_media(&mut self, worker: &WorkerTask) -> Result<Uuid, Error> {
         let last_media_uuid = match self.status {
-- 
2.30.2






More information about the pbs-devel mailing list