diff --git a/src/api2/tape/changer.rs b/src/api2/tape/changer.rs index a50e8c15..f81341cc 100644 --- a/src/api2/tape/changer.rs +++ b/src/api2/tape/changer.rs @@ -163,7 +163,6 @@ pub async fn transfer( tokio::task::spawn_blocking(move || { changer_config.transfer(from, to)?; - let _ = changer_config.status(false); // update status cache Ok(()) }).await? } diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs index 37428c4b..27af5d7d 100644 --- a/src/api2/tape/drive.rs +++ b/src/api2/tape/drive.rs @@ -154,11 +154,7 @@ pub fn load_media( move |worker, config| { task_log!(worker, "loading media '{}' into drive '{}'", label_text, drive); let (mut changer, _) = required_media_changer(&config, &drive)?; - changer.load_media(&label_text)?; - - let _ = changer.status(); // update status cache - - Ok(()) + changer.load_media(&label_text) }, )?; @@ -262,11 +258,7 @@ pub fn unload( task_log!(worker, "unloading media from drive '{}'", drive); let (mut changer, _) = required_media_changer(&config, &drive)?; - changer.unload_media(target_slot)?; - - let _ = changer.status(); // update status cache - - Ok(()) + changer.unload_media(target_slot) }, )?; @@ -424,7 +416,6 @@ pub fn eject_media( move |_worker, config| { if let Some((mut changer, _)) = media_changer(&config, &drive)? { changer.unload_media(None)?; - let _ = changer.status(); // update status cache } else { let mut drive = open_drive(&config, &drive)?; drive.eject_media()?; @@ -867,8 +858,6 @@ pub fn update_inventory( continue; } - let _ = changer.status(); // update status cache - let mut drive = open_drive(&config, &drive)?; match drive.read_label() { Err(err) => { @@ -887,7 +876,6 @@ pub fn update_inventory( } } changer.unload_media(None)?; - let _ = changer.status(); // update status cache } Ok(()) }, diff --git a/src/tape/changer/mod.rs b/src/tape/changer/mod.rs index af921728..469c1ff0 100644 --- a/src/tape/changer/mod.rs +++ b/src/tape/changer/mod.rs @@ -168,11 +168,11 @@ pub trait ScsiMediaChange { fn status(&mut self, use_cache: bool) -> Result; - fn load_slot(&mut self, from_slot: u64, drivenum: u64) -> Result<(), Error>; + fn load_slot(&mut self, from_slot: u64, drivenum: u64) -> Result; - fn unload(&mut self, to_slot: u64, drivenum: u64) -> Result<(), Error>; + fn unload(&mut self, to_slot: u64, drivenum: u64) -> Result; - fn transfer(&mut self, from_slot: u64, to_slot: u64) -> Result<(), Error>; + fn transfer(&mut self, from_slot: u64, to_slot: u64) -> Result; } /// Interface to the media changer device for a single drive @@ -431,31 +431,49 @@ impl ScsiMediaChange for ScsiTapeChanger { status } - fn load_slot(&mut self, from_slot: u64, drivenum: u64) -> Result<(), Error> { - if USE_MTX { + fn load_slot(&mut self, from_slot: u64, drivenum: u64) -> Result { + let result = if USE_MTX { mtx::mtx_load(&self.path, from_slot, drivenum) } else { let mut file = sg_pt_changer::open(&self.path)?; sg_pt_changer::load_slot(&mut file, from_slot, drivenum) - } + }; + + let status = self.status(false)?; // always update status + + result?; // check load result + + Ok(status) } - fn unload(&mut self, to_slot: u64, drivenum: u64) -> Result<(), Error> { - if USE_MTX { + fn unload(&mut self, to_slot: u64, drivenum: u64) -> Result { + let result = if USE_MTX { mtx::mtx_unload(&self.path, to_slot, drivenum) } else { let mut file = sg_pt_changer::open(&self.path)?; sg_pt_changer::unload(&mut file, to_slot, drivenum) - } + }; + + let status = self.status(false)?; // always update status + + result?; // check unload result + + Ok(status) } - fn transfer(&mut self, from_slot: u64, to_slot: u64) -> Result<(), Error> { - if USE_MTX { + fn transfer(&mut self, from_slot: u64, to_slot: u64) -> Result { + let result = if USE_MTX { mtx::mtx_transfer(&self.path, from_slot, to_slot) } else { let mut file = sg_pt_changer::open(&self.path)?; sg_pt_changer::transfer_medium(&mut file, from_slot, to_slot) - } + }; + + let status = self.status(false)?; // always update status + + result?; // check unload result + + Ok(status) } } @@ -539,19 +557,22 @@ impl MediaChange for MtxMediaChanger { } fn transfer_media(&mut self, from: u64, to: u64) -> Result<(), Error> { - self.config.transfer(from, to) + self.config.transfer(from, to)?; + Ok(()) } fn load_media_from_slot(&mut self, slot: u64) -> Result<(), Error> { - self.config.load_slot(slot, self.drive_number) + self.config.load_slot(slot, self.drive_number)?; + Ok(()) } fn unload_media(&mut self, target_slot: Option) -> Result<(), Error> { if let Some(target_slot) = target_slot { - self.config.unload(target_slot, self.drive_number) + self.config.unload(target_slot, self.drive_number)?; } else { let status = self.status()?; - self.unload_to_free_slot(status) + self.unload_to_free_slot(status)?; } + Ok(()) } }