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