[pbs-devel] [PATCH proxmox-backup] tape: prevent WORM tapes from being labeled

Dominik Csapak d.csapak at proxmox.com
Mon Dec 19 11:51:28 CET 2022


for now, we don't support WORM tapes, so prevent them from being labeled
such that they are not wasted with our media label

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 pbs-tape/src/sg_tape.rs        | 6 ++++++
 src/tape/drive/lto/mod.rs      | 8 ++++++++
 src/tape/drive/mod.rs          | 6 ++++++
 src/tape/drive/virtual_tape.rs | 4 ++++
 4 files changed, 24 insertions(+)

diff --git a/pbs-tape/src/sg_tape.rs b/pbs-tape/src/sg_tape.rs
index 7ad94d9d..0b3eb5db 100644
--- a/pbs-tape/src/sg_tape.rs
+++ b/pbs-tape/src/sg_tape.rs
@@ -193,6 +193,12 @@ impl SgTape {
         Ok(())
     }
 
+    /// Returns if the tape is a WORM tape
+    pub fn is_worm(&mut self) -> Result<bool, Error> {
+        let (_, _, page) = self.read_medium_configuration_page()?;
+        Ok(page.is_worm())
+    }
+
     /// Format media, single partition
     pub fn format_media(&mut self, fast: bool) -> Result<(), Error> {
         // try to get info about loaded media first
diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs
index 2c3a5a63..6c4e00e6 100644
--- a/src/tape/drive/lto/mod.rs
+++ b/src/tape/drive/lto/mod.rs
@@ -105,6 +105,10 @@ impl LtoTapeHandle {
         self.sg_tape.write_filemarks(count, false)
     }
 
+    pub fn is_worm(&mut self) -> Result<bool, Error> {
+        self.sg_tape.is_worm()
+    }
+
     /// Get Tape and Media status
     pub fn get_drive_and_media_status(&mut self) -> Result<LtoDriveAndMediaStatus, Error> {
         self.sg_tape.get_drive_and_media_status()
@@ -224,6 +228,10 @@ impl TapeDriver for LtoTapeHandle {
         Ok(Box::new(handle))
     }
 
+    fn is_worm<'a>(&'a mut self) -> Result<bool, Error> {
+        self.is_worm()
+    }
+
     fn write_media_set_label(
         &mut self,
         media_set_label: &MediaSetLabel,
diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs
index c69ebc63..7548ec42 100644
--- a/src/tape/drive/mod.rs
+++ b/src/tape/drive/mod.rs
@@ -73,8 +73,14 @@ pub trait TapeDriver {
     /// Write/Append a new file
     fn write_file<'a>(&'a mut self) -> Result<Box<dyn TapeWrite + 'a>, std::io::Error>;
 
+    /// Check if a tape is a WORM tape
+    fn is_worm<'a>(&'a mut self) -> Result<bool, Error>;
+
     /// Write label to tape (erase tape content)
     fn label_tape(&mut self, label: &MediaLabel) -> Result<(), Error> {
+        if self.is_worm()? {
+            bail!("cannot label WORM tape, currently unsupported");
+        }
         self.set_encryption(None)?;
 
         self.format_media(true)?; // this rewinds the tape
diff --git a/src/tape/drive/virtual_tape.rs b/src/tape/drive/virtual_tape.rs
index d3b7b0f3..d5540022 100644
--- a/src/tape/drive/virtual_tape.rs
+++ b/src/tape/drive/virtual_tape.rs
@@ -359,6 +359,10 @@ impl TapeDriver for VirtualTapeHandle {
         }
     }
 
+    fn is_worm<'a>(&'a mut self) -> Result<bool, Error> {
+        Ok(false)
+    }
+
     fn move_to_eom(&mut self, _write_missing_eof: bool) -> Result<(), Error> {
         let mut status = self.load_status()?;
         match status.current_tape {
-- 
2.30.2






More information about the pbs-devel mailing list