my $SGDISK = "/sbin/sgdisk";
my $PVS = "/sbin/pvs";
my $LVS = "/sbin/lvs";
-my $UDEVADM = "/bin/udevadm";
my $LSBLK = "/bin/lsblk";
sub verify_blockdev_path {
} elsif (defined($type) && $type eq 'text') {
$smartdata->{text} = '' if !defined $smartdata->{text};
$smartdata->{text} .= "$line\n";
- # extract wearout from nvme text, allow for decimal values
- if ($line =~ m/Percentage Used:\s*(\d+(?:\.\d+)?)\%/i) {
+ # extract wearout from nvme/sas text, allow for decimal values
+ if ($line =~ m/Percentage Used(?: endurance indicator)?:\s*(\d+(?:\.\d+)?)\%/i) {
$smartdata->{wearout} = 100 - $1;
}
} elsif ($line =~ m/SMART Disabled/) {
return $smartdata;
}
-sub get_parttype_info() {
+sub get_lsblk_info() {
my $cmd = [$LSBLK, '--json', '-o', 'path,parttype'];
my $output = "";
my $res = {};
warn "$@\n" if $@;
my $list = $parsed->{blockdevices} // [];
- foreach my $dev (@$list) {
- next if !($dev->{parttype});
- my $type = $dev->{parttype};
- $res->{$type} = [] if !defined($res->{$type});
- push @{$res->{$type}}, $dev->{path};
- }
+ $res = { map {
+ $_->{path} => { parttype => $_->{parttype} }
+ } @{$list} };
return $res;
}
my $get_devices_by_partuuid = sub {
- my ($parttype_map, $uuids, $res) = @_;
+ my ($lsblk_info, $uuids, $res) = @_;
$res = {} if !defined($res);
- foreach my $uuid (sort keys %$uuids) {
- map { $res->{$_} = $uuids->{$uuid} } @{$parttype_map->{$uuid}};
+ foreach my $dev (sort keys %{$lsblk_info}) {
+ my $uuid = $lsblk_info->{$dev}->{parttype};
+ next if !defined($uuid) || !defined($uuids->{$uuid});
+ $res->{$dev} = $uuids->{$uuid};
}
return $res;
};
sub get_zfs_devices {
- my ($parttype_map) = @_;
+ my ($lsblk_info) = @_;
my $res = {};
return {} if ! -x $ZPOOL;
};
- $res = $get_devices_by_partuuid->($parttype_map, $uuids, $res);
+ $res = $get_devices_by_partuuid->($lsblk_info, $uuids, $res);
return $res;
}
sub get_lvm_devices {
- my ($parttype_map) = @_;
+ my ($lsblk_info) = @_;
my $res = {};
eval {
run_command([$PVS, '--noheadings', '--readonly', '-o', 'pv_name'], outfunc => sub{
"e6d6d379-f507-44c2-a23c-238f2a3df928" => 1,
};
- $res = $get_devices_by_partuuid->($parttype_map, $uuids, $res);
+ $res = $get_devices_by_partuuid->($lsblk_info, $uuids, $res);
return $res;
}
sub get_ceph_journals {
- my ($parttype_map) = @_;
+ my ($lsblk_info) = @_;
my $res = {};
my $uuids = {
'cafecafe-9b03-4f30-b4c6-b4b80ceff106' => 4, # block
};
- $res = $get_devices_by_partuuid->($parttype_map, $uuids, $res);
+ $res = $get_devices_by_partuuid->($lsblk_info, $uuids, $res);
return $res;
}
my $info = "";
my $data = {};
eval {
- run_command([$UDEVADM, 'info', '-p', $dev, '--query', 'all'], outfunc => sub {
+ run_command(['udevadm', 'info', '-p', $dev, '--query', 'all'], outfunc => sub {
my ($line) = @_;
$info .= "$line\n";
});
$mounted->{abs_path($mount->[0])} = $mount->[1];
};
- my $dev_is_mounted = sub {
- my ($dev) = @_;
- return $mounted->{$dev};
- };
+ my $lsblk_info = get_lsblk_info();
- my $parttype_map = get_parttype_info();
-
- my $journalhash = get_ceph_journals($parttype_map);
+ my $journalhash = get_ceph_journals($lsblk_info);
my $ceph_volume_infos = get_ceph_volume_infos();
- my $zfshash = get_zfs_devices($parttype_map);
+ my $zfshash = get_zfs_devices($lsblk_info);
- my $lvmhash = get_lvm_devices($parttype_map);
+ my $lvmhash = get_lvm_devices($lsblk_info);
my $disk_regex = ".*";
if (defined($disks)) {
die "disks is not a string or array reference\n";
}
# we get cciss/c0d0 but need cciss!c0d0
- map { s|cciss/|cciss!| } @$disks;
+ $_ =~ s|cciss/|cciss!| for @$disks;
$disk_regex = "(?:" . join('|', @$disks) . ")";
}
$used = 'LVM' if $lvmhash->{$devpath};
- $used = 'mounted' if &$dev_is_mounted($devpath);
+ $used = 'mounted' if $mounted->{$devpath};
$used = 'ZFS' if $zfshash->{$devpath};
$found_partitions = 1;
- if (my $mp = &$dev_is_mounted("$partpath/$part")) {
+ if (my $mp = $mounted->{"$partpath/$part"}) {
$found_mountpoints = 1;
if ($mp =~ m|^/var/lib/ceph/osd/ceph-(\d+)$|) {
$osdid = $1;
sub get_blockdev {
my ($part_path) = @_;
- my $dev = $1 if $part_path =~ m|^/dev/(.*)$|;
- my $link = readlink "/sys/class/block/$dev";
- my $block_dev = $1 if $link =~ m|([^/]*)/$dev$|;
+ my ($dev, $block_dev);
+ if ($part_path =~ m|^/dev/(.*)$|) {
+ $dev = $1;
+ my $link = readlink "/sys/class/block/$dev";
+ $block_dev = $1 if $link =~ m|([^/]*)/$dev$|;
+ }
die "Can't parse parent device\n" if !defined($block_dev);
die "No valid block device\n" if index($dev, $block_dev) == -1;