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 11/11] tape: pmt - re-implement lock/unlock command
Date: Wed,  7 Apr 2021 12:23:08 +0200	[thread overview]
Message-ID: <20210407102308.9750-12-dietmar@proxmox.com> (raw)
In-Reply-To: <20210407102308.9750-1-dietmar@proxmox.com>

---
 src/bin/pmt.rs                |  6 ++----
 src/tape/drive/lto/mod.rs     | 12 ++++++++++++
 src/tape/drive/lto/sg_tape.rs | 19 +++++++++++++++++++
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/bin/pmt.rs b/src/bin/pmt.rs
index 7183dfe5..15fa591d 100644
--- a/src/bin/pmt.rs
+++ b/src/bin/pmt.rs
@@ -577,8 +577,7 @@ fn lock(param: Value) -> Result<(), Error> {
 
     let mut handle = get_tape_handle(&param)?;
 
-    unimplemented!();
-    // fixme: handle.mtop(MTCmd::MTLOCK, 1, "lock tape drive door")?;
+    handle.lock()?;
 
     Ok(())
 }
@@ -715,8 +714,7 @@ fn unlock(param: Value) -> Result<(), Error> {
 
     let mut handle = get_tape_handle(&param)?;
 
-    unimplemented!();
-    //handle.mtop(MTCmd::MTUNLOCK, 1, "unlock tape drive door")?;
+    handle.unlock()?;
 
     Ok(())
 }
diff --git a/src/tape/drive/lto/mod.rs b/src/tape/drive/lto/mod.rs
index f33049ab..de997cde 100644
--- a/src/tape/drive/lto/mod.rs
+++ b/src/tape/drive/lto/mod.rs
@@ -220,6 +220,18 @@ impl LtoTapeHandle {
     pub fn volume_statistics(&mut self) -> Result<Lp17VolumeStatistics, Error> {
         self.sg_tape.volume_statistics()
     }
+
+    /// Lock the drive door
+    pub fn lock(&mut self) -> Result<(), Error>  {
+        self.sg_tape.set_medium_removal(false)
+            .map_err(|err| format_err!("lock door failed - {}", err))
+    }
+
+    /// Unlock the drive door
+    pub fn unlock(&mut self) -> Result<(), Error>  {
+        self.sg_tape.set_medium_removal(true)
+            .map_err(|err| format_err!("unlock door failed - {}", err))
+    }
 }
 
 
diff --git a/src/tape/drive/lto/sg_tape.rs b/src/tape/drive/lto/sg_tape.rs
index f3d71edd..638ba330 100644
--- a/src/tape/drive/lto/sg_tape.rs
+++ b/src/tape/drive/lto/sg_tape.rs
@@ -189,6 +189,25 @@ impl SgTape {
         Ok(())
     }
 
+    /// Lock/Unlock drive door
+    pub fn set_medium_removal(&mut self, allow: bool) -> Result<(), ScsiError> {
+
+        let mut sg_raw = SgRaw::new(&mut self.file, 16)?;
+        sg_raw.set_timeout(Self::SCSI_TAPE_DEFAULT_TIMEOUT);
+        let mut cmd = Vec::new();
+        cmd.extend(&[0x1E, 0, 0, 0]);
+        if allow {
+            cmd.push(0);
+        } else {
+            cmd.push(1);
+        }
+        cmd.push(0); // control
+
+        sg_raw.do_command(&cmd)?;
+
+        Ok(())
+    }
+
     pub fn rewind(&mut self) -> Result<(), Error> {
 
         let mut sg_raw = SgRaw::new(&mut self.file, 16)?;
-- 
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 ` [pbs-devel] [PATCH 06/11] tape: make fsf/bsf driver specific Dietmar Maurer
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 ` Dietmar Maurer [this message]

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