* [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters
@ 2026-11-19 14:30 Denis V. Lunev
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image Denis V. Lunev
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Denis V. Lunev @ 2026-11-19 14:30 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis; +Cc: devel
An online backward merge copies the compressed clusters of the top image
into the lower image raw, so the merged device returns compressed
streams instead of data, and qemu-img check sees nothing wrong. Read
them through the decompression path instead. A failed decompression
setup also leaves one read, COW or merge qio unfinished, which would
now stall the merge.
https://virtuozzo.atlassian.net/browse/VSTOR-156064
Applies on top of the series "dm-qcow2: fix a read livelock at EOF of a
read-only image" v2.
Tested in an HCI 8.2 VM: the merged device matches the chain on zstd,
zlib and ext_l2 images, a failed buffer allocation ends the read
instead of hanging it, and the ploop test suite passes in qcow2 and
ploop formats.
Denis V. Lunev (2):
dm-qcow2: decompress compressed clusters merged into the lower image
dm-qcow2: end the popped qio when decompression setup fails
drivers/md/dm-qcow2-map.c | 43 +++++++++++++++++++++++++++++++--------
1 file changed, 34 insertions(+), 9 deletions(-)
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image
2026-11-19 14:30 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Denis V. Lunev
@ 2026-11-19 14:30 ` Denis V. Lunev
2026-11-19 14:39 ` no-reply
2026-11-19 16:45 ` Konstantin Khorenko
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: end the popped qio when decompression setup fails Denis V. Lunev
` (3 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Denis V. Lunev @ 2026-11-19 14:30 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
During a backward merge, process_one_qio() sends each merge qio of the
top image to submit_top_delta_read() before it checks map.compressed.
That read takes clu_size bytes from the compressed data offset, and
process_backward_merge_write() writes them into the lower image as a
plain cluster. After the merge the device returns the compressed
stream, and whatever follows it in the file, instead of the data, and
qemu-img check finds nothing wrong. If the raw read runs past the end
of the top image, the merge fails with -EIO instead, or never ends on
a kernel that resubmits a 0-byte read.
A guest write to a compressed cluster during the merge takes the same
path, and so does a guest read, which becomes a merge qio first.
Read such a cluster with submit_read_compressed(), as a COW does, but
with the copy mask of the merge and new_ext_l2 left 0 for the discard
of the top entry, and pass the decompressed slices on to the merge
write instead of the COW write.
https://virtuozzo.atlassian.net/browse/VSTOR-156064
Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
drivers/md/dm-qcow2-map.c | 41 ++++++++++++++++++++++++++++++---------
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index cf66b9a98085..990896d68016 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -3344,7 +3344,7 @@ static void compressed_read_endio(struct qcow2_target *tgt, struct qio *unused,
}
static void submit_read_compressed(struct qcow2_map *map, struct qio *qio,
- bool for_cow)
+ bool for_cow, bool merge)
{
struct qcow2 *qcow2 = map->qcow2;
struct qcow2_target *tgt = qcow2->tgt;
@@ -3363,8 +3363,12 @@ static void submit_read_compressed(struct qcow2_map *map, struct qio *qio,
nr_alloc = nr_pages;
if (for_cow) {
- qio->ext->cow_mask = calc_cow_mask(qcow2, map->ext_l2, qio,
- true, map->clu_is_cow, false);
+ if (merge)
+ qio->ext->cow_mask = calc_cow_mask(qcow2, map->ext_l2,
+ qio, false, true, true);
+ else
+ qio->ext->cow_mask = calc_cow_mask(qcow2, map->ext_l2,
+ qio, true, map->clu_is_cow, false);
/* COW reuses this qvec to write rest of cluster */
nr_alloc = nr_segs = 0;
@@ -3396,7 +3400,7 @@ static void submit_read_compressed(struct qcow2_map *map, struct qio *qio,
qio->ext->cleanup_mask |= FREE_QIO_DATA_QVEC;
qio->ext->lx_md = l2_md;
if (for_cow && qcow2->ext_l2)
- qio->ext->new_ext_l2 = 0x00000000FFFFFFFF;
+ qio->ext->new_ext_l2 = merge ? 0 : 0x00000000FFFFFFFF;
inc_wpc_readers(l2_md);
if (qio->bi_iter.bi_size == clu_size && for_cow) {
@@ -3406,7 +3410,12 @@ static void submit_read_compressed(struct qcow2_map *map, struct qio *qio,
* See the way process_cow_data_write()
* updates qvec. Also skips extract part.
*/
- cow_read_endio(qcow2->tgt, NULL, qio, BLK_STS_OK);
+ if (merge) {
+ dec_wpc_readers(qcow2, l2_md);
+ backward_merge_read_complete(tgt, NULL, qio, BLK_STS_OK);
+ } else {
+ cow_read_endio(tgt, NULL, qio, BLK_STS_OK);
+ }
qcow2_free_qio(read_qio, tgt->qio_pool);
return;
}
@@ -3555,6 +3564,12 @@ static void submit_read_sliced_cow_clu(struct qcow2_map *map, struct qio *qio)
submit_read_sliced_clu(map, qio, sliced_cow_read_complete);
}
+static bool backward_merge_qio(struct qcow2 *qcow2, struct qio *qio)
+{
+ return unlikely(qcow2->backward_merge_in_process) &&
+ (fake_merge_qio(qio) || qcow2_file_is_writable(qcow2));
+}
+
static void submit_top_delta_read(struct qcow2_map *map, struct qio *qio)
{
struct qcow2 *qcow2 = map->qcow2;
@@ -3864,9 +3879,11 @@ static void process_one_qio(struct qcow2 *qcow2, struct qio *qio)
* So process only actual merge qios or reads from writable
* images.
*/
- if (unlikely(qcow2->backward_merge_in_process) &&
- (fake_merge_qio(qio) || qcow2_file_is_writable(qcow2))) {
- submit_top_delta_read(&map, qio);
+ if (backward_merge_qio(qcow2, qio)) {
+ if (unlikely(map.compressed))
+ submit_read_compressed(&map, qio, true, true);
+ else
+ submit_top_delta_read(&map, qio);
return;
}
@@ -3880,7 +3897,7 @@ static void process_one_qio(struct qcow2 *qcow2, struct qio *qio)
if (unlikely(map.compressed)) {
/* Compressed qio never uses sub-clus */
- submit_read_compressed(&map, qio, write);
+ submit_read_compressed(&map, qio, write, false);
return;
}
@@ -4138,6 +4155,12 @@ static void process_compressed_read(struct list_head *read_list,
continue;
}
+ if (backward_merge_qio(qcow2, qio)) {
+ backward_merge_read_complete(qcow2->tgt, NULL, qio,
+ BLK_STS_OK);
+ continue;
+ }
+
/* Further COW processing */
qio->queue_list_id = QLIST_COW_DATA;
list_add_tail(&qio->link, cow_list);
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Devel] [PATCH hci-8.2 2/2] dm-qcow2: end the popped qio when decompression setup fails
2026-11-19 14:30 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Denis V. Lunev
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image Denis V. Lunev
@ 2026-11-19 14:30 ` Denis V. Lunev
2026-11-19 14:42 ` no-reply
2026-11-19 16:45 ` Konstantin Khorenko
2026-11-19 16:45 ` [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Konstantin Khorenko
` (2 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Denis V. Lunev @ 2026-11-19 14:30 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
process_compressed_read() pops a qio and only then allocates the
decompression buffer and, for zstd, sets up the decompression context.
If either fails, it ends the qios left on the list but not the popped one,
which never completes: a read or COW of a compressed cluster hangs,
and so does a backward merge that waits for it.
Put the popped qio back on the list before ending them.
https://virtuozzo.atlassian.net/browse/VSTOR-156064
Fixes: e6bcdf575c18 ("dm-qcow2: support mixed compression images")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
drivers/md/dm-qcow2-map.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 990896d68016..8f3e89de73c0 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4116,6 +4116,7 @@ static void process_compressed_read(struct list_head *read_list,
QC_ERR(qcow2->tgt->ti,
"can not allocate decompression buffer:%zu",
qcow2->clu_size + dctxlen);
+ list_add(&qio->link, read_list);
end_qios(read_list, BLK_STS_RESOURCE);
return;
}
@@ -4126,6 +4127,7 @@ static void process_compressed_read(struct list_head *read_list,
arg = zstd_init_dstream(qcow2->clu_size,
buf + qcow2->clu_size, dctxlen);
if (!arg) {
+ list_add(&qio->link, read_list);
end_qios(read_list, BLK_STS_RESOURCE);
kvfree(buf);
return;
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image Denis V. Lunev
@ 2026-11-19 14:39 ` no-reply
2026-11-19 16:45 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: no-reply @ 2026-11-19 14:39 UTC (permalink / raw)
To: Denis V. Lunev, alexander.ivanov, vasileios.almpanis; +Cc: devel
> From: Denis V. Lunev <den@openvz.org>
>
> During a backward merge, process_one_qio() sends each merge qio of the
> top image to submit_top_delta_read() before it checks map.compressed.
> That read takes clu_size bytes from the compressed data offset, and
> process_backward_merge_write() writes them into the lower image as a
> plain cluster. After the merge the device returns the compressed
> stream, and whatever follows it in the file, instead of the data, and
> qemu-img check finds nothing wrong. If the raw read runs past the end
> of the top image, the merge fails with -EIO instead, or never ends on
> a kernel that resubmits a 0-byte read.
>
> A guest write to a compressed cluster during the merge takes the same
> path, and so does a guest read, which becomes a merge qio first.
>
> Read such a cluster with submit_read_compressed(), as a COW does, but
> with the copy mask of the merge and new_ext_l2 left 0 for the discard
> of the top entry, and pass the decompressed slices on to the merge
> write instead of the COW write.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-156064
>
> Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
> Feature: dm-qcow2: block device over QCOW2 files driver
> Signed-off-by: Denis V. Lunev <den@openvz.org>
Sashiko has reviewed this patch and found no issues.
Carry the trailer below into the next revision and Sashiko will not review this patch again.
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261119143026.998715-2-den@openvz.org?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 2/2] dm-qcow2: end the popped qio when decompression setup fails
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: end the popped qio when decompression setup fails Denis V. Lunev
@ 2026-11-19 14:42 ` no-reply
2026-11-19 16:45 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: no-reply @ 2026-11-19 14:42 UTC (permalink / raw)
To: Denis V. Lunev, alexander.ivanov, vasileios.almpanis; +Cc: devel
> From: Denis V. Lunev <den@openvz.org>
>
> process_compressed_read() pops a qio and only then allocates the
> decompression buffer and, for zstd, sets up the decompression context.
> If either fails, it ends the qios left on the list but not the popped one,
> which never completes: a read or COW of a compressed cluster hangs,
> and so does a backward merge that waits for it.
>
> Put the popped qio back on the list before ending them.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-156064
>
> Fixes: e6bcdf575c18 ("dm-qcow2: support mixed compression images")
> Feature: dm-qcow2: block device over QCOW2 files driver
> Signed-off-by: Denis V. Lunev <den@openvz.org>
Sashiko has reviewed this patch and found no issues.
Carry the trailer below into the next revision and Sashiko will not review this patch again.
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261119143026.998715-2-den@openvz.org?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image Denis V. Lunev
2026-11-19 14:39 ` no-reply
@ 2026-11-19 16:45 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:45 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying with these fixes on my side:
- Items 1 and 2 of the cover letter reply.
On Thu, 19 Nov 2026 15:30:25 +0100, Denis V. Lunev wrote:
> plain cluster. After the merge the device returns the compressed
> stream, and whatever follows it in the file, instead of the data, and
Five sentences in one paragraph; the code walk ends at "plain
cluster", what the user sees starts after it.
> path, and so does a guest read, which becomes a merge qio first.
backward_merge_qio() takes a guest read only when the top image is
writable.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 2/2] dm-qcow2: end the popped qio when decompression setup fails
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: end the popped qio when decompression setup fails Denis V. Lunev
2026-11-19 14:42 ` no-reply
@ 2026-11-19 16:45 ` Konstantin Khorenko
1 sibling, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:45 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying as is.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters
2026-11-19 14:30 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Denis V. Lunev
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image Denis V. Lunev
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: end the popped qio when decompression setup fails Denis V. Lunev
@ 2026-11-19 16:45 ` Konstantin Khorenko
2026-11-19 16:45 ` Konstantin Khorenko
2026-11-19 16:48 ` Alexander Ivanov
4 siblings, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:45 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying the series with these fixes on my side:
1. 1/2: the first paragraph had five sentences; split it before "After
the merge the device returns".
2. 1/2: only a guest read of a writable top image becomes a merge qio, a
read of a read-only top keeps the normal compressed read; added "of a
writable top image".
On Thu, 19 Nov 2026 15:30:24 +0100, Denis V. Lunev wrote:
> Applies on top of the series "dm-qcow2: fix a read livelock at EOF of a
> read-only image" v2.
Both patches apply and are correct without it; only a merge from a
read-only image whose file ends mid-page still needs that series, as
before. I take it after the livelock series anyway.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters
2026-11-19 14:30 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Denis V. Lunev
` (2 preceding siblings ...)
2026-11-19 16:45 ` [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Konstantin Khorenko
@ 2026-11-19 16:45 ` Konstantin Khorenko
2026-11-19 16:48 ` Alexander Ivanov
4 siblings, 0 replies; 10+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:45 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis, Denis V. Lunev; +Cc: devel
On Thu, 19 Nov 2026 15:30:24 +0100, Denis V. Lunev wrote:
> dm-qcow2: fix backward merge of compressed clusters
>
> An online backward merge copies the compressed clusters of the top image
> into the lower image raw, so the merged device returns compressed
> streams instead of data, and qemu-img check sees nothing wrong. Read
> them through the decompression path instead. A failed decompression
> setup also leaves one read, COW or merge qio unfinished, which would
> now stall the merge.
>
> [...]
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.4.vz10, thanks!
[1/2] dm-qcow2: decompress compressed clusters merged into the lower image
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/074ddf4abbb9
[2/2] dm-qcow2: end the popped qio when decompression setup fails
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/84e1f393abbc
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters
2026-11-19 14:30 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Denis V. Lunev
` (3 preceding siblings ...)
2026-11-19 16:45 ` Konstantin Khorenko
@ 2026-11-19 16:48 ` Alexander Ivanov
4 siblings, 0 replies; 10+ messages in thread
From: Alexander Ivanov @ 2026-11-19 16:48 UTC (permalink / raw)
To: Denis V. Lunev, vasileios.almpanis; +Cc: devel
LGTM
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-19 16:49 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 14:30 [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Denis V. Lunev
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 1/2] dm-qcow2: decompress compressed clusters merged into the lower image Denis V. Lunev
2026-11-19 14:39 ` no-reply
2026-11-19 16:45 ` Konstantin Khorenko
2026-11-19 14:30 ` [Devel] [PATCH hci-8.2 2/2] dm-qcow2: end the popped qio when decompression setup fails Denis V. Lunev
2026-11-19 14:42 ` no-reply
2026-11-19 16:45 ` Konstantin Khorenko
2026-11-19 16:45 ` [Devel] [PATCH hci-8.2 0/2] dm-qcow2: fix backward merge of compressed clusters Konstantin Khorenko
2026-11-19 16:45 ` Konstantin Khorenko
2026-11-19 16:48 ` Alexander Ivanov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox