From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 5E7B41FF398 for ; Mon, 13 May 2024 14:14:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A10F914E88; Mon, 13 May 2024 14:14:10 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 13 May 2024 14:13:50 +0200 Message-ID: <20240513121357.1270503-2-c.heiss@proxmox.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240513121357.1270503-1-c.heiss@proxmox.com> References: <20240513121357.1270503-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.005 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 1/6] fix #5250: install: config: add new `btrfs_opts` with `compress` config option 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" Signed-off-by: Christoph Heiss --- Proxmox/Install/Config.pm | 15 ++++++++++ proxmox-auto-installer/src/utils.rs | 1 + proxmox-installer-common/src/options.rs | 31 +++++++++++++++++++++ proxmox-installer-common/src/setup.rs | 21 ++++++++++++-- proxmox-tui-installer/src/setup.rs | 2 ++ proxmox-tui-installer/src/views/bootdisk.rs | 5 ++-- 6 files changed, 71 insertions(+), 4 deletions(-) diff --git a/Proxmox/Install/Config.pm b/Proxmox/Install/Config.pm index ecd8a74..09edf11 100644 --- a/Proxmox/Install/Config.pm +++ b/Proxmox/Install/Config.pm @@ -79,6 +79,9 @@ my sub init_cfg { copies => 1, arc_max => Proxmox::Install::RunEnv::default_zfs_arc_max(), # in MiB }, + btrfs_opts => { + compress => 'off', + }, # TODO: single disk selection config target_hd => undef, disk_selection => {}, @@ -173,6 +176,18 @@ sub get_zfs_opt { return defined($k) ? $zfs_opts->{$k} : $zfs_opts; } +sub set_btrfs_opt { + my ($k, $v) = @_; + my $opts = get('btrfs_opts'); + croak "unknown btrfs opts key '$k'" if !exists($opts->{$k}); + $opts->{$k} = $v; +} +sub get_btrfs_opt { + my ($k) = @_; + my $opts = get('btrfs_opts'); + return defined($k) ? $opts->{$k} : $opts; +} + sub set_target_hd { set_key('target_hd', $_[0]); } sub get_target_hd { return get('target_hd'); } diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index 202ad41..30b6196 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -326,6 +326,7 @@ pub fn parse_answer( minfree: None, maxvz: None, zfs_opts: None, + btrfs_opts: None, target_hd: None, disk_selection: BTreeMap::new(), lvm_auto_rename: 1, diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index e77914b..972b66c 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -102,10 +102,40 @@ impl LvmBootdiskOptions { } } +/// See the accompanying mount option in btrfs(5). +#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, PartialEq)] +#[serde(rename_all(deserialize = "lowercase"))] +pub enum BtrfsCompressOption { + On, + #[default] + Off, + Zlib, + Lzo, + Zstd, +} + +impl fmt::Display for BtrfsCompressOption { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", format!("{self:?}").to_lowercase()) + } +} + +impl From<&BtrfsCompressOption> for String { + fn from(value: &BtrfsCompressOption) -> Self { + value.to_string() + } +} + +pub const BTRFS_COMPRESS_OPTIONS: &[BtrfsCompressOption] = { + use BtrfsCompressOption::*; + &[On, Off, Zlib, Lzo, Zstd] +}; + #[derive(Clone, Debug)] pub struct BtrfsBootdiskOptions { pub disk_size: f64, pub selected_disks: Vec, + pub compress: BtrfsCompressOption, } impl BtrfsBootdiskOptions { @@ -115,6 +145,7 @@ impl BtrfsBootdiskOptions { Self { disk_size: disk.size, selected_disks: (0..disks.len()).collect(), + compress: BtrfsCompressOption::default(), } } } diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index 64d05af..81f3533 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -13,8 +13,8 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use crate::{ options::{ - BtrfsRaidLevel, Disk, FsType, ZfsBootdiskOptions, ZfsChecksumOption, ZfsCompressOption, - ZfsRaidLevel, + BtrfsBootdiskOptions, BtrfsCompressOption, BtrfsRaidLevel, Disk, FsType, + ZfsBootdiskOptions, ZfsChecksumOption, ZfsCompressOption, ZfsRaidLevel, }, utils::CidrAddress, }; @@ -220,6 +220,20 @@ impl From for InstallZfsOption { } } +#[derive(Debug, Deserialize, Serialize)] +pub struct InstallBtrfsOption { + #[serde(serialize_with = "serialize_as_display")] + pub compress: BtrfsCompressOption, +} + +impl From for InstallBtrfsOption { + fn from(opts: BtrfsBootdiskOptions) -> Self { + InstallBtrfsOption { + compress: opts.compress, + } + } +} + pub fn read_json Deserialize<'de>, P: AsRef>(path: P) -> Result { let file = File::open(path).map_err(|err| err.to_string())?; let reader = BufReader::new(file); @@ -466,6 +480,9 @@ pub struct InstallConfig { #[serde(skip_serializing_if = "Option::is_none")] pub zfs_opts: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub btrfs_opts: Option, + #[serde( serialize_with = "serialize_disk_opt", skip_serializing_if = "Option::is_none", diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs index 8c01e42..2622c8e 100644 --- a/proxmox-tui-installer/src/setup.rs +++ b/proxmox-tui-installer/src/setup.rs @@ -15,6 +15,7 @@ impl From for InstallConfig { minfree: None, maxvz: None, zfs_opts: None, + btrfs_opts: None, target_hd: None, disk_selection: BTreeMap::new(), lvm_auto_rename: 0, @@ -60,6 +61,7 @@ impl From for InstallConfig { } AdvancedBootdiskOptions::Btrfs(btrfs) => { config.hdsize = btrfs.disk_size; + config.btrfs_opts = Some(btrfs.clone().into()); for (i, disk) in options.bootdisk.disks.iter().enumerate() { config diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs index f6fdb31..107fc9c 100644 --- a/proxmox-tui-installer/src/views/bootdisk.rs +++ b/proxmox-tui-installer/src/views/bootdisk.rs @@ -19,8 +19,8 @@ use proxmox_installer_common::{ check_zfs_raid_config, }, options::{ - AdvancedBootdiskOptions, BootdiskOptions, BtrfsBootdiskOptions, Disk, FsType, - LvmBootdiskOptions, ZfsBootdiskOptions, ZFS_CHECKSUM_OPTIONS, ZFS_COMPRESS_OPTIONS, + AdvancedBootdiskOptions, BootdiskOptions, BtrfsBootdiskOptions, BtrfsCompressOption, Disk, + FsType, LvmBootdiskOptions, ZfsBootdiskOptions, ZFS_CHECKSUM_OPTIONS, ZFS_COMPRESS_OPTIONS, }, setup::{BootType, ProductConfig, ProxmoxProduct, RuntimeInfo}, }; @@ -544,6 +544,7 @@ impl BtrfsBootdiskOptionsView { BtrfsBootdiskOptions { disk_size, selected_disks, + compress: BtrfsCompressOption::default(), }, )) } -- 2.44.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel