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 v3 5/9] drivers/md/dm-qcow2: report held requests with an IO_ERROR uevent
Date: Tue, 17 Nov 2026 11:43:25 +0100	[thread overview]
Message-ID: <20261117104329.3079812-6-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261117104329.3079812-1-alexander.ivanov@virtuozzo.com>

QEMU is to pause the VM when dm-qcow2 holds a failed request, but it
cannot use dm_table_event(): waiting for dm events needs dm ioctls
and CAP_SYS_ADMIN, which QEMU does not have. libvirt already passes
QEMU a NETLINK_KOBJECT_UEVENT socket to watch the vhost-blk disk for
RESIZE=1 change events.

Send a change uevent on the dm disk with

  IO_ERROR=1
  IO_ERROR_OP=read|write
  IO_ERROR_ERRNO=<positive errno>

when the held list turns non-empty. A periodic retry that fails
again repopulates the list, so the event is repeated while the error
persists and a lost netlink message is not fatal. This applies to
every dm-qcow2 device: a disk whose underlying storage stays full,
such as a container disk, now gets a change uevent and a udev probe
on every retry, that is every 20 seconds.

Only ENOSPC is held for now, for reads as well as writes; the op and
errno are reported so that other held errors need no new interface.
A flush is reported as a write, as QEMU does.

The event carries no DM_COOKIE, so udev handles it as a spurious
change and probes the disk, as it does after a close or a resize. A
cookie with the flags that disable the disk rules would avoid the probe
but makes 13-dm-disk.rules drop the by-id and by-uuid links, and the
flags stay in the udev database after the error is gone. The probe
only reads, but a read that fails with ENOSPC is held too, so the
probe may wait for the next retry like any other reader.

