[pve-devel] [PATCH storage v2 2/4] Diskmanage: allow get_disks to take multiple disks
Dominik Csapak
d.csapak at proxmox.com
Tue Jun 4 12:35:22 CEST 2019
we now expect the first parameter to be either a string with a single
disk, or an array ref with a list of disks
this way we can get the info of multiple disks simultaneously while
not iterating over all disks
this will be used to get the info for osd/db/wal disk
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* disk_regex instead of path
* die if disks is not the right type
* map cciss instead of looping
PVE/Diskmanage.pm | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index a7a7e70..281b378 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -416,7 +416,7 @@ sub is_iscsi {
}
sub get_disks {
- my ($disk, $nosmart) = @_;
+ my ($disks, $nosmart) = @_;
my $disklist = {};
my $mounted = {};
@@ -440,14 +440,21 @@ sub get_disks {
my $lvmlist = get_lvm_devices();
- # we get cciss/c0d0 but need cciss!c0d0
- if (defined($disk) && $disk =~ m|^cciss/|) {
- $disk =~ s|cciss/|cciss!|;
+ my $disk_regex = ".*";
+ if (defined($disks)) {
+ if (!ref($disks)) {
+ $disks = [ $disks ];
+ } elsif (ref($disks) ne 'ARRAY') {
+ die "disks is not a string or array reference\n";
+ }
+ # we get cciss/c0d0 but need cciss!c0d0
+ map { s|cciss/|cciss!| } @$disks;
+
+ $disk_regex = "(?:" . join('|', @$disks) . ")";
}
- dir_glob_foreach('/sys/block', '.*', sub {
+ dir_glob_foreach('/sys/block', $disk_regex, sub {
my ($dev) = @_;
- return if defined($disk) && $disk ne $dev;
# whitelisting following devices
# hdX: ide block device
# sdX: sd block device
--
2.11.0
More information about the pve-devel
mailing list