]> git.proxmox.com Git - pve-storage.git/commitdiff
Diskmanage: detect osds/journals/etc. created with ceph-volume
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 29 May 2019 13:48:06 +0000 (15:48 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 31 May 2019 09:41:33 +0000 (11:41 +0200)
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>
22 files changed:
PVE/Diskmanage.pm
test/disk_tests/usages/disklist
test/disk_tests/usages/disklist_expected.json
test/disk_tests/usages/lvs [new file with mode: 0644]
test/disk_tests/usages/pvs
test/disk_tests/usages/sdg/device/vendor [new file with mode: 0644]
test/disk_tests/usages/sdg/queue/rotational [new file with mode: 0644]
test/disk_tests/usages/sdg/size [new file with mode: 0644]
test/disk_tests/usages/sdg_udevadm [new file with mode: 0644]
test/disk_tests/usages/sdh/device/vendor [new file with mode: 0644]
test/disk_tests/usages/sdh/queue/rotational [new file with mode: 0644]
test/disk_tests/usages/sdh/size [new file with mode: 0644]
test/disk_tests/usages/sdh_udevadm [new file with mode: 0644]
test/disk_tests/usages/sdi/device/vendor [new file with mode: 0644]
test/disk_tests/usages/sdi/queue/rotational [new file with mode: 0644]
test/disk_tests/usages/sdi/size [new file with mode: 0644]
test/disk_tests/usages/sdi_udevadm [new file with mode: 0644]
test/disk_tests/usages/sdj/device/vendor [new file with mode: 0644]
test/disk_tests/usages/sdj/queue/rotational [new file with mode: 0644]
test/disk_tests/usages/sdj/size [new file with mode: 0644]
test/disk_tests/usages/sdj_udevadm [new file with mode: 0644]
test/disklist_test.pm

index de3e60e02146fc841826a491353127e3e088e29d..72c1432f438575e86a0e82c2805c141acdc9d08d 100644 (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;
index b5daaf1f203c19ed0210cd45d733cb6e1f314fdc..9092ce093464d3424f334a062bb3b2e5f866899e 100644 (file)
@@ -4,3 +4,7 @@ sdc
 sdd
 sde
 sdf
+sdg
+sdh
+sdi
+sdj
index 3205bbf294d347300be71dba19deec2099923988..4f9f5cc3d523aeee4724b04f4723e82e1b0c8007 100644 (file)
        "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
     }
 }
diff --git a/test/disk_tests/usages/lvs b/test/disk_tests/usages/lvs
new file mode 100644 (file)
index 0000000..b3fad43
--- /dev/null
@@ -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
index ab3ff755cb6aeff1487d89eea48d4c9b1be6042b..0df50803b4931958fe12cd98e38c4e20615376eb 100644 (file)
@@ -1 +1,5 @@
-  /dev/sdb 
+  /dev/sdb
+  /dev/sdg
+  /dev/sdh
+  /dev/sdi
+  /dev/sdj
diff --git a/test/disk_tests/usages/sdg/device/vendor b/test/disk_tests/usages/sdg/device/vendor
new file mode 100644 (file)
index 0000000..531030d
--- /dev/null
@@ -0,0 +1 @@
+ATA
diff --git a/test/disk_tests/usages/sdg/queue/rotational b/test/disk_tests/usages/sdg/queue/rotational
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/test/disk_tests/usages/sdg/size b/test/disk_tests/usages/sdg/size
new file mode 100644 (file)
index 0000000..13de30f
--- /dev/null
@@ -0,0 +1 @@
+3000
diff --git a/test/disk_tests/usages/sdg_udevadm b/test/disk_tests/usages/sdg_udevadm
new file mode 100644 (file)
index 0000000..6d40d35
--- /dev/null
@@ -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
diff --git a/test/disk_tests/usages/sdh/device/vendor b/test/disk_tests/usages/sdh/device/vendor
new file mode 100644 (file)
index 0000000..531030d
--- /dev/null
@@ -0,0 +1 @@
+ATA
diff --git a/test/disk_tests/usages/sdh/queue/rotational b/test/disk_tests/usages/sdh/queue/rotational
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/test/disk_tests/usages/sdh/size b/test/disk_tests/usages/sdh/size
new file mode 100644 (file)
index 0000000..13de30f
--- /dev/null
@@ -0,0 +1 @@
+3000
diff --git a/test/disk_tests/usages/sdh_udevadm b/test/disk_tests/usages/sdh_udevadm
new file mode 100644 (file)
index 0000000..3ff1a9e
--- /dev/null
@@ -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
diff --git a/test/disk_tests/usages/sdi/device/vendor b/test/disk_tests/usages/sdi/device/vendor
new file mode 100644 (file)
index 0000000..531030d
--- /dev/null
@@ -0,0 +1 @@
+ATA
diff --git a/test/disk_tests/usages/sdi/queue/rotational b/test/disk_tests/usages/sdi/queue/rotational
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/test/disk_tests/usages/sdi/size b/test/disk_tests/usages/sdi/size
new file mode 100644 (file)
index 0000000..13de30f
--- /dev/null
@@ -0,0 +1 @@
+3000
diff --git a/test/disk_tests/usages/sdi_udevadm b/test/disk_tests/usages/sdi_udevadm
new file mode 100644 (file)
index 0000000..a9eae5e
--- /dev/null
@@ -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
diff --git a/test/disk_tests/usages/sdj/device/vendor b/test/disk_tests/usages/sdj/device/vendor
new file mode 100644 (file)
index 0000000..531030d
--- /dev/null
@@ -0,0 +1 @@
+ATA
diff --git a/test/disk_tests/usages/sdj/queue/rotational b/test/disk_tests/usages/sdj/queue/rotational
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/test/disk_tests/usages/sdj/size b/test/disk_tests/usages/sdj/size
new file mode 100644 (file)
index 0000000..13de30f
--- /dev/null
@@ -0,0 +1 @@
+3000
diff --git a/test/disk_tests/usages/sdj_udevadm b/test/disk_tests/usages/sdj_udevadm
new file mode 100644 (file)
index 0000000..39d0cf3
--- /dev/null
@@ -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
index 902563c1f04634fa3118ca0e212ee21ddd1561b8..d9781ee38fe37b0149528721f894c9b0775342c4 100644 (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;