From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 38FBD1FF13B for ; Wed, 22 Apr 2026 13:15:19 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2D3C91775E; Wed, 22 Apr 2026 13:14:21 +0200 (CEST) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v1 12/54] plugin: use closure for inner loop logic in list_volumes Date: Wed, 22 Apr 2026 13:12:38 +0200 Message-ID: <20260422111322.257380-13-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260422111322.257380-1-m.carrara@proxmox.com> References: <20260422111322.257380-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1776856327895 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.086 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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: WKOEXY2GOQUR4JOTHHBE5VEA7J5ZD6NI X-Message-ID-Hash: WKOEXY2GOQUR4JOTHHBE5VEA7J5ZD6NI X-MailFrom: m.carrara@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: Factor most of the body of the inner loop of the `list_volumes()` plugin API method into a closure and provide additional context for why we have such an elaborate check for VM / CT disks in the first place. This has the added benefit that we now also do not modify the volume hashes on the fly anymore when determining whether a volume's type aligns with a guest's type. Small difference, but might make it a little easier to adapt that code in the future, e.g. when we align vtypes and content types. Also, rename `$item` to `$volume` for clarity's sake. Signed-off-by: Max R. Carrara --- src/PVE/Storage/Plugin.pm | 49 +++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 106cff6f..c96c1ed7 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1820,29 +1820,44 @@ sub list_volumes { return; }; + my $get_content_type_for_volume = sub { + my ($volume, $type) = @_; + + # It is currently impossible to determine whether a volume belongs to a + # VM or a CT based on the output of list_images alone. + # Therefore, we use the parsed ID ($volume->{vmid}) to look up the guest + # and make sure that the guest's type corresponds to the volume's type. + if ($type eq 'images' || $type eq 'rootdir') { + my $vminfo = $vmlist->{ids}->{ $volume->{vmid} }; + + my $vmtype; + if (defined($vminfo)) { + $vmtype = $vminfo->{type}; + } + + my $content_type = 'images'; + if (defined($vmtype) && $vmtype eq 'lxc') { + $content_type = 'rootdir'; + } + + return if $content_type ne $type; + } + + return $type; + }; + for my $type ($content_types->@*) { my $raw_volumes = $get_raw_volumes_for_type->($type); next if !defined($raw_volumes); - for my $item ($raw_volumes->@*) { - if ($type eq 'images' || $type eq 'rootdir') { - my $vminfo = $vmlist->{ids}->{ $item->{vmid} }; - my $vmtype; - if (defined($vminfo)) { - $vmtype = $vminfo->{type}; - } - if (defined($vmtype) && $vmtype eq 'lxc') { - $item->{content} = 'rootdir'; - } else { - $item->{content} = 'images'; - } - next if $type ne $item->{content}; - } else { - $item->{content} = $type; - } + for my $volume ($raw_volumes->@*) { + my $content_type = $get_content_type_for_volume->($volume, $type); - push $res->@*, $item; + next if !defined($content_type); + + $volume->{content} = $content_type; + push $res->@*, $volume; } } -- 2.47.3