tape: improve MediaChange trait

We expose the whole MtxStatus, and we can load/store from/to
specified slot numbers.
This commit is contained in:
Dietmar Maurer
2021-01-07 14:26:43 +01:00
parent 632756b6fb
commit 46a1863f88
9 changed files with 300 additions and 174 deletions

View File

@ -15,21 +15,52 @@ use anyhow::Error;
/// Interface to media change devices
pub trait MediaChange {
/// Load media into drive
/// Returns the changer status
fn status(&mut self) -> Result<MtxStatus, Error>;
/// Load media from storage slot into drive
fn load_media_from_slot(&mut self, slot: u64) -> Result<(), Error>;
/// Load media by changer-id into drive
///
/// This unloads first if the drive is already loaded with another media.
///
/// Note: This refuses to load media inside import/export slots.
fn load_media(&mut self, changer_id: &str) -> Result<(), Error>;
/// Unload media from drive
///
/// This is a nop on drives without autoloader.
fn unload_media(&mut self) -> Result<(), Error>;
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<(), Error>;
/// Returns true if unload_media automatically ejects drive media
fn eject_on_unload(&self) -> bool {
false
}
/// List media changer IDs (barcodes)
fn list_media_changer_ids(&self) -> Result<Vec<String>, Error>;
/// List online media changer IDs (barcodes)
///
/// List acessible (online) changer IDs. This does not include
/// media inside import-export slots or cleaning media.
fn online_media_changer_ids(&mut self) -> Result<Vec<String>, Error> {
let status = self.status()?;
let mut list = Vec::new();
for drive_status in status.drives.iter() {
if let ElementStatus::VolumeTag(ref tag) = drive_status.status {
list.push(tag.clone());
}
}
for (import_export, element_status) in status.slots.iter() {
if *import_export { continue; }
if let ElementStatus::VolumeTag(ref tag) = element_status {
if !tag.starts_with("CLN") { continue; }
list.push(tag.clone());
}
}
Ok(list)
}
}