public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup v2 1/2] tape: hide internal use of all zero uuid for unassigned tapes
@ 2022-11-29 14:17 Dominik Csapak
  2022-11-29 14:17 ` [pbs-devel] [PATCH proxmox-backup v2 2/2] tape: inventory: skip " Dominik Csapak
  2022-11-30 16:32 ` [pbs-devel] applied-series: [PATCH proxmox-backup v2 1/2] tape: hide internal use of all zero uuid for " Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Dominik Csapak @ 2022-11-29 14:17 UTC (permalink / raw)
  To: pbs-devel

a tape assigned to a pool but no media-set, gets the special 'all zero'
media set in it's MediaSetLabel. Instead of having that constant
scattered all over the code, hide this fact by using wrapper functions
to initialize it that way and to check for it

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
replaces my previous patch:
 tape: refactor uuid of empty media set into constant

 src/api2/tape/drive.rs       |  6 +++---
 src/api2/tape/media.rs       |  3 +--
 src/tape/file_formats/mod.rs |  8 ++++++++
 src/tape/inventory.rs        | 26 +++++++++++---------------
 src/tape/media_pool.rs       |  2 +-
 5 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 107bcfd8..2175a460 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -528,7 +528,7 @@ fn write_media_label(
             label.label_text,
             pool
         );
-        let set = MediaSetLabel::with_data(pool, [0u8; 16].into(), 0, label.ctime, None);
+        let set = MediaSetLabel::new_unassigned(pool, label.ctime);
 
         drive.write_media_set_label(&set, None)?;
 
