[Devel] [PATCH hci-8.1 v2 5/9] drivers/md/dm-qcow2: report held requests with an IO_ERROR uevent
Alexander Ivanov
alexander.ivanov at virtuozzo.com
Tue Nov 17 13:10:22 MSK 2026
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 at 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
More information about the Devel
mailing list