From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] tape: fix 'eject-before-unload' api type
Date: Wed, 13 Dec 2023 11:11:12 +0100 [thread overview]
Message-ID: <20231213101112.76140-1-d.csapak@proxmox.com> (raw)
by converting the bool into an option, otherwise having the options not
set at all will fail the unload while deserializing with
'eject-before-unload is not optional'
Also if we can automatically decide this in the future, we can now
detect if the option was explicitely set or not.
Fixes: 66402cdc ("fix #4904: tape changer: add option to eject before unload")
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
pbs-api-types/src/tape/changer.rs | 17 ++++++++++-------
src/tape/changer/mod.rs | 2 +-
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/pbs-api-types/src/tape/changer.rs b/pbs-api-types/src/tape/changer.rs
index e3cf27c1..9e36b12e 100644
--- a/pbs-api-types/src/tape/changer.rs
+++ b/pbs-api-types/src/tape/changer.rs
@@ -39,18 +39,21 @@ 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]
+#[api(
+ properties: {
+ "eject-before-unload": {
+ optional: true,
+ default: false,
+ },
+ },
+)]
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
/// Options for Changers
pub struct ChangerOptions {
- #[serde(default, skip_serializing_if = "is_false")]
+ #[serde(skip_serializing_if = "Option::is_none")]
/// if set to true, tapes are ejected manually before unloading
- pub eject_before_unload: bool,
+ pub eject_before_unload: Option<bool>,
}
pub const CHANGER_OPTIONS_STRING_SCHEMA: Schema = StringSchema::new("Changer options")
diff --git a/src/tape/changer/mod.rs b/src/tape/changer/mod.rs
index df63f6f8..9d90e29d 100644
--- a/src/tape/changer/mod.rs
+++ b/src/tape/changer/mod.rs
@@ -433,7 +433,7 @@ impl MediaChange for MtxMediaChanger {
.parse_property_string(self.config.options.as_deref().unwrap_or_default())?,
)?;
- if options.eject_before_unload {
+ if options.eject_before_unload.unwrap_or(false) {
let file = open_lto_tape_device(&self.drive.path)?;
let mut handle = LtoTapeHandle::new(file)?;
--
2.39.2
next reply other threads:[~2023-12-13 10:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 10:11 Dominik Csapak [this message]
2023-12-14 7:46 ` Thomas Lamprecht
2023-12-14 7:52 ` Dominik Csapak
2023-12-14 8:18 ` Dietmar Maurer
2023-12-14 8:32 ` Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231213101112.76140-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox