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 6535A71201 for ; Wed, 7 Apr 2021 12:24:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5CB24F3B8 for ; Wed, 7 Apr 2021 12:24:13 +0200 (CEST) Received: from elsa.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP id 60451F358 for ; Wed, 7 Apr 2021 12:24:07 +0200 (CEST) Received: by elsa.proxmox.com (Postfix, from userid 0) id 22088AEAF2C; 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:08 +0200 Message-Id: <20210407102308.9750-12-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. [pmt.rs, mod.rs] Subject: [pbs-devel] [PATCH 11/11] tape: pmt - re-implement lock/unlock command 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:43 -0000 --- 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 { 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