* [pve-devel] [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels
@ 2024-11-20 18:24 Daniel Kral
2024-11-20 18:24 ` [pve-devel] [PATCH installer 2/3] common: allow lowercase and uppercase btrfs " Daniel Kral
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Daniel Kral @ 2024-11-20 18:24 UTC (permalink / raw)
To: 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 <d.kral@proxmox.com>
---
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<Self::Value, __E>
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pve-devel] [PATCH installer 2/3] common: allow lowercase and uppercase btrfs raid levels
2024-11-20 18:24 [pve-devel] [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels Daniel Kral
@ 2024-11-20 18:24 ` Daniel Kral
2024-11-20 18:24 ` [pve-devel] [PATCH installer 3/3] common: make btrfs disk options uppercase for consistency Daniel Kral
2024-11-20 19:09 ` [pve-devel] applied-series: [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels Thomas Lamprecht
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Kral @ 2024-11-20 18:24 UTC (permalink / raw)
To: pve-devel
Allows the BTRFS RAID levels to be either lowercase or uppercase when
deserializing them from string values, i.e. currently only the config
value of `btrfs.raid` in auto-installer answer files.
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
When we're already at it, let's do the same for btrfs...
Here's the output from `cargo expand` again, first for deserialization:
```
fn visit_str<__E>(
self,
__value: &str,
) -> _serde::__private::Result<Self::Value, __E>
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)
}
_ => {
_serde::__private::Err(
_serde::de::Error::unknown_variant(__value, VARIANTS),
)
}
}
}
```
and second for serialization:
```
impl _serde::Serialize for BtrfsRaidLevel {
fn serialize<__S>(
&self,
__serializer: __S,
) -> _serde::__private::Result<__S::Ok, __S::Error>
where
__S: _serde::Serializer,
{
match *self {
BtrfsRaidLevel::Raid0 => {
_serde::Serializer::serialize_unit_variant(
__serializer,
"BtrfsRaidLevel",
0u32,
"RAID0",
)
}
BtrfsRaidLevel::Raid1 => {
_serde::Serializer::serialize_unit_variant(
__serializer,
"BtrfsRaidLevel",
1u32,
"RAID1",
)
}
BtrfsRaidLevel::Raid10 => {
_serde::Serializer::serialize_unit_variant(
__serializer,
"BtrfsRaidLevel",
2u32,
"RAID10",
)
}
}
}
}
```
On some error (`btrfs.raid = "rAID10"`), the message is:
```
proxmox-auto-install-assistant validate-answer answer.toml
Error: Error parsing answer file: TOML parse error at line 21, column 14
|
21 | btrfs.raid = "rAID10"
| ^^^^^^^^
unknown variant `rAID10`, expected one of `raid0`, `raid1`, `raid10`
```
proxmox-installer-common/src/options.rs | 3 +++
1 file changed, 3 insertions(+)
diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs
index 434ce26..58fadf8 100644
--- a/proxmox-installer-common/src/options.rs
+++ b/proxmox-installer-common/src/options.rs
@@ -14,8 +14,11 @@ use crate::utils::{CidrAddress, Fqdn};
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all(deserialize = "lowercase", serialize = "UPPERCASE"))]
pub enum BtrfsRaidLevel {
+ #[serde(alias = "RAID0")]
Raid0,
+ #[serde(alias = "RAID1")]
Raid1,
+ #[serde(alias = "RAID10")]
Raid10,
}
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pve-devel] [PATCH installer 3/3] common: make btrfs disk options uppercase for consistency
2024-11-20 18:24 [pve-devel] [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels Daniel Kral
2024-11-20 18:24 ` [pve-devel] [PATCH installer 2/3] common: allow lowercase and uppercase btrfs " Daniel Kral
@ 2024-11-20 18:24 ` Daniel Kral
2024-11-20 19:09 ` [pve-devel] applied-series: [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels Thomas Lamprecht
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Kral @ 2024-11-20 18:24 UTC (permalink / raw)
To: pve-devel
As XFS and ZFS are spelled in uppercase letters in the installer UI and
BTRFS is usually written in this way too, make the BTRFS string
uppercase too for consistency wrt to the other options.
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
I just noticed this while booting up the PVE installer and as it
(vaguely) fits with the theme of this patch series, let's also make the
bootdisk option in the GUI/TUI consistent wrt to the others.
proxmox-installer-common/src/options.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs
index 58fadf8..37e6260 100644
--- a/proxmox-installer-common/src/options.rs
+++ b/proxmox-installer-common/src/options.rs
@@ -69,7 +69,7 @@ impl fmt::Display for FsType {
FsType::Ext4 => write!(f, "ext4"),
FsType::Xfs => write!(f, "XFS"),
FsType::Zfs(level) => write!(f, "ZFS ({level})"),
- FsType::Btrfs(level) => write!(f, "Btrfs ({level})"),
+ FsType::Btrfs(level) => write!(f, "BTRFS ({level})"),
}
}
}
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pve-devel] applied-series: [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels
2024-11-20 18:24 [pve-devel] [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels Daniel Kral
2024-11-20 18:24 ` [pve-devel] [PATCH installer 2/3] common: allow lowercase and uppercase btrfs " Daniel Kral
2024-11-20 18:24 ` [pve-devel] [PATCH installer 3/3] common: make btrfs disk options uppercase for consistency Daniel Kral
@ 2024-11-20 19:09 ` Thomas Lamprecht
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2024-11-20 19:09 UTC (permalink / raw)
To: Proxmox VE development discussion, Daniel Kral
Am 20.11.24 um 19:24 schrieb Daniel Kral:> 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 <d.kral@proxmox.com>
> ---
> proxmox-installer-common/src/options.rs | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
>
applied, thanks!
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-11-20 19:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-20 18:24 [pve-devel] [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels Daniel Kral
2024-11-20 18:24 ` [pve-devel] [PATCH installer 2/3] common: allow lowercase and uppercase btrfs " Daniel Kral
2024-11-20 18:24 ` [pve-devel] [PATCH installer 3/3] common: make btrfs disk options uppercase for consistency Daniel Kral
2024-11-20 19:09 ` [pve-devel] applied-series: [PATCH installer 1/3] common: allow lowercase and uppercase zfs raid levels Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox