All Virtuozzo development lists (kernel + QEMU)
 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 6/9] drivers/md/dm-qcow2: add the resubmit and fail_held messages
Date: Tue, 17 Nov 2026 11:10:23 +0100	[thread overview]
Message-ID: <20261117101026.3071579-7-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261117101026.3071579-1-alexander.ivanov@virtuozzo.com>

Held requests are retried every 20 seconds. QEMU pauses the VM on
the IO_ERROR uevent, and the requests should be retried as soon as
the VM is resumed, and dropped if the VM is destroyed: vhost-blk waits
for all in-flight requests on release, so a request held while the
error persists leaves QEMU in D state.

QEMU has no CAP_SYS_ADMIN, so libvirt sends the messages:

  resubmit   - resubmit the held requests now
  fail_held  - fail the held requests and stop holding new ones
               until resubmit or resume

fail_held has to be sticky: requests in flight when it arrives, a
timer resubmission included, fail later and would otherwise be held
again with the timer rearmed.

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-qcow2-cmd.c    | 21 +++++++++++++++++++++
 drivers/md/dm-qcow2-map.c    | 35 ++++++++++++++++++++++++++++++++++-
 drivers/md/dm-qcow2-target.c | 16 +++++++---------
 drivers/md/dm-qcow2.h        |  4 ++++
 4 files changed, 66 insertions(+), 10 deletions(-)

diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index 7af3ac154127..ea9c69b454ea 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -643,6 +643,27 @@ int qcow2_message(struct dm_target *ti, unsigned int argc, char **argv,
 		}
 		ret = qcow2_get_event(tgt, result, maxlen);
 		goto out;
+	} else if (!strcmp(argv[0], "resubmit")) {
+		if (argc != 1) {
+			ret = -EINVAL;
+			goto out;
+		}
+		spin_lock_irq(&tgt->event_lock);
+		tgt->fail_held = false;
+		spin_unlock_irq(&tgt->event_lock);
+		timer_delete(&tgt->held_timer);
+		qcow2_resubmit_held_qios(tgt);
+		ret = 0;
+		goto out;
+	} else if (!strcmp(argv[0], "fail_held")) {
+		if (argc != 1) {
+			ret = -EINVAL;
+			goto out;
+		}
+		timer_delete(&tgt->held_timer);
+		qcow2_fail_held_qios(tgt);
+		ret = 0;
+		goto out;
 	} else if (!strcmp(argv[0], "merge_backward")) {
 		if (argc < 2) {
 			ret = -EINVAL;
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 2a663eb652f4..b2962c77cc15 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4577,12 +4577,13 @@ static bool qcow2_try_hold_error(struct qcow2_target *tgt, struct qcow2_rq *qrq,
 		return false;
 
 	spin_lock_irqsave(&tgt->event_lock, flags);
-	if (unlikely(tgt->wants_suspend)) {
+	if (unlikely(tgt->wants_suspend || tgt->fail_held)) {
 		held = false;
 		goto unlock;
 	}
 
 	init_qrq_and_embedded_qio(tgt, qrq->rq, qrq, qio);
+	qrq->held_status = bi_status;
 
 	pr_err_once(QCOW2_FMT("underlying disk is almost full"),
 			qcow2_device_name(tgt->ti));
@@ -4689,6 +4690,38 @@ void qcow2_submit_embedded_qios(struct qcow2_target *tgt, struct list_head *list
 		qcow2_submit_embedded_qio(tgt, qio);
 }
 
+void qcow2_resubmit_held_qios(struct qcow2_target *tgt)
+{
+	unsigned long flags;
+	LIST_HEAD(list);
+
+	spin_lock_irqsave(&tgt->event_lock, flags);
+	list_splice_init(&tgt->held_qios, &list);
+	spin_unlock_irqrestore(&tgt->event_lock, flags);
+
+	qcow2_submit_embedded_qios(tgt, &list);
+}
+
+void qcow2_fail_held_qios(struct qcow2_target *tgt)
+{
+	struct qcow2_rq *qrq;
+	struct request *rq;
+	struct qio *qio;
+	LIST_HEAD(list);
+
+	spin_lock_irq(&tgt->event_lock);
+	tgt->fail_held = true;
+	list_splice_init(&tgt->held_qios, &list);
+	spin_unlock_irq(&tgt->event_lock);
+
+	while ((qio = qio_list_pop(&list)) != NULL) {
+		qrq = qio->endio_cb_data;
+		rq = qrq->rq;
+		dm_complete_request(rq, qrq->held_status);
+		mempool_free(qrq, tgt->qrq_pool);
+	}
+}
+
 int qcow2_clone_and_map(struct dm_target *ti, struct request *rq,
 		    union map_info *info, struct request **clone)
 {
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 2a57f66fe25d..590c2e6a4bec 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -484,14 +484,8 @@ static void inflight_ref_exit1(struct percpu_ref *ref)
 static void qcow2_held_timer(struct timer_list *timer)
 {
 	struct qcow2_target *tgt = timer_container_of(tgt, timer, held_timer);
-	unsigned long flags;
-	LIST_HEAD(list);
 
-	spin_lock_irqsave(&tgt->event_lock, flags);
-	list_splice_init(&tgt->held_qios, &list);
-	spin_unlock_irqrestore(&tgt->event_lock, flags);
-
-	qcow2_submit_embedded_qios(tgt, &list);
+	qcow2_resubmit_held_qios(tgt);
 }
 
 static void qcow2_send_io_error_uevent(struct qcow2_target *tgt,
@@ -1247,8 +1241,12 @@ static int qcow2_preresume(struct dm_target *ti)
 		if (ret)
 			QC_ERR(ti, "Can't set features");
 	}
-	if (!ret)
-		qcow2_set_wants_suspend(ti, false);
+	if (!ret) {
+		spin_lock_irq(&tgt->event_lock);
+		tgt->fail_held = false;
+		tgt->wants_suspend = false;
+		spin_unlock_irq(&tgt->event_lock);
+	}
 
 	return ret;
 }
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 03233090da23..df20826c6060 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -206,6 +206,7 @@ struct qcow2_target {
 
 	bool service_operations_allowed;
 	bool wants_suspend;
+	bool fail_held;
 	bool md_writeback_error;
 	bool truncate_error;
 	bool event_io_error;
@@ -345,6 +346,7 @@ struct qio_ext {
 struct qcow2_rq {
 	struct request *rq;
 	struct bio_vec *bvec;
+	blk_status_t held_status;
 };
 
 struct qio;
@@ -426,6 +428,8 @@ void qcow2_init_qio(struct qio *qio, unsigned int bi_op, struct qcow2 *qcow2);
 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);
 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);
-- 
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 ` Alexander Ivanov [this message]
2026-11-17 10:32   ` [Devel] [PATCH hci-8.1 v2 6/9] drivers/md/dm-qcow2: add the resubmit and fail_held messages 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 ` [Devel] [PATCH hci-8.1 v2 8/9] drivers/md/dm-qcow2: requeue held requests on a noflush suspend Alexander Ivanov
2026-11-17 10:37   ` 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-7-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.