Diskmanage: detect osds/journals/etc. created with ceph-volume

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@proxmox.com>
This commit is contained in:
Dominik Csapak
2019-05-29 15:48:06 +02:00
committed by Thomas Lamprecht
parent cd814c0453
commit 19dcd1adcb
22 changed files with 184 additions and 1 deletions

View File

@ -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;

View File

@ -4,3 +4,7 @@ sdc
sdd
sde
sdf
sdg
sdh
sdi
sdj

View File

@ -88,5 +88,69 @@
"vendor" : "ATA",
"wwn" : "0x0000000000000000",
"devpath" : "/dev/sdd"
},
"sdg" : {
"serial" : "SERIAL1",
"vendor" : "ATA",
"wwn" : "0x0000000000000000",
"devpath" : "/dev/sdg",
"model" : "MODEL1",
"used" : "LVM",
"wearout" : "N/A",
"health" : "UNKNOWN",
"gpt" : 1,
"size" : 1536000,
"rpm" : 0,
"type" : "hdd",
"bluestore": 1,
"osdid" : 1
},
"sdh" : {
"serial" : "SERIAL1",
"vendor" : "ATA",
"wwn" : "0x0000000000000000",
"devpath" : "/dev/sdh",
"model" : "MODEL1",
"used" : "LVM",
"wearout" : "N/A",
"health" : "UNKNOWN",
"gpt" : 1,
"journals": 1,
"size" : 1536000,
"rpm" : 0,
"type" : "hdd",
"osdid" : -1
},
"sdi" : {
"serial" : "SERIAL1",
"vendor" : "ATA",
"wwn" : "0x0000000000000000",
"devpath" : "/dev/sdi",
"model" : "MODEL1",
"used" : "LVM",
"wearout" : "N/A",
"health" : "UNKNOWN",
"gpt" : 1,
"size" : 1536000,
"rpm" : 0,
"type" : "hdd",
"db": 1,
"osdid" : -1
},
"sdj" : {
"serial" : "SERIAL1",
"vendor" : "ATA",
"wwn" : "0x0000000000000000",
"devpath" : "/dev/sdj",
"model" : "MODEL1",
"used" : "LVM",
"wearout" : "N/A",
"health" : "UNKNOWN",
"gpt" : 1,
"size" : 1536000,
"rpm" : 0,
"bluestore": 0,
"type" : "hdd",
"osdid" : 2
}
}

View File

@ -0,0 +1,4 @@
/dev/sdg(0);osd-block-01234;ceph.osd_id=1
/dev/sdh(0);osd-journal-01234;ceph.osd_id=1
/dev/sdi(0);osd-db-01234;ceph.osd_id=1
/dev/sdj(0);osd-data-01234;ceph.osd_id=2

View File

@ -1 +1,5 @@
/dev/sdb
/dev/sdb
/dev/sdg
/dev/sdh
/dev/sdi
/dev/sdj

View File

@ -0,0 +1 @@
ATA

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
3000

View File

@ -0,0 +1,12 @@
E: DEVNAME=/dev/sdg
E: DEVTYPE=disk
E: ID_ATA_ROTATION_RATE_RPM=0
E: ID_BUS=ata
E: ID_MODEL=MODEL1
E: ID_PART_TABLE_TYPE=gpt
E: ID_PART_TABLE_UUID=8417b93f-eff9-4e8f-8d84-dc2e77fc07a2
E: ID_SERIAL=SERIAL1
E: ID_SERIAL_SHORT=SERIAL1
E: ID_TYPE=disk
E: ID_WWN=0x0000000000000000
E: ID_WWN_WITH_EXTENSION=0x0000000000000000

View File

@ -0,0 +1 @@
ATA

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
3000

View File

@ -0,0 +1,12 @@
E: DEVNAME=/dev/sdh
E: DEVTYPE=disk
E: ID_ATA_ROTATION_RATE_RPM=0
E: ID_BUS=ata
E: ID_MODEL=MODEL1
E: ID_PART_TABLE_TYPE=gpt
E: ID_PART_TABLE_UUID=8417b93f-eff9-4e8f-8d84-dc2e77fc07a2
E: ID_SERIAL=SERIAL1
E: ID_SERIAL_SHORT=SERIAL1
E: ID_TYPE=disk
E: ID_WWN=0x0000000000000000
E: ID_WWN_WITH_EXTENSION=0x0000000000000000

View File

@ -0,0 +1 @@
ATA

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
3000

View File

@ -0,0 +1,12 @@
E: DEVNAME=/dev/sdi
E: DEVTYPE=disk
E: ID_ATA_ROTATION_RATE_RPM=0
E: ID_BUS=ata
E: ID_MODEL=MODEL1
E: ID_PART_TABLE_TYPE=gpt
E: ID_PART_TABLE_UUID=8417b93f-eff9-4e8f-8d84-dc2e77fc07a2
E: ID_SERIAL=SERIAL1
E: ID_SERIAL_SHORT=SERIAL1
E: ID_TYPE=disk
E: ID_WWN=0x0000000000000000
E: ID_WWN_WITH_EXTENSION=0x0000000000000000

View File

@ -0,0 +1 @@
ATA

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
3000

View File

@ -0,0 +1,12 @@
E: DEVNAME=/dev/sdj
E: DEVTYPE=disk
E: ID_ATA_ROTATION_RATE_RPM=0
E: ID_BUS=ata
E: ID_MODEL=MODEL1
E: ID_PART_TABLE_TYPE=gpt
E: ID_PART_TABLE_UUID=8417b93f-eff9-4e8f-8d84-dc2e77fc07a2
E: ID_SERIAL=SERIAL1
E: ID_SERIAL_SHORT=SERIAL1
E: ID_TYPE=disk
E: ID_WWN=0x0000000000000000
E: ID_WWN_WITH_EXTENSION=0x0000000000000000

View File

@ -52,6 +52,8 @@ sub mocked_run_command {
} elsif ($cmd->[0] =~ m/pvs/i) {
# simulate lvs output
@$outputlines = split(/\n/, read_test_file('pvs'));
} elsif ($cmd->[0] =~ m/lvs/i) {
@$outputlines = split(/\n/, read_test_file('lvs'));
} else {
print "unexpected run_command call: '@$cmd', aborting\n";
die;