From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage 2/3] lvm: qcow2 resize: size the LV for the cluster settings of the image
Date: Fri, 13 Nov 2026 02:17:24 +0100 [thread overview]
Message-ID: <20261113012702.864671-3-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261113012702.864671-1-t.lamprecht@proxmox.com>
When resizing, the LV size was always measured for 64 KiB clusters
without extended L2 entries, which are the settings of base images.
Snapshot overlays use 128 KiB clusters with extended L2 entries, for
which 'qemu-img measure' reports a different size. For small overlays,
the result could be a few hundred KiB too small, which the rounding up
to full extents usually, but not always, covers. For large overlays,
the LV got bigger than needed, by 14 MiB for 900 GiB for example.
Measure with the cluster settings of the image that is resized.
Fixes: eda88c94 ("lvmplugin: add qcow2 snapshot")
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
src/PVE/Storage/LVMPlugin.pm | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index d9845e4d..6b9867f3 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -1303,14 +1303,12 @@ my sub lvm_qcow2_format {
}
my sub calculate_lvm_size {
- my ($size, $fmt, $backing_snap) = @_;
+ my ($size, $fmt, $measure_options) = @_;
#input size = qcow2 image size in kb
return $size if $fmt ne 'qcow2';
- my $options = $backing_snap ? ['extended_l2=on', 'cluster_size=128k'] : [];
-
- my $json = PVE::Storage::Common::qemu_img_measure($size, $fmt, 5, $options);
+ my $json = PVE::Storage::Common::qemu_img_measure($size, $fmt, 5, $measure_options);
die "failed to query file information with qemu-img measure\n" if !$json;
my $info = eval { decode_json($json) };
if ($@) {
@@ -1322,6 +1320,21 @@ my sub calculate_lvm_size {
return $info->{'fully-allocated'} / 1024;
}
+# snapshot overlays use other cluster settings than base images, which changes the measured size
+my sub qcow2_measure_options {
+ my ($path) = @_;
+
+ my $json = PVE::Storage::Common::qemu_img_info($path, 'qcow2', 10);
+ my $info = eval { decode_json($json) } // {};
+ my $cluster_size = $info->{'cluster-size'}
+ or die "unable to determine the cluster size of '$path'\n";
+
+ my $options = ["cluster_size=$cluster_size"];
+ push $options->@*, 'extended_l2=on' if $info->{'format-specific'}->{data}->{'extended-l2'};
+
+ return $options;
+}
+
my sub alloc_lvm_image {
my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size, $backing_snap) = @_;
@@ -1340,7 +1353,8 @@ my sub alloc_lvm_image {
die "no such volume group '$vg'\n" if !defined($vgs->{$vg});
my $free = int($vgs->{$vg}->{free});
- my $lvmsize = calculate_lvm_size($size, $fmt, $backing_snap);
+ my $measure_options = $backing_snap ? ['extended_l2=on', 'cluster_size=128k'] : [];
+ my $lvmsize = calculate_lvm_size($size, $fmt, $measure_options);
die "not enough free space ($free < $size)\n" if $free < $size;
@@ -1691,10 +1705,11 @@ sub volume_resize {
my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) =
$class->parse_volname($volname);
- my $lvmsize = calculate_lvm_size($size / 1024, $format);
-
my $path = $class->path($scfg, $volname, $storeid, $snapname);
+ my $measure_options = $format eq 'qcow2' ? qcow2_measure_options($path) : undef;
+ my $lvmsize = calculate_lvm_size($size / 1024, $format, $measure_options);
+
# For qcow2, the expected size of the LV might get out of sync, so check.
my ($skip_lvextend, $old_lvmsize);
if ($format eq 'qcow2') {
--
2.47.3
next prev parent reply other threads:[~2026-11-13 1:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 1:17 [PATCH storage 0/3] lvm: fix qcow2 images outgrowing their LV Thomas Lamprecht
2026-11-13 1:17 ` [PATCH storage 1/3] lvm: avoid qcow2 images outgrowing their LV after offline snapshot delete Thomas Lamprecht
2026-11-13 1:17 ` Thomas Lamprecht [this message]
2026-11-13 1:17 ` [PATCH storage 3/3] lvm: qcow2: reserve LV space for persistent dirty bitmaps Thomas Lamprecht
2026-11-13 9:54 ` Fiona Ebner
2026-11-13 11:12 ` Thomas Lamprecht
2026-11-13 12:33 ` applied: " Fiona Ebner
2026-11-13 9:52 ` applied: (subset) [PATCH storage 0/3] lvm: fix qcow2 images outgrowing their LV 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=20261113012702.864671-3-t.lamprecht@proxmox.com \
--to=t.lamprecht@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.