[pbs-devel] [PATCH proxmox-backup v2 1/8] tape/drive: add 'move_to_file' to TapeDriver trait
Dominik Csapak
d.csapak at proxmox.com
Wed May 5 12:09:11 CEST 2021
so that we can directly move to a specified file on the tape
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/tape/drive/lto/mod.rs | 4 ++++
src/tape/drive/mod.rs | 3 +++
src/tape/drive/virtual_tape.rs | 22 ++++++++++++++++++++++
3 files changed, 29 insertions(+)
diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs
index 642c3cc7..3894b034 100644
--- a/src/tape/drive/lto/mod.rs
+++ b/src/tape/drive/lto/mod.rs
@@ -309,6 +309,10 @@ impl TapeDriver for LtoTapeHandle {
Ok(())
}
+ fn move_to_file(&mut self, file: u64) -> Result<(), Error> {
+ self.locate_file(file)
+ }
+
fn rewind(&mut self) -> Result<(), Error> {
self.sg_tape.rewind()
}
diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs
index fd8f503d..f72e0b51 100644
--- a/src/tape/drive/mod.rs
+++ b/src/tape/drive/mod.rs
@@ -80,6 +80,9 @@ pub trait TapeDriver {
/// Move to last file
fn move_to_last_file(&mut self) -> Result<(), Error>;
+ /// Move to given file nr
+ fn move_to_file(&mut self, file: u64) -> Result<(), Error>;
+
/// Current file number
fn current_file_number(&mut self) -> Result<u64, Error>;
diff --git a/src/tape/drive/virtual_tape.rs b/src/tape/drive/virtual_tape.rs
index f7ebc0bb..3c5f9502 100644
--- a/src/tape/drive/virtual_tape.rs
+++ b/src/tape/drive/virtual_tape.rs
@@ -261,6 +261,28 @@ impl TapeDriver for VirtualTapeHandle {
Ok(())
}
+ fn move_to_file(&mut self, file: u64) -> 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()))?;
+
+ if file as usize > index.files {
+ bail!("invalid file nr");
+ }
+
+ *pos = file as usize;
+
+ 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 read_next_file(&mut self) -> Result<Box<dyn TapeRead>, BlockReadError> {
let mut status = self.load_status()
--
2.20.1
More information about the pbs-devel
mailing list