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 v2 8/9] drivers/md/dm-qcow2: requeue held requests on a noflush suspend
Date: Tue, 17 Nov 2026 11:10:25 +0100	[thread overview]
Message-ID: <20261117101026.3071579-9-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261117101026.3071579-1-alexander.ivanov@virtuozzo.com>

A request failed under the enospc or stop policy cannot stay held
across a suspend: the suspend waits for it to complete. So presuspend
retries the held requests once, and a request that fails again is
completed with its error. A table reload or a snapshot taken while the
VM is paused on a held request then delivers the error that the policy
was meant to keep from the guest.

On a noflush suspend, requeue such a request to the dm queue instead.
It is dispatched through the new table on resume and is held again if
the error persists. This follows dm-mpath, which requeues on a noflush
suspend and fails the I/O queued for no paths on a flush suspend.

ploop suspends with flags 0, a flush suspend, for a snapshot and a
resize in ploop_suspend_device(), so it gets the requeue only with the
ploop.ovz change "lib: suspend unpartitioned dm-qcow2 devices with
noflush". A partitioned device keeps the flush suspend there and still
completes a held request with its error.

The noflush mode is recorded in presuspend rather than read with
dm_noflush_suspending(): an interrupted suspend clears
DMF_NOFLUSH_SUSPENDING and restarts the queue before presuspend_undo
runs, and a request failing in between would get its error although
the suspend was cancelled.

The request is requeued with a delay, as dm-mpath does for the no-path
case: until the queue is stopped, or after an interrupted suspend
restarts it, a request that keeps failing would otherwise be dispatched
and requeued in a loop. dm_requeue_original_rq() gets a delay argument
for that.

Requeued requests keep the device open: their submitter cannot drop
its last reference until they complete, so a remove fails with EBUSY
until the device is resumed with a working table or with an error
table, as dmsetup remove --force does. dm-mpath with queue_if_no_path
behaves the same way.

fail_held fails with EBUSY during a noflush suspend: the requeued
requests are out of the target's reach, and the flag would not
survive a table reload. Userspace sends it again after resume.

https://virtuozzo.atlassian.net/browse/VSTOR-152175
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 drivers/md/dm-push-backup.c  |  2 +-
 drivers/md/dm-qcow2-cmd.c    |  6 +++---
 drivers/md/dm-qcow2-map.c    | 22 +++++++++++++++++++---
 drivers/md/dm-qcow2-target.c |  2 ++
 drivers/md/dm-qcow2.h        |  3 ++-
 drivers/md/dm-rq.c           |  4 ++--
 drivers/md/dm-rq.h           |  2 +-
 7 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/drivers/md/dm-push-backup.c b/drivers/md/dm-push-backup.c
index 4f6dc1f3c130..ca1f623f56a7 100644
--- a/drivers/md/dm-push-backup.c
+++ b/drivers/md/dm-push-backup.c
@@ -218,7 +218,7 @@ static void resubmit_pbios(struct push_backup *pb, struct list_head *list)
 
 		list_del_init(&pbio->list);
 		mempool_free(pbio, pb->pbio_pool);
-		dm_requeue_original_rq(rq);
+		dm_requeue_original_rq(rq, false);
 	}
 }
 
diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index 6a56919bec73..9106ce65d355 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -660,9 +660,9 @@ int qcow2_message(struct dm_target *ti, unsigned int argc, char **argv,
 			ret = -EINVAL;
 			goto out;
 		}
