From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 8B8CF1FF0AA for ; Tue, 17 Nov 2026 21:41:47 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 749C82179A; Tue, 17 Nov 2026 21:40:52 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 11/51] plugin: use closure for inner loop logic in list_volumes Date: Tue, 17 Nov 2026 21:38:43 +0100 Message-ID: <20261117203953.913035-12-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117203953.913035-1-m.carrara@proxmox.com> References: <20261117203953.913035-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: 1794948016602 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.268 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: BTALH5GZG7DRVQH2WF6QLALUC2NQWGUF X-Message-ID-Hash: BTALH5GZG7DRVQH2WF6QLALUC2NQWGUF 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 CC: Wolfgang Bumiller 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 | 56 ++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 61f6f221..df8526bd 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -2021,36 +2021,54 @@ 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 (VM or CT) corresponds to the + # volume's type. + if ($type eq 'images' || $type eq 'rootdir') { + my (undef, $volname) = parse_volume_id($volume->{volid}); + my $parsed_vtype = eval { ($class->parse_volname($volname))[0] } // ''; + + my $vminfo = $vmlist->{ids}->{ $volume->{vmid} }; + + my $vmtype; + if (defined($vminfo)) { + $vmtype = $vminfo->{type}; + } + + my $expected_vtype; + if ($parsed_vtype eq 'ct-vol' || (defined($vmtype) && $vmtype eq 'lxc')) { + $expected_vtype = 'rootdir'; + } else { + $expected_vtype = 'images'; + } + + return if $expected_vtype 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 (undef, $volname) = parse_volume_id($item->{volid}); - my $vtype = eval { ($class->parse_volname($volname))[0] } // ''; + for my $volume ($raw_volumes->@*) { + my $content_type = $get_content_type_for_volume->($volume, $type); - my $vminfo = $vmlist->{ids}->{ $item->{vmid} }; - my $vmtype; - if (defined($vminfo)) { - $vmtype = $vminfo->{type}; - } - if ($vtype eq 'ct-vol' || (defined($vmtype) && $vmtype eq 'lxc')) { - $item->{content} = 'rootdir'; - } else { - $item->{content} = 'images'; - } - next if $type ne $item->{content}; - } else { - $item->{content} = $type; - } + next if !defined($content_type); - push $res->@*, $item; + $volume->{content} = $content_type; + push $res->@*, $volume; } } return $res; } -- 2.47.3