From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 1B3C91FF16F for ; Tue, 14 Oct 2025 15:23:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7CD7E4039; Tue, 14 Oct 2025 15:22:52 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Tue, 14 Oct 2025 15:21:54 +0200 Message-ID: <20251014132207.1171073-10-c.heiss@proxmox.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014132207.1171073-1-c.heiss@proxmox.com> References: <20251014132207.1171073-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1760448096027 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.038 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH installer 09/14] post-hook: avoid redundant Option for (de-)serialization X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Instead, for the serialization case just skip it if the value is falsy, for deserialization default-initialize it with `false`. No functional changes. Signed-off-by: Christoph Heiss --- proxmox-installer-common/src/setup.rs | 12 ++---------- proxmox-post-hook/src/main.rs | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index 3e99576..1a584ba 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -275,14 +275,6 @@ where Ok(val != 0) } -fn deserialize_bool_from_int_maybe<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - let val: Option = Deserialize::deserialize(deserializer)?; - Ok(val.map(|v| v != 0)) -} - fn deserialize_cczones_map<'de, D>( deserializer: D, ) -> Result>, D::Error> @@ -389,8 +381,8 @@ pub struct RuntimeInfo { pub hvm_supported: bool, /// Whether the system was booted with SecureBoot enabled - #[serde(default, deserialize_with = "deserialize_bool_from_int_maybe")] - pub secure_boot: Option, + #[serde(default, deserialize_with = "deserialize_bool_from_int")] + pub secure_boot: bool, /// Default upper limit for the ZFS ARC size, in MiB. pub default_zfs_arc_max: usize, diff --git a/proxmox-post-hook/src/main.rs b/proxmox-post-hook/src/main.rs index bd27121..0a9e661 100644 --- a/proxmox-post-hook/src/main.rs +++ b/proxmox-post-hook/src/main.rs @@ -44,8 +44,8 @@ struct BootInfo { /// Whether the system is booted using UEFI or legacy BIOS. mode: BootType, /// Whether SecureBoot is enabled for the installation. - #[serde(skip_serializing_if = "Option::is_none")] - secureboot: Option, + #[serde(skip_serializing_if = "bool_is_false")] + secureboot: bool, } /// Holds all the public keys for the different algorithms available. @@ -66,8 +66,8 @@ struct DiskInfo { /// Size in bytes size: usize, /// Set to true if the disk is used for booting. - #[serde(skip_serializing_if = "Option::is_none")] - is_bootdisk: Option, + #[serde(skip_serializing_if = "bool_is_false")] + is_bootdisk: bool, /// Properties about the device as given by udev. udev_properties: UdevProperties, } @@ -83,12 +83,16 @@ struct NetworkInterfaceInfo { address: Option, /// Set to true if the interface is the chosen management interface during /// installation. - #[serde(skip_serializing_if = "Option::is_none")] - is_management: Option, + #[serde(skip_serializing_if = "bool_is_false")] + is_management: bool, /// Properties about the device as given by udev. udev_properties: UdevProperties, } +fn bool_is_false(value: &bool) -> bool { + !value +} + /// Information about the installed product itself. #[derive(Serialize)] #[serde(rename_all = "kebab-case")] @@ -323,7 +327,8 @@ impl PostHookInfo { let is_bootdisk = config .target_hd .as_ref() - .and_then(|hd| (*hd == disk.path).then_some(true)); + .map(|hd| *hd == disk.path) + .unwrap_or_default(); anyhow::Ok(DiskInfo { size: (config.hdsize * (SIZE_GIB as f64)) as usize, @@ -341,9 +346,7 @@ impl PostHookInfo { .disks .iter() .flat_map(|disk| { - let is_bootdisk = selected_disks_indices - .contains(&&disk.index) - .then_some(true); + let is_bootdisk = selected_disks_indices.contains(&&disk.index); anyhow::Ok(DiskInfo { size: (config.hdsize * (SIZE_GIB as f64)) as usize, @@ -389,14 +392,14 @@ impl PostHookInfo { anyhow::Ok(NetworkInterfaceInfo { mac: nic.mac.clone(), address: Some(config.cidr.clone()), - is_management: Some(true), + is_management: true, udev_properties, }) } else { anyhow::Ok(NetworkInterfaceInfo { mac: nic.mac.clone(), address: None, - is_management: None, + is_management: false, udev_properties, }) } -- 2.51.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel