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 097C69A68F for ; Fri, 17 Nov 2023 13:13:39 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DE775325CC for ; Fri, 17 Nov 2023 13:13:38 +0100 (CET) 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 ; Fri, 17 Nov 2023 13:13:38 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id DAE9D43DD9 for ; Fri, 17 Nov 2023 13:13:37 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Fri, 17 Nov 2023 13:12:18 +0100 Message-ID: <20231117121319.482709-1-c.heiss@proxmox.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [bootdisk.rs] Subject: [pve-devel] [PATCH installer] tui: fix changing between non-LVM and LVM filesystem in bootdisk chooser 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: Fri, 17 Nov 2023 12:13:39 -0000 Happens due to a force-unwrap() under the false assumption that the disk for LVM configurations always exists when switching to a LVM filesystem. This fails spectacularly with a panic when switching from e.g. Btrfs to ext4 in the filesystem chooser. Fixes: eda9fa0 ("fix #4856: tui: bootdisk: use correct defaults in advanced dialog") Reported-by: Christian Ebner Signed-off-by: Christoph Heiss --- proxmox-tui-installer/src/views/bootdisk.rs | 29 +++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs index 4bd504b..00e6ade 100644 --- a/proxmox-tui-installer/src/views/bootdisk.rs +++ b/proxmox-tui-installer/src/views/bootdisk.rs @@ -49,7 +49,9 @@ impl BootdiskOptionsView { target_bootdisk_selectview( &runinfo.disks, advanced_options.clone(), - options.disks.first(), + // At least one disk must always exist to even get to this point, + // see proxmox_installer_common::setup::installer_setup() + &options.disks[0], ), ) .with_name("bootdisk-options-target-disk"); @@ -181,9 +183,14 @@ impl AdvancedBootdiskOptionsView { let product_conf = state.setup_info.config.clone(); // Only used for LVM configurations, ZFS and Btrfs do not use the target disk selector + // Must be done here, as we cannot mutable borrow `siv` a second time inside the closure + // below. let selected_lvm_disk = siv .find_name::("bootdisk-options-target-disk") - .and_then(|v| v.get_value::, _>(0)); + .and_then(|v| v.get_value::, _>(0)) + // If not defined, then the view was switched from a non-LVM filesystem to a LVM one. + // Just use the first disk is such a case. + .unwrap_or_else(|| runinfo.disks[0].clone()); // Update the (inner) options view siv.call_on_name("advanced-bootdisk-options-dialog", |view: &mut Dialog| { @@ -193,11 +200,8 @@ impl AdvancedBootdiskOptionsView { view.remove_child(3); match fstype { 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_with_defaults( - &selected_disk, + &selected_lvm_disk, &product_conf, )); } @@ -222,11 +226,7 @@ impl AdvancedBootdiskOptionsView { FsType::Ext4 | FsType::Xfs => { view.replace_child( 0, - target_bootdisk_selectview( - &runinfo.disks, - options_ref, - selected_lvm_disk.as_ref(), - ), + target_bootdisk_selectview(&runinfo.disks, options_ref, &selected_lvm_disk), ); } other => view.replace_child(0, TextView::new(other.to_string())), @@ -714,10 +714,11 @@ fn advanced_options_view( fn target_bootdisk_selectview( avail_disks: &[Disk], options_ref: BootdiskOptionsRef, - selected_disk: Option<&Disk>, + selected_disk: &Disk, ) -> SelectView { - let selected_disk_pos = selected_disk - .and_then(|disk| avail_disks.iter().position(|d| d.index == disk.index)) + let selected_disk_pos = avail_disks + .iter() + .position(|d| d.index == selected_disk.index) .unwrap_or_default(); SelectView::new() -- 2.42.0