From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id F0E89FDF3 for ; Tue, 25 Jul 2023 10:36:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CD13A17904 for ; Tue, 25 Jul 2023 10:35:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 25 Jul 2023 10:35:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2134143F93 for ; Tue, 25 Jul 2023 10:35:54 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Tue, 25 Jul 2023 10:35:42 +0200 Message-ID: <20230725083544.212737-4-c.heiss@proxmox.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725083544.212737-1-c.heiss@proxmox.com> References: <20230725083544.212737-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.050 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH installer 3/3] fix #4856: tui: bootdisk: use correct defaults in advanced dialog 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: , X-List-Received-Date: Tue, 25 Jul 2023 08:36:26 -0000 The size of the install disk was set to the size of the first disk, regardless of what disk was selected. This only happened if the advanced options dialog was never opened, and only a disk was selected in the main bootdisk dialog. This has quite a bit of churn, but properly solving this involved restructuring the LVM advanced bootdisk dialog, to also hold the selected disks, like the ZFS and Btrfs dialogs. In addition to that, the `BootdiskOptionsRef` needs quite some passing around, to cover all the cases, since the dialog also needs to be "reentrant-safe". I tested (among other things): * Only select disk, don't open the advanced dialog, go to summary, then back to the bootdisk dialog -> selected disk should be kept * Select disk, open advanced dialog but leave everything as is, go to summary, then go back again -> selected disk should be kept * Same as previous, but change the "Total size" for the disk, go to summary and back -> selected disk and size should be kept * Same as previous, but additionally change filesystem to XFS -> disk, filesystem and size should be kept * Same as previous, but then create a ZFS RAID, go to summary & back, ZFS RAID should be kept with all parameters * etc .. Further I also verified that the correct disk size(s) get written into the setup structure for the low-level installer. Signed-off-by: Christoph Heiss --- proxmox-tui-installer/src/views/bootdisk.rs | 156 ++++++++++++++------ 1 file changed, 109 insertions(+), 47 deletions(-) diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs index c3ac60f..365e5bc 100644 --- a/proxmox-tui-installer/src/views/bootdisk.rs +++ b/proxmox-tui-installer/src/views/bootdisk.rs @@ -27,17 +27,19 @@ pub struct BootdiskOptionsView { impl BootdiskOptionsView { pub fn new(avail_disks: &[Disk], options: &BootdiskOptions) -> Self { + let advanced_options = Rc::new(RefCell::new(options.clone())); + let bootdisk_form = FormView::new() .child( "Target harddisk", - SelectView::new() - .popup() - .with_all(avail_disks.iter().map(|d| (d.to_string(), d.clone()))), + target_bootdisk_selectview( + avail_disks, + advanced_options.clone(), + options.disks.first(), + ), ) .with_name("bootdisk-options-target-disk"); - let advanced_options = Rc::new(RefCell::new(options.clone())); - let advanced_button = LinearLayout::horizontal() .child(DummyView.full_width()) .child(Button::new("Advanced options", { @@ -60,21 +62,10 @@ impl BootdiskOptionsView { } pub fn get_values(&mut self) -> Result { - let mut options = (*self.advanced_options).clone().into_inner(); - - if [FsType::Ext4, FsType::Xfs].contains(&options.fstype) { - let disk = self - .view - .get_child_mut(0) - .and_then(|v| v.downcast_mut::>()) - .map(NamedView::::get_mut) - .and_then(|v| v.get_value::, _>(0)) - .ok_or("failed to retrieve bootdisk")?; - - options.disks = vec![disk]; - } - - Ok(options) + // The simple disk selector, as well as the advanced bootdisk dialog save their + // info on submit directly to the shared `BootdiskOptionsRef` - so just clone() + return + // it. + Ok((*self.advanced_options).clone().into_inner()) } } @@ -87,10 +78,10 @@ struct AdvancedBootdiskOptionsView { } impl AdvancedBootdiskOptionsView { - fn new(avail_disks: &[Disk], options: &BootdiskOptions) -> Self { + fn new(avail_disks: &[Disk], options_ref: BootdiskOptionsRef) -> Self { let enable_btrfs = crate::setup_info().config.enable_btrfs; - let filter_btrfs = |fstype: &&FsType| -> bool { enable_btrfs || !fstype.is_btrfs() }; + let options = (*options_ref).borrow(); let fstype_select = SelectView::new() .popup() @@ -109,7 +100,10 @@ impl AdvancedBootdiskOptionsView { ) .on_submit({ let avail_disks = avail_disks.to_owned(); - move |siv, fstype| Self::fstype_on_submit(siv, &avail_disks, fstype) + let options_ref = options_ref.clone(); + move |siv, fstype| { + Self::fstype_on_submit(siv, &avail_disks, options_ref.clone(), fstype) + } }); let mut view = LinearLayout::vertical() @@ -117,8 +111,11 @@ impl AdvancedBootdiskOptionsView { .child(FormView::new().child("Filesystem", fstype_select)) .child(DummyView.full_width()); + // Create the appropriate (inner) advanced options view match &options.advanced { - AdvancedBootdiskOptions::Lvm(lvm) => view.add_child(LvmBootdiskOptionsView::new(lvm)), + AdvancedBootdiskOptions::Lvm(lvm) => { + view.add_child(LvmBootdiskOptionsView::new(&options.disks[0], lvm)) + } AdvancedBootdiskOptions::Zfs(zfs) => { view.add_child(ZfsBootdiskOptionsView::new(avail_disks, zfs)) } @@ -130,16 +127,39 @@ impl AdvancedBootdiskOptionsView { Self { view } } - fn fstype_on_submit(siv: &mut Cursive, avail_disks: &[Disk], fstype: &FsType) { + /// Called when a new filesystem type is choosen by the user. + /// It first creates the inner (filesystem-specific) options view according to the selected + /// filesytem type. + /// Further, it replaces the (outer) bootdisk selector in the main dialog, either with a + /// selector for LVM configurations or a simple label displaying the chosen RAID for ZFS and + /// Btrfs configurations. + fn fstype_on_submit( + siv: &mut Cursive, + avail_disks: &[Disk], + options_ref: BootdiskOptionsRef, + fstype: &FsType, + ) { + // Only used for LVM configurations, ZFS and Btrfs do not use the target disk selector + let selected_lvm_disk = siv + .find_name::("bootdisk-options-target-disk") + .and_then(|v| v.get_value::, _>(0)); + + // Update the (inner) options view siv.call_on_name("advanced-bootdisk-options-dialog", |view: &mut Dialog| { if let Some(AdvancedBootdiskOptionsView { view }) = view.get_content_mut().downcast_mut() { view.remove_child(3); match fstype { - FsType::Ext4 | FsType::Xfs => view.add_child(LvmBootdiskOptionsView::new( - &LvmBootdiskOptions::defaults_from(&avail_disks[0]), - )), + FsType::Ext4 | FsType::Xfs => { + // Safety: For LVM setups, the bootdisk SelectView always exists, thus + // there will also always be a value. + let selected_disk = selected_lvm_disk.clone().unwrap(); + view.add_child(LvmBootdiskOptionsView::new( + &selected_disk, + &LvmBootdiskOptions::defaults_from(&selected_disk), + )); + } FsType::Zfs(_) => view.add_child(ZfsBootdiskOptionsView::new( avail_disks, &ZfsBootdiskOptions::defaults_from(avail_disks), @@ -152,15 +172,21 @@ impl AdvancedBootdiskOptionsView { } }); + // The "bootdisk-options-target-disk" view might be either a `SelectView` (if ext4 of XFS + // is used) or a label containing the filesytem/RAID type (for ZFS and Btrfs). + // Now, unconditionally replace it with the appropriate type of these two, depending on the + // newly selected filesystem type. siv.call_on_name( "bootdisk-options-target-disk", - |view: &mut FormView| match fstype { + move |view: &mut FormView| match fstype { FsType::Ext4 | FsType::Xfs => { view.replace_child( 0, - SelectView::new() - .popup() - .with_all(avail_disks.iter().map(|d| (d.to_string(), d.clone()))), + target_bootdisk_selectview( + avail_disks, + options_ref, + selected_lvm_disk.as_ref(), + ), ); } other => view.replace_child(0, TextView::new(other.to_string())), @@ -178,10 +204,12 @@ impl AdvancedBootdiskOptionsView { let advanced = self.view.get_child_mut(3)?; if let Some(view) = advanced.downcast_mut::() { + let (disk, advanced) = view.get_values()?; + Some(BootdiskOptions { - disks: vec![], + disks: vec![disk], fstype, - advanced: view.get_values().map(AdvancedBootdiskOptions::Lvm)?, + advanced: AdvancedBootdiskOptions::Lvm(advanced), }) } else if let Some(view) = advanced.downcast_mut::() { let (disks, advanced) = view.get_values()?; @@ -211,12 +239,13 @@ impl ViewWrapper for AdvancedBootdiskOptionsView { struct LvmBootdiskOptionsView { view: FormView, + disk: Disk, } impl LvmBootdiskOptionsView { - fn new(options: &LvmBootdiskOptions) -> Self { + fn new(disk: &Disk, options: &LvmBootdiskOptions) -> Self { let is_pve = crate::setup_info().config.product == ProxmoxProduct::PVE; - // TODO: Set maximum accordingly to disk size + let view = FormView::new() .child( "Total size", @@ -243,10 +272,13 @@ impl LvmBootdiskOptionsView { DiskSizeEditView::new_emptyable().content_maybe(options.min_lvm_free), ); - Self { view } + Self { + view, + disk: disk.clone(), + } } - fn get_values(&mut self) -> Option { + fn get_values(&mut self) -> Option<(Disk, LvmBootdiskOptions)> { let is_pve = crate::setup_info().config.product == ProxmoxProduct::PVE; let min_lvm_free_id = if is_pve { 4 } else { 2 }; let max_root_size = if is_pve { @@ -259,13 +291,16 @@ impl LvmBootdiskOptionsView { } else { None }; - Some(LvmBootdiskOptions { - total_size: self.view.get_value::(0)?, - swap_size: self.view.get_value::(1), - max_root_size, - max_data_size, - min_lvm_free: self.view.get_value::(min_lvm_free_id), - }) + Some(( + self.disk.clone(), + LvmBootdiskOptions { + total_size: self.view.get_value::(0)?, + swap_size: self.view.get_value::(1), + max_root_size, + max_data_size, + min_lvm_free: self.view.get_value::(min_lvm_free_id), + }, + )) } } @@ -535,11 +570,10 @@ impl ViewWrapper for ZfsBootdiskOptionsView { fn advanced_options_view(avail_disks: &[Disk], options_ref: BootdiskOptionsRef) -> impl View { Dialog::around(AdvancedBootdiskOptionsView::new( avail_disks, - &(*options_ref).borrow(), + options_ref.clone(), )) .title("Advanced bootdisk options") .button("Ok", { - let options_ref = options_ref.clone(); move |siv| { let options = siv .call_on_name("advanced-bootdisk-options-dialog", |view: &mut Dialog| { @@ -575,3 +609,31 @@ fn advanced_options_view(avail_disks: &[Disk], options_ref: BootdiskOptionsRef) .with_name("advanced-bootdisk-options-dialog") .max_size((120, 40)) } + +/// Creates a select view for all disks specified. +/// +/// # Arguments +/// +/// * `avail_disks` - Disks that should be shown in the select view +/// * `options_ref` - A `BootdiskOptionsRef`, which is used to set the disk (and its defaults) +/// when a disk is selected +/// * `selected_disk` - Optional, specifies which disk should be pre-selected +fn target_bootdisk_selectview( + avail_disks: &[Disk], + options_ref: BootdiskOptionsRef, + selected_disk: Option<&Disk>, +) -> SelectView { + let selected_disk_pos = selected_disk + .and_then(|disk| avail_disks.iter().position(|d| d.index == disk.index)) + .unwrap_or_default(); + + SelectView::new() + .popup() + .with_all(avail_disks.iter().map(|d| (d.to_string(), d.clone()))) + .selected(selected_disk_pos) + .on_submit(move |_, disk| { + options_ref.borrow_mut().disks = vec![disk.clone()]; + options_ref.borrow_mut().advanced = + AdvancedBootdiskOptions::Lvm(LvmBootdiskOptions::defaults_from(disk)); + }) +} -- 2.41.0