From: Fiona Ebner <f.ebner@proxmox.com>
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 [thread overview]
Message-ID: <20260513130548.143270-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20260513130548.143270-1-f.ebner@proxmox.com>
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 <f.ebner@proxmox.com>
---
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
next prev parent reply other threads:[~2026-05-13 13:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 13:05 [PATCH-SERIES storage/manager/container/qemu-server 0/8] fix #6819: lvm plugin: list images: use approximate size for inactive qcow2 volumes Fiona Ebner
2026-05-13 13:05 ` [PATCH storage 1/8] api: content: add missing imports and group/order according to style guide Fiona Ebner
2026-05-13 13:05 ` [PATCH storage 2/8] pvesm: " Fiona Ebner
2026-05-13 13:05 ` Fiona Ebner [this message]
2026-05-13 13:05 ` [PATCH storage 4/8] fix #6819: lvm plugin: list images: use approximate size for inactive qcow2 volumes Fiona Ebner
2026-05-13 13:05 ` [PATCH manager 5/8] fix #6819: storage: content view: fallback to approximate size Fiona Ebner
2026-05-13 13:05 ` [PATCH container 6/8] volume rescan: also consider zero-sized volumes Fiona Ebner
2026-05-13 13:05 ` [PATCH container 7/8] volume rescan: also consider volumes listed only with an approximate size Fiona Ebner
2026-05-13 13:05 ` [PATCH qemu-server 8/8] " Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260513130548.143270-4-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.