-		timer_delete(&tgt->held_timer);
-		qcow2_fail_held_qios(tgt);
-		ret = 0;
+		ret = qcow2_fail_held_qios(tgt);
+		if (!ret)
+			timer_delete(&tgt->held_timer);
 		goto out;
 	} else if (!strcmp(argv[0], "merge_backward")) {
 		if (argc < 2) {
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index adbebe728f99..830e3af28730 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4570,7 +4570,8 @@ static bool qcow2_try_hold_error(struct qcow2_target *tgt, struct qcow2_rq *qrq,
 				 struct qio *qio, blk_status_t bi_status)
 {
 	bool write = op_is_write(qio->bi_op) || qio->bi_op == REQ_OP_FLUSH;
-	bool held = true, first = false;
+	bool held = true, first = false, requeue = false;
+	struct request *rq = qrq->rq;
 	unsigned long flags;
 	u8 policy;
 
@@ -4584,7 +4585,10 @@ static bool qcow2_try_hold_error(struct qcow2_target *tgt, struct qcow2_rq *qrq,
 
 	spin_lock_irqsave(&tgt->event_lock, flags);
 	if (unlikely(tgt->wants_suspend || tgt->fail_held)) {
-		held = false;
+		if (!tgt->fail_held && tgt->noflush_suspend)
+			requeue = true;
+		else
+			held = false;
 		goto unlock;
 	}
 
@@ -4613,6 +4617,12 @@ static bool qcow2_try_hold_error(struct qcow2_target *tgt, struct qcow2_rq *qrq,
 unlock:
 	spin_unlock_irqrestore(&tgt->event_lock, flags);
 
+	if (requeue) {
+		mempool_free(qrq, tgt->qrq_pool);
+		dm_requeue_original_rq(rq, true);
+		return true;
+	}
+
 	if (first)
 		mod_timer(&tgt->held_timer, jiffies + HOLD_TIMEOUT_JI);
 	schedule_work(&tgt->event_work);
@@ -4717,7 +4727,7 @@ void qcow2_resubmit_held_qios(struct qcow2_target *tgt)
 	qcow2_submit_embedded_qios(tgt, &list);
 }
 
-void qcow2_fail_held_qios(struct qcow2_target *tgt)
+int qcow2_fail_held_qios(struct qcow2_target *tgt)
 {
 	struct qcow2_rq *qrq;
 	struct request *rq;
@@ -4725,6 +4735,10 @@ void qcow2_fail_held_qios(struct qcow2_target *tgt)
 	LIST_HEAD(list);
 
 	spin_lock_irq(&tgt->event_lock);
+	if (tgt->noflush_suspend) {
+		spin_unlock_irq(&tgt->event_lock);
+		return -EBUSY;
+	}
 	tgt->fail_held = true;
 	list_splice_init(&tgt->held_qios, &list);
 	spin_unlock_irq(&tgt->event_lock);
@@ -4735,6 +4749,8 @@ void qcow2_fail_held_qios(struct qcow2_target *tgt)
 		dm_complete_request(rq, qrq->held_status);
 		mempool_free(qrq, tgt->qrq_pool);
 	}
+
+	return 0;
 }
 
 int qcow2_clone_and_map(struct dm_target *ti, struct request *rq,
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index b3365f92c7dd..dd74e7c84b75 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -36,6 +36,7 @@ static void qcow2_set_wants_suspend(struct dm_target *ti, bool wants)
 
 	spin_lock_irq(&tgt->event_lock);
 	tgt->wants_suspend = wants;
+	tgt->noflush_suspend = wants && dm_noflush_suspending(ti);
 	spin_unlock_irq(&tgt->event_lock);
 }
 
@@ -1289,6 +1290,7 @@ static int qcow2_preresume(struct dm_target *ti)
 		spin_lock_irq(&tgt->event_lock);
 		tgt->fail_held = false;
 		tgt->wants_suspend = false;
+		tgt->noflush_suspend = false;
 		spin_unlock_irq(&tgt->event_lock);
 	}
 
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index cd73314ee28c..6b719113aeb6 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -212,6 +212,7 @@ struct qcow2_target {
 
 	bool service_operations_allowed;
 	bool wants_suspend;
+	bool noflush_suspend;
 	bool fail_held;
 	bool md_writeback_error;
 	bool truncate_error;
@@ -439,7 +440,7 @@ void qcow2_dispatch_qios(struct qcow2 *qcow2, struct qio *qio,
 		   struct list_head *qio_list);
 void qcow2_submit_embedded_qios(struct qcow2_target *tgt, struct list_head *list);
 void qcow2_resubmit_held_qios(struct qcow2_target *tgt);
-void qcow2_fail_held_qios(struct qcow2_target *tgt);
+int qcow2_fail_held_qios(struct qcow2_target *tgt);
 struct qcow2 *qcow2_ref_inc(struct qcow2_target *tgt, u8 *ref_index);
 void qcow2_ref_dec(struct qcow2_target *tgt, u8 ref_index);
 int qcow2_inflight_ref_switch(struct qcow2_target *tgt);
diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index 5a8cd59ec257..b2fb6f853a41 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -204,11 +204,11 @@ static void dm_requeue_original_request(struct dm_rq_target_io *tio, bool delay_
 	rq_completed(md);
 }
 
-void dm_requeue_original_rq(struct request *rq)
+void dm_requeue_original_rq(struct request *rq, bool delay)
 {
 	struct dm_rq_target_io *tio = tio_from_request(rq);
 
-	dm_requeue_original_request(tio, false);
+	dm_requeue_original_request(tio, delay);
 }
 EXPORT_SYMBOL(dm_requeue_original_rq);
 
diff --git a/drivers/md/dm-rq.h b/drivers/md/dm-rq.h
index 53abc3cf9aee..d04cdb8adda2 100644
--- a/drivers/md/dm-rq.h
+++ b/drivers/md/dm-rq.h
@@ -46,6 +46,6 @@ ssize_t dm_attr_rq_based_seq_io_merge_deadline_store(struct mapped_device *md,
 						     const char *buf, size_t count);
 
 void dm_complete_request(struct request *rq, blk_status_t error);
-void dm_requeue_original_rq(struct request *rq);
+void dm_requeue_original_rq(struct request *rq, bool delay);
 
 #endif
-- 
2.53.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-11-17 10:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 10:10 [Devel] [PATCH hci-8.1 v2 0/9] dm-qcow2: support the werror/rerror policies for vhost-blk disks Alexander Ivanov
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 1/9] drivers/md/dm-qcow2: cancel the event work and ENOSPC timer in the destructor Alexander Ivanov
2026-11-17 10:22   ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 2/9] drivers/md/dm-qcow2: always resubmit delayed ENOSPC requests in presuspend Alexander Ivanov
2026-11-17 10:25   ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 3/9] drivers/md/dm-qcow2: rename the ENOSPC delay list to a held request list Alexander Ivanov
2026-11-17 10:25   ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 4/9] drivers/md/dm-qcow2: arm the hold timer only for the first held request Alexander Ivanov
2026-11-17 10:27   ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 5/9] drivers/md/dm-qcow2: report held requests with an IO_ERROR uevent Alexander Ivanov
2026-11-17 10:29   ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 6/9] drivers/md/dm-qcow2: add the resubmit and fail_held messages Alexander Ivanov
2026-11-17 10:32   ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 7/9] drivers/md/dm-qcow2: add the error_policy table argument Alexander Ivanov
2026-11-17 10:34   ` no-reply
2026-11-17 10:10 ` Alexander Ivanov [this message]
2026-11-17 10:37   ` [Devel] [PATCH hci-8.1 v2 8/9] drivers/md/dm-qcow2: requeue held requests on a noflush suspend no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 9/9] drivers/vhost/blk: fix a hang on release after the vhost worker is killed Alexander Ivanov
2026-11-17 10:42   ` no-reply

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=20261117101026.3071579-9-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