public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 3/5] api: tape: don't allow duplicate media label-texts
Date: Thu, 11 Jan 2024 11:40:34 +0100	[thread overview]
Message-ID: <20240111104036.3341854-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20240111104036.3341854-1-d.csapak@proxmox.com>

quite a few parts of our code assumes that the label-text is unique in
the inventory, which leads to rather unexpected behaviour when having
more than one tape with the same label-text, e.g. a
`proxmox-tape media destroy <LABEL>`
destroys the first one in the config
(same with moving to vault, etc.)

since having multiple tapes with the same human readable name is always
confusing, simply disallow that here

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/api2/tape/drive.rs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 54d15db8..19c8e78a 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -539,6 +539,14 @@ fn write_media_label(
     label: MediaLabel,
     pool: Option<String>,
 ) -> Result<(), Error> {
+    let mut inventory = Inventory::new(TAPE_STATUS_DIR);
+    inventory.reload()?;
+    if inventory
+        .find_media_by_label_text(&label.label_text)?
+        .is_some()
+    {
+        bail!("Media with label '{}' already exists", label.label_text);
+    }
     drive.label_tape(&label)?;
     if let Some(ref pool) = pool {
         task_log!(
@@ -562,8 +570,6 @@ fn write_media_label(
 
     // Create the media catalog
     MediaCatalog::overwrite(TAPE_STATUS_DIR, &media_id, false)?;
-
-    let mut inventory = Inventory::new(TAPE_STATUS_DIR);
     inventory.store(media_id.clone(), false)?;
 
     drive.rewind()?;
-- 
2.30.2





  parent reply	other threads:[~2024-01-11 10:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 10:40 [pbs-devel] [PATCH proxmox-backup 0/5] improve duplicate label-text handling Dominik Csapak
2024-01-11 10:40 ` [pbs-devel] [PATCH proxmox-backup 1/5] tape: handle duplicate label-texts in inventory Dominik Csapak
2024-01-12  7:29   ` Dietmar Maurer
2024-01-12  7:35     ` Dominik Csapak
2024-01-12  8:01       ` Dietmar Maurer
2024-01-12  8:09         ` Dominik Csapak
2024-01-11 10:40 ` [pbs-devel] [PATCH proxmox-backup 2/5] api: tape: optinally accept uuid for destroy/move media Dominik Csapak
2024-01-11 10:40 ` Dominik Csapak [this message]
2024-01-11 10:40 ` [pbs-devel] [PATCH proxmox-backup 4/5] ui: tape inventory: use uuid as id Dominik Csapak
2024-01-11 10:40 ` [pbs-devel] [PATCH proxmox-backup 5/5] ui: tape: add remove media button Dominik Csapak
2024-01-11 10:43 ` [pbs-devel] [PATCH proxmox-backup 0/5] improve duplicate label-text handling Dominik Csapak
2024-01-12  9:27 ` [pbs-devel] applied: " Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240111104036.3341854-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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