all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase
@ 2021-02-16  8:35 Dominik Csapak
  2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 2/3] ui: tape/TapeInventory: add erase button Dominik Csapak
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-02-16  8:35 UTC (permalink / raw)
  To: pbs-devel

if given, erases the tape only iff the inserted tape contains that label
used to safeguard tape erasing from ui for standalone drives

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

diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 4991d66b..12709df9 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -202,19 +202,23 @@ pub async fn unload(
                 optional: true,
                 default: true,
             },
+            "label-text": {
+                schema: MEDIA_LABEL_SCHEMA,
+                optional: true,
+            },
         },
     },
     returns: {
         schema: UPID_SCHEMA,
     },
 )]
-/// Erase media
+/// Erase media. Check for label-text if given (cancels if wrong media).
 pub fn erase_media(
     drive: String,
     fast: Option<bool>,
+    label_text: Option<String>,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Value, Error> {
-
     let (config, _digest) = config::drive::config()?;
 
     // early check/lock before starting worker
@@ -236,16 +240,32 @@ pub fn erase_media(
 
             match drive.read_label() {
                 Err(err) => {
+                    if let Some(label) = label_text {
+                        bail!("expected label '{}', found unrelated data", label);
+                    }
                     /* assume drive contains no or unrelated data */
                     task_log!(worker, "unable to read media label: {}", err);
                     task_log!(worker, "erase anyways");
                     drive.erase_media(fast.unwrap_or(true))?;
                 }
                 Ok((None, _)) => {
+                    if let Some(label) = label_text {
+                        bail!("expected label '{}', found empty tape", label);
+                    }
                     task_log!(worker, "found empty media - erase anyways");
                     drive.erase_media(fast.unwrap_or(true))?;
                 }
                 Ok((Some(media_id), _key_config)) => {
+                    if let Some(label_text) = label_text {
+                        if media_id.label.label_text != label_text {
+                            bail!(
+                                "expected label '{}', found '{}', aborting",
+                                label_text,
+                                media_id.label.label_text
+                            );
+                        }
+                    }
+
                     task_log!(
                         worker,
                         "found media '{}' with uuid '{}'",
-- 
2.20.1





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

end of thread, other threads:[~2021-02-16  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16  8:35 [pbs-devel] [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase Dominik Csapak
2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 2/3] ui: tape/TapeInventory: add erase button Dominik Csapak
2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/BackupOverview: show mediaset loading error in msg box instead Dominik Csapak
2021-02-16  9:18 ` [pbs-devel] applied: [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase Dietmar Maurer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal