Diskmanage: refactor and rename get_parttype_info
in preparation to also query the file system type from lsblk. Note that the result now also includes devices without a parttype, so a definedness check in get_devices_by_partuuid is needed. This will be useful when the whole device contains a filesystem. Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
committed by
Thomas Lamprecht
parent
0cca5356bb
commit
b6bbc2ab28
@ -156,7 +156,7 @@ sub get_smart_data {
|
|||||||
return $smartdata;
|
return $smartdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_parttype_info() {
|
sub get_lsblk_info() {
|
||||||
my $cmd = [$LSBLK, '--json', '-o', 'path,parttype'];
|
my $cmd = [$LSBLK, '--json', '-o', 'path,parttype'];
|
||||||
my $output = "";
|
my $output = "";
|
||||||
my $res = {};
|
my $res = {};
|
||||||
@ -173,30 +173,29 @@ sub get_parttype_info() {
|
|||||||
warn "$@\n" if $@;
|
warn "$@\n" if $@;
|
||||||
my $list = $parsed->{blockdevices} // [];
|
my $list = $parsed->{blockdevices} // [];
|
||||||
|
|
||||||
foreach my $dev (@$list) {
|
$res = { map {
|
||||||
next if !($dev->{parttype});
|
$_->{path} => { parttype => $_->{parttype} }
|
||||||
my $type = $dev->{parttype};
|
} @{$list} };
|
||||||
$res->{$type} = [] if !defined($res->{$type});
|
|
||||||
push @{$res->{$type}}, $dev->{path};
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $get_devices_by_partuuid = sub {
|
my $get_devices_by_partuuid = sub {
|
||||||
my ($parttype_map, $uuids, $res) = @_;
|
my ($lsblk_info, $uuids, $res) = @_;
|
||||||
|
|
||||||
$res = {} if !defined($res);
|
$res = {} if !defined($res);
|
||||||
|
|
||||||
foreach my $uuid (sort keys %$uuids) {
|
foreach my $dev (sort keys %{$lsblk_info}) {
|
||||||
map { $res->{$_} = $uuids->{$uuid} } @{$parttype_map->{$uuid}};
|
my $uuid = $lsblk_info->{$dev}->{parttype};
|
||||||
|
next if !defined($uuid) || !defined($uuids->{$uuid});
|
||||||
|
$res->{$dev} = $uuids->{$uuid};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
};
|
};
|
||||||
|
|
||||||
sub get_zfs_devices {
|
sub get_zfs_devices {
|
||||||
my ($parttype_map) = @_;
|
my ($lsblk_info) = @_;
|
||||||
my $res = {};
|
my $res = {};
|
||||||
|
|
||||||
return {} if ! -x $ZPOOL;
|
return {} if ! -x $ZPOOL;
|
||||||
@ -224,13 +223,13 @@ sub get_zfs_devices {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$res = $get_devices_by_partuuid->($parttype_map, $uuids, $res);
|
$res = $get_devices_by_partuuid->($lsblk_info, $uuids, $res);
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_lvm_devices {
|
sub get_lvm_devices {
|
||||||
my ($parttype_map) = @_;
|
my ($lsblk_info) = @_;
|
||||||
my $res = {};
|
my $res = {};
|
||||||
eval {
|
eval {
|
||||||
run_command([$PVS, '--noheadings', '--readonly', '-o', 'pv_name'], outfunc => sub{
|
run_command([$PVS, '--noheadings', '--readonly', '-o', 'pv_name'], outfunc => sub{
|
||||||
@ -250,13 +249,13 @@ sub get_lvm_devices {
|
|||||||
"e6d6d379-f507-44c2-a23c-238f2a3df928" => 1,
|
"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;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_ceph_journals {
|
sub get_ceph_journals {
|
||||||
my ($parttype_map) = @_;
|
my ($lsblk_info) = @_;
|
||||||
my $res = {};
|
my $res = {};
|
||||||
|
|
||||||
my $uuids = {
|
my $uuids = {
|
||||||
@ -266,7 +265,7 @@ sub get_ceph_journals {
|
|||||||
'cafecafe-9b03-4f30-b4c6-b4b80ceff106' => 4, # block
|
'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;
|
return $res;
|
||||||
}
|
}
|
||||||
@ -479,14 +478,14 @@ sub get_disks {
|
|||||||
$mounted->{abs_path($mount->[0])} = $mount->[1];
|
$mounted->{abs_path($mount->[0])} = $mount->[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
my $parttype_map = get_parttype_info();
|
my $lsblk_info = get_lsblk_info();
|
||||||
|
|
||||||
my $journalhash = get_ceph_journals($parttype_map);
|
my $journalhash = get_ceph_journals($lsblk_info);
|
||||||
my $ceph_volume_infos = get_ceph_volume_infos();
|
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 = ".*";
|
my $disk_regex = ".*";
|
||||||
if (defined($disks)) {
|
if (defined($disks)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user