From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 477D31FF0C0 for ; Wed, 18 Nov 2026 07:54:05 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A07CB21661; Wed, 18 Nov 2026 07:53:40 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v6 storage 16/42] diskmanage: look up the requested disks by name Date: Wed, 18 Nov 2026 07:52:33 +0100 Message-ID: <20261118065302.3033937-17-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118065302.3033937-1-t.lamprecht@proxmox.com> References: <20261118065302.3033937-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794984787942 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.183 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: D32SNFFUXZW3WAHPQKVNW6Q2NCDEASNI X-Message-ID-Hash: D32SNFFUXZW3WAHPQKVNW6Q2NCDEASNI X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: get_disks() turned the requested disks into one regular expression for its walk over /sys/block. The partition lookup of each disk in that walk goes through the same match with another expression, so perl compiled the expression with all names again for every disk. Other callers ask about a few disks only. But the SAN LUN inventory that follows asks about every disk that is not a path of a multipath map. On a lab node, the compiling cost 0.3 seconds for 1000 iSCSI disks and 1.2 seconds for 2000. A disk name is no pattern, so look it up as it is. Signed-off-by: Thomas Lamprecht --- src/PVE/Diskmanage.pm | 11 +++++++---- src/test/disklist_test.pm | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/PVE/Diskmanage.pm b/src/PVE/Diskmanage.pm index f1a5cd18..c4b4ce68 100644 --- a/src/PVE/Diskmanage.pm +++ b/src/PVE/Diskmanage.pm @@ -572,7 +572,7 @@ sub get_disks { my $lvmhash = get_lvm_devices($lsblk_info, $san_inventory); - my $disk_regex = ".*"; + my $wanted; if (defined($disks)) { if (!ref($disks)) { $disks = [$disks]; @@ -583,21 +583,24 @@ sub get_disks { $_ =~ s|cciss/|cciss!| for @$disks; if ($include_partitions) { - # Proper blockdevice is needed for the regex, use parent for partitions. + # Proper blockdevice is needed for the lookup, 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) . ")"; + # Not as one regex of all names: the lookup of the partitions of each disk below goes + # through the same match, so perl would compile that regex again for every disk. + $wanted = { map { $_ => 1 } @$disks }; } dir_glob_foreach( '/sys/block', - $disk_regex, + '.*', sub { my ($dev) = @_; + return if $wanted && !$wanted->{$dev}; # whitelisting following devices # - hdX ide block device # - sdX scsi/sata block device diff --git a/src/test/disklist_test.pm b/src/test/disklist_test.pm index 15068aba..dde3d29f 100644 --- a/src/test/disklist_test.pm +++ b/src/test/disklist_test.pm @@ -222,6 +222,8 @@ sub test_disk_list { $expected_disk_list->{$disk}, "disk $disk should be the same", ); + $testcount++; + is_deeply([keys %$disk_tmp], [$disk], "only disk $disk gets returned"); # test wrong parameter eval { PVE::Diskmanage::get_disks({ test => 1 }); };