From 99f24b2079bd42de1b603ab04bf600225912241d Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 7 Dec 2023 13:51:02 +0100 Subject: [PATCH] fix #4904: tape changer: add option to eject before unload some tape libraries need the tape being ejected from the drive before doing an unload. Since we cannot easily detect if that's the case, introduce an 'eject_before_unload' option. Instead of just adding a bool flag to the config, add a new 'options' property string where we can put such niche options similar to how we handle the datastore tuning options. Extend the LtoTapeHandle with 'medium_present' which just uses a TEST UNIT READY command to check for present medium, so we don't try to eject an already ejected tape. Signed-off-by: Dominik Csapak --- pbs-api-types/src/tape/changer.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pbs-api-types/src/tape/changer.rs b/pbs-api-types/src/tape/changer.rs index c9c7fcaa..e3cf27c1 100644 --- a/pbs-api-types/src/tape/changer.rs +++ b/pbs-api-types/src/tape/changer.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use proxmox_schema::{ - api, ApiStringFormat, ArraySchema, IntegerSchema, Schema, StringSchema, Updater, + api, ApiStringFormat, ApiType, ArraySchema, IntegerSchema, Schema, StringSchema, Updater, }; use crate::{OptionalDeviceIdentification, PROXMOX_SAFE_ID_FORMAT}; @@ -39,6 +39,26 @@ Import/Export, i.e. any media in those slots are considered to be .format(&ApiStringFormat::PropertyString(&SLOT_ARRAY_SCHEMA)) .schema(); +fn is_false(b: &bool) -> bool { + !b +} + +#[api] +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +/// Options for Changers +pub struct ChangerOptions { + #[serde(default, skip_serializing_if = "is_false")] + /// if set to true, tapes are ejected manually before unloading + pub eject_before_unload: bool, +} + +pub const CHANGER_OPTIONS_STRING_SCHEMA: Schema = StringSchema::new("Changer options") + .format(&ApiStringFormat::PropertyString( + &ChangerOptions::API_SCHEMA, + )) + .schema(); + #[api( properties: { name: { @@ -51,6 +71,10 @@ Import/Export, i.e. any media in those slots are considered to be schema: EXPORT_SLOT_LIST_SCHEMA, optional: true, }, + options: { + optional: true, + schema: CHANGER_OPTIONS_STRING_SCHEMA, + }, }, )] #[derive(Serialize, Deserialize, Updater)] @@ -62,6 +86,8 @@ pub struct ScsiTapeChanger { pub path: String, #[serde(skip_serializing_if = "Option::is_none")] pub export_slots: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub options: Option, } #[api(