From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 7642C90B1E for ; Mon, 19 Dec 2022 11:52:01 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7AC7726B84 for ; Mon, 19 Dec 2022 11:51:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 19 Dec 2022 11:51:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9968144630 for ; Mon, 19 Dec 2022 11:51:29 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 19 Dec 2022 11:51:28 +0100 Message-Id: <20221219105128.1989631-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.064 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup] tape: prevent WORM tapes from being labeled X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Dec 2022 10:52:01 -0000 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 --- 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 { + 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 { + self.sg_tape.is_worm() + } + /// Get Tape and Media status pub fn get_drive_and_media_status(&mut self) -> Result { 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 { + 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, std::io::Error>; + /// Check if a tape is a WORM tape + fn is_worm<'a>(&'a mut self) -> Result; + /// 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 { + 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