public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH 06/11] tape: make fsf/bsf driver specific
Date: Wed,  7 Apr 2021 12:23:03 +0200	[thread overview]
Message-ID: <20210407102308.9750-7-dietmar@proxmox.com> (raw)
In-Reply-To: <20210407102308.9750-1-dietmar@proxmox.com>

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<u64, Error>;
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<Option<Box<dyn TapeRead>>, 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




  parent reply	other threads:[~2021-04-07 10:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 10:22 [pbs-devel] [PATCH 00/11] Userspace tape driver Dietmar Maurer
2021-04-07 10:22 ` [pbs-devel] [PATCH 01/11] tape: introduce trait BlockRead Dietmar Maurer
2021-04-07 10:22 ` [pbs-devel] [PATCH 02/11] tape: introduce trait BlockWrite Dietmar Maurer
2021-04-07 10:23 ` [pbs-devel] [PATCH 03/11] tape: implement LTO userspace driver Dietmar Maurer
2021-04-07 10:23 ` [pbs-devel] [PATCH 04/11] tape: implement format/erase Dietmar Maurer
2021-04-07 10:23 ` [pbs-devel] [PATCH 05/11] tape: fix LEOM handling Dietmar Maurer
2021-04-07 10:23 ` Dietmar Maurer [this message]
2021-04-07 10:23 ` [pbs-devel] [PATCH 07/11] tape: make sure there is a filemark at the end of the tape Dietmar Maurer
2021-04-07 10:23 ` [pbs-devel] [PATCH 08/11] sgutils2: add scsi_mode_sense helper Dietmar Maurer
2021-04-07 10:23 ` [pbs-devel] [PATCH 09/11] tape: correctly set/display drive option Dietmar Maurer
2021-04-07 10:23 ` [pbs-devel] [PATCH 10/11] tape: pmt - re-implement fsr/bsr Dietmar Maurer
2021-04-07 10:23 ` [pbs-devel] [PATCH 11/11] tape: pmt - re-implement lock/unlock command Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210407102308.9750-7-dietmar@proxmox.com \
    --to=dietmar@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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