follouwp: get_ceph_volume_infos: code and comment cleanup

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2019-05-31 12:04:13 +02:00
parent 19dcd1adcb
commit 248f43f58b

View File

@ -240,27 +240,25 @@ sub get_ceph_journals {
sub get_ceph_volume_infos { sub get_ceph_volume_infos {
my $result = {}; my $result = {};
my $cmd = [$LVS, '-S', 'lv_name=~^osd-','-o','devices,lv_name,lv_tags', my $cmd = [ $LVS, '-S', 'lv_name=~^osd-', '-o', 'devices,lv_name,lv_tags',
'--noheadings', '--readonly', '--separator', ';']; '--noheadings', '--readonly', '--separator', ';' ];
run_command($cmd, outfunc => sub { run_command($cmd, outfunc => sub {
my $line = shift; my $line = shift;
$line =~ s/(?:^\s+)|(?:\s+$)//g; # trim $line =~ s/(?:^\s+)|(?:\s+$)//g; # trim whitespaces
my $fields = [split(';', $line)];
my $fields = [ split(';', $line) ];
# lvs syntax is /dev/sdX(Y) where Y is the start (which we do not need) # lvs syntax is /dev/sdX(Y) where Y is the start (which we do not need)
my ($dev) = $fields->[0] =~ m|^(/dev/[a-z]+)|; my ($dev) = $fields->[0] =~ m|^(/dev/[a-z]+)|;
if ($fields->[1] =~ m|^osd-([^-]+)-|) { if ($fields->[1] =~ m|^osd-([^-]+)-|) {
my $type = $1; my $type = $1;
# we use autovivification here to not concern us with # $result autovivification is wanted, to not creating empty hashes
# creation of empty hashes if (($type eq 'block' || $type eq 'data') && $fields->[2] =~ m/ceph.osd_id=([^,])/) {
if (($type eq 'block' || $type eq 'data') &&
$fields->[2] =~ m/ceph.osd_id=([^,])/)
{
$result->{$dev}->{osdid} = $1; $result->{$dev}->{osdid} = $1;
$result->{$dev}->{bluestore} = ($type eq 'block'); $result->{$dev}->{bluestore} = ($type eq 'block');
} else { } else {
# if $foo is undef $foo++ results in '1' (and is well defined) # undef++ becomes '1' (see `perldoc perlop`: Auto-increment)
$result->{$dev}->{$type}++; $result->{$dev}->{$type}++;
} }
} }