[pve-devel] applied: [PATCH storage 2/2] Diskmanage: detect osds/journals/etc. created with ceph-volume

Thomas Lamprecht t.lamprecht at proxmox.com
Fri May 31 12:10:18 CEST 2019


Am 5/29/19 um 3:48 PM schrieb Dominik Csapak:
> ceph-volume creates osds/journal/etc. on LVM instead of partitions,
> so to detect them, we have to parse the lv_tags of the LVs and
> match them with the underlying device
> 
> also add tests for this detection
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> i first wanted to use the methods in LVMPlugin, but the way the result
> is structured is really different from what we need here, so i simply
> added it inline.
> 
> in pve-manager we probably want to use the output of ceph-volume lvm list
> (we can't here to avoid the dependency on ceph-volume) so
> we probably won't reuse this code. if we do want to reuse it after all,
> we can still refactor it later
> 

applied, with two code and comment cleanup follow ups, thanks!
btw. for such more general "gather host setup data" like block devices,
filesystems setups, ..., it could also make sense to have that in pve-common,
maybe in it's own module, but as long it's pretty re-usable, and mostly just
dependent of common Linux host tools I have no issue with this, we can always
check if the tool is installed easily, so no hard dependency required here.
Just as a thought..

> 
> diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
> index de3e60e..72c1432 100644
> --- a/PVE/Diskmanage.pm
> +++ b/PVE/Diskmanage.pm
> @@ -13,6 +13,7 @@ my $SMARTCTL = "/usr/sbin/smartctl";
>  my $ZPOOL = "/sbin/zpool";
>  my $SGDISK = "/sbin/sgdisk";
>  my $PVS = "/sbin/pvs";
> +my $LVS = "/sbin/lvs";
>  my $UDEVADM = "/bin/udevadm";
>  
>  sub verify_blockdev_path {
> @@ -235,6 +236,39 @@ sub get_ceph_journals {
>      return $journalhash;
>  }
>  
> +# reads the lv_tags and matches them with the devices
> +sub get_ceph_volume_infos {
> +    my $result = {};
> +
> +    my $cmd = [$LVS, '-S', 'lv_name=~^osd-','-o','devices,lv_name,lv_tags',
> +	       '--noheadings', '--readonly', '--separator', ';'];
> +
> +    run_command($cmd, outfunc => sub {
> +	my $line = shift;
> +	$line =~ s/(?:^\s+)|(?:\s+$)//g; # trim
> +	my $fields = [split(';', $line)];
> +
> +	# lvs syntax is /dev/sdX(Y) where Y is the start (which we do not need)
> +	my ($dev) = $fields->[0] =~ m|^(/dev/[a-z]+)|;
> +	if ($fields->[1] =~ m|^osd-([^-]+)-|) {
> +	    my $type = $1;
> +	    # we use autovivification here to not concern us with
> +	    # creation of empty hashes
> +	    if (($type eq 'block' || $type eq 'data') &&
> +		$fields->[2] =~ m/ceph.osd_id=([^,])/)
> +	    {
> +		$result->{$dev}->{osdid} = $1;
> +		$result->{$dev}->{bluestore} = ($type eq 'block');
> +	    } else {
> +		# if $foo is undef $foo++ results in '1' (and is well defined)
> +		$result->{$dev}->{$type}++;
> +	    }
> +	}
> +    });
> +
> +    return $result;
> +}
> +
>  sub get_udev_info {
>      my ($dev) = @_;
>  
> @@ -402,6 +436,7 @@ sub get_disks {
>      };
>  
>      my $journalhash = get_ceph_journals();
> +    my $ceph_volume_infos = get_ceph_volume_infos();
>  
>      my $zfslist = get_zfs_devices();
>  
> @@ -549,6 +584,16 @@ sub get_disks {
>  	    }
>  	});
>  
> +	if ($ceph_volume_infos->{$devpath}) {
> +	    $journal_count += $ceph_volume_infos->{$devpath}->{journal} // 0;
> +	    $db_count += $ceph_volume_infos->{$devpath}->{db} // 0;
> +	    $wal_count += $ceph_volume_infos->{$devpath}->{wal} // 0;
> +	    if ($ceph_volume_infos->{$devpath}->{osdid}) {
> +		$osdid = $ceph_volume_infos->{$devpath}->{osdid};
> +		$bluestore = 1 if $ceph_volume_infos->{$devpath}->{bluestore};
> +	    }
> +	}
> +
>  	$used = 'mounted' if $found_mountpoints && !$used;
>  	$used = 'LVM' if $found_lvm && !$used;
>  	$used = 'ZFS' if $found_zfs && !$used;




More information about the pve-devel mailing list