tape: changer: save whole LtoTapeDrive config in MtxMediaChanger

we'll need more info from there in the future, so derive clone for it
and save the whole config instead of adding an additional field.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2023-12-07 13:51:01 +01:00 committed by Dietmar Maurer
parent 9c1c0780c2
commit d555c3839b
2 changed files with 7 additions and 9 deletions

View File

@ -59,7 +59,7 @@ pub struct VirtualTapeDrive {
}, },
} }
)] )]
#[derive(Serialize, Deserialize, Updater)] #[derive(Serialize, Deserialize, Updater, Clone)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
/// Lto SCSI tape driver /// Lto SCSI tape driver
pub struct LtoTapeDrive { pub struct LtoTapeDrive {

View File

@ -384,8 +384,7 @@ fn load_changer_state_cache(changer: &str) -> Result<Option<MtxStatus>, Error> {
/// Implements MediaChange using 'mtx' linux cli tool /// Implements MediaChange using 'mtx' linux cli tool
pub struct MtxMediaChanger { pub struct MtxMediaChanger {
drive_name: String, // used for error messages drive: LtoTapeDrive,
drive_number: u64,
config: ScsiTapeChanger, config: ScsiTapeChanger,
} }
@ -398,8 +397,7 @@ impl MtxMediaChanger {
}; };
Ok(Self { Ok(Self {
drive_name: drive_config.name.clone(), drive: drive_config.clone(),
drive_number: drive_config.changer_drivenum.unwrap_or(0),
config: changer_config, config: changer_config,
}) })
} }
@ -407,11 +405,11 @@ impl MtxMediaChanger {
impl MediaChange for MtxMediaChanger { impl MediaChange for MtxMediaChanger {
fn drive_number(&self) -> u64 { fn drive_number(&self) -> u64 {
self.drive_number self.drive.changer_drivenum.unwrap_or(0)
} }
fn drive_name(&self) -> &str { fn drive_name(&self) -> &str {
&self.drive_name &self.drive.name
} }
fn status(&mut self) -> Result<MtxStatus, Error> { fn status(&mut self) -> Result<MtxStatus, Error> {
@ -423,12 +421,12 @@ impl MediaChange for MtxMediaChanger {
} }
fn load_media_from_slot(&mut self, slot: u64) -> Result<MtxStatus, Error> { fn load_media_from_slot(&mut self, slot: u64) -> Result<MtxStatus, Error> {
self.config.load_slot(slot, self.drive_number) self.config.load_slot(slot, self.drive_number())
} }
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error> { fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error> {
if let Some(target_slot) = target_slot { if let Some(target_slot) = target_slot {
self.config.unload(target_slot, self.drive_number) self.config.unload(target_slot, self.drive_number())
} else { } else {
let status = self.status()?; let status = self.status()?;
self.unload_to_free_slot(status) self.unload_to_free_slot(status)