tape: extend MediaChange trait to return MtxStatus
This commit is contained in:
parent
3f16f1b006
commit
86d9f4e733
@ -154,7 +154,8 @@ 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)
|
||||
changer.load_media(&label_text)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
@ -183,7 +184,8 @@ pub async fn load_slot(drive: String, source_slot: u64) -> Result<(), Error> {
|
||||
format!("load from slot {}", source_slot),
|
||||
move |config| {
|
||||
let (mut changer, _) = required_media_changer(&config, &drive)?;
|
||||
changer.load_media_from_slot(source_slot)
|
||||
changer.load_media_from_slot(source_slot)?;
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
.await
|
||||
@ -258,7 +260,8 @@ pub fn unload(
|
||||
task_log!(worker, "unloading media from drive '{}'", drive);
|
||||
|
||||
let (mut changer, _) = required_media_changer(&config, &drive)?;
|
||||
changer.unload_media(target_slot)
|
||||
changer.unload_media(target_slot)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
|
@ -190,10 +190,10 @@ pub trait MediaChange {
|
||||
/// Transfer media from on slot to another (storage or import export slots)
|
||||
///
|
||||
/// Target slot needs to be empty
|
||||
fn transfer_media(&mut self, from: u64, to: u64) -> Result<(), Error>;
|
||||
fn transfer_media(&mut self, from: u64, to: u64) -> Result<MtxStatus, Error>;
|
||||
|
||||
/// Load media from storage slot into drive
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<(), Error>;
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<MtxStatus, Error>;
|
||||
|
||||
/// Load media by label-text into drive
|
||||
///
|
||||
@ -202,7 +202,7 @@ pub trait MediaChange {
|
||||
/// Note: This refuses to load media inside import/export
|
||||
/// slots. Also, you cannot load cleaning units with this
|
||||
/// interface.
|
||||
fn load_media(&mut self, label_text: &str) -> Result<(), Error> {
|
||||
fn load_media(&mut self, label_text: &str) -> Result<MtxStatus, Error> {
|
||||
|
||||
if label_text.starts_with("CLN") {
|
||||
bail!("unable to load media '{}' (seems to be a cleaning unit)", label_text);
|
||||
@ -220,7 +220,7 @@ pub trait MediaChange {
|
||||
bail!("unable to load media '{}' - media in wrong drive ({} != {})",
|
||||
label_text, i, self.drive_number());
|
||||
}
|
||||
return Ok(()) // already loaded
|
||||
return Ok(status) // already loaded
|
||||
}
|
||||
}
|
||||
if i as u64 == self.drive_number() {
|
||||
@ -232,8 +232,7 @@ pub trait MediaChange {
|
||||
}
|
||||
|
||||
if unload_drive {
|
||||
self.unload_to_free_slot(status)?;
|
||||
status = self.status()?;
|
||||
status = self.unload_to_free_slot(status)?;
|
||||
}
|
||||
|
||||
let mut slot = None;
|
||||
@ -258,7 +257,7 @@ pub trait MediaChange {
|
||||
}
|
||||
|
||||
/// Unload media from drive (eject media if necessary)
|
||||
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<(), Error>;
|
||||
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error>;
|
||||
|
||||
/// List online media labels (label_text/barcodes)
|
||||
///
|
||||
@ -290,7 +289,7 @@ pub trait MediaChange {
|
||||
///
|
||||
/// This fail if there is no cleaning cartridge online. Any media
|
||||
/// inside the drive is automatically unloaded.
|
||||
fn clean_drive(&mut self) -> Result<(), Error> {
|
||||
fn clean_drive(&mut self) -> Result<MtxStatus, Error> {
|
||||
let status = self.status()?;
|
||||
|
||||
let mut cleaning_cartridge_slot = None;
|
||||
@ -313,15 +312,13 @@ pub trait MediaChange {
|
||||
if let Some(drive_status) = status.drives.get(self.drive_number() as usize) {
|
||||
match drive_status.status {
|
||||
ElementStatus::Empty => { /* OK */ },
|
||||
_ => self.unload_to_free_slot(status)?,
|
||||
_ => { self.unload_to_free_slot(status)?; }
|
||||
}
|
||||
}
|
||||
|
||||
self.load_media_from_slot(cleaning_cartridge_slot)?;
|
||||
|
||||
self.unload_media(Some(cleaning_cartridge_slot))?;
|
||||
|
||||
Ok(())
|
||||
self.unload_media(Some(cleaning_cartridge_slot))
|
||||
}
|
||||
|
||||
/// Export media
|
||||
@ -381,8 +378,8 @@ pub trait MediaChange {
|
||||
///
|
||||
/// If posible to the slot it was previously loaded from.
|
||||
///
|
||||
/// Note: This method consumes status - so please read again afterward.
|
||||
fn unload_to_free_slot(&mut self, status: MtxStatus) -> Result<(), Error> {
|
||||
/// Note: This method consumes status - so please use returned status afterward.
|
||||
fn unload_to_free_slot(&mut self, status: MtxStatus) -> Result<MtxStatus, Error> {
|
||||
|
||||
let drive_status = &status.drives[self.drive_number() as usize];
|
||||
if let Some(slot) = drive_status.loaded_slot {
|
||||
@ -556,23 +553,20 @@ impl MediaChange for MtxMediaChanger {
|
||||
self.config.status(false)
|
||||
}
|
||||
|
||||
fn transfer_media(&mut self, from: u64, to: u64) -> Result<(), Error> {
|
||||
self.config.transfer(from, to)?;
|
||||
Ok(())
|
||||
fn transfer_media(&mut self, from: u64, to: u64) -> Result<MtxStatus, Error> {
|
||||
self.config.transfer(from, to)
|
||||
}
|
||||
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<(), Error> {
|
||||
self.config.load_slot(slot, self.drive_number)?;
|
||||
Ok(())
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<MtxStatus, Error> {
|
||||
self.config.load_slot(slot, self.drive_number)
|
||||
}
|
||||
|
||||
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<(), Error> {
|
||||
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, 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(())
|
||||
}
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ impl MediaChange for VirtualTapeHandle {
|
||||
Ok(MtxStatus { drives, slots, transports: Vec::new() })
|
||||
}
|
||||
|
||||
fn transfer_media(&mut self, _from: u64, _to: u64) -> Result<(), Error> {
|
||||
fn transfer_media(&mut self, _from: u64, _to: u64) -> Result<MtxStatus, Error> {
|
||||
bail!("media tranfer is not implemented!");
|
||||
}
|
||||
|
||||
@ -436,7 +436,7 @@ impl MediaChange for VirtualTapeHandle {
|
||||
bail!("media export is not implemented!");
|
||||
}
|
||||
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<(), Error> {
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<MtxStatus, Error> {
|
||||
if slot < 1 {
|
||||
bail!("invalid slot ID {}", slot);
|
||||
}
|
||||
@ -454,7 +454,7 @@ impl MediaChange for VirtualTapeHandle {
|
||||
///
|
||||
/// We automatically create an empty virtual tape here (if it does
|
||||
/// not exist already)
|
||||
fn load_media(&mut self, label: &str) -> Result<(), Error> {
|
||||
fn load_media(&mut self, label: &str) -> Result<MtxStatus, Error> {
|
||||
let name = format!("tape-{}.json", label);
|
||||
let mut path = self.path.clone();
|
||||
path.push(&name);
|
||||
@ -470,17 +470,20 @@ impl MediaChange for VirtualTapeHandle {
|
||||
pos: 0,
|
||||
}),
|
||||
};
|
||||
self.store_status(&status)
|
||||
self.store_status(&status)?;
|
||||
|
||||
self.status()
|
||||
}
|
||||
|
||||
fn unload_media(&mut self, _target_slot: Option<u64>) -> Result<(), Error> {
|
||||
fn unload_media(&mut self, _target_slot: Option<u64>) -> Result<MtxStatus, Error> {
|
||||
// Note: we currently simply ignore target_slot
|
||||
self.eject_media()?;
|
||||
Ok(())
|
||||
self.status()
|
||||
}
|
||||
|
||||
fn clean_drive(&mut self) -> Result<(), Error> {
|
||||
Ok(())
|
||||
fn clean_drive(&mut self) -> Result<MtxStatus, Error> {
|
||||
// do nothing
|
||||
self.status()
|
||||
}
|
||||
}
|
||||
|
||||
@ -499,7 +502,7 @@ impl MediaChange for VirtualTapeDrive {
|
||||
handle.status()
|
||||
}
|
||||
|
||||
fn transfer_media(&mut self, from: u64, to: u64) -> Result<(), Error> {
|
||||
fn transfer_media(&mut self, from: u64, to: u64) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
handle.transfer_media(from, to)
|
||||
}
|
||||
@ -509,20 +512,19 @@ impl MediaChange for VirtualTapeDrive {
|
||||
handle.export_media(label_text)
|
||||
}
|
||||
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<(), Error> {
|
||||
fn load_media_from_slot(&mut self, slot: u64) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
handle.load_media_from_slot(slot)
|
||||
}
|
||||
|
||||
fn load_media(&mut self, label_text: &str) -> Result<(), Error> {
|
||||
fn load_media(&mut self, label_text: &str) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
handle.load_media(label_text)
|
||||
}
|
||||
|
||||
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<(), Error> {
|
||||
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
handle.unload_media(target_slot)?;
|
||||
Ok(())
|
||||
handle.unload_media(target_slot)
|
||||
}
|
||||
|
||||
fn online_media_label_texts(&mut self) -> Result<Vec<String>, Error> {
|
||||
@ -530,8 +532,8 @@ impl MediaChange for VirtualTapeDrive {
|
||||
handle.online_media_label_texts()
|
||||
}
|
||||
|
||||
fn clean_drive(&mut self) -> Result<(), Error> {
|
||||
Ok(())
|
||||
fn clean_drive(&mut self) -> Result<MtxStatus, Error> {
|
||||
let mut handle = self.open()?;
|
||||
handle.clean_drive()
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user