From: Thomas Lamprecht <t.lamprecht@proxmox.com>
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 [thread overview]
Message-ID: <20261113012702.864671-2-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261113012702.864671-1-t.lamprecht@proxmox.com>
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 <t.lamprecht@proxmox.com>
---
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
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 ` Thomas Lamprecht [this message]
2026-11-13 1:17 ` [PATCH storage 2/3] lvm: qcow2 resize: size the LV for the cluster settings of the image Thomas Lamprecht
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-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox