tape: mtx_status - consider new export-slots property

This commit is contained in:
Dietmar Maurer 2021-01-06 11:53:33 +01:00
parent 38ae42b11a
commit d5035c5600
4 changed files with 37 additions and 8 deletions

View File

@ -52,7 +52,7 @@ pub async fn get_status(name: String) -> Result<Vec<MtxStatusEntry>, Error> {
let data: ScsiTapeChanger = config.lookup("changer", &name)?;
let status = tokio::task::spawn_blocking(move || {
mtx_status(&data.path)
mtx_status(&data)
}).await??;
let state_path = Path::new(TAPE_STATUS_DIR);

View File

@ -56,7 +56,7 @@ impl MediaChange for LinuxTapeDrive {
None => bail!("drive '{}' has no associated changer", self.name),
};
let status = mtx_status(&changer.path)?;
let status = mtx_status(&changer)?;
let drivenum = self.changer_drive_id.unwrap_or(0);
@ -111,7 +111,7 @@ impl MediaChange for LinuxTapeDrive {
let drivenum = self.changer_drive_id.unwrap_or(0);
let status = mtx_status(&changer.path)?;
let status = mtx_status(&changer)?;
unload_to_free_slot(&self.name, &changer.path, &status, drivenum)
}
@ -128,7 +128,7 @@ impl MediaChange for LinuxTapeDrive {
None => return Ok(Vec::new()),
};
let status = mtx_status(&changer.path)?;
let status = mtx_status(&changer)?;
let mut list = Vec::new();

View File

@ -1,11 +1,19 @@
use std::collections::HashSet;
use anyhow::Error;
use serde_json::Value;
use proxmox::tools::Uuid;
use proxmox::{
tools::Uuid,
api::schema::parse_property_string,
};
use crate::{
tools::run_command,
api2::types::{
SLOT_ARRAY_SCHEMA,
ScsiTapeChanger,
},
tape::{
Inventory,
changer::{
@ -17,14 +25,35 @@ use crate::{
};
/// Run 'mtx status' and return parsed result.
pub fn mtx_status(path: &str) -> Result<MtxStatus, Error> {
pub fn mtx_status(config: &ScsiTapeChanger) -> Result<MtxStatus, Error> {
let path = &config.path;
let mut export_slots: HashSet<u64> = HashSet::new();
if let Some(slots) = &config.export_slots {
let slots: Value = parse_property_string(&slots, &SLOT_ARRAY_SCHEMA)?;
export_slots = slots
.as_array()
.unwrap()
.iter()
.filter_map(|v| v.as_u64())
.collect();
}
let mut command = std::process::Command::new("mtx");
command.args(&["-f", path, "status"]);
let output = run_command(command, None)?;
let status = parse_mtx_status(&output)?;
let mut status = parse_mtx_status(&output)?;
for (i, entry) in status.slots.iter_mut().enumerate() {
let slot = i as u64 + 1;
if export_slots.contains(&slot) {
entry.0 = true; // mark as IMPORT/EXPORT
}
}
Ok(status)
}

View File

@ -103,7 +103,7 @@ pub fn update_online_status(state_path: &Path) -> Result<OnlineStatusMap, Error>
let mut map = OnlineStatusMap::new(&config)?;
for changer in changers {
let status = match mtx_status(&changer.path) {
let status = match mtx_status(&changer) {
Ok(status) => status,
Err(err) => {
eprintln!("unable to get changer '{}' status - {}", changer.name, err);