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 6B5DB1FF161 for ; Wed, 20 Nov 2024 19:24:32 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9C72F15EE6; Wed, 20 Nov 2024 19:24:26 +0100 (CET) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Wed, 20 Nov 2024 19:24:12 +0100 Message-Id: <20241120182414.125789-1-d.kral@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.002 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [options.rs] Subject: [pve-devel] [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels 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" Allows the ZFS RAID levels to be either lowercase or uppercase when deserializing them from string values, i.e. currently only the config value of `zfs.raid` in auto-installer answer files. This partly fixes a regression, where deserializing the `zfs.raid` property in answer files were only possible with uppercase values for the ZFS RAID Z-levels, opposed to only lowercase as in previous versions. This breaks the user API, as users cannot use the same answer files as before for ZFS RAID Z-levels (the prepare-iso command fails). Fixes: 510b0c008fb1 ("common: simplifying filesystem type serializing & Display trait impl") Signed-off-by: Daniel Kral --- As suggested by Thomas off-list, we could improve this in the future to use a case-insensitive deserializer, but this should work as a rather quick fix to not break user API in the answer file. Serde does not have a native case-insensitive deserializer and this was the minimal option without having to implement a case-insensitive deserializer on my own (or pulling in `serde_aux` as a dependency for this), allowing the `serde_plain::derive_display_from_serialize!` afterwards and showing the lowercase variants as the correct values on error (e.g. using `zfs.raid = "Raidz-3"`, which is incorrect): ``` $ proxmox-auto-install-assistant validate-answer answer.toml Error: Error parsing answer file: TOML parse error at line 23, column 12 | 23 | zfs.raid = "Raidz-3" | ^^^^^^^^^ unknown variant `Raidz-3`, expected one of `raid0`, `raid1`, `raid10`, `raidz-1`, `raidz-2`, `raidz-3` ``` I checked the correctness by using either lowercase or uppercase in a answer file and checking the expanded version of this with `cargo expand` in the proxmox-installer-common directory. These parts show the following for deserialization (only the string variant next to the bytes variant)... ``` fn visit_str<__E>( self, __value: &str, ) -> _serde::__private::Result where __E: _serde::de::Error, { match __value { "RAID0" | "raid0" => _serde::__private::Ok(__Field::__field0), "RAID1" | "raid1" => _serde::__private::Ok(__Field::__field1), "RAID10" | "raid10" => { _serde::__private::Ok(__Field::__field2) } "RAIDZ-1" | "raidz-1" => { _serde::__private::Ok(__Field::__field3) } "RAIDZ-2" | "raidz-2" => { _serde::__private::Ok(__Field::__field4) } "RAIDZ-3" | "raidz-3" => { _serde::__private::Ok(__Field::__field5) } _ => { _serde::__private::Err( _serde::de::Error::unknown_variant(__value, VARIANTS), ) } } } ``` ...and the following serialization: ``` impl _serde::Serialize for ZfsRaidLevel { fn serialize<__S>( &self, __serializer: __S, ) -> _serde::__private::Result<__S::Ok, __S::Error> where __S: _serde::Serializer, { match *self { ZfsRaidLevel::Raid0 => { _serde::Serializer::serialize_unit_variant( __serializer, "ZfsRaidLevel", 0u32, "RAID0", ) } ZfsRaidLevel::Raid1 => { _serde::Serializer::serialize_unit_variant( __serializer, "ZfsRaidLevel", 1u32, "RAID1", ) } ZfsRaidLevel::Raid10 => { _serde::Serializer::serialize_unit_variant( __serializer, "ZfsRaidLevel", 2u32, "RAID10", ) } ZfsRaidLevel::RaidZ => { _serde::Serializer::serialize_unit_variant( __serializer, "ZfsRaidLevel", 3u32, "RAIDZ-1", ) } ZfsRaidLevel::RaidZ2 => { _serde::Serializer::serialize_unit_variant( __serializer, "ZfsRaidLevel", 4u32, "RAIDZ-2", ) } ZfsRaidLevel::RaidZ3 => { _serde::Serializer::serialize_unit_variant( __serializer, "ZfsRaidLevel", 5u32, "RAIDZ-3", ) } } } } ``` proxmox-installer-common/src/options.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index 8b6c281..434ce26 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -24,14 +24,17 @@ serde_plain::derive_display_from_serialize!(BtrfsRaidLevel); #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all(deserialize = "lowercase", serialize = "UPPERCASE"))] pub enum ZfsRaidLevel { + #[serde(alias = "RAID0")] Raid0, + #[serde(alias = "RAID1")] Raid1, + #[serde(alias = "RAID10")] Raid10, - #[serde(rename = "RAIDZ-1")] + #[serde(alias = "RAIDZ-1", rename(deserialize = "raidz-1", serialize = "RAIDZ-1"))] RaidZ, - #[serde(rename = "RAIDZ-2")] + #[serde(alias = "RAIDZ-2", rename(deserialize = "raidz-2", serialize = "RAIDZ-2"))] RaidZ2, - #[serde(rename = "RAIDZ-3")] + #[serde(alias = "RAIDZ-3", rename(deserialize = "raidz-3", serialize = "RAIDZ-3"))] RaidZ3, } -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel