From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id EED6A1FF0B7 for ; Fri, 13 Nov 2026 02:27:16 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A3C9E216F5; Fri, 13 Nov 2026 02:27:12 +0100 (CET) From: Thomas Lamprecht 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 Message-ID: <20261113012702.864671-3-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113012702.864671-1-t.lamprecht@proxmox.com> References: <20261113012702.864671-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794533227762 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.251 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: SBJK3F2SHE3YJ43ZPJ6VL67SZ7QTE4AF X-Message-ID-Hash: SBJK3F2SHE3YJ43ZPJ6VL67SZ7QTE4AF X-MailFrom: t.lamprecht@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: 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 --- 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