diskmanage: allow passing partitions to get_disks
Requires that the $include_partitions parameter is set too, which: 1. Makes sense, because the partition won't be included in the result otherwise. 2. Ensures backwards compatibility for existing callers that don't use $include_partitions. No existing callers use both $disks and $include_partitions at the same time, so nothing learns to "support" partitions by accident. Moving the strip_dev helper to the top, so it can be used everywhere. Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
committed by
Thomas Lamprecht
parent
0f4533476d
commit
a64aedd3eb
@ -20,6 +20,12 @@ my $PVS = "/sbin/pvs";
|
|||||||
my $LVS = "/sbin/lvs";
|
my $LVS = "/sbin/lvs";
|
||||||
my $LSBLK = "/bin/lsblk";
|
my $LSBLK = "/bin/lsblk";
|
||||||
|
|
||||||
|
my sub strip_dev :prototype($) {
|
||||||
|
my ($devpath) = @_;
|
||||||
|
$devpath =~ s|^/dev/||;
|
||||||
|
return $devpath;
|
||||||
|
}
|
||||||
|
|
||||||
sub check_bin {
|
sub check_bin {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
return -x $path;
|
return -x $path;
|
||||||
@ -518,6 +524,14 @@ sub get_disks {
|
|||||||
# we get cciss/c0d0 but need cciss!c0d0
|
# we get cciss/c0d0 but need cciss!c0d0
|
||||||
$_ =~ s|cciss/|cciss!| for @$disks;
|
$_ =~ s|cciss/|cciss!| for @$disks;
|
||||||
|
|
||||||
|
if ($include_partitions) {
|
||||||
|
# Proper blockdevice is needed for the regex, use parent for partitions.
|
||||||
|
for my $disk ($disks->@*) {
|
||||||
|
next if !is_partition("/dev/$disk");
|
||||||
|
$disk = strip_dev(get_blockdev("/dev/$disk"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$disk_regex = "(?:" . join('|', @$disks) . ")";
|
$disk_regex = "(?:" . join('|', @$disks) . ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -847,12 +861,6 @@ sub append_partition {
|
|||||||
return $partition;
|
return $partition;
|
||||||
}
|
}
|
||||||
|
|
||||||
my sub strip_dev :prototype($) {
|
|
||||||
my ($devpath) = @_;
|
|
||||||
$devpath =~ s|^/dev/||;
|
|
||||||
return $devpath;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if a disk or any of its partitions has a holder.
|
# Check if a disk or any of its partitions has a holder.
|
||||||
# Can also be called with a partition.
|
# Can also be called with a partition.
|
||||||
# Expected to be called with a result of verify_blockdev_path().
|
# Expected to be called with a result of verify_blockdev_path().
|
||||||
|
|||||||
Reference in New Issue
Block a user