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 B8A471FF0B7 for ; Fri, 13 Nov 2026 02:27:49 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 8744B21758; Fri, 13 Nov 2026 02:27:13 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH storage 1/3] lvm: avoid qcow2 images outgrowing their LV after offline snapshot delete Date: Fri, 13 Nov 2026 02:17:23 +0100 Message-ID: <20261113012702.864671-2-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: 1794533227689 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.252 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: IAN6T23RMLDBRS553LNKDN5QWH2TXGYO X-Message-ID-Hash: IAN6T23RMLDBRS553LNKDN5QWH2TXGYO 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: Deleting the oldest snapshot of a stopped VM commits the current image into the snapshot image with 'qemu-img commit'. For every range that the overlay holds as zeroes, the commit job writes zeroes with unmap to the base. Such ranges come from guest discards, but also from zero writes detected by the default 'detect-zeroes=on'. Without the 'discard-no-unref' option, qcow2 then drops the preallocated clusters of the base image that these ranges fully cover. Guest writes to such ranges later need newly allocated clusters. The allocator searches forward from a cursor that only moves back when clusters get freed, and skips holes that are too small for a request. So the image can grow beyond the size reported by 'qemu-img measure', and thus beyond its LV, while free clusters remain inside it. Writes then fail with ENOSPC, which pauses the VM with the default error policy. Set 'discard-no-unref' for the base image of the commit, as qemu-server commit a3a9a2ab ("fix #6543: use qcow2 'discard-no-unref' option when using snapshot-as-volume-chain") already does for running VMs and 'qemu-img convert'. Images that already lost clusters stay affected until they are moved to a newly allocated volume. Fixes: eda88c94 ("lvmplugin: add qcow2 snapshot") Signed-off-by: Thomas Lamprecht --- src/PVE/Storage/LVMPlugin.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm index 1b0c8020..d9845e4d 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -1910,7 +1910,10 @@ sub volume_snapshot_delete { print "running 'qemu-img commit $childpath'\n"; #can't use -d here, as it's an lvm volume - $cmd = ['/usr/bin/qemu-img', 'commit', '--', $childpath]; + # keep preallocated base clusters, freeing them lets the image outgrow the LV + my $opts = "driver=qcow2,file.driver=host_device,file.filename=$childpath" + . ",backing.discard-no-unref=on"; + $cmd = ['/usr/bin/qemu-img', 'commit', '--image-opts', '--', $opts]; eval { run_command($cmd) }; if ($@) { warn -- 2.47.3