All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Jean-Louis Dupond <jean-louis@dupond.be>
Cc: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org, hreitz@redhat.com,
	den@openvz.org
Subject: Re: [PATCH 2/3] qcow2: fix snapshot data corruption with discard-no-unref=on
Date: Tue, 3 Nov 2026 17:06:40 +0100	[thread overview]
Message-ID: <auoGkJ_RCxFRjh3U@redhat.com> (raw)
In-Reply-To: <713e8c49-5a9c-4d42-9038-8b6f9cc70260@dupond.be>

Am 29.10.2026 um 15:58 hat Jean-Louis Dupond geschrieben:
> 
> On 27/10/2026 11:44, Andrey Drobyshev wrote:
> > Whenever option discard-no-unref=on is enabled, we bypass refcount
> > machinery and unconditionally punch hole in the data on 'discard' and
> > 'write -z -u' paths.  However, when this same cluster is also referenced
> > by an internal snapshot, such operations lead to problems.  The active L2
> > table is copied before it is changed, so the snapshot metadata stays
> > correct, but the host range under it is punched out and the snapshot reads
> > zeroes there afterwards. qemu-img check finds nothing wrong.
> > 
> > Fix this by guarding the 'keep_reference' flag by the presence of the
> > QCOW_OFLAG_COPIED bit.  I.e. only proceed with unconditional data
> > punching if we own this cluster exclusively.
> > 
> > Fixes: 42a2890a76f4 ("qcow2: add discard-no-unref option")
> > Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
> > ---
> >   block/qcow2-cluster.c | 6 ++++--
> >   1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> > index e02fae6a0c6..cc473c7c796 100644
> > --- a/block/qcow2-cluster.c
> > +++ b/block/qcow2-cluster.c
> > @@ -1953,6 +1953,7 @@ discard_in_l2_slice(BlockDriverState *bs, uint64_t offset, uint64_t nb_clusters,
> >           QCow2ClusterType cluster_type =
> >               qcow2_get_cluster_type(bs, old_l2_entry);
> >           bool keep_reference = (cluster_type != QCOW2_CLUSTER_COMPRESSED) &&
> > +                              (old_l2_entry & QCOW_OFLAG_COPIED) &&
> >                                 !full_discard &&
> >                                 (s->discard_no_unref &&
> >                                  type == QCOW2_DISCARD_REQUEST);
> 
> Wouldn't it be better to gate only qcow2_discard_cluster when the cluster is
> QCOW_OFLAG_COPIED?
> Cause with the above change, we fully clear/remove the offset of the
> cluster, causing fragmentation again in the image afterwards.
> And that was just the goal for discard-no-unref :)

I thought of this, too, but merely because it seems to be a closer match
for the expectation the name "discard-no-unref" sets.

In practice, I don't expect that you'd see any advantage from it.
Writing again to this cluster will cause COW, so you'll get
fragmentation either way.

Kevin



  reply	other threads:[~2026-11-03 16:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 10:44 [PATCH 0/3] qcow2: fix discard-no-unref=on data corruption Andrey Drobyshev
2026-10-27 10:44 ` [PATCH 1/3] iotests/290: add test case to check 'discard-no-unref' option behavior Andrey Drobyshev
2026-10-29 14:58   ` Jean-Louis Dupond
2026-11-05 15:59     ` Andrey Drobyshev
2026-11-03 15:53   ` Kevin Wolf
2026-11-05 15:59     ` Andrey Drobyshev
2026-10-27 10:44 ` [PATCH 2/3] qcow2: fix snapshot data corruption with discard-no-unref=on Andrey Drobyshev
2026-10-29 14:58   ` Jean-Louis Dupond
2026-11-03 16:06     ` Kevin Wolf [this message]
2026-11-05 16:00       ` Andrey Drobyshev
2026-10-27 10:44 ` [PATCH 3/3] iotests/290: add 'discard' and 'write -z -u' case with a snapshot Andrey Drobyshev
2026-10-27 11:39 ` [PATCH 0/3] qcow2: fix discard-no-unref=on data corruption Denis V. Lunev
2026-11-03 16:07 ` Kevin Wolf

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=auoGkJ_RCxFRjh3U@redhat.com \
    --to=kwolf@redhat.com \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=hreitz@redhat.com \
    --cc=jean-louis@dupond.be \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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.