public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] tape: prevent WORM tapes from being labeled
@ 2022-12-19 10:51 Dominik Csapak
  2022-12-20  8:26 ` Dietmar Maurer
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2022-12-19 10:51 UTC (permalink / raw)
  To: pbs-devel

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@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





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

* Re: [pbs-devel] [PATCH proxmox-backup] tape: prevent WORM tapes from being labeled
  2022-12-19 10:51 [pbs-devel] [PATCH proxmox-backup] tape: prevent WORM tapes from being labeled Dominik Csapak
@ 2022-12-20  8:26 ` Dietmar Maurer
  0 siblings, 0 replies; 2+ messages in thread
From: Dietmar Maurer @ 2022-12-20  8:26 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

Maybe it would be better to expose read_medium_configuration_page(),
and query it in open_lto_tape_drive(). We could cache the returned info inside LtoTapeHandle?

> On 12/19/2022 11:51 AM CET Dominik Csapak <d.csapak@proxmox.com> wrote:
> 
>  
> for now, we don't support WORM tapes, so prevent them from being labeled
> such that they are not wasted with our media label
>




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

end of thread, other threads:[~2022-12-20  8:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 10:51 [pbs-devel] [PATCH proxmox-backup] tape: prevent WORM tapes from being labeled Dominik Csapak
2022-12-20  8:26 ` Dietmar Maurer

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