[pve-devel] [PATCH storage 3/5] add 'single' raidlevel for zfs

Dominik Csapak d.csapak at proxmox.com
Wed Aug 8 10:20:07 CEST 2018


the syntax for creating a pool with a single disk is
not the same as for mirror, so let the user select it
explicitely

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Disks/ZFS.pm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Disks/ZFS.pm b/PVE/API2/Disks/ZFS.pm
index 7531af0..ad6da23 100644
--- a/PVE/API2/Disks/ZFS.pm
+++ b/PVE/API2/Disks/ZFS.pm
@@ -237,8 +237,8 @@ __PACKAGE__->register_method ({
 	    name => get_standard_option('pve-storage-id'),
 	    raidlevel => {
 		type => 'string',
-		description => 'The RAID level to use, for single disk, use mirror.',
-		enum => ['mirror', 'raid10', 'raidz', 'raidz2', 'raidz3'],
+		description => 'The RAID level to use.',
+		enum => ['single', 'mirror', 'raid10', 'raidz', 'raidz2', 'raidz3'],
 	    },
 	    devices => {
 		type => 'string', format => 'string-list',
@@ -294,7 +294,8 @@ __PACKAGE__->register_method ({
 
 	my $numdisks = scalar(@$devs);
 	my $mindisks = {
-	    mirror => 1,
+	    single => 1,
+	    mirror => 2,
 	    raid10 => 4,
 	    raidz => 3,
 	    raidz2 => 4,
@@ -305,6 +306,9 @@ __PACKAGE__->register_method ({
 	die "raid10 needs an even number of disks\n"
 	    if $raidlevel eq 'raid10' && $numdisks % 2 != 0;
 
+	die "please give only one disk for single disk mode\n"
+	    if $raidlevel eq 'single' && $numdisks > 1;
+
 	die "$raidlevel needs at least $mindisks->{$raidlevel} disks\n"
 	    if $numdisks < $mindisks->{$raidlevel};
 
@@ -318,6 +322,8 @@ __PACKAGE__->register_method ({
 		    for (my $i = 0; $i < @$devs; $i+=2) {
 			push @$cmd, 'mirror', $devs->[$i], $devs->[$i+1];
 		    }
+		} elsif ($raidlevel eq 'single') {
+		    push @$cmd, $devs->[0];
 		} else {
 		    push @$cmd, $raidlevel, @$devs;
 		}
-- 
2.11.0





More information about the pve-devel mailing list