@@ -575,7 +575,7 @@ fn write_media_label(
             if let Some(ref pool) = pool {
                 match info.media_set_label {
                     Some(set) => {
-                        if set.uuid != [0u8; 16].into() {
+                        if !set.unassigned() {
                             bail!("verify media set label failed - got wrong set uuid");
                         }
                         if &set.pool != pool {
@@ -1301,7 +1301,7 @@ pub fn catalog_media(
                     return Ok(());
                 }
                 Some(ref set) => {
-                    if set.uuid.as_ref() == [0u8; 16] {
+                    if set.unassigned() {
                         // media is empty
                         task_log!(worker, "media is empty");
                         let _lock = lock_unassigned_media_pool(TAPE_STATUS_DIR)?;
diff --git a/src/api2/tape/media.rs b/src/api2/tape/media.rs
index ed0105b0..cdeffd5b 100644
--- a/src/api2/tape/media.rs
+++ b/src/api2/tape/media.rs
@@ -336,8 +336,7 @@ pub fn destroy_media(label_text: String, force: Option<bool>) -> Result<(), Erro
 
     if !force {
         if let Some(ref set) = media_id.media_set_label {
-            let is_empty = set.uuid.as_ref() == [0u8; 16];
-            if !is_empty {
+            if !set.unassigned() {
                 bail!(
                     "media '{}' contains data (please use 'force' flag to remove.",
                     label_text
diff --git a/src/tape/file_formats/mod.rs b/src/tape/file_formats/mod.rs
index 2b7c9866..f80e2d90 100644
--- a/src/tape/file_formats/mod.rs
+++ b/src/tape/file_formats/mod.rs
@@ -168,4 +168,12 @@ impl MediaSetLabel {
             encryption_key_fingerprint,
         }
     }
+
+    pub fn new_unassigned(pool: &str, ctime: i64) -> Self {
+        Self::with_data(pool, [0u8; 16].into(), 0, ctime, None)
+    }
+
+    pub fn unassigned(&self) -> bool {
+        self.uuid.as_ref() == [0u8; 16]
+    }
 }
diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs
index 9c5887d7..dd560179 100644
--- a/src/tape/inventory.rs
+++ b/src/tape/inventory.rs
@@ -185,7 +185,7 @@ impl Inventory {
             // do not overwrite unsaved pool assignments
             if media_id.media_set_label.is_none() {
                 if let Some(ref set) = previous.id.media_set_label {
-                    if set.uuid.as_ref() == [0u8; 16] {
+                    if set.unassigned() {
                         media_id.media_set_label = Some(set.clone());
                     }
                 }
@@ -251,15 +251,11 @@ impl Inventory {
     pub fn lookup_media_pool(&self, uuid: &Uuid) -> Option<(&str, bool)> {
         match self.map.get(uuid) {
             None => None,
-            Some(entry) => {
-                match entry.id.media_set_label {
-                    None => None, // not assigned to any pool
-                    Some(ref set) => {
-                        let is_empty = set.uuid.as_ref() == [0u8; 16];
-                        Some((&set.pool, is_empty))
-                    }
-                }
-            }
+            Some(entry) => entry
+                .id
+                .media_set_label
+                .as_ref()
+                .map(|set| (set.pool.as_str(), set.unassigned())),
         }
     }
 
@@ -275,7 +271,7 @@ impl Inventory {
                         continue; // belong to another pool
                     }
 
-                    if set.uuid.as_ref() == [0u8; 16] {
+                    if set.unassigned() {
                         list.push(MediaId {
                             label: entry.id.label.clone(),
                             media_set_label: None,
@@ -298,7 +294,7 @@ impl Inventory {
             match entry.id.media_set_label {
                 None => continue, // not assigned to any pool
                 Some(ref set) => {
-                    if set.uuid.as_ref() != [0u8; 16] {
+                    if set.unassigned() {
                         list.push(entry.id.clone());
                     }
                 }
@@ -410,7 +406,7 @@ impl Inventory {
             .map
             .values()
             .filter_map(|entry| entry.id.media_set_label.as_ref())
-            .filter(|set| set.pool == pool && set.uuid.as_ref() != [0u8; 16]);
+            .filter(|set| set.pool == pool && !set.unassigned());
 
         for set in set_list {
             match last_set {
@@ -435,7 +431,7 @@ impl Inventory {
             .map
             .values()
             .filter_map(|entry| entry.id.media_set_label.as_ref())
-            .filter(|set| set.pool == pool && set.uuid.as_ref() != [0u8; 16]);
+            .filter(|set| set.pool == pool && !set.unassigned());
 
         for set in set_list {
             if set.uuid != uuid && set.ctime >= ctime {
@@ -600,7 +596,7 @@ impl Inventory {
 
         let uuid = label.uuid.clone();
 
-        let set = MediaSetLabel::with_data(pool, [0u8; 16].into(), 0, ctime, None);
+        let set = MediaSetLabel::new_unassigned(pool, ctime);
 
         self.store(
             MediaId {
diff --git a/src/tape/media_pool.rs b/src/tape/media_pool.rs
index eb477885..e1bba9ab 100644
--- a/src/tape/media_pool.rs
+++ b/src/tape/media_pool.rs
@@ -181,7 +181,7 @@ impl MediaPool {
             // should never trigger
             return (MediaStatus::Unknown, location); // belong to another pool
         }
-        if set.uuid.as_ref() == [0u8; 16] {
+        if set.unassigned() {
             // not assigned to any pool
             return (MediaStatus::Writable, location);
         }
-- 
2.30.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pbs-devel] [PATCH proxmox-backup v2 2/2] tape: inventory: skip unassigned tapes
  2022-11-29 14:17 [pbs-devel] [PATCH proxmox-backup v2 1/2] tape: hide internal use of all zero uuid for unassigned tapes Dominik Csapak
@ 2022-11-29 14:17 ` Dominik Csapak
  2022-11-30 16:32 ` [pbs-devel] applied-series: [PATCH proxmox-backup v2 1/2] tape: hide internal use of all zero uuid for " Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Dominik Csapak @ 2022-11-29 14:17 UTC (permalink / raw)
  To: pbs-devel

tapes that are labeled into a pool but are not in a media-set yet, belong
to the special 'all zero' media-set. these will never have a catalog on them,
so skip them

fixes the issue, that an inventory with 'catalog restore' aborted on
such a tape

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* use the 'unassigned' function of the MediaSetLabel
* better commit message

 src/api2/tape/drive.rs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 2175a460..f8f29d88 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -952,17 +952,17 @@ pub fn update_inventory(
                             media_id.label.uuid
                         );
 
-                        if let Some(MediaSetLabel {
-                            ref pool, ref uuid, ..
-                        }) = media_id.media_set_label
-                        {
-                            let _pool_lock = lock_media_pool(TAPE_STATUS_DIR, pool)?;
-                            let _lock = lock_media_set(TAPE_STATUS_DIR, uuid, None)?;
+                        if let Some(ref set) = media_id.media_set_label {
+                            if set.unassigned() {
+                                continue;
+                            }
+                            let _pool_lock = lock_media_pool(TAPE_STATUS_DIR, &set.pool)?;
+                            let _lock = lock_media_set(TAPE_STATUS_DIR, &set.uuid, None)?;
                             MediaCatalog::destroy_unrelated_catalog(TAPE_STATUS_DIR, &media_id)?;
                             inventory.store(media_id.clone(), false)?;
 
                             if catalog {
-                                let media_set = inventory.compute_media_set_members(uuid)?;
+                                let media_set = inventory.compute_media_set_members(&set.uuid)?;
                                 if let Err(err) = fast_catalog_restore(
                                     &worker,
                                     &mut drive,
-- 
2.30.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pbs-devel] applied-series: [PATCH proxmox-backup v2 1/2] tape: hide internal use of all zero uuid for unassigned tapes
  2022-11-29 14:17 [pbs-devel] [PATCH proxmox-backup v2 1/2] tape: hide internal use of all zero uuid for unassigned tapes Dominik Csapak
  2022-11-29 14:17 ` [pbs-devel] [PATCH proxmox-backup v2 2/2] tape: inventory: skip " Dominik Csapak
@ 2022-11-30 16:32 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2022-11-30 16:32 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

Am 29/11/2022 um 15:17 schrieb Dominik Csapak:
> a tape assigned to a pool but no media-set, gets the special 'all zero'
> media set in it's MediaSetLabel. Instead of having that constant
> scattered all over the code, hide this fact by using wrapper functions
> to initialize it that way and to check for it
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> replaces my previous patch:
>  tape: refactor uuid of empty media set into constant
> 
>  src/api2/tape/drive.rs       |  6 +++---
>  src/api2/tape/media.rs       |  3 +--
>  src/tape/file_formats/mod.rs |  8 ++++++++
>  src/tape/inventory.rs        | 26 +++++++++++---------------
>  src/tape/media_pool.rs       |  2 +-
>  5 files changed, 24 insertions(+), 21 deletions(-)
> 
>

applied both patches, thanks!

ps. I like those commit subjects/messages, many thanks for making my work
slightly easier (it adds up).




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-30 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-29 14:17 [pbs-devel] [PATCH proxmox-backup v2 1/2] tape: hide internal use of all zero uuid for unassigned tapes Dominik Csapak
2022-11-29 14:17 ` [pbs-devel] [PATCH proxmox-backup v2 2/2] tape: inventory: skip " Dominik Csapak
2022-11-30 16:32 ` [pbs-devel] applied-series: [PATCH proxmox-backup v2 1/2] tape: hide internal use of all zero uuid for " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal