tape: move 'eject-before-unload' to a plain changer config option

instead of having it in a property string. For now this should be fine,
and if we need many more such options, we can still move them into a
property string if we want.

Also update the cli command in the docs on how to set it now.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2023-12-14 10:05:19 +01:00 committed by Dietmar Maurer
parent f622695532
commit c7321e2ea3
5 changed files with 16 additions and 44 deletions

View File

@ -367,7 +367,7 @@ You can set these options with `proxmox-tape` like this:
.. code-block:: console .. code-block:: console
# proxmox-tape changer update sl3 --options eject-before-unload=true # proxmox-tape changer update sl3 --eject-before-unload true
.. _tape_drive_config: .. _tape_drive_config:

View File

@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use proxmox_schema::{ use proxmox_schema::{
api, ApiStringFormat, ApiType, ArraySchema, IntegerSchema, Schema, StringSchema, Updater, api, ApiStringFormat, ArraySchema, IntegerSchema, Schema, StringSchema, Updater,
}; };
use crate::{OptionalDeviceIdentification, PROXMOX_SAFE_ID_FORMAT}; use crate::{OptionalDeviceIdentification, PROXMOX_SAFE_ID_FORMAT};
@ -39,29 +39,6 @@ Import/Export, i.e. any media in those slots are considered to be
.format(&ApiStringFormat::PropertyString(&SLOT_ARRAY_SCHEMA)) .format(&ApiStringFormat::PropertyString(&SLOT_ARRAY_SCHEMA))
.schema(); .schema();
#[api(
properties: {
"eject-before-unload": {
optional: true,
default: false,
},
},
)]
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
/// Options for Changers
pub struct ChangerOptions {
#[serde(skip_serializing_if = "Option::is_none")]
/// if set to true, tapes are ejected manually before unloading
pub eject_before_unload: Option<bool>,
}
pub const CHANGER_OPTIONS_STRING_SCHEMA: Schema = StringSchema::new("Changer options")
.format(&ApiStringFormat::PropertyString(
&ChangerOptions::API_SCHEMA,
))
.schema();
#[api( #[api(
properties: { properties: {
name: { name: {
@ -74,10 +51,10 @@ pub const CHANGER_OPTIONS_STRING_SCHEMA: Schema = StringSchema::new("Changer opt
schema: EXPORT_SLOT_LIST_SCHEMA, schema: EXPORT_SLOT_LIST_SCHEMA,
optional: true, optional: true,
}, },
options: { "eject-before-unload": {
optional: true, optional: true,
schema: CHANGER_OPTIONS_STRING_SCHEMA, default: false,
}, }
}, },
)] )]
#[derive(Serialize, Deserialize, Updater)] #[derive(Serialize, Deserialize, Updater)]
@ -90,7 +67,8 @@ pub struct ScsiTapeChanger {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub export_slots: Option<String>, pub export_slots: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub options: Option<String>, /// if set to true, tapes are ejected manually before unloading
pub eject_before_unload: Option<bool>,
} }
#[api( #[api(

View File

@ -138,8 +138,8 @@ pub fn list_changers(
pub enum DeletableProperty { pub enum DeletableProperty {
/// Delete export-slots. /// Delete export-slots.
ExportSlots, ExportSlots,
/// Delete options. /// Delete eject-before-unload.
Options, EjectBeforeUnload,
} }
#[api( #[api(
@ -196,8 +196,8 @@ pub fn update_changer(
DeletableProperty::ExportSlots => { DeletableProperty::ExportSlots => {
data.export_slots = None; data.export_slots = None;
} }
DeletableProperty::Options => { DeletableProperty::EjectBeforeUnload => {
data.options = None; data.eject_before_unload = None;
} }
} }
} }
@ -227,8 +227,8 @@ pub fn update_changer(
} }
} }
if let Some(options) = update.options { if let Some(eject_before_unload) = update.eject_before_unload {
data.options = Some(options); data.eject_before_unload = Some(eject_before_unload);
} }
config.set_data(&name, "changer", &data)?; config.set_data(&name, "changer", &data)?;

View File

@ -161,7 +161,7 @@ fn get_config(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error
let options = default_table_format_options() let options = default_table_format_options()
.column(ColumnConfig::new("name")) .column(ColumnConfig::new("name"))
.column(ColumnConfig::new("path")) .column(ColumnConfig::new("path"))
.column(ColumnConfig::new("options")) .column(ColumnConfig::new("eject-before-unload"))
.column(ColumnConfig::new("export-slots")); .column(ColumnConfig::new("export-slots"));
format_and_print_result_full(&mut data, &info.returns, &output_format, &options); format_and_print_result_full(&mut data, &info.returns, &output_format, &options);

View File

@ -4,7 +4,6 @@ pub mod mtx;
mod online_status_map; mod online_status_map;
pub use online_status_map::*; pub use online_status_map::*;
use proxmox_schema::ApiType;
use std::path::PathBuf; use std::path::PathBuf;
@ -12,7 +11,7 @@ use anyhow::{bail, Error};
use proxmox_sys::fs::{file_read_optional_string, replace_file, CreateOptions}; use proxmox_sys::fs::{file_read_optional_string, replace_file, CreateOptions};
use pbs_api_types::{ChangerOptions, LtoTapeDrive, ScsiTapeChanger}; use pbs_api_types::{LtoTapeDrive, ScsiTapeChanger};
use pbs_tape::{linux_list_drives::open_lto_tape_device, sg_pt_changer, ElementStatus, MtxStatus}; use pbs_tape::{linux_list_drives::open_lto_tape_device, sg_pt_changer, ElementStatus, MtxStatus};
@ -428,12 +427,7 @@ impl MediaChange for MtxMediaChanger {
} }
fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error> { fn unload_media(&mut self, target_slot: Option<u64>) -> Result<MtxStatus, Error> {
let options: ChangerOptions = serde_json::from_value( if self.config.eject_before_unload.unwrap_or(false) {
ChangerOptions::API_SCHEMA
.parse_property_string(self.config.options.as_deref().unwrap_or_default())?,
)?;
if options.eject_before_unload.unwrap_or(false) {
let file = open_lto_tape_device(&self.drive.path)?; let file = open_lto_tape_device(&self.drive.path)?;
let mut handle = LtoTapeHandle::new(file)?; let mut handle = LtoTapeHandle::new(file)?;