disk manage: draid: style clean ups

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2022-11-11 09:23:49 +01:00
parent 8a5ffcd991
commit e698cbb9af

View File

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use PVE::Diskmanage; use PVE::Diskmanage;
use PVE::JSONSchema qw(get_standard_option); use PVE::JSONSchema qw(get_standard_option parse_property_string);
use PVE::Systemd; use PVE::Systemd;
use PVE::API2::Storage::Config; use PVE::API2::Storage::Config;
use PVE::Storage; use PVE::Storage;
@ -361,14 +361,12 @@ __PACKAGE__->register_method ({
my $devs = [PVE::Tools::split_list($param->{devices})]; my $devs = [PVE::Tools::split_list($param->{devices})];
my $raidlevel = $param->{raidlevel}; my $raidlevel = $param->{raidlevel};
my $compression = $param->{compression} // 'on'; my $compression = $param->{compression} // 'on';
my $draid_config = {};
my $draid_config;
if (exists $param->{'draid-config'}) { if (exists $param->{'draid-config'}) {
die "draid-config set without using dRAID level\n" if $raidlevel !~ m/^draid/; die "draid-config set without using dRAID level\n" if $raidlevel !~ m/^draid/;
$draid_config = PVE::JSONSchema::parse_property_string( $draid_config = parse_property_string($draid_config_format, $param->{'draid-config'});
$draid_config_format, $param->{'draid-config'});
} }
my $draid_data = $draid_config->{data};
my $draid_spares = $draid_config->{spares};
for my $dev (@$devs) { for my $dev (@$devs) {
$dev = PVE::Diskmanage::verify_blockdev_path($dev); $dev = PVE::Diskmanage::verify_blockdev_path($dev);
@ -423,15 +421,15 @@ __PACKAGE__->register_method ({
# draid checks # draid checks
if ($raidlevel =~ m/^draid/) { if ($raidlevel =~ m/^draid/) {
# bare minimum would be two drives: # bare minimum would be two drives: one for parity & one for data, but forbid that
# one parity & one data drive this code doesn't allow that because # because it makes no sense in practice, at least one spare disk should be used
# it makes no sense, at least one spare disk should be used my $draid_min = $mindisks->{$raidlevel} - 2;
my $draidmin = $mindisks->{$raidlevel} - 2; if ($draid_config) {
$draidmin += $draid_data if $draid_data; $draid_min += $draid_config->{data} || 0;
$draidmin += $draid_spares if $draid_spares; $draid_min += $draid_config->{spares} || 0;
}
die "At least $draidmin disks needed for current dRAID config\n" die "At least $draid_min disks needed for current dRAID config\n"
if $numdisks < $draidmin; if $numdisks < $draid_min;
} }
my $code = sub { my $code = sub {
@ -472,8 +470,8 @@ __PACKAGE__->register_method ({
push @$cmd, $devs->[0]; push @$cmd, $devs->[0];
} elsif ($raidlevel =~ m/^draid/) { } elsif ($raidlevel =~ m/^draid/) {
my $draid_cmd = $raidlevel; my $draid_cmd = $raidlevel;
$draid_cmd .= ":${draid_data}d" if $draid_data; $draid_cmd .= ":$$draid_config->{data}d" if $$draid_config->{data};
$draid_cmd .= ":${draid_spares}s" if $draid_spares; $draid_cmd .= ":$$draid_config->{spares}s" if $draid_config->{spares};
push @$cmd, $draid_cmd, @$devs; push @$cmd, $draid_cmd, @$devs;
} else { } else {
push @$cmd, $raidlevel, @$devs; push @$cmd, $raidlevel, @$devs;