zfs diskmanage: code/indentation cleanup in get_pool_data

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2022-11-11 08:01:14 +01:00
parent 0bcfafa471
commit 8b06da647a

View File

@ -19,9 +19,7 @@ my $ZPOOL = '/sbin/zpool';
my $ZFS = '/sbin/zfs'; my $ZFS = '/sbin/zfs';
sub get_pool_data { sub get_pool_data {
if (!-f $ZPOOL) { die "zfsutils-linux not installed\n" if ! -f $ZPOOL;
die "zfsutils-linux not installed\n";
}
my $propnames = [qw(name size alloc free frag dedup health)]; my $propnames = [qw(name size alloc free frag dedup health)];
my $numbers = { my $numbers = {
@ -32,24 +30,21 @@ sub get_pool_data {
dedup => 1, dedup => 1,
}; };
my $cmd = [$ZPOOL,'list', '-HpPLo', join(',', @$propnames)];
my $pools = []; my $pools = [];
run_command([$ZPOOL, 'list', '-HpPLo', join(',', @$propnames)], outfunc => sub {
run_command($cmd, outfunc => sub {
my ($line) = @_; my ($line) = @_;
my @props = split('\s+', trim($line)); my @props = split('\s+', trim($line));
my $pool = {}; my $pool = {};
for (my $i = 0; $i < scalar(@$propnames); $i++) { for (my $i = 0; $i < scalar(@$propnames); $i++) {
if ($numbers->{$propnames->[$i]}) { if ($numbers->{$propnames->[$i]}) {
$pool->{$propnames->[$i]} = $props[$i] + 0; $pool->{$propnames->[$i]} = $props[$i] + 0;
} else { } else {
$pool->{$propnames->[$i]} = $props[$i]; $pool->{$propnames->[$i]} = $props[$i];
}
} }
}
push @$pools, $pool; push @$pools, $pool;
}); });
return $pools; return $pools;