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 6AA511FF13A for ; Wed, 13 May 2026 15:06:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4F58EDA5E; Wed, 13 May 2026 15:06:33 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH storage 3/8] api/cli: list content: declare size optional and add approximate-size Date: Wed, 13 May 2026 15:05:35 +0200 Message-ID: <20260513130548.143270-4-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260513130548.143270-1-f.ebner@proxmox.com> References: <20260513130548.143270-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1778677547963 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.009 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: JKHS2JHGPDSTGNFKMGJI7KGZWUFAZLYZ X-Message-ID-Hash: JKHS2JHGPDSTGNFKMGJI7KGZWUFAZLYZ X-MailFrom: f.ebner@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: For inactive qcow2 volumes on LVM, currently no size information is returned, because that would require activating each LV to scan the qcow2 header. For a shared LVM, an LV might already be active on another node, so it cannot be activated. Also, doing so for each volume would be costly. Prepare the API and CLI for handling an approximate size returned instead. Signed-off-by: Fiona Ebner --- src/PVE/API2/Storage/Content.pm | 15 ++++++++++++--- src/PVE/CLI/pvesm.pm | 22 +++++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/PVE/API2/Storage/Content.pm b/src/PVE/API2/Storage/Content.pm index 59ac0ba..cffb555 100644 --- a/src/PVE/API2/Storage/Content.pm +++ b/src/PVE/API2/Storage/Content.pm @@ -89,6 +89,15 @@ __PACKAGE__->register_method({ description => "Volume size in bytes.", type => 'integer', renderer => 'bytes', + optional => 1, + }, + 'approximate-size' => { + description => + "Approximate volume size in bytes. Present instead of 'size' for storages" + . " where determining the exact size has technical limitations.", + type => 'integer', + renderer => 'bytes', + optional => 1, }, used => { description => "Used space. Please note that most storage plugins " @@ -163,9 +172,9 @@ __PACKAGE__->register_method({ ); }; next if $@; - $item->{vmid} = int($item->{vmid}) if defined($item->{vmid}); - $item->{size} = int($item->{size}) if defined($item->{size}); - $item->{used} = int($item->{used}) if defined($item->{used}); + for my $prop (qw(approximate-size size used vmid)) { + $item->{$prop} = int($item->{$prop}) if defined($item->{$prop}); + } push @$res, $item; } diff --git a/src/PVE/CLI/pvesm.pm b/src/PVE/CLI/pvesm.pm index d34e520..523970f 100755 --- a/src/PVE/CLI/pvesm.pm +++ b/src/PVE/CLI/pvesm.pm @@ -198,30 +198,46 @@ my $print_content = sub { my ($list) = @_; my ($maxlenname, $maxsize) = (0, 0); + my $has_approximate_size; foreach my $info (@$list) { my $volid = $info->{volid}; my $sidlen = length($volid); $maxlenname = $sidlen if $sidlen > $maxlenname; - $maxsize = $info->{size} if ($info->{size} // 0) > $maxsize; + if (defined($info->{size})) { + $maxsize = $info->{size} if $info->{size} > $maxsize; + } elsif (defined($info->{'approximate-size'})) { + $has_approximate_size = 1; + $maxsize = $info->{'approximate-size'} if $info->{'approximate-size'} > $maxsize; + } } my $sizemaxdigits = length($maxsize); + $sizemaxdigits += 1 if $has_approximate_size; my $basefmt = "%-${maxlenname}s %-7s %-9s %${sizemaxdigits}s"; printf "$basefmt %s\n", "Volid", "Format", "Type", "Size", "VMID"; + my $get_size_str = sub { + my ($info) = @_; + return "$info->{size}" if defined($info->{size}); + return "~$info->{'approximate-size'}" if defined($info->{'approximate-size'}); + return "-"; + }; + foreach my $info (@$list) { next if !$info->{vmid}; my $volid = $info->{volid}; + my $size_str = $get_size_str->($info); - printf "$basefmt %d\n", $volid, $info->{format}, $info->{content}, $info->{size}, + printf "$basefmt %d\n", $volid, $info->{format}, $info->{content}, $size_str, $info->{vmid}; } foreach my $info (sort { $a->{format} cmp $b->{format} } @$list) { next if $info->{vmid}; my $volid = $info->{volid}; + my $size_str = $get_size_str->($info); - printf "$basefmt\n", $volid, $info->{format}, $info->{content}, $info->{size}; + printf "$basefmt\n", $volid, $info->{format}, $info->{content}, $size_str; } }; -- 2.47.3