* [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend
@ 2026-11-10 7:51 Alexander Ivanov
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 01/12] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
` (13 more replies)
0 siblings, 14 replies; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
Discard punches holes in place of freed clusters, but doesn't change
the file size. On postsuspend dm-qcow2 truncates the image file only
down to file_preallocated_area_start, so if clusters at the end of the
file are freed, the file never shrinks.
This series makes postsuspend scan the refcount blocks backward and
truncate the file to the end of the last used cluster. Close and
reload to RO go through postsuspend too, so the file is shrunk in these
cases as well.
Patch 1 adds qcow2_md_page_read_sync() helper, which is needed by the
scan. Patch 2 is a small cleanup of duplicate prefixes in QC_ERR/QC_INFO
messages. Patches 3-9 fix existing cases where the refcounts or the
dirty bit on disk don't reflect real cluster usage, or where such an
image is not flagged for check, which the scan relies on. Patch 10
retries an R1/R2 writeback that failed with ENOSPC, so the next resume
is refused only if the space is still missing at suspend. Patch 11
does the actual truncation. Patch 12 fixes a WARN on a flush that
fails with ENOSPC.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
v12:
- Patch 8: new patch.
- Patch 12: new patch.
- Patch 9 (was 8): skip a qio without ext when clearing
FREE_ALLOCATED_CLU in complete_wbd(). Say in the commit message what
is leaked: one cluster per failed L1/L2 write of a request.
- Patch 10 (was 9): say in the commit message and the comment that a
page that failed before the flush gets up to two attempts during it,
and that MD_DIRTY is dropped when the write is submitted. Say that a
request whose L2 write keeps failing with ENOSPC leaks one data
cluster on every resubmission.
- Patch 11 (was 10): run postsuspend under a memalloc_noio scope, as
the scan and truncation allocate memory while the device is
suspended. Say in the commit message that the scan is skipped on
md_writeback_error, which a late reftable relocation failure sets
too.
v11:
- Patch 7: set ret to -ERANGE when the new R2 position runs past its
end, instead of returning a stale ret.
Update the relocate_refcount_table() comment about rollback.
- Patch 8: drop the comments about reverted cluster allocations in
do_md_page_write_complete() and qcow2_flush_deferred_activity().
- Patch 9: retry the R1/R2 writeback on both passes of every flush of
deferred md activity (suspend, merge, target destruction) via a new
md_wb_no_retry flag instead of checking wants_suspend, so no timer is
left armed before the image is freed.
- Patch 10: say in the commit message that the scan trusts refcounts.
v10:
- Rebase onto 22.19.
- Drop patch 7 "fix md page cleanup on failed reftable relocation",
merged as beada5e3721a ("dm-qcow2: fix a failed refcount table
relocation leaking md pages").
- Add Fixes tag to patches 3, 4, 5, 7 and 8.
- Patch 1: set *md to NULL on error, document that a lookup of the page
while it is read is never woken.
- Patch 4: describe what happens to the R2 page dirtied after the flush.
- Patch 5: drop the claims about L2 tables and a missed md writeback
error from the commit message, retitle.
- Patches 4-6: add a blank line before Signed-off-by.
- Patch 7 (was 8): log the error code and tell the two failures apart.
- Patch 8 (was 9): keep the refcounts of clusters allocated for a
failed L1/L2 writeback, leaking them, instead of flagging the image
with MD_LX_REVERTED / lx_writeback_error. Retitled accordingly.
- Patch 9: new patch.
- Patch 10: drop lx_writeback_error handling, mention v2
images in the commit message.
v9:
- Patch 5: new patch.
- Patch 6: also keep the dirty bit while wants_check is set, as
md_writeback_error is kept only in the target and is lost on table
reload or host restart. Rename kernel_dirty_bit to
kernel_dirty_bit_set. Retitled accordingly.
- Patch 7: new patch.
- Patches 8, 9: split from patch 10: setting md_writeback_error on a
late reftable relocation failure and the MD_LX_REVERTED /
lx_writeback_error tracking are separate fixes now.
- Patch 10: rename qcow2_truncate_preallocations() to
qcow2_truncate_unused_tail() and update the dm-ploop comment that
refers to it. Move the rationale from code comments to the commit
message.
v8:
- Patch 3: instead of extending the file in place_r2(), make
find_unused_cluster() return the position for the new refblock and
let allocate_cluster() prepare it the same way as a data cluster
(punch, extend, watermark update moved into prepare_unused_cluster())
before calling place_r2(). Retitled accordingly.
v7:
- Patch 5: track whether the image was opened dirty in a new opened_dirty
flag instead of checking the parsed header, which is reread on resume
and may carry the bit set by the kernel itself (e.g. on the lower image
of a cancelled backward merge). A new kernel_dirty_bit flag tells
whether the bit on disk is the kernel's own.
- Patch 6: use opened_dirty to skip the scan.
v6:
- Add Reviewed-by lines to patches 1 and 2.
- Patch 2: fix "pase" typo in a message touched by the patch.
- Patches 3-5: new patches.
- Patch 6: drop Reviewed-by, as the patch changed a lot.
- Patch 6: mark L1/L2 pages, whose failed writeback reverted refcounts
of new clusters, with MD_LX_REVERTED and report it via the new
lx_writeback_error flag, which skips the scan and is included in
wants_check.
Set md_writeback_error if relocate_refcount_table() fails
after the new header is written, and clamp the scan start to
reftable_max_file_size.
Skip the scan for an image opened with the dirty bit set
when kernel_sets_dirty_bit is enabled.
Check the R1 entry before calc_r2_page_id(), so a corrupted
one fails the scan without WARN.
Reword the commit message to make clear that discard does
free the clusters but doesn't shrink the file.
v5:
- Add Reviewed-by line.
v4:
- Patch 1: document in the comment that the caller must ensure no read
of the page is in flight.
- Patch 3: say in the commit message that close and reload to RO go
through postsuspend too.
v3:
- Split from the common series with dm-ploop: dm-ploop patches are
sent as a separate series.
- Patch 1: rename qcow2_get_md_page_sync() to qcow2_md_page_read_sync(),
reword commit message and comment.
- Patch 2: new patch.
- Patch 3: start the scan from file_preallocated_area_start instead of
the end of the file and clamp the result to it, as the last cluster
may be partial; print the scan error with %pe and drop the duplicate
"dm-qcow2:" prefix from it.
v2:
- Add dm-ploop support (patches 3-6), as requested in v1 review.
- dm-qcow2: move get_md_page_sync() to a separate patch as
qcow2_md_page_read_sync() and use it in qcow2_parse_header() as well.
- dm-qcow2: start the refcount scan below file_preallocated_area_start
instead of the end of the file, and truncate to the used end directly
instead of min(file_preallocated_area_start, used end).
Alexander Ivanov (12):
dm-qcow2: add qcow2_md_page_read_sync() helper
dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages
dm-qcow2: extend the file for a new refblock in allocate_cluster()
dm-qcow2: complete wbd before ending the data qio
dm-qcow2: flush lower md before clearing dirty bit on merge failure
dm-qcow2: keep the dirty bit of an image that needs check
dm-qcow2: flag the image for check if reftable relocation fails late
dm-qcow2: fail the L2 table allocation request on L1 writeback error
dm-qcow2: leak clusters allocated for a failed L1/L2 writeback
dm-qcow2: retry R1/R2 writeback that failed with ENOSPC
dm-qcow2: truncate unused tail of image on suspend
dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC
drivers/md/dm-ploop-target.c | 2 +-
drivers/md/dm-qcow2-cmd.c | 1 +
drivers/md/dm-qcow2-map.c | 264 +++++++++++++++++++++--------------
drivers/md/dm-qcow2-target.c | 123 ++++++++++++----
drivers/md/dm-qcow2.h | 6 +
5 files changed, 262 insertions(+), 134 deletions(-)
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 01/12] dm-qcow2: add qcow2_md_page_read_sync() helper
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 7:55 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 02/12] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages Alexander Ivanov
` (12 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
Add a helper, which returns an up to date md page from md cache,
or allocates a new one, inserts it and reads it synchronously.
On read failure the page is erased from cache and freed.
Use it in qcow2_parse_header() instead of open-coded allocation
and read of page 0. It will also be used by a later patch in the series.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
drivers/md/dm-qcow2-target.c | 48 ++++++++++++++++++++++++++++++++----
drivers/md/dm-qcow2.h | 2 ++
2 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 7c572bd66e1c..0cbbd8e4f493 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -418,6 +418,48 @@ int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_pag
}
ALLOW_ERROR_INJECTION(qcow2_alloc_and_insert_md_page, ERRNO);
+/*
+ * Returns up to date md page from cache, or allocates
+ * a new one and reads it synchronously. Sets *md to NULL on error.
+ *
+ * The caller must ensure nobody else looks this page up until this
+ * returns (e.g., the device is suspended). A lookup before MD_UPTODATE
+ * is set queues its qio on md->wait_list, which is never woken here,
+ * and the page is freed with the qio still queued on read error.
+ * A cached page that is not MD_UPTODATE yet makes the insert fail.
+ */
+int qcow2_md_page_read_sync(struct qcow2 *qcow2, u64 id, struct md_page **md)
+{
+ int ret;
+
+ spin_lock_irq(&qcow2->md_pages_lock);
+ *md = qcow2_md_page_find_or_postpone(qcow2, id, NULL);
+ spin_unlock_irq(&qcow2->md_pages_lock);
+ if (*md)
+ return 0;
+
+ ret = qcow2_alloc_and_insert_md_page(qcow2, id, md);
+ if (ret)
+ goto err;
+
+ ret = qcow2_rw_page_sync(READ, qcow2, id, (*md)->page);
+ if (ret) {
+ spin_lock_irq(&qcow2->md_pages_lock);
+ qcow2_md_page_erase(qcow2, *md);
+ spin_unlock_irq(&qcow2->md_pages_lock);
+ qcow2_free_md_page(*md);
+ goto err;
+ }
+
+ spin_lock_irq(&qcow2->md_pages_lock);
+ (*md)->status |= MD_UPTODATE;
+ spin_unlock_irq(&qcow2->md_pages_lock);
+ return 0;
+err:
+ *md = NULL;
+ return ret;
+}
+
static void inflight_ref_exit0(struct percpu_ref *ref)
{
struct qcow2_target *tgt = container_of(ref, struct qcow2_target,
@@ -851,13 +893,9 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
}
qcow2->file_preallocated_area_start = qcow2->file_size;
- ret = qcow2_alloc_and_insert_md_page(qcow2, 0, &md);
- if (ret)
- return ret;
- ret = qcow2_rw_page_sync(READ, qcow2, md->id, md->page);
+ ret = qcow2_md_page_read_sync(qcow2, 0, &md);
if (ret)
return ret;
- md->status |= MD_UPTODATE;
raw_hdr = kmap(md->page);
min_len = to_bytes(ti->len);
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index ad5286b16883..5abc7f5ad239 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -388,6 +388,8 @@ void do_qcow2_work(struct work_struct *ws);
void do_qcow2_fsync_work(struct work_struct *ws);
int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index,
struct md_page **md);
+int qcow2_md_page_read_sync(struct qcow2 *qcow2, u64 id,
+ struct md_page **md);
struct md_page *qcow2_md_page_find_or_postpone(struct qcow2 *qcow2,
u64 id, struct qio **qio);
struct md_page *qcow2_md_page_renumber(struct qcow2 *qcow2, u64 id,
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 02/12] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 01/12] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 7:55 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 03/12] dm-qcow2: extend the file for a new refblock in allocate_cluster() Alexander Ivanov
` (11 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
QCOW2_FMT already adds the "dm-qcow2: <dev>: " prefix and the trailing
newline, so several messages were printed like:
dm-qcow2: <dev>: dm-qcow2: Can't parse metadata
and some of them were followed by an empty line. Drop the redundant
prefix and newlines.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
drivers/md/dm-qcow2-target.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 0cbbd8e4f493..bb322254cea9 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -192,7 +192,7 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2
md = rb_entry(node, struct md_page, node);
/* FIXME: call md_make_dirty() and try once again? */
if (md->status & MD_WRITEBACK_ERROR) {
- QC_ERR(tgt->ti, "qcow2: Failed to write dirty pages");
+ QC_ERR(tgt->ti, "Failed to write dirty pages");
tgt->md_writeback_error = true;
break;
}
@@ -840,19 +840,19 @@ static int qcow2_parse_extensions(struct dm_target *ti, struct qcow2 *qcow2,
struct Qcow2BitmapHeaderExt bitmaps_ext;
if (ext.len != sizeof(bitmaps_ext)) {
- QC_ERR(ti, "unexpected bitmap extension size\n");
+ QC_ERR(ti, "unexpected bitmap extension size");
return -EINVAL;
}
if (offset + sizeof(bitmaps_ext) > end) {
- QC_ERR(ti, "unexpected end of extension area\n");
+ QC_ERR(ti, "unexpected end of extension area");
return -EINVAL;
}
memcpy(&bitmaps_ext, addr + offset, sizeof(bitmaps_ext));
ret = qcow2_parse_bitmap_ext(ti, qcow2, &bitmaps_ext);
if (ret) {
- QC_ERR(ti, "unable to pase bitmap extension\n");
+ QC_ERR(ti, "unable to parse bitmap extension");
return ret;
}
break;
@@ -886,7 +886,7 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
new_size = PAGE_ALIGN(qcow2->file_size);
ret = qcow2_truncate_safe(file, new_size);
if (ret) {
- QC_ERR(ti, "qcow2: Can't truncate file");
+ QC_ERR(ti, "Can't truncate file");
return ret;
} /* See md_page_read_complete() */
qcow2->file_size = new_size;
@@ -918,14 +918,14 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
ret = -EXDEV;
if (upper) {
if (upper->clu_size != qcow2->clu_size) {
- QC_ERR(ti, "dm-qcow2: clu_size mismatch\n");
+ QC_ERR(ti, "clu_size mismatch");
goto out;
}
if (upper->ext_l2 != qcow2->ext_l2) {
if (is_bottom && upper->ext_l2 && !qcow2->ext_l2) {
- QC_INFO(ti, "dm-qcow2: using bottom delta without ext_l2\n");
+ QC_INFO(ti, "using bottom delta without ext_l2");
} else {
- QC_ERR(ti, "dm-qcow2: upper delta without ext_l2 is unsupported\n");
+ QC_ERR(ti, "upper delta without ext_l2 is unsupported");
goto out; /* This is not supported yet */
}
}
@@ -947,11 +947,11 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
ext_end = PAGE_SIZE;
if (ext_end > PAGE_SIZE) {
- QC_INFO(ti, "extensions are too long, skipping them\n");
+ QC_INFO(ti, "extensions are too long, skipping them");
} else {
ret = qcow2_parse_extensions(ti, qcow2, ext_start, ext_end, raw_hdr);
if (ret) {
- QC_ERR(ti, "failed to parse extensions\n");
+ QC_ERR(ti, "failed to parse extensions");
goto out;
}
}
@@ -986,7 +986,7 @@ static int qcow2_parse_metadata(struct dm_target *ti, struct qcow2_target *tgt)
ret = 0;
out:
if (ret)
- QC_ERR(ti, "dm-qcow2: Can't parse metadata");
+ QC_ERR(ti, "Can't parse metadata");
return ret;
}
@@ -1067,7 +1067,7 @@ static void qcow2_truncate_preallocations(struct dm_target *ti)
ret = qcow2_truncate_safe(qcow2->file, end);
if (ret) {
- QC_ERR(ti, "dm-qcow2: Can't truncate preallocations");
+ QC_ERR(ti, "Can't truncate preallocations");
tgt->truncate_error = true;
return;
}
@@ -1153,7 +1153,7 @@ static void qcow2_postsuspend(struct dm_target *ti)
if (dm_table_get_mode(ti->table) & FMODE_WRITE) {
ret = qcow2_set_image_file_features(qcow2, false);
if (ret)
- QC_ERR(ti, "qcow2: Can't set features");
+ QC_ERR(ti, "Can't set features");
}
}
static int qcow2_preresume(struct dm_target *ti)
@@ -1162,7 +1162,7 @@ static int qcow2_preresume(struct dm_target *ti)
int ret = 0;
if (qcow2_wants_check(tgt)) {
- QC_ERR(ti, "qcow2: image check and target reload are required");
+ QC_ERR(ti, "image check and target reload are required");
return -EIO;
}
@@ -1183,7 +1183,7 @@ static int qcow2_preresume(struct dm_target *ti)
if (dm_table_get_mode(ti->table) & FMODE_WRITE) {
ret = qcow2_set_image_file_features(tgt->top, true);
if (ret)
- QC_ERR(ti, "qcow2: Can't set features");
+ QC_ERR(ti, "Can't set features");
}
if (!ret)
qcow2_set_wants_suspend(ti, false);
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 03/12] dm-qcow2: extend the file for a new refblock in allocate_cluster()
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 01/12] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 02/12] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 7:56 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 04/12] dm-qcow2: complete wbd before ending the data qio Alexander Ivanov
` (10 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
place_r2() links a new refblock into R1, but moves neither file_size
nor file_preallocated_area_start. The refblock stays at or above the
watermark if truncate_prealloc_safe() in allocate_cluster() fails
after place_r2(), or if a parallel mark_cluster_unused() lowers
free_cluster_search_pos before the second pass of
find_unused_cluster(). Truncation of preallocations on suspend then
cuts the file under the refblock: R1 on disk points past EOF, and
the next session gets -EIO on allocations in the range it covers.
Make find_unused_cluster() report a position not covered by R2
instead of placing the refblock there itself. allocate_cluster()
prepares that cluster the same way as a data cluster, with the punch,
extend and watermark update moved into prepare_unused_cluster(), and
calls place_r2() before searching again.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 88 ++++++++++++++++++++++-----------------
1 file changed, 50 insertions(+), 38 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 34d9d9810f60..e8a41954c4c6 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2083,21 +2083,12 @@ static int parse_metadata(struct qcow2 *qcow2, struct qio **qio,
* and connects it to R1 table entry.
*/
static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1,
- struct qcow2_map_item *r2, loff_t r2_pos, struct qio **qio)
+ struct qcow2_map_item *r2, loff_t r2_pos)
{
struct dm_target *ti = qcow2->tgt->ti;
u64 page_id = r2_pos >> PAGE_SHIFT;
int ret;
- if (delay_if_writeback(qcow2, r1->md, r1->index_in_page, qio, true))
- return 0;
-
- ret = qcow2_punch_hole(qcow2->file, r2_pos, qcow2->clu_size);
- if (ret) {
- QC_ERR(ti, "punch hole: %d", ret);
- return ret;
- }
-
ret = qcow2_alloc_and_insert_md_page(qcow2, page_id, &r2->md);
if (ret < 0) {
QC_ERR(ti, "Can't alloc: ret=%d, page_id=%llu", ret, page_id);
@@ -2113,7 +2104,7 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1,
spin_unlock_irq(&qcow2->md_pages_lock);
mark_cluster_used(qcow2, r2->md, r2->index_in_page);
- return 1;
+ return 0;
}
static s32 find_unused_block_entry(struct qcow2 *qcow2, struct md_page *md,
@@ -2135,11 +2126,13 @@ static s32 find_unused_block_entry(struct qcow2 *qcow2, struct md_page *md,
static loff_t find_unused_cluster(struct qcow2 *qcow2, struct qio **qio,
struct qcow2_map_item *r1,
- struct qcow2_map_item *r2)
+ struct qcow2_map_item *r2, bool *needs_r2)
{
u32 clu_size = qcow2->clu_size;
s32 index, ret;
loff_t pos;
+
+ *needs_r2 = false;
again:
pos = READ_ONCE(qcow2->free_cluster_search_pos);
if (pos >= qcow2->reftable_max_file_size)
@@ -2151,15 +2144,15 @@ static loff_t find_unused_cluster(struct qcow2 *qcow2, struct qio **qio,
return ret;
/*
* Since pos is not covered by R2, the whole cluster
- * must be unused. Use it to store R2 cluster.
+ * must be unused. The caller stores R2 cluster there.
* Both indexes must be 0 here, because of we allocate
* clusters from small to big.
*/
WARN_ON_ONCE(r2->index_in_page != 0 || r2->index != 0);
- ret = place_r2(qcow2, r1, r2, pos, qio);
- if (ret <= 0)
- return ret;
- goto again;
+ if (delay_if_writeback(qcow2, r1->md, r1->index_in_page, qio, true))
+ return 0;
+ *needs_r2 = true;
+ return pos;
}
spin_lock_irq(&qcow2->md_pages_lock);
@@ -2436,6 +2429,37 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
return -EIO;
}
+/*
+ * Zero the unused cluster at @pos and make the file size and
+ * file_preallocated_area_start cover it.
+ */
+static int prepare_unused_cluster(struct qcow2 *qcow2, loff_t pos)
+{
+ loff_t off, end = pos + qcow2->clu_size;
+ loff_t old_size = qcow2->file_size;
+ int ret;
+
+ if (pos < qcow2->file_preallocated_area_start) {
+ /* Clu at @pos may contain dirty data */
+ off = min_t(loff_t, old_size, end);
+ ret = qcow2_punch_hole(qcow2->file, pos, off - pos);
+ if (ret) {
+ QC_ERR(qcow2->tgt->ti, "punch hole: %d", ret);
+ return ret;
+ }
+ }
+
+ if (end > old_size) {
+ ret = truncate_prealloc_safe(qcow2, end, __func__);
+ if (ret)
+ return ret;
+ }
+
+ if (end > qcow2->file_preallocated_area_start)
+ qcow2->file_preallocated_area_start = end;
+ return 0;
+}
+
/*
* This function is aimed to be called only from main work.
* In case of wish to use it from more places, it's needed
@@ -2445,13 +2469,12 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
static loff_t allocate_cluster(struct qcow2 *qcow2, struct qio *qio,
struct md_page **r2_md, u32 *r2_index_in_page)
{
- u32 clu_size = qcow2->clu_size;
- struct file *file = qcow2->file;
- loff_t pos, off, end, old_size;
struct qcow2_map_item r1, r2;
+ bool needs_r2;
+ loff_t pos;
int ret;
again:
- pos = find_unused_cluster(qcow2, &qio, &r1, &r2);
+ pos = find_unused_cluster(qcow2, &qio, &r1, &r2, &needs_r2);
if (unlikely(pos == -ENOENT)) {
ret = relocate_refcount_table(qcow2, &qio);
if (ret <= 0)
@@ -2461,28 +2484,17 @@ static loff_t allocate_cluster(struct qcow2 *qcow2, struct qio *qio,
if (pos <= 0)
return pos;
- end = pos + clu_size;
- old_size = qcow2->file_size;
-
- if (pos < qcow2->file_preallocated_area_start) {
- /* Clu at @pos may contain dirty data */
- off = min_t(loff_t, old_size, end);
- ret = qcow2_punch_hole(file, pos, off - pos);
- if (ret) {
- QC_ERR(qcow2->tgt->ti, "punch hole: %d", ret);
- return ret;
- }
- }
+ ret = prepare_unused_cluster(qcow2, pos);
+ if (ret)
+ return ret;
- if (end > old_size) {
- ret = truncate_prealloc_safe(qcow2, end, __func__);
+ if (needs_r2) {
+ ret = place_r2(qcow2, &r1, &r2, pos);
if (ret)
return ret;
+ goto again;
}
- if (end > qcow2->file_preallocated_area_start)
- qcow2->file_preallocated_area_start = end;
-
mark_cluster_used(qcow2, r2.md, r2.index_in_page);
if (r2_md)
*r2_md = r2.md;
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 04/12] dm-qcow2: complete wbd before ending the data qio
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (2 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 03/12] dm-qcow2: extend the file for a new refblock in allocate_cluster() Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 7:58 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 05/12] dm-qcow2: flush lower md before clearing dirty bit on merge failure Alexander Ivanov
` (9 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
data_rw_complete() calls qio_endio() before complete_wbd(). qio_endio()
drops the inflight ref, so qcow2_flush_deferred_activity() may return
on suspend while complete_wbd() for a failed L1/L2 writeback is still
running in AIO completion context. revert_l_entries_update() then
marks clusters unused and dirties an R2 page after the flush.
That page sits on slow_wb_batch_list with the slow writeback timer
armed. If the timer fires first, the page is written while the device
is suspended, after postsuspend has cleared the dirty bit. If
preresume comes first, qcow2_free_md_pages_all() frees the page
without taking it off the list, and the timer later walks freed
memory.
Complete the wbd first, so the R2 update is in place before the
inflight ref goes away and the suspend flush writes it back. The md
writeback path already does it in this order.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index e8a41954c4c6..7866c791325b 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2892,13 +2892,14 @@ static void data_rw_complete(struct qio *qio)
spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
}
+ /* qio_endio() drops the inflight ref, which suspend waits for */
+ if (finalize_wbd)
+ complete_wbd(qcow2, wbd);
if (call_endio) {
if (bi_status != BLK_STS_OK)
qio->bi_status = bi_status;
qio_endio(qio);
}
- if (finalize_wbd)
- complete_wbd(qcow2, wbd);
}
static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio)
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 05/12] dm-qcow2: flush lower md before clearing dirty bit on merge failure
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (3 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 04/12] dm-qcow2: complete wbd before ending the data qio Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 7:58 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 06/12] dm-qcow2: keep the dirty bit of an image that needs check Alexander Ivanov
` (8 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
When qcow2_merge_common() fails, qcow2_merge_backward_work() clears the
dirty bit of the lower image right away. qcow2_service_iter() waits only
for the service qios, so delayed md writeback of the lower image may
still be pending. With kernel_sets_dirty_bit, a crash at that point
leaves the lower image marked clean on disk with refblocks that lag
behind the merged data.
Flush the deferred activity of the lower image before writing its
header, as qcow2_merge_backward_complete() does.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-cmd.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index 45c517ce0ef8..3bccce090f01 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -330,6 +330,7 @@ void qcow2_merge_backward_work(struct work_struct *work)
ret = qcow2_merge_common(tgt, qcow2);
if (ret) {
set_backward_merge_in_process(tgt, qcow2, false);
+ qcow2_flush_deferred_activity(tgt, lower);
ret2 = qcow2_set_image_file_features(lower, false);
if (ret2 < 0)
QC_ERR(tgt->ti, "Can't unuse lower (%d)", ret2);
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 06/12] dm-qcow2: keep the dirty bit of an image that needs check
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (4 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 05/12] dm-qcow2: flush lower md before clearing dirty bit on merge failure Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 7:59 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 07/12] dm-qcow2: flag the image for check if reftable relocation fails late Alexander Ivanov
` (7 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
The dm-qcow2 module parameter kernel_sets_dirty_bit makes the kernel set
the dirty bit on resume and clear it on postsuspend. It is off by
default and Virtuozzo does not set it: ploop manages the dirty bit from
userspace itself. So this is a hardening patch for the non-default mode.
With kernel_sets_dirty_bit, postsuspend clears the dirty bit
unconditionally. An image that is dirty at open, e.g. after a crash,
has unrepaired refcounts, which may be below real usage, yet it is
marked clean on disk after the first suspend. A userspace check before
the next open then has no reason to repair it. The same happens after
an error that sets wants_check, e.g. md_writeback_error: it is kept only
in the target, so resume is refused, but after a table reload or a host
restart the image is reopened with a clean header.
Clear the bit only if the image was clean before the kernel set it and
wants_check is not set. The parsed header can't tell the former: it is
reread on every preresume and may carry the kernel's own bit, e.g. on
the lower image of a backward merge cancelled by suspend in
waiting_completion or of a merge with depth > 0. So track two flags per
image: kernel_dirty_bit_set is set only while the last header write was
a successful set and the reread header still has the bit, opened_dirty
is set when the header has the bit and kernel_dirty_bit_set is not set.
Clearing the bit of an image opened dirty is left to userspace check.
After a failed write the bit found on disk is taken as opened dirty,
which costs an extra check, rather than as the kernel's, which could
clear a bit set by userspace while the device was suspended.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-target.c | 14 ++++++++++++--
drivers/md/dm-qcow2.h | 2 ++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index bb322254cea9..6824d95193ae 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -666,6 +666,7 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty)
u64 dirty_mask = cpu_to_be64(INCOMPATIBLE_FEATURES_DIRTY_BIT);
struct QCowHeader *raw_hdr;
struct md_page *md;
+ int ret;
if (qcow2->hdr.version == 2)
return 0;
@@ -682,12 +683,15 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty)
if (kernel_sets_dirty_bit) {
if (dirty)
raw_hdr->incompatible_features |= dirty_mask;
- else
+ else if (!qcow2->opened_dirty && !qcow2_wants_check(qcow2->tgt))
raw_hdr->incompatible_features &= ~dirty_mask;
}
kunmap(md->page);
- return qcow2_rw_page_sync(WRITE, qcow2, md->id, md->page);
+ ret = qcow2_rw_page_sync(WRITE, qcow2, md->id, md->page);
+ if (kernel_sets_dirty_bit)
+ qcow2->kernel_dirty_bit_set = dirty && !ret;
+ return ret;
}
ALLOW_ERROR_INJECTION(qcow2_set_image_file_features, ERRNO);
@@ -911,6 +915,12 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
goto out;
qcow2_calc_cached_parameters(qcow2, hdr);
+ if (!(hdr->incompatible_features & INCOMPATIBLE_FEATURES_DIRTY_BIT)) {
+ qcow2->opened_dirty = false;
+ qcow2->kernel_dirty_bit_set = false;
+ } else if (!qcow2->kernel_dirty_bit_set) {
+ qcow2->opened_dirty = true;
+ }
ret = -EOPNOTSUPP;
if (qcow2->clu_size < PAGE_SIZE ||
(qcow2->ext_l2 && qcow2->clu_size < PAGE_SIZE * 32))
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 5abc7f5ad239..2a6203c86e3a 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -259,6 +259,8 @@ struct qcow2 {
u32 refblock_bits;
u32 refblock_entries;
bool ext_l2;
+ bool opened_dirty;
+ bool kernel_dirty_bit_set;
bool pause_submitting_qios; /* This is used only on top qcow2 image */
bool backward_merge_in_process;
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 07/12] dm-qcow2: flag the image for check if reftable relocation fails late
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (5 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 06/12] dm-qcow2: keep the dirty bit of an image that needs check Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 8:00 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 08/12] dm-qcow2: fail the L2 table allocation request on L1 writeback error Alexander Ivanov
` (6 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
Once relocate_refcount_table() has issued the header write pointing to
the new reftable, any failure returns -EIO. The header on disk may
already point to the new reftable even if its own write fails: a short
write is reported as -ENODATA, and the old reftable position is
restored only in the cached header page, which a v2 image never
rewrites on suspend. The new reftable on disk may then be unfilled or
miss the new refblocks, while refcounts of the new and old reftable
clusters may not be updated. Refcounts no longer match the header, but
nothing reports that, so the device can be resumed and the image
reopened as if it were consistent.
Set md_writeback_error on these paths, so wants_check reports the image
and resume is refused until it is checked, and log the failure.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 44 ++++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 7866c791325b..995f611ae5bb 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2247,7 +2247,7 @@ static void set_reftable_in_raw_hdr(struct page *page0, loff_t pos, loff_t clus)
* complicated, we should not demonstrate excessive creativity
* and optimize it in prejudice of readability.
*
- * We act in the way to provide safe rollback throughout whole function.
+ * We act in the way to provide safe rollback until new hdr is written.
* Firstly, we cache every related md we're going to use on relocation.
* New reftable (R1) is placed next to max cluster covered by old R1.
* Since new reftable (R1) clusters should be marked as used after
@@ -2256,8 +2256,10 @@ static void set_reftable_in_raw_hdr(struct page *page0, loff_t pos, loff_t clus)
* clusters are in the part of file, which is not covered by old R1.
*
* Then, we try to write new hdr on disk. In case of failure, we
- * restore old hdr in memory and do safe rollback. In case of success,
- * there should not be more reasons to fail (only this driver's bugs).
+ * restore old hdr in memory, but the write may have reached the disk,
+ * so the image is flagged for check (md_writeback_error). In case of
+ * success, there should not be more reasons to fail (only this driver's
+ * bugs); such a failure flags the image for check too.
* Cached old reftable (R1) pages we renumber to point to new reftable (R1)
* place. Then we mark old reftable (R1) clusters as unused, while
* new reftable (R1) clusters as used.
@@ -2351,6 +2353,10 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
if (ret) {
/* Restore old R1 */
set_reftable_in_raw_hdr(md0->page, old_pos, old_clus);
+ QC_ERR(qcow2->tgt->ti,
+ "failed to write header with relocated refcount table: %d",
+ ret);
+ qcow2->tgt->md_writeback_error = true;
goto err_free_r2_pages;
}
@@ -2372,24 +2378,27 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
if (!WARN_ON_ONCE(!md))
qcow2_md_make_dirty(qcow2, md, true);
if (!md)
- break; /* goto err_eio */
+ break;
}
spin_unlock_irq(&qcow2->md_pages_lock);
- if (i != nr_pages)
- goto err_eio;
+ if (i != nr_pages) {
+ ret = -ENOENT;
+ goto err_hdr_written;
+ }
/* Connect new R2 to new R1: one for each group new R1 and R2 span */
group_size = (u64)qcow2->refblock_entries * clu_size;
for (i = pos, r2_pos = end; i < r2_end; i += group_size, r2_pos += clu_size) {
- if (WARN_ON_ONCE(r2_pos >= r2_end))
- goto err_eio;
- if (calc_refcounters_map(qcow2, i, &r1, &r2) < 0) {
- WARN_ON_ONCE(1);
- goto err_eio;
+ if (WARN_ON_ONCE(r2_pos >= r2_end)) {
+ ret = -ERANGE;
+ goto err_hdr_written;
}
+ ret = calc_refcounters_map(qcow2, i, &r1, &r2);
+ if (WARN_ON_ONCE(ret < 0))
+ goto err_hdr_written;
ret = handle_md_page(qcow2, r1.page_id, NULL, &md);
if (WARN_ON_ONCE(ret <= 0))
- goto err_eio;
+ goto err_hdr_written;
spin_lock_irq(&qcow2->md_pages_lock);
set_u64_to_be_page(md->page, r1.index_in_page, r2_pos);
qcow2_md_make_dirty(qcow2, md, true);
@@ -2400,7 +2409,7 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
for (i = pos; i < r2_end; i += clu_size) {
ret = qcow2_handle_r1r2_maps(qcow2, i, NULL, &r1, &r2, false);
if (WARN_ON_ONCE(ret <= 0))
- goto err_eio;
+ goto err_hdr_written;
mark_cluster_used(qcow2, r2.md, r2.index_in_page);
}
@@ -2408,12 +2417,18 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
for (i = old_pos; i < old_end; i += clu_size) {
ret = qcow2_handle_r1r2_maps(qcow2, i, NULL, &r1, &r2, false);
if (WARN_ON_ONCE(ret <= 0))
- goto err_eio;
+ goto err_hdr_written;
mark_cluster_unused(qcow2, r2.md, r2.index_in_page, i);
}
return 1;
+err_hdr_written:
+ /* 0: md page is not cached */
+ QC_ERR(qcow2->tgt->ti, "failed to fill relocated refcount table: %d",
+ ret ?: -ENOENT);
+ qcow2->tgt->md_writeback_error = true;
+ return -EIO;
err_free_r2_pages:
for (i = new_md_start; i < new_md_end; i += PAGE_SIZE) {
ret = handle_md_page(qcow2, i >> PAGE_SHIFT, NULL, &md);
@@ -2424,7 +2439,6 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio)
spin_unlock_irq(&qcow2->md_pages_lock);
qcow2_free_md_page(md);
}
-err_eio:
/* TODO: switch to RO */
return -EIO;
}
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 08/12] dm-qcow2: fail the L2 table allocation request on L1 writeback error
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (6 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 07/12] dm-qcow2: flag the image for check if reftable relocation fails late Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 8:01 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback Alexander Ivanov
` (5 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
A request that allocates an L2 table waits for the L1 writeback on the
page wait list. If the writeback fails, the L1 entry is reverted and the
request is dispatched again, so it allocates another L2 table and dirties
L1 once more. With a persistent write error the request never completes.
Queue the request on the wbd dependent list instead, like requests
waiting for an L2 update. It is dispatched again after a successful
writeback and ends with the error after a failed one.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 995f611ae5bb..7f61ff67646c 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2616,7 +2616,7 @@ static int prepare_l1l2_allocation(struct qcow2 *qcow2, struct qio *qio,
* 2)For COW from backing file this is must.
*/
spin_lock_irq(&qcow2->md_pages_lock);
- list_add_tail(&qio->link, &map->l1.md->wait_list);
+ list_add_tail(&qio->link, &map->l1.md->wbd->dependent_list);
spin_unlock_irq(&qcow2->md_pages_lock);
return 0;
}
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (7 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 08/12] dm-qcow2: fail the L2 table allocation request on L1 writeback error Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 8:04 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC Alexander Ivanov
` (4 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
A failed L1/L2 writeback reverts the page in memory and frees each
cluster allocated for it: revert_l_entries_update() drops the refcount
of a newly allocated cluster, and a COW qio waiting on the page frees
its cluster through FREE_ALLOCATED_CLU when it ends with the error. The
write may still have partially reached the disk, so L1/L2 on disk may
point to such a cluster. Until the page is rewritten, the allocator may
give the cluster to another offset, and two guest offsets then share
it. If the page is not rewritten before suspend, the image is left with
a reference to a free cluster.
Keep the refcount of these clusters instead. If L1/L2 on disk points to
such a cluster, the image stays consistent; otherwise the cluster is
leaked. A request ends with the error once its L1 or L2 write fails, so
each failed write leaks one cluster per request: the L2 table for an L1
write, the data cluster for an L2 write. Check frees them, so the image
needs no check and resume needs no refusal.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 53 ++++++++----------------------------
drivers/md/dm-qcow2-target.c | 4 ---
2 files changed, 11 insertions(+), 46 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 7f61ff67646c..8dfdbedac10d 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -1331,50 +1331,15 @@ static void do_md_page_read_complete(int ret, struct qcow2 *qcow2,
/* Be careful with dirty_or_writeback()/etc! Check races. */
static void revert_l_entries_update(struct qcow2 *qcow2, struct wb_desc *wbd)
{
- struct qcow2_map_item r1, r2;
- struct page *pe_page;
- bool skip_odd;
- u64 pos, old;
- bool cleared;
- int i, ret;
-
- skip_odd = qcow2->ext_l2 && wbd->lx_level == L2_LEVEL;
+ struct page *pe_page = wbd->pe_page;
+ u64 old;
+ int i;
lockdep_assert_held(&qcow2->md_pages_lock);
for_each_set_bit(i, wbd->changed_indexes, LX_INDEXES_PER_PAGE) {
- pos = get_u64_from_be_page(wbd->md->page, i);
-
- cleared = !(pos & ~(u64)L2_READS_ALL_ZEROES);
-
/* Here we restore prealloced and compressed clu mappings */
- pe_page = wbd->pe_page;
- if (pe_page) { /* Only L2 has this. */
- old = get_u64_from_be_page(pe_page, i);
- if (old != 0) {
- set_u64_to_be_page(wbd->md->page, i, old);
- continue; /* Avoid mark_cluster_unused() */
- }
- }
-
- set_u64_to_be_page(wbd->md->page, i, 0);
- if (skip_odd && (i & 1))
- continue; /* pos contains ext_l2 part of L2 entry */
- if (cleared)
- continue; /* no cluster was allocated */
-
- spin_unlock(&qcow2->md_pages_lock);
- pos &= ~LX_REFCOUNT_EXACTLY_ONE;
-
- /*
- * R1/R2 should be cached, since we was able
- * to submit cluster allocation.
- */
- ret = qcow2_handle_r1r2_maps(qcow2, pos, NULL, &r1, &r2, false);
- if (WARN_ON_ONCE(ret <= 0))
- continue;
-
- mark_cluster_unused(qcow2, r2.md, r2.index_in_page, pos);
- spin_lock(&qcow2->md_pages_lock);
+ old = pe_page ? get_u64_from_be_page(pe_page, i) : 0;
+ set_u64_to_be_page(wbd->md->page, i, old);
}
}
@@ -1408,6 +1373,7 @@ static void complete_wbd(struct qcow2 *qcow2, struct wb_desc *wbd)
LIST_HEAD(wait_list);
LIST_HEAD(end_list);
unsigned long flags;
+ struct qio *qio;
spin_lock_irqsave(&qcow2->md_pages_lock, flags);
revert_l_entries_update(qcow2, wbd);
@@ -1415,6 +1381,10 @@ static void complete_wbd(struct qcow2 *qcow2, struct wb_desc *wbd)
&wait_list, &end_list);
spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
+ list_for_each_entry(qio, &end_list, link) {
+ if (qio->ext)
+ qio->ext->cleanup_mask &= ~FREE_ALLOCATED_CLU;
+ }
qcow2_dispatch_qios(qcow2, NULL, &wait_list);
end_qios(&end_list, errno_to_blk_status(wbd->ret));
}
@@ -1445,8 +1415,7 @@ static void do_md_page_write_complete(int ret, struct qcow2 *qcow2,
/*
* We can finish wb only in case of success.
* Otherwise this is done in finalize_wbd()
- * after data qios stopped use wbd clusters
- * and clusters allocations reverted.
+ * after data qios stopped use wbd clusters.
*/
if (likely(ret == 0)) {
clear_writeback_status(qcow2, md, ret,
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 6824d95193ae..99fb68a5535e 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -173,10 +173,6 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2
struct md_page *md;
int i;
- /*
- * We need second iteration, since revert_l_entries_update()
- * may start timer again after failed wb.
- */
for (i = 0; i < 2; i++) {
if (timer_delete_sync_try(&qcow2->slow_wb_timer) != -1)
qcow2_slow_wb_timer_fn(&qcow2->slow_wb_timer);
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (8 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 8:06 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 11/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (3 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
MD_DIRTY is dropped when an R1/R2 page writeback is submitted, and a
failed writeback sets MD_WRITEBACK_ERROR. Nothing writes the page again
unless its refcounts change. On suspend the md writeback flush finds the
error and sets md_writeback_error, so resume is refused until the image
is checked and the target reloaded, even if the failure was a transient
ENOSPC of the underlying fs and the space has been freed since.
Redirty the page on -ENOSPC, so the slow writeback timer retries it, as
data writes delayed on ENOSPC are retried. Flushing deferred md activity
on suspend, merge and target destruction fires the timer on each of its
two passes, so a page that failed before the flush gets up to two
attempts during it. A failure in the last pass does not redirty the
page, so no timer is left armed after the flush, before the image is
freed, and md_writeback_error is set as before.
complete_metadata_writeback() turned every failed write into -EIO.
Pass the errno of the write through and keep -EIO for a short write.
A data request depending on a failed L1/L2 write then ends with
BLK_STS_NOSPC and is delayed and resubmitted like any other write
failing with ENOSPC, as already happens when fsync fails with it.
Since failed L1/L2 writebacks leak their clusters, a request whose L2
write keeps failing with ENOSPC leaks one data cluster on every
resubmission, until the space is back.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 6 ++++--
drivers/md/dm-qcow2-target.c | 4 +++-
drivers/md/dm-qcow2.h | 1 +
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 8dfdbedac10d..2aaf11ee3b64 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -1357,6 +1357,8 @@ static void clear_writeback_status(struct qcow2 *qcow2, struct md_page *md,
* so here we care about R1R2 only.
*/
md->status |= MD_WRITEBACK_ERROR;
+ if (ret == -ENOSPC && !READ_ONCE(qcow2->md_wb_no_retry))
+ qcow2_md_make_dirty(qcow2, md, true);
}
if (md->wbd) {
if (likely(ret == 0))
@@ -3869,9 +3871,9 @@ static int complete_metadata_writeback(struct qcow2 *qcow2)
md = qio->ext->md;
qvec = qio->data;
ret = qio->ret;
- if (unlikely(ret != PAGE_SIZE))
+ if (unlikely(ret >= 0 && ret != PAGE_SIZE))
ret = -EIO;
- else
+ else if (ret == PAGE_SIZE)
ret = fsync_ret;
do_md_page_write_complete(ret, qcow2, md);
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 99fb68a5535e..3c1df4c225b4 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -173,7 +173,9 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2
struct md_page *md;
int i;
+ /* Do not redirty R1/R2 failed with ENOSPC on the last pass */
for (i = 0; i < 2; i++) {
+ WRITE_ONCE(qcow2->md_wb_no_retry, i == 1);
if (timer_delete_sync_try(&qcow2->slow_wb_timer) != -1)
qcow2_slow_wb_timer_fn(&qcow2->slow_wb_timer);
/* Start md writeback */
@@ -181,12 +183,12 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2
/* Wait AIO of md wb */
qcow2_inflight_ref_switch(tgt);
}
+ WRITE_ONCE(qcow2->md_wb_no_retry, false);
spin_lock_irq(&qcow2->md_pages_lock);
for (node = rb_first(&qcow2->md_pages);
node; node = rb_next(node)) {
md = rb_entry(node, struct md_page, node);
- /* FIXME: call md_make_dirty() and try once again? */
if (md->status & MD_WRITEBACK_ERROR) {
QC_ERR(tgt->ti, "Failed to write dirty pages");
tgt->md_writeback_error = true;
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 2a6203c86e3a..ebab22d505e8 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -281,6 +281,7 @@ struct qcow2 {
struct list_head wb_batch_list;
struct list_head slow_wb_batch_list;
struct timer_list slow_wb_timer;
+ bool md_wb_no_retry;
struct work_struct worker;
struct work_struct fsync_worker;
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 11/12] dm-qcow2: truncate unused tail of image on suspend
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (9 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 8:07 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 12/12] dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC Alexander Ivanov
` (2 subsequent siblings)
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
Discard punches holes in place of freed clusters, so they hold no
physical extents, but it doesn't change the file size. On postsuspend
we truncate the image file only down to file_preallocated_area_start,
i.e. we drop preallocations only. So if clusters at the end of the
file are freed (refcount dropped to zero), the file size stays the
same and the image never shrinks.
Add qcow2_calc_used_end(), which scans refcount blocks backward from
file_preallocated_area_start and returns the end of the last cluster
with non-zero refcount, clamped to file_preallocated_area_start since
the last cluster may be partial. Refcount ranges with no allocated
refblock are skipped at once.
The scan walks R1 entries normal I/O may never touch, so it validates
them itself instead of letting calc_r2_page_id() WARN on a corrupted
one. Metadata pages are taken from md cache or read synchronously.
This is called on suspended device after md writeback, so R1 and R2
can't change under us. A failed relocation of the reftable leaves
file_preallocated_area_start beyond the space covered by the reftable,
so the scan starts at most from its end.
The scan allocates md pages with GFP_KERNEL, and truncation and the
header write allocate in the lower filesystem. Reclaim from there may
wait on I/O to this suspended device, which can't complete until
resume. Run the whole postsuspend under a memalloc_noio scope, as the
workers do.
Truncate the file to the used end. Fall back to the old behaviour on
scan error and if md_writeback_error is set: a failed R1/R2 writeback
or a late reftable relocation failure leaves refcounts on disk stale.
Refcounts may also be below real usage after a crash, since both QEMU
with lazy_refcounts and this driver write L2 before refcounts. The scan
would then cut off clusters L2 still points to, even in a session
without guest writes. With kernel_sets_dirty_bit such an image has the
dirty bit set at open, and the disabled dirty bit check lets it be
opened RW, so skip the scan for it.
In the default mode userspace sets the dirty bit on every RW open, so
the bit doesn't mean the image is inconsistent. There the scan is safe
only because userspace checks the image before an RW open. A v2 image
has no dirty bit, so the opened_dirty guard never applies to it, and
it is covered only by that check too.
The scan trusts refcounts, as the rest of the driver does. Only a walk
over all L2 tables would catch a zeroed or misplaced R1 entry, so
corrupted refcounts are left to the same image check as stale ones.
Close and reload to RO go through postsuspend too. On remove,
__dm_destroy() calls the presuspend and postsuspend hooks if the live
table isn't suspended yet. It neither stops the queue nor waits for
I/O, but the device is idle there, because dm_lock_for_deletion()
refuses to remove an open device.
On table swap, do_resume() suspends the old (RW) table before
dm_swap_table(). So the file is shrunk in these cases as well.
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-ploop-target.c | 2 +-
drivers/md/dm-qcow2-map.c | 63 ++++++++++++++++++++++++++++++++++--
drivers/md/dm-qcow2-target.c | 25 +++++++++++---
drivers/md/dm-qcow2.h | 1 +
4 files changed, 84 insertions(+), 7 deletions(-)
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index d8279c79ef56..b869c92bbe72 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -447,7 +447,7 @@ static struct ploop_worker *ploop_worker_create(struct ploop *ploop,
*
* FIXME: We must implement metadata reload on resume. After that we can
* implement preallocation truncation on suspend (see dm-qcow2 as it already
- * implements that in qcow2_parse_metadata and qcow2_truncate_preallocations).
+ * implements that in qcow2_parse_metadata and qcow2_truncate_unused_tail).
*/
static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 2aaf11ee3b64..823b2e23644f 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -1090,6 +1090,11 @@ static int calc_refcounters_map(struct qcow2 *qcow2, loff_t pos,
return -EIO;
}
+static bool r1_entry_is_valid(struct qcow2 *qcow2, u64 entry)
+{
+ return !(entry & R1_RESERVED_ZERO_MASK) && CLU_OFF(qcow2, entry) == 0;
+}
+
static int calc_r2_page_id(struct qcow2 *qcow2, struct qcow2_map_item *r1,
struct qcow2_map_item *r2)
{
@@ -1097,8 +1102,7 @@ static int calc_r2_page_id(struct qcow2 *qcow2, struct qcow2_map_item *r1,
u32 bits = qcow2->refblock_bits;
loff_t pos;
- if (WARN_ON_ONCE((entry & R1_RESERVED_ZERO_MASK) ||
- (CLU_OFF(qcow2, entry) != 0)))
+ if (WARN_ON_ONCE(!r1_entry_is_valid(qcow2, entry)))
return -EIO;
/* The corresponding refcount block has not yet been allocated */
@@ -2170,6 +2174,61 @@ int qcow2_truncate_safe(struct file *file, loff_t new_len)
return do_ftruncate(file, new_len, 0);
}
+/*
+ * Return the end of the last cluster with non-zero refcount. Must be
+ * called on a suspended device after md writeback.
+ */
+loff_t qcow2_calc_used_end(struct qcow2 *qcow2)
+{
+ u32 clu_size = qcow2->clu_size;
+ struct qcow2_map_item r1, r2;
+ struct md_page *r1_md = NULL;
+ loff_t pos;
+ s32 i;
+ int ret;
+
+ pos = min(qcow2->file_preallocated_area_start,
+ qcow2->reftable_max_file_size);
+ pos = round_down(pos - 1, clu_size);
+ while (pos >= 0) {
+ if (calc_refcounters_map(qcow2, pos, &r1, &r2) < 0)
+ return -EIO;
+
+ if (!r1_md || r1_md->id != r1.page_id) {
+ ret = qcow2_md_page_read_sync(qcow2, r1.page_id, &r1_md);
+ if (ret)
+ return ret;
+ }
+ r1.md = r1_md;
+
+ if (!r1_entry_is_valid(qcow2, get_u64_from_be_page(r1_md->page,
+ r1.index_in_page)))
+ return -EIO;
+
+ ret = calc_r2_page_id(qcow2, &r1, &r2);
+ if (ret == -ENOENT) {
+ pos = (loff_t)r1.index * qcow2->refblock_entries * clu_size;
+ pos -= clu_size;
+ continue;
+ }
+
+ if (ret < 0)
+ return ret;
+
+ ret = qcow2_md_page_read_sync(qcow2, r2.page_id, &r2.md);
+ if (ret)
+ return ret;
+
+ for (i = r2.index_in_page; i >= 0; i--, pos -= clu_size) {
+ if (get_r2_entry(qcow2, r2.md, i))
+ return min_t(loff_t, pos + clu_size,
+ qcow2->file_preallocated_area_start);
+ }
+ }
+
+ return -EIO;
+}
+
static int truncate_prealloc_safe(struct qcow2 *qcow2, loff_t len, const char *func)
{
loff_t prealloc_len, max_prealloc_len = qcow2->reftable_max_file_size;
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 3c1df4c225b4..8061bd9456f1 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -3,6 +3,7 @@
* Copyright (C) 2021 Virtuozzo International GmbH. All rights reserved.
*/
#include <linux/random.h>
+#include <linux/sched/mm.h>
#include <linux/uio.h>
#include <linux/file.h>
#include <linux/fs.h>
@@ -1061,21 +1062,34 @@ static void qcow2_dtr(struct dm_target *ti)
qcow2_tgt_destroy(tgt);
}
-static void qcow2_truncate_preallocations(struct dm_target *ti)
+static void qcow2_truncate_unused_tail(struct dm_target *ti)
{
struct qcow2_target *tgt = to_qcow2_target(ti);
struct qcow2 *qcow2 = top_qcow2_protected(ti);
- loff_t end = qcow2->file_preallocated_area_start;
+ loff_t used_end, end = qcow2->file_preallocated_area_start;
int ret;
if (!(dm_table_get_mode(ti->table) & FMODE_WRITE))
return;
+
+ if (tgt->md_writeback_error) {
+ QC_INFO(ti, "Skip shrinking to used end after md writeback error");
+ } else if (kernel_sets_dirty_bit && qcow2->opened_dirty) {
+ QC_INFO(ti, "Skip shrinking to used end of dirty image");
+ } else {
+ used_end = qcow2_calc_used_end(qcow2);
+ if (used_end < 0)
+ QC_ERR(ti, "Can't find used end: %pe", ERR_PTR(used_end));
+ else
+ end = used_end;
+ }
+
if (end == qcow2->file_size)
return;
ret = qcow2_truncate_safe(qcow2->file, end);
if (ret) {
- QC_ERR(ti, "Can't truncate preallocations");
+ QC_ERR(ti, "Can't truncate unused tail");
tgt->truncate_error = true;
return;
}
@@ -1153,16 +1167,19 @@ static void qcow2_presuspend_undo(struct dm_target *ti)
static void qcow2_postsuspend(struct dm_target *ti)
{
struct qcow2 *qcow2 = top_qcow2_protected(ti);
+ unsigned int noio_flag;
int ret;
+ noio_flag = memalloc_noio_save();
qcow2_flush_deferred_activity_all(to_qcow2_target(ti));
- qcow2_truncate_preallocations(ti);
+ qcow2_truncate_unused_tail(ti);
if (dm_table_get_mode(ti->table) & FMODE_WRITE) {
ret = qcow2_set_image_file_features(qcow2, false);
if (ret)
QC_ERR(ti, "Can't set features");
}
+ memalloc_noio_restore(noio_flag);
}
static int qcow2_preresume(struct dm_target *ti)
{
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index ebab22d505e8..ed427a0a7699 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -416,6 +416,7 @@ void qcow2_ref_dec(struct qcow2_target *tgt, u8 ref_index);
int qcow2_inflight_ref_switch(struct qcow2_target *tgt);
void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2);
int qcow2_truncate_safe(struct file *file, loff_t new_len);
+loff_t qcow2_calc_used_end(struct qcow2 *qcow2);
void qcow2_merge_backward_work(struct work_struct *work);
void qcow2_merge_backward_cancel(struct qcow2_target *tgt);
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* [Devel] [PATCH hci-8.1 v12 12/12] dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (10 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 11/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
@ 2026-11-10 7:51 ` Alexander Ivanov
2026-11-10 8:07 ` no-reply
2026-11-10 11:42 ` [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Konstantin Khorenko
2026-11-10 11:43 ` Konstantin Khorenko
13 siblings, 1 reply; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 7:51 UTC (permalink / raw)
To: andrey.zhadchenko; +Cc: devel
A REQ_OP_FLUSH request is completed by do_qcow2_fsync_work() with
errno_to_blk_status() of the vfs_fsync() result, so a failed fsync
with -ENOSPC ends it with BLK_STS_NOSPC. qrq_endio() then hits
WARN_ON_ONCE(!op_is_write()), as op_is_write(REQ_OP_FLUSH) is false.
With panic_on_warn this takes the node down.
fsync returns ENOSPC on file systems that allocate on writeback (NFS,
FUSE, thin or reflink backends), and when ext4 or xfs report a failed
delayed write. Delaying and resubmitting the flush is already correct,
so only let the WARN accept REQ_OP_FLUSH.
Fixes: 7d49e18c5c36 ("dm-qcow2: Pause IO and notify about ENOSPC events")
https://virtuozzo.atlassian.net/browse/VSTOR-148171
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/md/dm-qcow2-map.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 823b2e23644f..c2154c4f6f76 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4491,7 +4491,8 @@ static void qrq_endio(struct qcow2_target *tgt, struct qio *qio,
* callers receive -ENOSPC synchronous without intermediaries.
*/
if (unlikely(bi_status == BLK_STS_NOSPC)) {
- WARN_ON_ONCE(!op_is_write(qio->bi_op));
+ WARN_ON_ONCE(!op_is_write(qio->bi_op) &&
+ qio->bi_op != REQ_OP_FLUSH);
if (qcow2_try_delay_enospc(tgt, qrq, qio))
return;
}
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 01/12] dm-qcow2: add qcow2_md_page_read_sync() helper
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 01/12] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
@ 2026-11-10 7:55 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 7:55 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
> Add a helper, which returns an up to date md page from md cache,
> or allocates a new one, inserts it and reads it synchronously.
> On read failure the page is erased from cache and freed.
>
> Use it in qcow2_parse_header() instead of open-coded allocation
> and read of page 0. It will also be used by a later patch in the series.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 02/12] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 02/12] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages Alexander Ivanov
@ 2026-11-10 7:55 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 7:55 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
> QCOW2_FMT already adds the "dm-qcow2: <dev>: " prefix and the trailing
> newline, so several messages were printed like:
>
> dm-qcow2: <dev>: dm-qcow2: Can't parse metadata
>
> and some of them were followed by an empty line. Drop the redundant
> prefix and newlines.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 03/12] dm-qcow2: extend the file for a new refblock in allocate_cluster()
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 03/12] dm-qcow2: extend the file for a new refblock in allocate_cluster() Alexander Ivanov
@ 2026-11-10 7:56 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 7:56 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
> place_r2() links a new refblock into R1, but moves neither file_size
> nor file_preallocated_area_start. The refblock stays at or above the
> watermark if truncate_prealloc_safe() in allocate_cluster() fails
> after place_r2(), or if a parallel mark_cluster_unused() lowers
> free_cluster_search_pos before the second pass of
> find_unused_cluster(). Truncation of preallocations on suspend then
> cuts the file under the refblock: R1 on disk points past EOF, and
> the next session gets -EIO on allocations in the range it covers.
>
> Make find_unused_cluster() report a position not covered by R2
> instead of placing the refblock there itself. allocate_cluster()
> prepares that cluster the same way as a data cluster, with the punch,
> extend and watermark update moved into prepare_unused_cluster(), and
> calls place_r2() before searching again.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
> Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=3
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 05/12] dm-qcow2: flush lower md before clearing dirty bit on merge failure
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 05/12] dm-qcow2: flush lower md before clearing dirty bit on merge failure Alexander Ivanov
@ 2026-11-10 7:58 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 7:58 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
> When qcow2_merge_common() fails, qcow2_merge_backward_work() clears the
> dirty bit of the lower image right away. qcow2_service_iter() waits only
> for the service qios, so delayed md writeback of the lower image may
> still be pending. With kernel_sets_dirty_bit, a crash at that point
> leaves the lower image marked clean on disk with refblocks that lag
> behind the merged data.
>
> Flush the deferred activity of the lower image before writing its
> header, as qcow2_merge_backward_complete() does.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
> Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=5
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 04/12] dm-qcow2: complete wbd before ending the data qio
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 04/12] dm-qcow2: complete wbd before ending the data qio Alexander Ivanov
@ 2026-11-10 7:58 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 7:58 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
> data_rw_complete() calls qio_endio() before complete_wbd(). qio_endio()
> drops the inflight ref, so qcow2_flush_deferred_activity() may return
> on suspend while complete_wbd() for a failed L1/L2 writeback is still
> running in AIO completion context. revert_l_entries_update() then
> marks clusters unused and dirties an R2 page after the flush.
>
> That page sits on slow_wb_batch_list with the slow writeback timer
> armed. If the timer fires first, the page is written while the device
> is suspended, after postsuspend has cleared the dirty bit. If
> preresume comes first, qcow2_free_md_pages_all() frees the page
> without taking it off the list, and the timer later walks freed
> memory.
>
> Complete the wbd first, so the R2 update is in place before the
> inflight ref goes away and the suspend flush writes it back. The md
> writeback path already does it in this order.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
> Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=4
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 06/12] dm-qcow2: keep the dirty bit of an image that needs check
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 06/12] dm-qcow2: keep the dirty bit of an image that needs check Alexander Ivanov
@ 2026-11-10 7:59 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 7:59 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
> The dm-qcow2 module parameter kernel_sets_dirty_bit makes the kernel set
> the dirty bit on resume and clear it on postsuspend. It is off by
> default and Virtuozzo does not set it: ploop manages the dirty bit from
> userspace itself. So this is a hardening patch for the non-default mode.
>
> With kernel_sets_dirty_bit, postsuspend clears the dirty bit
> unconditionally. An image that is dirty at open, e.g. after a crash,
> has unrepaired refcounts, which may be below real usage, yet it is
> marked clean on disk after the first suspend. A userspace check before
> the next open then has no reason to repair it. The same happens after
> an error that sets wants_check, e.g. md_writeback_error: it is kept only
> in the target, so resume is refused, but after a table reload or a host
> restart the image is reopened with a clean header.
>
> Clear the bit only if the image was clean before the kernel set it and
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=6
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 07/12] dm-qcow2: flag the image for check if reftable relocation fails late
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 07/12] dm-qcow2: flag the image for check if reftable relocation fails late Alexander Ivanov
@ 2026-11-10 8:00 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 8:00 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
> Once relocate_refcount_table() has issued the header write pointing to
> the new reftable, any failure returns -EIO. The header on disk may
> already point to the new reftable even if its own write fails: a short
> write is reported as -ENODATA, and the old reftable position is
> restored only in the cached header page, which a v2 image never
> rewrites on suspend. The new reftable on disk may then be unfilled or
> miss the new refblocks, while refcounts of the new and old reftable
> clusters may not be updated. Refcounts no longer match the header, but
> nothing reports that, so the device can be resumed and the image
> reopened as if it were consistent.
>
> Set md_writeback_error on these paths, so wants_check reports the image
> and resume is refused until it is checked, and log the failure.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
> Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=7
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 08/12] dm-qcow2: fail the L2 table allocation request on L1 writeback error
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 08/12] dm-qcow2: fail the L2 table allocation request on L1 writeback error Alexander Ivanov
@ 2026-11-10 8:01 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 8:01 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
> A request that allocates an L2 table waits for the L1 writeback on the
> page wait list. If the writeback fails, the L1 entry is reverted and the
> request is dispatched again, so it allocates another L2 table and dirties
> L1 once more. With a persistent write error the request never completes.
>
> Queue the request on the wbd dependent list instead, like requests
> waiting for an L2 update. It is dispatched again after a successful
> writeback and ends with the error after a failed one.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
> Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=8
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback Alexander Ivanov
@ 2026-11-10 8:04 ` no-reply
2026-11-10 8:25 ` Alexander Ivanov
0 siblings, 1 reply; 30+ messages in thread
From: no-reply @ 2026-11-10 8:04 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] dm-qcow2: clusters leaked silently after failed L1/L2 writeback, no log or check flag
- [Low] dm-qcow2: qcow2_flush_deferred_activity() two-pass loop lost its rationale
--
commit 9ad1bd4fdc16fdd64c7c406c8964d581b12af819
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
dm-qcow2: leak clusters allocated for a failed L1/L2 writeback
This commit stops revert_l_entries_update() from dropping the refcount of
clusters allocated for a failed L1/L2 writeback. It also clears
FREE_ALLOCATED_CLU for COW qios that end with the writeback error. The
clusters are leaked instead of being freed, so an on-disk L1/L2 entry that
points to one stays valid.
Link: https://virtuozzo.atlassian.net/browse/VSTOR-148171
> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
> --- a/drivers/md/dm-qcow2-map.c
> +++ b/drivers/md/dm-qcow2-map.c
[ ... ]
> static void revert_l_entries_update(struct qcow2 *qcow2, struct wb_desc *wbd)
> {
> - struct qcow2_map_item r1, r2;
[ ... ]
> + struct page *pe_page = wbd->pe_page;
> + u64 old;
> + int i;
>
> lockdep_assert_held(&qcow2->md_pages_lock);
> for_each_set_bit(i, wbd->changed_indexes, LX_INDEXES_PER_PAGE) {
[ ... ]
> + old = pe_page ? get_u64_from_be_page(pe_page, i) : 0;
> + set_u64_to_be_page(wbd->md->page, i, old);
> }
> }
[ ... ]
> @@ -1408,6 +1373,7 @@ static void complete_wbd(struct qcow2 *qcow2, struct wb_desc *wbd)
[ ... ]
> + list_for_each_entry(qio, &end_list, link) {
> + if (qio->ext)
> + qio->ext->cleanup_mask &= ~FREE_ALLOCATED_CLU;
> + }
> qcow2_dispatch_qios(qcow2, NULL, &wait_list);
> end_qios(&end_list, errno_to_blk_status(wbd->ret));
[Severity: Medium]
The commit message says "Check frees them, so the image needs no check and
resume needs no refusal." Is that accurate?
Once revert_l_entries_update() no longer calls mark_cluster_unused(), the
L2-table cluster (for an L1 write) or the data cluster (for an L2 write)
allocated in prepare_l_entry_update() keeps its refcount. The same applies
to COW clusters, because complete_wbd() clears FREE_ALLOCATED_CLU, which
bypasses handle_cleanup_mask()->mark_cluster_unused().
Nothing seems to report this leak. clear_writeback_status() sets
MD_WRITEBACK_ERROR only when !md->wbd, which is not the case on this path.
There is also no QC_ERR message and no counter, so wants_check and the
status output do not tell the operator that a check is needed to reclaim
the space.
With persistent write failures and guest retries, each failed request
leaks one more cluster. Leaked clusters also stay counted as used, so the
used-end tail truncation added later in the series cannot shrink past
them.
Would it make sense to log the leak, or to flag the image so that a check
is requested, and to reword the commit message accordingly?
> diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
> --- a/drivers/md/dm-qcow2-target.c
> +++ b/drivers/md/dm-qcow2-target.c
> @@ -173,10 +173,6 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2
> struct md_page *md;
> int i;
>
> - /*
> - * We need second iteration, since revert_l_entries_update() may start timer again after failed wb.
> - */
> for (i = 0; i < 2; i++) {
[Severity: Low]
This isn't a bug, but the comment explaining why the loop runs twice is
deleted while the loop itself stays.
mark_cluster_unused() is still reached from handle_cleanup_mask() with
FREE_ALLOCATED_CLU, and process_indexes_end() still dirties R2 pages. Both
can re-arm slow_wb_timer after the first pass.
Could the comment be rewritten to state the remaining reason for the second
iteration, rather than removed?
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=9
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC Alexander Ivanov
@ 2026-11-10 8:06 ` no-reply
2026-11-10 8:31 ` Alexander Ivanov
0 siblings, 1 reply; 30+ messages in thread
From: no-reply @ 2026-11-10 8:06 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dm-qcow2: ENOSPC retry of failed L1/L2 writeback leaks a data cluster per retry
--
commit 647503fd94be077d5a1fad60c25b0ae7127ab8cf
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
dm-qcow2: retry R1/R2 writeback that failed with ENOSPC
This commit redirties an R1/R2 metadata page whose writeback failed with
-ENOSPC, so the slow writeback timer retries it. It also passes the errno
of a failed metadata write through complete_metadata_writeback() instead of
turning it into -EIO. As a result, a data request that depends on a failed
L1/L2 write can now end with BLK_STS_NOSPC and be delayed and resubmitted.
> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
> --- a/drivers/md/dm-qcow2-map.c
> +++ b/drivers/md/dm-qcow2-map.c
[ ... ]
> @@ -3869,9 +3871,9 @@ static int complete_metadata_writeback(struct qcow2 *qcow2)
> md = qio->ext->md;
> qvec = qio->data;
> ret = qio->ret;
> - if (unlikely(ret != PAGE_SIZE))
> + if (unlikely(ret >= 0 && ret != PAGE_SIZE))
> ret = -EIO;
> - else
> + else if (ret == PAGE_SIZE)
> ret = fsync_ret;
>
> do_md_page_write_complete(ret, qcow2, md);
[Severity: Medium]
Can this change make the cluster leak repeat? With the errno now passed
through, a failed L2 write ends up as -ENOSPC instead of -EIO:
complete_metadata_writeback()
do_md_page_write_complete(-ENOSPC, ...)
wbd->ret = ret
complete_wbd()
list_for_each_entry(qio, &end_list, link) {
if (qio->ext)
qio->ext->cleanup_mask &= ~FREE_ALLOCATED_CLU;
}
end_qios(&end_list, errno_to_blk_status(ret))
qrq_endio()
if (unlikely(bi_status == BLK_STS_NOSPC)) {
if (qcow2_try_delay_enospc(tgt, qrq, qio))
return;
}
complete_wbd() deliberately does not free the newly allocated data cluster
when an L1/L2 writeback fails. Before this patch the request ended once with
-EIO and was not retried, so this leak happened at most once per request.
Now qrq_endio() delays the request and resubmits it. Each resubmission
allocates a new cluster. If the L2 write fails with -ENOSPC again, that
cluster is leaked as well, and this repeats for as long as ENOSPC persists.
The leaked clusters stay counted in the refcounts, and the image file keeps
growing on an underlying filesystem that is already full.
The commit message acknowledges this ("a request whose L2 write keeps failing
with ENOSPC leaks one data cluster on every resubmission, until the space is
back"), but the patch does not bound or fix it. Could the cluster be freed
(or the leak otherwise limited) before the request is resubmitted on
BLK_STS_NOSPC?
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=10
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 12/12] dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 12/12] dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC Alexander Ivanov
@ 2026-11-10 8:07 ` no-reply
2026-11-10 8:35 ` Alexander Ivanov
0 siblings, 1 reply; 30+ messages in thread
From: no-reply @ 2026-11-10 8:07 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dm-qcow2: retried flush after fsync ENOSPC can succeed because errseq reports the error once
--
commit cfe92a6a11a8e762b7903b1085d1bba233f67647
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC
This patch relaxes the WARN_ON_ONCE in qrq_endio() so that a REQ_OP_FLUSH
completing with BLK_STS_NOSPC no longer triggers the warning. The flush is
still delayed and resubmitted through qcow2_try_delay_enospc().
> diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
> --- a/drivers/md/dm-qcow2-map.c
> +++ b/drivers/md/dm-qcow2-map.c
[ ... ]
> @@ -4491,7 +4491,8 @@ static void qrq_endio(struct qcow2_target *tgt, struct qio *qio,
> * callers receive -ENOSPC synchronous without intermediaries.
> */
> if (unlikely(bi_status == BLK_STS_NOSPC)) {
> - WARN_ON_ONCE(!op_is_write(qio->bi_op));
> + WARN_ON_ONCE(!op_is_write(qio->bi_op) &&
> + qio->bi_op != REQ_OP_FLUSH);
> if (qcow2_try_delay_enospc(tgt, qrq, qio))
> return;
> }
[Severity: Medium]
The commit message says "Delaying and resubmitting the flush is already
correct". Is that accurate?
The flush ENOSPC originates in do_qcow2_fsync_work():
if (fsync_ret == -EAGAIN)
fsync_ret = vfs_fsync(qcow2->file, 0);
end_qios(&flush_qios, errno_to_blk_status(fsync_ret));
On -ENOSPC, qrq_endio() calls qcow2_try_delay_enospc(), which requeues the
qio on tgt->enospc_qios. After the timer fires, qcow2_submit_embedded_qio()
sends it back to the fsync worker:
WARN_ON_ONCE(qio->bi_op != REQ_OP_FLUSH);
queue_list_id = QLIST_FLUSH;
worker = &qcow2->fsync_worker;
The worker then calls vfs_fsync() again on the same struct file.
Writeback errors are reported through errseq. As documented in
file_check_and_advance_wb_err(), fsync reports errors that occurred since
the last fsync, and the call advances file->f_wb_err:
err = errseq_check_and_advance(&mapping->wb_err,
&file->f_wb_err);
Can the retried vfs_fsync() on the same qcow2->file therefore return 0 on
ext4 or xfs, which the commit message names for "a failed delayed write"?
If so, the flush that originally failed with -ENOSPC would complete with
BLK_STS_OK. The upper layer could then treat earlier writes as durable
when they were not.
A retried write resends its data, but a retried flush resends nothing. Is
there something in dm-qcow2 that retains the earlier failure, or that
otherwise makes the retry safe?
Could the commit message explain why resubmitting the flush is correct,
given the errseq behaviour?
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=12
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 11/12] dm-qcow2: truncate unused tail of image on suspend
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 11/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
@ 2026-11-10 8:07 ` no-reply
0 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2026-11-10 8:07 UTC (permalink / raw)
To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel
> Discard punches holes in place of freed clusters, so they hold no
> physical extents, but it doesn't change the file size. On postsuspend
> we truncate the image file only down to file_preallocated_area_start,
> i.e. we drop preallocations only. So if clusters at the end of the
> file are freed (refcount dropped to zero), the file size stays the
> same and the image never shrinks.
>
> Add qcow2_calc_used_end(), which scans refcount blocks backward from
> file_preallocated_area_start and returns the end of the last cluster
> with non-zero refcount, clamped to file_preallocated_area_start since
> the last cluster may be partial. Refcount ranges with no allocated
> refblock are skipped at once.
>
> The scan walks R1 entries normal I/O may never touch, so it validates
> them itself instead of letting calc_r2_page_id() WARN on a corrupted
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261110075140.1475607-1-alexander.ivanov@virtuozzo.com?part=11
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback
2026-11-10 8:04 ` no-reply
@ 2026-11-10 8:25 ` Alexander Ivanov
0 siblings, 0 replies; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 8:25 UTC (permalink / raw)
To: no-reply, andrey.zhadchenko; +Cc: devel
>> + list_for_each_entry(qio, &end_list, link) {
>> + if (qio->ext)
>> + qio->ext->cleanup_mask &= ~FREE_ALLOCATED_CLU;
>> + }
>> qcow2_dispatch_qios(qcow2, NULL, &wait_list);
>> end_qios(&end_list, errno_to_blk_status(wbd->ret));
> [Severity: Medium]
> The commit message says "Check frees them, so the image needs no check and
> resume needs no refusal." Is that accurate?
>
> Once revert_l_entries_update() no longer calls mark_cluster_unused(), the
> L2-table cluster (for an L1 write) or the data cluster (for an L2 write)
> allocated in prepare_l_entry_update() keeps its refcount. The same applies
> to COW clusters, because complete_wbd() clears FREE_ALLOCATED_CLU, which
> bypasses handle_cleanup_mask()->mark_cluster_unused().
>
> Nothing seems to report this leak. clear_writeback_status() sets
> MD_WRITEBACK_ERROR only when !md->wbd, which is not the case on this path.
> There is also no QC_ERR message and no counter, so wants_check and the
> status output do not tell the operator that a check is needed to reclaim
> the space.
>
> With persistent write failures and guest retries, each failed request
> leaks one more cluster. Leaked clusters also stay counted as used, so the
> used-end tail truncation added later in the series cannot shrink past
> them.
>
> Would it make sense to log the leak, or to flag the image so that a check
> is requested, and to reword the commit message accordingly?
A leaked cluster does not corrupt the image: nothing on disk points to a
free
cluster, and no two offsets share a cluster. It is the same harmless
leak that
qemu-img check reclaims during any check. Setting wants_check would bring
back the resume refusal that this commit removes. The message already says
that each failed request leaks one cluster. A separate log message adds
nothing,
since the guest already gets the write error.
>> diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
>> --- a/drivers/md/dm-qcow2-target.c
>> +++ b/drivers/md/dm-qcow2-target.c
>> @@ -173,10 +173,6 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2
>> struct md_page *md;
>> int i;
>>
>> - /*
>> - * We need second iteration, since revert_l_entries_update() may start timer again after failed wb.
>> - */
>> for (i = 0; i < 2; i++) {
> [Severity: Low]
> This isn't a bug, but the comment explaining why the loop runs twice is
> deleted while the loop itself stays.
>
> mark_cluster_unused() is still reached from handle_cleanup_mask() with
> FREE_ALLOCATED_CLU, and process_indexes_end() still dirties R2 pages. Both
> can re-arm slow_wb_timer after the first pass.
>
> Could the comment be rewritten to state the remaining reason for the second
> iteration, rather than removed?
The loop itself explains why it runs twice.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC
2026-11-10 8:06 ` no-reply
@ 2026-11-10 8:31 ` Alexander Ivanov
0 siblings, 0 replies; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 8:31 UTC (permalink / raw)
To: no-reply, andrey.zhadchenko; +Cc: devel
>> @@ -3869,9 +3871,9 @@ static int complete_metadata_writeback(struct qcow2 *qcow2)
>> md = qio->ext->md;
>> qvec = qio->data;
>> ret = qio->ret;
>> - if (unlikely(ret != PAGE_SIZE))
>> + if (unlikely(ret >= 0 && ret != PAGE_SIZE))
>> ret = -EIO;
>> - else
>> + else if (ret == PAGE_SIZE)
>> ret = fsync_ret;
>>
>> do_md_page_write_complete(ret, qcow2, md);
> [Severity: Medium]
> Can this change make the cluster leak repeat? With the errno now passed
> through, a failed L2 write ends up as -ENOSPC instead of -EIO:
>
> complete_metadata_writeback()
> do_md_page_write_complete(-ENOSPC, ...)
> wbd->ret = ret
> complete_wbd()
> list_for_each_entry(qio, &end_list, link) {
> if (qio->ext)
> qio->ext->cleanup_mask &= ~FREE_ALLOCATED_CLU;
> }
> end_qios(&end_list, errno_to_blk_status(ret))
> qrq_endio()
> if (unlikely(bi_status == BLK_STS_NOSPC)) {
> if (qcow2_try_delay_enospc(tgt, qrq, qio))
> return;
> }
>
> complete_wbd() deliberately does not free the newly allocated data cluster
> when an L1/L2 writeback fails. Before this patch the request ended once with
> -EIO and was not retried, so this leak happened at most once per request.
>
> Now qrq_endio() delays the request and resubmits it. Each resubmission
> allocates a new cluster. If the L2 write fails with -ENOSPC again, that
> cluster is leaked as well, and this repeats for as long as ENOSPC persists.
> The leaked clusters stay counted in the refcounts, and the image file keeps
> growing on an underlying filesystem that is already full.
>
> The commit message acknowledges this ("a request whose L2 write keeps failing
> with ENOSPC leaks one data cluster on every resubmission, until the space is
> back"), but the patch does not bound or fix it. Could the cluster be freed
> (or the leak otherwise limited) before the request is resubmitted on
> BLK_STS_NOSPC?
The leak only happens in a narrow window: the data write to the new cluster
succeeds, but the overwrite of the already allocated L2 page then fails with
ENOSPC. Once the filesystem is really full, the data write fails first
and its cluster
is freed through FREE_ALLOCATED_CLU, so the leak stops by itself.
Freeing the
cluster before the request is resubmitted is unsafe, because the failed
L2 write
may have partially reached the disk, and two guest offsets could then
share the
cluster. A leaked cluster leaves the image consistent and check reclaims it.
Leaking a few clusters is better than failing the guest write with EIO,
which is
what happened before this patch.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 12/12] dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC
2026-11-10 8:07 ` no-reply
@ 2026-11-10 8:35 ` Alexander Ivanov
0 siblings, 0 replies; 30+ messages in thread
From: Alexander Ivanov @ 2026-11-10 8:35 UTC (permalink / raw)
To: no-reply, andrey.zhadchenko; +Cc: devel
>> @@ -4491,7 +4491,8 @@ static void qrq_endio(struct qcow2_target *tgt, struct qio *qio,
>> * callers receive -ENOSPC synchronous without intermediaries.
>> */
>> if (unlikely(bi_status == BLK_STS_NOSPC)) {
>> - WARN_ON_ONCE(!op_is_write(qio->bi_op));
>> + WARN_ON_ONCE(!op_is_write(qio->bi_op) &&
>> + qio->bi_op != REQ_OP_FLUSH);
>> if (qcow2_try_delay_enospc(tgt, qrq, qio))
>> return;
>> }
> [Severity: Medium]
> The commit message says "Delaying and resubmitting the flush is already
> correct". Is that accurate?
>
> The flush ENOSPC originates in do_qcow2_fsync_work():
>
> if (fsync_ret == -EAGAIN)
> fsync_ret = vfs_fsync(qcow2->file, 0);
>
> end_qios(&flush_qios, errno_to_blk_status(fsync_ret));
>
> On -ENOSPC, qrq_endio() calls qcow2_try_delay_enospc(), which requeues the
> qio on tgt->enospc_qios. After the timer fires, qcow2_submit_embedded_qio()
> sends it back to the fsync worker:
>
> WARN_ON_ONCE(qio->bi_op != REQ_OP_FLUSH);
> queue_list_id = QLIST_FLUSH;
> worker = &qcow2->fsync_worker;
>
> The worker then calls vfs_fsync() again on the same struct file.
>
> Writeback errors are reported through errseq. As documented in
> file_check_and_advance_wb_err(), fsync reports errors that occurred since
> the last fsync, and the call advances file->f_wb_err:
>
> err = errseq_check_and_advance(&mapping->wb_err,
> &file->f_wb_err);
>
> Can the retried vfs_fsync() on the same qcow2->file therefore return 0 on
> ext4 or xfs, which the commit message names for "a failed delayed write"?
>
> If so, the flush that originally failed with -ENOSPC would complete with
> BLK_STS_OK. The upper layer could then treat earlier writes as durable
> when they were not.
>
> A retried write resends its data, but a retried flush resends nothing. Is
> there something in dm-qcow2 that retains the earlier failure, or that
> otherwise makes the retry safe?
>
> Could the commit message explain why resubmitting the flush is correct,
> given the errseq behaviour?
dm-qcow2 refuses an image file without O_DIRECT (qcow2_attach_file()),
so it leaves no dirty page cache. Allocation failures of direct writes are
returned to the write itself, not through errseq, so there is no one-shot
error for the retried fsync to miss. An fsync ENOSPC can only come from
the backing fs's own fsync handler (e.g. a FUSE daemon), which reports
it again on the next call. Besides, this patch only silences the WARN: the
flush was delayed and resubmitted before it too.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (11 preceding siblings ...)
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 12/12] dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC Alexander Ivanov
@ 2026-11-10 11:42 ` Konstantin Khorenko
2026-11-10 11:43 ` Konstantin Khorenko
13 siblings, 0 replies; 30+ messages in thread
From: Konstantin Khorenko @ 2026-11-10 11:42 UTC (permalink / raw)
To: Alexander Ivanov; +Cc: devel
Applying as is.
On 11/10/26 08:51, Alexander Ivanov wrote:
> Alexander Ivanov (12):
> dm-qcow2: add qcow2_md_page_read_sync() helper
> dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages
> dm-qcow2: extend the file for a new refblock in allocate_cluster()
> dm-qcow2: complete wbd before ending the data qio
> dm-qcow2: flush lower md before clearing dirty bit on merge failure
> dm-qcow2: keep the dirty bit of an image that needs check
> dm-qcow2: flag the image for check if reftable relocation fails late
> dm-qcow2: fail the L2 table allocation request on L1 writeback error
> dm-qcow2: leak clusters allocated for a failed L1/L2 writeback
> dm-qcow2: retry R1/R2 writeback that failed with ENOSPC
> dm-qcow2: truncate unused tail of image on suspend
> dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC
While reviewing v12 we found two older bugs in the L2 writeback revert
path. Both are there since the driver was added, and this series does
not touch them. Please fix them as separate patches:
1. https://virtuozzo.atlassian.net/browse/VSTOR-154310
On an ext_l2 image a second update of the subcluster bitmap in the
same wbd overwrites the saved original in pe_page. If the L2
writeback then fails, the revert leaves entry 0 with allocated
bits, and the next write to those subclusters goes into the image
header cluster.
2. https://virtuozzo.atlassian.net/browse/VSTOR-154311
On an image without ext_l2, a write to an all-zeroes entry with no
host cluster takes no pe_page. If the L2 writeback then fails, the
revert clears L2_READS_ALL_ZEROES, and discarded data comes back
from the backing image.
The scenarios and the proposed fixes are in the tickets.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
` (12 preceding siblings ...)
2026-11-10 11:42 ` [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Konstantin Khorenko
@ 2026-11-10 11:43 ` Konstantin Khorenko
13 siblings, 0 replies; 30+ messages in thread
From: Konstantin Khorenko @ 2026-11-10 11:43 UTC (permalink / raw)
To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel
On Tue, 10 Nov 2026 08:51:28 +0100, Alexander Ivanov wrote:
> dm-qcow2: truncate unused tail of image on suspend
>
> Discard punches holes in place of freed clusters, but doesn't change
> the file size. On postsuspend dm-qcow2 truncates the image file only
> down to file_preallocated_area_start, so if clusters at the end of the
> file are freed, the file never shrinks.
>
> [...]
Applied to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.20.vz10, thanks!
[01/12] dm-qcow2: add qcow2_md_page_read_sync() helper
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/424f96b846c6
[02/12] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/aab68837199d
[03/12] dm-qcow2: extend the file for a new refblock in allocate_cluster()
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/da5c9dc5a036
[04/12] dm-qcow2: complete wbd before ending the data qio
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/ea70f57c04d8
[05/12] dm-qcow2: flush lower md before clearing dirty bit on merge failure
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/7416f7aa1472
[06/12] dm-qcow2: keep the dirty bit of an image that needs check
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/d36c0c7a0923
[07/12] dm-qcow2: flag the image for check if reftable relocation fails late
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/2ba8da09eb4b
[08/12] dm-qcow2: fail the L2 table allocation request on L1 writeback error
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/e5014ff7b2e3
[09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/5b1f91c85436
[10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/1946985fee9d
[11/12] dm-qcow2: truncate unused tail of image on suspend
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/eed0d96e6c09
[12/12] dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/f4e3ac242fb8
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2026-11-10 11:44 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 7:51 [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 01/12] dm-qcow2: add qcow2_md_page_read_sync() helper Alexander Ivanov
2026-11-10 7:55 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 02/12] dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages Alexander Ivanov
2026-11-10 7:55 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 03/12] dm-qcow2: extend the file for a new refblock in allocate_cluster() Alexander Ivanov
2026-11-10 7:56 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 04/12] dm-qcow2: complete wbd before ending the data qio Alexander Ivanov
2026-11-10 7:58 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 05/12] dm-qcow2: flush lower md before clearing dirty bit on merge failure Alexander Ivanov
2026-11-10 7:58 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 06/12] dm-qcow2: keep the dirty bit of an image that needs check Alexander Ivanov
2026-11-10 7:59 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 07/12] dm-qcow2: flag the image for check if reftable relocation fails late Alexander Ivanov
2026-11-10 8:00 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 08/12] dm-qcow2: fail the L2 table allocation request on L1 writeback error Alexander Ivanov
2026-11-10 8:01 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback Alexander Ivanov
2026-11-10 8:04 ` no-reply
2026-11-10 8:25 ` Alexander Ivanov
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC Alexander Ivanov
2026-11-10 8:06 ` no-reply
2026-11-10 8:31 ` Alexander Ivanov
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 11/12] dm-qcow2: truncate unused tail of image on suspend Alexander Ivanov
2026-11-10 8:07 ` no-reply
2026-11-10 7:51 ` [Devel] [PATCH hci-8.1 v12 12/12] dm-qcow2: fix WARN in qrq_endio() on flush failing with ENOSPC Alexander Ivanov
2026-11-10 8:07 ` no-reply
2026-11-10 8:35 ` Alexander Ivanov
2026-11-10 11:42 ` [Devel] [PATCH hci-8.1 v12 00/12] dm-qcow2: truncate unused tail of image on suspend Konstantin Khorenko
2026-11-10 11:43 ` Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox