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 8EFC4DAE4 for ; Tue, 19 Apr 2022 14:03:15 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 86632279E4 for ; Tue, 19 Apr 2022 14:02:45 +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 id 5ECF9279C4 for ; Tue, 19 Apr 2022 14:02:43 +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 E090742268 for ; Tue, 19 Apr 2022 14:02:42 +0200 (CEST) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Tue, 19 Apr 2022 14:02:30 +0200 Message-Id: <20220419120231.2161474-2-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419120231.2161474-1-s.ivanov@proxmox.com> References: <20220419120231.2161474-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.208 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 1/2] fix #3188: update hdsize spin-button on disk-selection change 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, 19 Apr 2022 12:03:15 -0000 the patch splits get_hdsize_spinbtn into a sub for generating the adjustment gtk-element and one for the button itself and moves them above create_raid_disk_raid (so that the adjustment sub can be called) The adjustment gets it's data from the disks selected for installation in the GUI, if a size is not provided. Additionally the bogus 'zfs' argument to the create_raid_advanced_grid was dropped. Tested with a VM with 2x 100G disks, and one with 20G Signed-off-by: Stoiko Ivanov --- proxinstall | 78 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/proxinstall b/proxinstall index 8ec7d2c..5360b08 100755 --- a/proxinstall +++ b/proxinstall @@ -2950,7 +2950,40 @@ my $create_label_widget_grid = sub { return $grid; }; +my $get_hdsize_adjustment = sub { + my $hdsize = shift; + + if (!defined($hdsize)) { + #compute based on selected disks + my $hd_count = scalar(@$hds); + for (my $i = 0; $i < $hd_count; $i++) { + if (defined(my $cur_hd = $config_options->{"disksel$i"})) { + my $disksize = int(@$cur_hd[2] / (2*1024*1024.0)); # size in GB + $hdsize //= $disksize; + $hdsize = $disksize if $disksize < $hdsize; + } + } + } + die "could not determine hdsize for adjustment!\n" if !$hdsize; + + return Gtk3::Adjustment->new($config_options->{hdsize} || $hdsize, 0, $hdsize+1, 1, 1, 1); +}; + +my $get_hdsize_spinbtn = sub { + my $hdsize = shift; + + my $hdsize_entry_buffer = Gtk3::EntryBuffer->new(undef, 1); + my $hdsize_size_adj = $get_hdsize_adjustment->($hdsize); + + my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1); + $spinbutton_hdsize->set_buffer($hdsize_entry_buffer); + $spinbutton_hdsize->set_adjustment($hdsize_size_adj); + $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)"); + return $spinbutton_hdsize; +}; + my $create_raid_disk_grid = sub { + my ($hdsize_btn) = @_; my $hd_count = scalar(@$hds); my $disk_labeled_widgets = []; for (my $i = 0; $i < $hd_count; $i++) { @@ -2967,6 +3000,8 @@ my $create_raid_disk_grid = sub { my $diskid = $w->{pve_disk_id}; my $a = $w->get_active - 1; $config_options->{"disksel${diskid}"} = ($a >= 0) ? $hds->[$a] : undef; + my $hdsize_adj = $get_hdsize_adjustment->(); + $hdsize_btn->set_adjustment($hdsize_adj); }); } @@ -3022,30 +3057,8 @@ my $create_raid_disk_grid = sub { return $vbox; }; -# shared between different ui parts (e.g., ZFS and "normal" single disk FS) -my $hdsize_size_adj; -my $hdsize_entry_buffer; - -my $get_hdsize_spinbtn = sub { - my $hdsize = shift; - - $hdsize_entry_buffer //= Gtk3::EntryBuffer->new(undef, 1); - - if (defined($hdsize)) { - $hdsize_size_adj = Gtk3::Adjustment->new($config_options->{hdsize} || $hdsize, 0, $hdsize+1, 1, 1, 1); - } else { - die "called get_hdsize_spinbtn with \$hdsize_size_adj not defined but did not pass hdsize!\n" - if !defined($hdsize_size_adj); - } - - my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1); - $spinbutton_hdsize->set_buffer($hdsize_entry_buffer); - $spinbutton_hdsize->set_adjustment($hdsize_size_adj); - $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)"); - return $spinbutton_hdsize; -}; - my $create_raid_advanced_grid = sub { + my ($hdsize_btn) = @_; my $labeled_widgets = []; my $spinbutton_ashift = Gtk3::SpinButton->new_with_range(9, 13, 1); $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)"); @@ -3098,7 +3111,7 @@ my $create_raid_advanced_grid = sub { $spinbutton_copies->set_value($config_options->{copies}); push @$labeled_widgets, "copies", $spinbutton_copies; - push @$labeled_widgets, "hdsize", $get_hdsize_spinbtn->(); + push @$labeled_widgets, "hdsize", $hdsize_btn; return $create_label_widget_grid->($labeled_widgets);; }; @@ -3176,8 +3189,9 @@ sub create_hdoption_view { $hdsize = int((-s $target_hd) / (1024*1024*1024.0)); } - my $spinbutton_hdsize = $get_hdsize_spinbtn->($hdsize); - push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize; + my $spinbutton_hdsize_nonraid = $get_hdsize_spinbtn->($hdsize); + push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize_nonraid; + my $spinbutton_hdsize = $spinbutton_hdsize_nonraid; my $entry_swapsize = Gtk3::Entry->new(); $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)"); @@ -3208,13 +3222,14 @@ sub create_hdoption_view { push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz; } + my $spinbutton_hdsize_zfs = $get_hdsize_spinbtn->($hdsize); my $options_stack = Gtk3::Stack->new(); $options_stack->set_visible(1); $options_stack->set_hexpand(1); $options_stack->set_vexpand(1); - $options_stack->add_titled(&$create_raid_disk_grid(), "raiddisk", "Disk Setup"); + $options_stack->add_titled(&$create_raid_disk_grid($spinbutton_hdsize_zfs), "raiddisk", "Disk Setup"); $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options"); - $options_stack->add_titled(&$create_raid_advanced_grid("zfs"), "raidzfsadvanced", "Advanced Options"); + $options_stack->add_titled(&$create_raid_advanced_grid($spinbutton_hdsize_zfs), "raidzfsadvanced", "Advanced Options"); $options_stack->set_visible_child_name("raiddisk"); my $options_stack_switcher = Gtk3::StackSwitcher->new(); $options_stack_switcher->set_halign('center'); @@ -3250,6 +3265,13 @@ sub create_hdoption_view { } else { $target_hd_label->set_text("Target Harddisk: "); } + + if ($raid) { + $spinbutton_hdsize = $spinbutton_hdsize_zfs; + } else { + $spinbutton_hdsize = $spinbutton_hdsize_nonraid; + } + my (undef, $pref_width) = $dialog->get_preferred_width(); my (undef, $pref_height) = $dialog->get_preferred_height(); $pref_height = 750 if $pref_height > 750; -- 2.30.2