[pve-devel] [PATCH installer 2/2] Consider hdsize setting when comparing raid disks

Stoiko Ivanov s.ivanov at proxmox.com
Fri Dec 7 12:35:32 CET 2018


Honoring hdsize for ZFS setups introduced the possibility to use differently
sized disks for a mirror-setup, by restricting hdsize to the smallest disk.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 proxinstall | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/proxinstall b/proxinstall
index 159c727..5f83d3f 100755
--- a/proxinstall
+++ b/proxinstall
@@ -2791,10 +2791,15 @@ my $get_raid_devlist = sub {
 };
 
 sub zfs_mirror_size_check {
-    my ($expected, $actual) = @_;
+    my ($expected, $actual, $restricted_size_gb) = @_;
 
-    die "mirrored disks must have same size\n"
-	if abs($expected - $actual) > $expected / 10;
+    if (defined($restricted_size_gb)) {
+	die "bootdisks must have at least hdsize: $restricted_size_gb GB\n"
+	    if ($actual < ($restricted_size_gb * 1024 * 1024 * 2)); #$actual is in 512b
+    } else {
+	die "mirrored disks must have same size\n"
+	    if abs($expected - $actual) > $expected / 10;
+    }
 }
 
 sub get_zfs_raid_setup {
@@ -2817,10 +2822,7 @@ sub get_zfs_raid_setup {
     } elsif ($filesys eq 'zfs (RAID1)') {
 	die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
 	$cmd .= ' mirror ';
-	my $hd = @$devlist[0];
-	my $expected_size = @$hd[2]; # all disks need approximately same size
-	foreach $hd (@$devlist) {
-	    zfs_mirror_size_check($expected_size, @$hd[2]);
+	foreach my $hd (@$devlist) {
 	    $cmd .= " @$hd[1]";
 	    push @$bootdevlist, $hd;
 	}
@@ -2828,9 +2830,12 @@ sub get_zfs_raid_setup {
 	die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
 	die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
 
-	push @$bootdevlist, @$devlist[0], @$devlist[1];
+	my ($hd1, $hd2) = (@$devlist[0], @$devlist[1]);
+	push @$bootdevlist, $hd1, $hd2;
+	$cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
 
-	for (my $i = 0; $i < $diskcount; $i+=2) {
+	# first 2 (boot) disks get checked separately
+	for (my $i = 2; $i < $diskcount; $i+=2) {
 	    my $hd1 = @$devlist[$i];
 	    my $hd2 = @$devlist[$i+1];
 	    zfs_mirror_size_check(@$hd1[2], @$hd2[2]); # pairs need approximately same size
@@ -2841,11 +2846,8 @@ sub get_zfs_raid_setup {
 	my $level = $1;
 	my $mindisks = 2 + $level;
 	die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
-	my $hd = @$devlist[0];
-	my $expected_size = @$hd[2]; # all disks need approximately same size
 	$cmd .= " raidz$level";
-	foreach $hd (@$devlist) {
-	    zfs_mirror_size_check($expected_size, @$hd[2]);
+	foreach my $hd (@$devlist) {
 	    $cmd .= " @$hd[1]";
 	    push @$bootdevlist, $hd;
 	}
@@ -2853,6 +2855,15 @@ sub get_zfs_raid_setup {
 	die "unknown zfs mode '$filesys'\n";
     }
 
+    #bootdisks honor hdsize setting if present
+    my $restricted_size_gb = $config_options->{hdsize};
+
+    my $hd = @$bootdevlist[0];
+    my $expected_size = @$hd[2];
+    foreach $hd (@$bootdevlist) {
+	zfs_mirror_size_check($expected_size, @$hd[2], $restricted_size_gb);
+    }
+
     return ($devlist, $bootdevlist, $cmd);
 }
 
-- 
2.11.0





More information about the pve-devel mailing list