[pbs-devel] [PATCH proxmox-backup 1/5] tape/pool_writer: give proper types to 'contains_snapshot'

Dominik Csapak d.csapak at proxmox.com
Tue May 17 08:52:11 CEST 2022


instead of a string. The underlying catalog implementation has to
care about how this is formatted, not the external caller

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/api2/tape/backup.rs             | 12 ++++++++++--
 src/tape/media_catalog.rs           | 19 +++++++++++++++----
 src/tape/pool_writer/catalog_set.rs | 12 +++++++++---
 src/tape/pool_writer/mod.rs         |  9 +++++++--
 4 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs
index c7d042fb..ba08994f 100644
--- a/src/api2/tape/backup.rs
+++ b/src/api2/tape/backup.rs
@@ -496,7 +496,11 @@ fn backup_worker(
             if let Some(info) = snapshot_list.pop() {
                 let rel_path =
                     print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref());
-                if pool_writer.contains_snapshot(datastore_name, &rel_path) {
+                if pool_writer.contains_snapshot(
+                    datastore_name,
+                    &info.backup_dir.backup_ns(),
+                    info.backup_dir.as_ref(),
+                ) {
                     task_log!(worker, "skip snapshot {}", rel_path);
                     continue;
                 }
@@ -517,7 +521,11 @@ fn backup_worker(
                 let rel_path =
                     print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref());
 
-                if pool_writer.contains_snapshot(datastore_name, &rel_path) {
+                if pool_writer.contains_snapshot(
+                    datastore_name,
+                    &info.backup_dir.backup_ns(),
+                    info.backup_dir.as_ref(),
+                ) {
                     task_log!(worker, "skip snapshot {}", rel_path);
                     continue;
                 }
diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs
index 85128f80..38fdcc6e 100644
--- a/src/tape/media_catalog.rs
+++ b/src/tape/media_catalog.rs
@@ -411,10 +411,16 @@ impl MediaCatalog {
     }
 
     /// Test if the catalog already contain a snapshot
-    pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool {
+    pub fn contains_snapshot(
+        &self,
+        store: &str,
+        ns: &BackupNamespace,
+        snapshot: &BackupDir,
+    ) -> bool {
+        let path = print_ns_and_snapshot(ns, snapshot);
         match self.content.get(store) {
             None => false,
-            Some(content) => content.snapshot_index.contains_key(snapshot),
+            Some(content) => content.snapshot_index.contains_key(&path),
         }
     }
 
@@ -960,9 +966,14 @@ impl MediaSetCatalog {
     }
 
     /// Test if the catalog already contain a snapshot
-    pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool {
+    pub fn contains_snapshot(
+        &self,
+        store: &str,
+        ns: &BackupNamespace,
+        snapshot: &BackupDir,
+    ) -> bool {
         for catalog in self.catalog_list.values() {
-            if catalog.contains_snapshot(store, snapshot) {
+            if catalog.contains_snapshot(store, ns, snapshot) {
                 return true;
             }
         }
diff --git a/src/tape/pool_writer/catalog_set.rs b/src/tape/pool_writer/catalog_set.rs
index 1acc108a..d588df18 100644
--- a/src/tape/pool_writer/catalog_set.rs
+++ b/src/tape/pool_writer/catalog_set.rs
@@ -29,13 +29,19 @@ impl CatalogSet {
     }
 
     /// Test if the catalog already contains a snapshot
-    pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool {
+    pub fn contains_snapshot(
+        &self,
+        store: &str,
+        ns: &pbs_api_types::BackupNamespace,
+        snapshot: &pbs_api_types::BackupDir,
+    ) -> bool {
         if let Some(ref catalog) = self.catalog {
-            if catalog.contains_snapshot(store, snapshot) {
+            if catalog.contains_snapshot(store, ns, snapshot) {
                 return true;
             }
         }
-        self.media_set_catalog.contains_snapshot(store, snapshot)
+        self.media_set_catalog
+            .contains_snapshot(store, ns, snapshot)
     }
 
     /// Test if the catalog already contains a chunk
diff --git a/src/tape/pool_writer/mod.rs b/src/tape/pool_writer/mod.rs
index d00c16e6..b2ff8620 100644
--- a/src/tape/pool_writer/mod.rs
+++ b/src/tape/pool_writer/mod.rs
@@ -100,11 +100,16 @@ impl PoolWriter {
         Ok(())
     }
 
-    pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool {
+    pub fn contains_snapshot(
+        &self,
+        store: &str,
+        ns: &pbs_api_types::BackupNamespace,
+        snapshot: &pbs_api_types::BackupDir,
+    ) -> bool {
         self.catalog_set
             .lock()
             .unwrap()
-            .contains_snapshot(store, snapshot)
+            .contains_snapshot(store, ns, snapshot)
     }
 
     /// Eject media and drop PoolWriterState (close drive)
-- 
2.30.2






More information about the pbs-devel mailing list