tape: don't call sg-tape-cmd for unloading encryption keys

since sg-tape-cmd is only necessary if we want to load the key, we don't
have to call it when we don't have one.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2024-01-22 12:50:31 +01:00 committed by Thomas Lamprecht
parent f1467d23f3
commit 8ee5a5d302

View File

@ -271,18 +271,18 @@ impl TapeDriver for LtoTapeHandle {
&mut self, &mut self,
key_fingerprint: Option<(Fingerprint, Uuid)>, key_fingerprint: Option<(Fingerprint, Uuid)>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let output = if let Some((fingerprint, uuid)) = key_fingerprint { if let Some((fingerprint, uuid)) = key_fingerprint {
let fingerprint = fingerprint.signature(); let fingerprint = fingerprint.signature();
run_sg_tape_cmd( let output = run_sg_tape_cmd(
"encryption", "encryption",
&["--fingerprint", &fingerprint, "--uuid", &uuid.to_string()], &["--fingerprint", &fingerprint, "--uuid", &uuid.to_string()],
self.sg_tape.file_mut().as_raw_fd(), self.sg_tape.file_mut().as_raw_fd(),
)? )?;
} else {
run_sg_tape_cmd("encryption", &[], self.sg_tape.file_mut().as_raw_fd())?
};
let result: Result<(), String> = serde_json::from_str(&output)?; let result: Result<(), String> = serde_json::from_str(&output)?;
result.map_err(|err| format_err!("{}", err)) result.map_err(|err| format_err!("{}", err))
} else {
self.sg_tape.set_encryption(None)
}
} }
} }