[pbs-devel] [PATCH 11/11] tape: pmt - re-implement lock/unlock command
Dietmar Maurer
dietmar at proxmox.com
Wed Apr 7 12:23:08 CEST 2021
---
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(¶m)?;
- 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(¶m)?;
- 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
More information about the pbs-devel
mailing list