From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Subject: [Devel] [PATCH VZ10 v3 11/11] drivers/md/dm-qcow2: respect zeroes during merge
Date: Tue, 25 Aug 2026 15:24:30 +0300 [thread overview]
Message-ID: <20260825122430.252094-12-andrey.zhadchenko@virtuozzo.com> (raw)
In-Reply-To: <20260825122430.252094-1-andrey.zhadchenko@virtuozzo.com>
The merge machinery used to skip unallocated clusters, therefore
breaking all clusters with zero bits and non-zero backing.
Technically this bug was present even before discard changes, as
qcow2 image could have 'reads as zero' bits before being inserted
into dm-qcow2.
Properly commit all zero clusters (albeit with data for now).
https://virtuozzo.atlassian.net/browse/VSTOR-138288
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 41a504c65b722..e909548530d27 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2744,6 +2744,13 @@ static void requeue_if_ok(struct qcow2_target *tgt, struct qio *unused,
qcow2_dispatch_qios(qio->qcow2, qio, NULL);
}
+static bool clu_zeroes_present(struct qcow2 *qcow2, struct qcow2_map *map)
+{
+ if (qcow2->ext_l2)
+ return (map->ext_l2 >> 32) != 0;
+ return map->all_zeroes;
+}
+
static int prepare_backward_merge(struct qcow2 *qcow2, struct qio **qio,
struct qcow2_map *map, bool write)
{
@@ -2761,7 +2768,7 @@ static int prepare_backward_merge(struct qcow2 *qcow2, struct qio **qio,
}
}
- if (!map->data_clu_alloced) {
+ if (!map->data_clu_alloced && !clu_zeroes_present(qcow2, map)) {
/* Strange COW at L1, except the merge from RO image */
WARN_ON_ONCE(map->clu_is_cow && qio_may_modify_image(qcow2, *qio));
if (fake_merge_qio(*qio)) {
@@ -2808,7 +2815,7 @@ static int prepare_backward_merge(struct qcow2 *qcow2, struct qio **qio,
goto endio;
}
- if (!map->clu_is_cow) {
+ if (!map->clu_is_cow && map->data_clu_alloced) {
/* Forced set these to unuse them after discard */
(*qio)->ext->unuse_clu_pos = map->data_clu_pos;
(*qio)->ext->unuse_clu_end = map->data_clu_pos + qcow2->clu_size;
--
2.43.5
next prev parent reply other threads:[~2026-08-25 12:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 12:24 [Devel] [PATCH VZ10 v3 00/11] dm-qcow2: improve discard and read-only merge handling Andrey Zhadchenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 01/11] drivers/md/dm-qcow2: do not attach a bvec to discard qios Andrey Zhadchenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 02/11] drivers/md/dm-qcow2: fix revert_cluster_alloc() for ext_l2 case Andrey Zhadchenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 03/11] drivers/md/dm-qcow2: generalize COW index update machinery Andrey Zhadchenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 04/11] drivers/md/dm-qcow2: update metadata on whole cluster discard Andrey Zhadchenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 05/11] drivers/md/dm-qcow2: never trigger COW or allocation on discard Andrey Zhadchenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 06/11] drivers/md/dm-qcow2: set L2_READS_ALL_ZEROES after some discards Andrey Zhadchenko
2026-08-25 17:10 ` Konstantin Khorenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 07/11] drivers/md/dm-qcow2: update metadata on subclusters discard Andrey Zhadchenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 08/11] drivers/md/dm-qcow2: unmap cluster when discard clears last allocated subclusters Andrey Zhadchenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 09/11] drivers/md/dm-qcow2: do discards during backward merge only for writable image Andrey Zhadchenko
2026-08-25 17:12 ` Konstantin Khorenko
2026-08-25 12:24 ` [Devel] [PATCH VZ10 v3 10/11] drivers/md/dm-qcow2: allow shared L1 entries during merge from RO image Andrey Zhadchenko
2026-08-25 12:24 ` Andrey Zhadchenko [this message]
2026-08-25 16:54 ` [Devel] [PATCH VZ10 v3 00/11] dm-qcow2: improve discard and read-only merge handling Pavel Tikhomirov
2026-08-26 10:27 ` Vasileios Almpanis
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=20260825122430.252094-12-andrey.zhadchenko@virtuozzo.com \
--to=andrey.zhadchenko@virtuozzo.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.