OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC
Date: Tue, 10 Nov 2026 08:51:38 +0100	[thread overview]
Message-ID: <20261110075140.1475607-11-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261110075140.1475607-1-alexander.ivanov@virtuozzo.com>

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

  parent reply	other threads:[~2026-11-10  7:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Alexander Ivanov [this message]
2026-11-10  8:06   ` [Devel] [PATCH hci-8.1 v12 10/12] dm-qcow2: retry R1/R2 writeback that failed with ENOSPC 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261110075140.1475607-11-alexander.ivanov@virtuozzo.com \
    --to=alexander.ivanov@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=devel@openvz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox