tape: avoid unneccessary SCSI request in Drop
This commit is contained in:
parent
fad95a334a
commit
8204d9b095
@ -97,6 +97,7 @@ pub struct LtoTapeStatus {
|
|||||||
pub struct SgTape {
|
pub struct SgTape {
|
||||||
file: File,
|
file: File,
|
||||||
info: InquiryInfo,
|
info: InquiryInfo,
|
||||||
|
encryption_key_loaded: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SgTape {
|
impl SgTape {
|
||||||
@ -113,7 +114,11 @@ impl SgTape {
|
|||||||
if info.peripheral_type != 1 {
|
if info.peripheral_type != 1 {
|
||||||
bail!("not a tape device (peripheral_type = {})", info.peripheral_type);
|
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
|
/// Access to file descriptor - useful for testing
|
||||||
@ -472,6 +477,9 @@ impl SgTape {
|
|||||||
&mut self,
|
&mut self,
|
||||||
key: Option<[u8; 32]>,
|
key: Option<[u8; 32]>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
|
self.encryption_key_loaded = key.is_some();
|
||||||
|
|
||||||
set_encryption(&mut self.file, key)
|
set_encryption(&mut self.file, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -664,7 +672,9 @@ impl SgTape {
|
|||||||
impl Drop for SgTape {
|
impl Drop for SgTape {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// For security reasons, clear the encryption key
|
// For security reasons, clear the encryption key
|
||||||
let _ = self.set_encryption(None);
|
if self.encryption_key_loaded {
|
||||||
|
let _ = self.set_encryption(None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user