From 8204d9b095ee8f89b2496c45cc48e8aab092ca8c Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 8 Apr 2021 11:26:08 +0200 Subject: [PATCH] tape: avoid unneccessary SCSI request in Drop --- src/tape/drive/lto/sg_tape.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tape/drive/lto/sg_tape.rs b/src/tape/drive/lto/sg_tape.rs index 8e822924..b7cd677f 100644 --- a/src/tape/drive/lto/sg_tape.rs +++ b/src/tape/drive/lto/sg_tape.rs @@ -97,6 +97,7 @@ pub struct LtoTapeStatus { pub struct SgTape { file: File, info: InquiryInfo, + encryption_key_loaded: bool, } impl SgTape { @@ -113,7 +114,11 @@ impl SgTape { if info.peripheral_type != 1 { bail!("not a tape device (peripheral_type = {})", info.peripheral_type); } - Ok(Self { file, info }) + Ok(Self { + file, + info, + encryption_key_loaded: false, + }) } /// Access to file descriptor - useful for testing @@ -472,6 +477,9 @@ impl SgTape { &mut self, key: Option<[u8; 32]>, ) -> Result<(), Error> { + + self.encryption_key_loaded = key.is_some(); + set_encryption(&mut self.file, key) } @@ -664,7 +672,9 @@ impl SgTape { impl Drop for SgTape { fn drop(&mut self) { // For security reasons, clear the encryption key - let _ = self.set_encryption(None); + if self.encryption_key_loaded { + let _ = self.set_encryption(None); + } } }