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 4DA6A71145 for ; Wed, 7 Apr 2021 12:24:10 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4A39AF372 for ; Wed, 7 Apr 2021 12:24:10 +0200 (CEST) Received: from elsa.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2662EF344 for ; Wed, 7 Apr 2021 12:24:07 +0200 (CEST) Received: by elsa.proxmox.com (Postfix, from userid 0) id 12CD2AEAF25; Wed, 7 Apr 2021 12:24:07 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Wed, 7 Apr 2021 12:23:03 +0200 Message-Id: <20210407102308.9750-7-dietmar@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210407102308.9750-1-dietmar@proxmox.com> References: <20210407102308.9750-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs] Subject: [pbs-devel] [PATCH 06/11] tape: make fsf/bsf driver specific 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: Wed, 07 Apr 2021 10:24:10 -0000 Because the virtual tape driver behaves different than LTO drives. --- src/tape/drive/lto/mod.rs | 31 ++++++++-- src/tape/drive/mod.rs | 19 +----- src/tape/drive/virtual_tape.rs | 106 +++++++++++++++++++-------------- 3 files changed, 89 insertions(+), 67 deletions(-) diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs index a4e0499e..25df897f 100644 --- a/src/tape/drive/lto/mod.rs +++ b/src/tape/drive/lto/mod.rs @@ -179,6 +179,14 @@ impl LtoTapeHandle { Ok(status) } + pub fn forward_space_count_files(&mut self, count: usize) -> Result<(), Error> { + self.sg_tape.space_filemarks(isize::try_from(count)?) + } + + pub fn backward_space_count_files(&mut self, count: usize) -> Result<(), Error> { + self.sg_tape.space_filemarks(-isize::try_from(count)?) + } + pub fn erase_media(&mut self, fast: bool) -> Result<(), Error> { self.sg_tape.erase_media(fast) } @@ -211,12 +219,25 @@ impl TapeDriver for LtoTapeHandle { self.sg_tape.move_to_eom() } - fn forward_space_count_files(&mut self, count: usize) -> Result<(), Error> { - self.sg_tape.space_filemarks(isize::try_from(count)?) - } + fn move_to_last_file(&mut self) -> Result<(), Error> { - fn backward_space_count_files(&mut self, count: usize) -> Result<(), Error> { - self.sg_tape.space_filemarks(-isize::try_from(count)?) + self.move_to_eom()?; + + let pos = self.current_file_number()?; + + if pos == 0 { + bail!("move_to_last_file failed - media contains no data"); + } + + if pos == 1 { + self.rewind()?; + return Ok(()); + } + + self.backward_space_count_files(2)?; + self.forward_space_count_files(1)?; + + Ok(()) } fn rewind(&mut self) -> Result<(), Error> { diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs index 061c1cfc..28ff0a3a 100644 --- a/src/tape/drive/mod.rs +++ b/src/tape/drive/mod.rs @@ -88,24 +88,7 @@ pub trait TapeDriver { fn move_to_eom(&mut self) -> Result<(), Error>; /// Move to last file - fn move_to_last_file(&mut self) -> Result<(), Error> { - - self.move_to_eom()?; - - if self.current_file_number()? == 0 { - bail!("move_to_last_file failed - media contains no data"); - } - - self.backward_space_count_files(2)?; - - Ok(()) - } - - /// Forward space count files. The tape is positioned on the first block of the next file. - fn forward_space_count_files(&mut self, count: usize) -> Result<(), Error>; - - /// Backward space count files. The tape is positioned on the last block of the previous file. - fn backward_space_count_files(&mut self, count: usize) -> Result<(), Error>; + fn move_to_last_file(&mut self) -> Result<(), Error>; /// Current file number fn current_file_number(&mut self) -> Result; diff --git a/src/tape/drive/virtual_tape.rs b/src/tape/drive/virtual_tape.rs index e4d09c2f..bb4b4e3c 100644 --- a/src/tape/drive/virtual_tape.rs +++ b/src/tape/drive/virtual_tape.rs @@ -181,6 +181,53 @@ impl VirtualTapeHandle { Ok(list) } + #[allow(dead_code)] + fn forward_space_count_files(&mut self, count: usize) -> Result<(), Error> { + let mut status = self.load_status()?; + match status.current_tape { + Some(VirtualTapeStatus { ref name, ref mut pos }) => { + + let index = self.load_tape_index(name) + .map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string()))?; + + let new_pos = *pos + count; + if new_pos <= index.files { + *pos = new_pos; + } else { + bail!("forward_space_count_files failed: move beyond EOT"); + } + + self.store_status(&status) + .map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string()))?; + + Ok(()) + } + None => bail!("drive is empty (no tape loaded)."), + } + } + + // Note: behavior differs from LTO, because we always position at + // EOT side. + fn backward_space_count_files(&mut self, count: usize) -> Result<(), Error> { + let mut status = self.load_status()?; + match status.current_tape { + Some(VirtualTapeStatus { ref mut pos, .. }) => { + + if count <= *pos { + *pos = *pos - count; + } else { + bail!("backward_space_count_files failed: move before BOT"); + } + + self.store_status(&status) + .map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string()))?; + + Ok(()) + } + None => bail!("drive is empty (no tape loaded)."), + } + } + } impl TapeDriver for VirtualTapeHandle { @@ -199,6 +246,21 @@ impl TapeDriver for VirtualTapeHandle { } } + /// Move to last file + fn move_to_last_file(&mut self) -> Result<(), Error> { + + self.move_to_eom()?; + + if self.current_file_number()? == 0 { + bail!("move_to_last_file failed - media contains no data"); + } + + self.backward_space_count_files(1)?; + + Ok(()) + } + + fn read_next_file(&mut self) -> Result>, io::Error> { let mut status = self.load_status() .map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string()))?; @@ -304,50 +366,6 @@ impl TapeDriver for VirtualTapeHandle { } } - fn forward_space_count_files(&mut self, count: usize) -> Result<(), Error> { - let mut status = self.load_status()?; - match status.current_tape { - Some(VirtualTapeStatus { ref name, ref mut pos }) => { - - let index = self.load_tape_index(name) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string()))?; - - let new_pos = *pos + count; - if new_pos <= index.files { - *pos = new_pos; - } else { - bail!("forward_space_count_files failed: move beyond EOT"); - } - - self.store_status(&status) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string()))?; - - Ok(()) - } - None => bail!("drive is empty (no tape loaded)."), - } - } - - fn backward_space_count_files(&mut self, count: usize) -> Result<(), Error> { - let mut status = self.load_status()?; - match status.current_tape { - Some(VirtualTapeStatus { ref mut pos, .. }) => { - - if count <= *pos { - *pos = *pos - count; - } else { - bail!("backward_space_count_files failed: move before BOT"); - } - - self.store_status(&status) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err.to_string()))?; - - Ok(()) - } - None => bail!("drive is empty (no tape loaded)."), - } - } - fn rewind(&mut self) -> Result<(), Error> { let mut status = self.load_status()?; match status.current_tape { -- 2.20.1