tape: implement option changer-drive-id
This commit is contained in:
parent
a3c709ef21
commit
f70d8091d3
@ -10,6 +10,7 @@ use crate::{
|
|||||||
PROXMOX_CONFIG_DIGEST_SCHEMA,
|
PROXMOX_CONFIG_DIGEST_SCHEMA,
|
||||||
DRIVE_ID_SCHEMA,
|
DRIVE_ID_SCHEMA,
|
||||||
CHANGER_ID_SCHEMA,
|
CHANGER_ID_SCHEMA,
|
||||||
|
CHANGER_DRIVE_ID_SCHEMA,
|
||||||
LINUX_DRIVE_PATH_SCHEMA,
|
LINUX_DRIVE_PATH_SCHEMA,
|
||||||
DriveListEntry,
|
DriveListEntry,
|
||||||
LinuxTapeDrive,
|
LinuxTapeDrive,
|
||||||
@ -36,6 +37,10 @@ use crate::{
|
|||||||
schema: CHANGER_ID_SCHEMA,
|
schema: CHANGER_ID_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
"changer-drive-id": {
|
||||||
|
schema: CHANGER_DRIVE_ID_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
@ -142,10 +147,13 @@ pub fn list_drives(
|
|||||||
#[api()]
|
#[api()]
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
/// Deletable property name
|
/// Deletable property name
|
||||||
pub enum DeletableProperty {
|
pub enum DeletableProperty {
|
||||||
/// Delete the changer property.
|
/// Delete the changer property.
|
||||||
changer,
|
changer,
|
||||||
|
/// Delete the changer-drive-id property.
|
||||||
|
changer_drive_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
@ -163,6 +171,10 @@ pub enum DeletableProperty {
|
|||||||
schema: CHANGER_ID_SCHEMA,
|
schema: CHANGER_ID_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
"changer-drive-id": {
|
||||||
|
schema: CHANGER_DRIVE_ID_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
delete: {
|
delete: {
|
||||||
description: "List of properties to delete.",
|
description: "List of properties to delete.",
|
||||||
type: Array,
|
type: Array,
|
||||||
@ -183,6 +195,7 @@ pub fn update_drive(
|
|||||||
name: String,
|
name: String,
|
||||||
path: Option<String>,
|
path: Option<String>,
|
||||||
changer: Option<String>,
|
changer: Option<String>,
|
||||||
|
changer_drive_id: Option<u64>,
|
||||||
delete: Option<Vec<DeletableProperty>>,
|
delete: Option<Vec<DeletableProperty>>,
|
||||||
digest: Option<String>,
|
digest: Option<String>,
|
||||||
_param: Value,
|
_param: Value,
|
||||||
@ -202,7 +215,11 @@ pub fn update_drive(
|
|||||||
if let Some(delete) = delete {
|
if let Some(delete) = delete {
|
||||||
for delete_prop in delete {
|
for delete_prop in delete {
|
||||||
match delete_prop {
|
match delete_prop {
|
||||||
DeletableProperty::changer => { data.changer = None; },
|
DeletableProperty::changer => {
|
||||||
|
data.changer = None;
|
||||||
|
data.changer_drive_id = None;
|
||||||
|
},
|
||||||
|
DeletableProperty::changer_drive_id => { data.changer_drive_id = None; },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +235,17 @@ pub fn update_drive(
|
|||||||
data.changer = Some(changer);
|
data.changer = Some(changer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(changer_drive_id) = changer_drive_id {
|
||||||
|
if changer_drive_id == 0 {
|
||||||
|
data.changer_drive_id = None;
|
||||||
|
} else {
|
||||||
|
if data.changer.is_none() {
|
||||||
|
bail!("Option 'changer-drive-id' requires option 'changer'.");
|
||||||
|
}
|
||||||
|
data.changer_drive_id = Some(changer_drive_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config.set_data(&name, "linux", &data)?;
|
config.set_data(&name, "linux", &data)?;
|
||||||
|
|
||||||
config::drive::save_config(&config)?;
|
config::drive::save_config(&config)?;
|
||||||
|
@ -52,7 +52,7 @@ pub fn load_slot(
|
|||||||
None => bail!("drive '{}' has no associated changer", drive),
|
None => bail!("drive '{}' has no associated changer", drive),
|
||||||
};
|
};
|
||||||
|
|
||||||
let drivenum = 0;
|
let drivenum = drive_config.changer_drive_id.unwrap_or(0);
|
||||||
|
|
||||||
mtx_load(&changer.path, slot, drivenum)
|
mtx_load(&changer.path, slot, drivenum)
|
||||||
}
|
}
|
||||||
@ -217,11 +217,6 @@ pub fn eject_media(drive: String) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const SUBDIRS: SubdirMap = &[
|
pub const SUBDIRS: SubdirMap = &[
|
||||||
(
|
|
||||||
"rewind",
|
|
||||||
&Router::new()
|
|
||||||
.put(&API_METHOD_REWIND)
|
|
||||||
),
|
|
||||||
(
|
(
|
||||||
"erase-media",
|
"erase-media",
|
||||||
&Router::new()
|
&Router::new()
|
||||||
@ -237,6 +232,11 @@ pub const SUBDIRS: SubdirMap = &[
|
|||||||
&Router::new()
|
&Router::new()
|
||||||
.put(&API_METHOD_LOAD_SLOT)
|
.put(&API_METHOD_LOAD_SLOT)
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"rewind",
|
||||||
|
&Router::new()
|
||||||
|
.put(&API_METHOD_REWIND)
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"scan",
|
"scan",
|
||||||
&Router::new()
|
&Router::new()
|
||||||
|
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use proxmox::api::{
|
use proxmox::api::{
|
||||||
api,
|
api,
|
||||||
schema::{Schema, StringSchema},
|
schema::{Schema, IntegerSchema, StringSchema},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::api2::types::PROXMOX_SAFE_ID_FORMAT;
|
use crate::api2::types::PROXMOX_SAFE_ID_FORMAT;
|
||||||
@ -35,6 +35,13 @@ pub const MEDIA_LABEL_SCHEMA: Schema = StringSchema::new("Media Label/Barcode.")
|
|||||||
.max_length(32)
|
.max_length(32)
|
||||||
.schema();
|
.schema();
|
||||||
|
|
||||||
|
pub const CHANGER_DRIVE_ID_SCHEMA: Schema = IntegerSchema::new(
|
||||||
|
"Associated changer drive number (requires option changer)")
|
||||||
|
.minimum(0)
|
||||||
|
.maximum(8)
|
||||||
|
.default(0)
|
||||||
|
.schema();
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
properties: {
|
properties: {
|
||||||
name: {
|
name: {
|
||||||
@ -65,17 +72,23 @@ pub struct VirtualTapeDrive {
|
|||||||
changer: {
|
changer: {
|
||||||
schema: CHANGER_ID_SCHEMA,
|
schema: CHANGER_ID_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
}
|
},
|
||||||
|
"changer-drive-id": {
|
||||||
|
schema: CHANGER_DRIVE_ID_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)]
|
)]
|
||||||
#[derive(Serialize,Deserialize)]
|
#[derive(Serialize,Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
/// Linux SCSI tape driver
|
/// Linux SCSI tape driver
|
||||||
pub struct LinuxTapeDrive {
|
pub struct LinuxTapeDrive {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
/// Associated changer device
|
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub changer: Option<String>,
|
pub changer: Option<String>,
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub changer_drive_id: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
|
@ -179,6 +179,7 @@ fn get_config(
|
|||||||
.column(ColumnConfig::new("name"))
|
.column(ColumnConfig::new("name"))
|
||||||
.column(ColumnConfig::new("path"))
|
.column(ColumnConfig::new("path"))
|
||||||
.column(ColumnConfig::new("changer"))
|
.column(ColumnConfig::new("changer"))
|
||||||
|
.column(ColumnConfig::new("changer-drive-id"))
|
||||||
;
|
;
|
||||||
|
|
||||||
format_and_print_result_full(&mut data, info.returns, &output_format, &options);
|
format_and_print_result_full(&mut data, info.returns, &output_format, &options);
|
||||||
|
@ -57,20 +57,20 @@ impl MediaChange for LinuxTapeDrive {
|
|||||||
|
|
||||||
let status = mtx_status(&changer.path)?;
|
let status = mtx_status(&changer.path)?;
|
||||||
|
|
||||||
let drivenum = 0; // fixme: read from drive config
|
let drivenum = self.changer_drive_id.unwrap_or(0);
|
||||||
|
|
||||||
// already loaded?
|
// already loaded?
|
||||||
for (i, drive_status) in status.drives.iter().enumerate() {
|
for (i, drive_status) in status.drives.iter().enumerate() {
|
||||||
if let ElementStatus::VolumeTag(ref tag) = drive_status.status {
|
if let ElementStatus::VolumeTag(ref tag) = drive_status.status {
|
||||||
if *tag == changer_id {
|
if *tag == changer_id {
|
||||||
if i != drivenum {
|
if i as u64 != drivenum {
|
||||||
bail!("unable to load media '{}' - media in wrong drive ({} != {})",
|
bail!("unable to load media '{}' - media in wrong drive ({} != {})",
|
||||||
changer_id, i, drivenum);
|
changer_id, i, drivenum);
|
||||||
}
|
}
|
||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i == drivenum {
|
if i as u64 == drivenum {
|
||||||
match drive_status.status {
|
match drive_status.status {
|
||||||
ElementStatus::Empty => { /* OK */ },
|
ElementStatus::Empty => { /* OK */ },
|
||||||
_ => unload_to_free_slot(&self.name, &changer.path, &status, drivenum as u64)?,
|
_ => unload_to_free_slot(&self.name, &changer.path, &status, drivenum as u64)?,
|
||||||
@ -105,7 +105,7 @@ impl MediaChange for LinuxTapeDrive {
|
|||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let drivenum: u64 = 0;
|
let drivenum = self.changer_drive_id.unwrap_or(0);
|
||||||
|
|
||||||
let status = mtx_status(&changer.path)?;
|
let status = mtx_status(&changer.path)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user