get_event keeps reporting a held ENOSPC as "event_ENOSPC", which
dm-ploop answers too, and reports other held errors as
"event_io_error <op> <errno>".

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    | 11 ++++++++---
 drivers/md/dm-qcow2-map.c    |  8 +++++++-
 drivers/md/dm-qcow2-target.c | 28 ++++++++++++++++++++++++++++
 drivers/md/dm-qcow2.h        |  5 ++++-
 4 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index 3bccce090f01..7af3ac154127 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -584,10 +584,15 @@ static int qcow2_get_event(struct qcow2_target *tgt, char *result, unsigned int
 	int ret = 0;
 
 	spin_lock_irq(&tgt->event_lock);
-	if (tgt->event_enospc) {
-		ret = (DMEMIT("event_ENOSPC\n")) ? 1 : 0;
+	if (tgt->event_io_error) {
+		if (tgt->event_errno == ENOSPC)
+			ret = (DMEMIT("event_ENOSPC\n")) ? 1 : 0;
+		else
+			ret = (DMEMIT("event_io_error %s %d\n",
+				      tgt->event_write ? "write" : "read",
+				      tgt->event_errno)) ? 1 : 0;
 		if (ret)
-			tgt->event_enospc = false;
+			tgt->event_io_error = false;
 	}
 	spin_unlock_irq(&tgt->event_lock);
 
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index d6f8bcd98a39..2a663eb652f4 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4569,6 +4569,7 @@ void do_qcow2_fsync_work(struct work_struct *ws)
 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;
 	unsigned long flags;
 
@@ -4585,8 +4586,13 @@ static bool qcow2_try_hold_error(struct qcow2_target *tgt, struct qcow2_rq *qrq,
 
 	pr_err_once(QCOW2_FMT("underlying disk is almost full"),
 			qcow2_device_name(tgt->ti));
-	tgt->event_enospc = true;
+	tgt->event_io_error = true;
 	first = list_empty(&tgt->held_qios);
+	if (first) {
+		tgt->event_uevent = true;
+		tgt->event_write = write;
+		tgt->event_errno = -blk_status_to_errno(bi_status);
+	}
 	list_add_tail(&qio->link, &tgt->held_qios);
 unlock:
 	spin_unlock_irqrestore(&tgt->event_lock, flags);
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 89b12c4f971b..2a57f66fe25d 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -8,6 +8,7 @@
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/error-injection.h>
+#include <linux/sched/mm.h>
 
 #include "dm.h"
 #include "dm-qcow2.h"
@@ -493,11 +494,38 @@ static void qcow2_held_timer(struct timer_list *timer)
 	qcow2_submit_embedded_qios(tgt, &list);
 }
 
+static void qcow2_send_io_error_uevent(struct qcow2_target *tgt,
+				       bool write, int err)
+{
+	struct mapped_device *md = dm_table_get_md(tgt->ti->table);
+	char op[24], errno_env[24];
+	char *envp[] = { "IO_ERROR=1", op, errno_env, NULL };
+	unsigned int noio_flag;
+
+	snprintf(op, sizeof(op), "IO_ERROR_OP=%s", write ? "write" : "read");
+	snprintf(errno_env, sizeof(errno_env), "IO_ERROR_ERRNO=%d", err);
+
+	noio_flag = memalloc_noio_save();
+	kobject_uevent_env(&disk_to_dev(dm_disk(md))->kobj, KOBJ_CHANGE, envp);
+	memalloc_noio_restore(noio_flag);
+}
+
 static void qcow2_event_work(struct work_struct *ws)
 {
 	struct qcow2_target *tgt = container_of(ws, struct qcow2_target, event_work);
+	bool uevent, write;
+	int err;
+
+	spin_lock_irq(&tgt->event_lock);
+	uevent = tgt->event_uevent;
+	tgt->event_uevent = false;
+	write = tgt->event_write;
+	err = tgt->event_errno;
+	spin_unlock_irq(&tgt->event_lock);
 
 	dm_table_event(tgt->ti->table);
+	if (uevent)
+		qcow2_send_io_error_uevent(tgt, write, err);
 }
 
 static struct qcow2_target *alloc_qcow2_target(struct dm_target *ti)
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index ea6bc6258cb0..03233090da23 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -208,7 +208,10 @@ struct qcow2_target {
 	bool wants_suspend;
 	bool md_writeback_error;
 	bool truncate_error;
-	bool event_enospc;
+	bool event_io_error;
+	bool event_uevent;
+	bool event_write;
+	int event_errno;
 
 	atomic_t service_qios;
 	struct wait_queue_head service_wq;
-- 
2.53.0

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

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

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 10:43 [Devel] [PATCH hci-8.1 v3 0/9] dm-qcow2: support the werror/rerror policies for vhost-blk disks Alexander Ivanov
2026-11-17 10:43 ` [Devel] [PATCH hci-8.1 v3 1/9] drivers/md/dm-qcow2: cancel the event work and ENOSPC timer in the destructor Alexander Ivanov
2026-11-17 10:52   ` no-reply
2026-11-17 10:43 ` [Devel] [PATCH hci-8.1 v3 2/9] drivers/md/dm-qcow2: always resubmit delayed ENOSPC requests in presuspend Alexander Ivanov
2026-11-17 10:50   ` no-reply
2026-11-17 10:43 ` [Devel] [PATCH hci-8.1 v3 3/9] drivers/md/dm-qcow2: rename the ENOSPC delay list to a held request list Alexander Ivanov
2026-11-17 10:51   ` no-reply
2026-11-17 10:43 ` [Devel] [PATCH hci-8.1 v3 4/9] drivers/md/dm-qcow2: arm the hold timer only for the first held request Alexander Ivanov
2026-11-17 10:52   ` no-reply
2026-11-17 10:43 ` Alexander Ivanov [this message]
2026-11-17 10:53   ` [Devel] [PATCH hci-8.1 v3 5/9] drivers/md/dm-qcow2: report held requests with an IO_ERROR uevent no-reply
2026-11-17 10:43 ` [Devel] [PATCH hci-8.1 v3 6/9] drivers/md/dm-qcow2: add the resubmit and fail_held messages Alexander Ivanov
2026-11-17 10:54   ` no-reply
2026-11-17 10:43 ` [Devel] [PATCH hci-8.1 v3 7/9] drivers/md/dm-qcow2: add the error_policy table argument Alexander Ivanov
2026-11-17 10:56   ` no-reply
2026-11-17 10:43 ` [Devel] [PATCH hci-8.1 v3 8/9] drivers/md/dm-qcow2: requeue held requests on a noflush suspend Alexander Ivanov
2026-11-17 10:57   ` no-reply
2026-11-17 10:43 ` [Devel] [PATCH hci-8.1 v3 9/9] drivers/vhost/blk: fix a hang on release after the vhost worker is killed Alexander Ivanov
2026-11-17 11:01   ` no-reply
2026-11-17 11:25   ` Konstantin Khorenko
2026-11-17 11:25 ` [Devel] [PATCH hci-8.1 v3 0/9] dm-qcow2: support the werror/rerror policies for vhost-blk disks 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=20261117104329.3079812-6-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