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 7/9] drivers/md/dm-qcow2: add the error_policy table argument
Date: Tue, 17 Nov 2026 11:10:24 +0100	[thread overview]
Message-ID: <20261117101026.3071579-8-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261117101026.3071579-1-alexander.ivanov@virtuozzo.com>

QEMU disks have the werror/rerror policies: report the error to the
guest, or pause the VM and retry the request on resume, either for
ENOSPC only (enospc) or for any error (stop). A vhost-blk disk
completes requests to the guest from the kernel, so the request has
to be held in dm-qcow2 for QEMU to have a chance to pause the VM.

Accept an optional first table argument

  error_policy=<read>,<write>

where each policy is report, enospc or stop. Requests failed under
the enospc or stop policy are held, reported and resubmitted like
ENOSPC writes are now. All other table arguments are numeric fds, so
the option cannot be confused with an image.

With error_policy=stop for reads the udev probe that follows the
IO_ERROR uevent may be held too, and waits for resubmit, fail_held or
the next timer retry like any other reader. The timer retries and
reports every held error, not only ENOSPC, so a lost uevent is not
fatal and a transient error clears by itself; the VM stays paused
until cont regardless.

The default is read=report, write=enospc, which is the QEMU default
and keeps the current behaviour for writes. A read that fails with
ENOSPC, which only the image file's read_iter can return, is now
reported to the guest instead of being held.

Requests held at the same time may now fail with different errors.
get_event reports the op and errno of the first request held since the
previous get_event, so a later ENOSPC is not hidden behind an error
that was already read, and an unread one is kept when its request is
resubmitted. The uevent is still sent only when the held list turns
non-empty and carries the error of the request that made it so,
whatever get_event has read: QEMU keeps the first error as the
io-status too, and a uevent per distinct error would make udev probe
the disk each time.

get_event keeps the event_ENOSPC form for writes only. A held read is
reported as event_io_error, which userspace that sets a read policy
understands.

A flush follows the write policy and is reported as a write, as QEMU
does.

Requests failed with BLK_STS_NOTSUPP are not held either: a retry
fails the same way. A discard on a filesystem that cannot punch holes
would otherwise be held under the stop policy forever and pause the VM
again after every resume. QEMU ignores ENOTSUP from a discard for the
same reason.

The policy is appended to the table status if it is not the default,
after the fields that existing parsers read by position. The status
does not hold the table arguments anyway, so userspace that reloads
the table has to pass the policy back as the first argument.

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    |  2 +-
 drivers/md/dm-qcow2-map.c    | 27 ++++++++++++++-----
 drivers/md/dm-qcow2-target.c | 50 +++++++++++++++++++++++++++++++++---
 drivers/md/dm-qcow2.h        | 10 ++++++++
 4 files changed, 79 insertions(+), 10 deletions(-)

diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index ea9c69b454ea..6a56919bec73 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -585,7 +585,7 @@ static int qcow2_get_event(struct qcow2_target *tgt, char *result, unsigned int
 
 	spin_lock_irq(&tgt->event_lock);
 	if (tgt->event_io_error) {
-		if (tgt->event_errno == ENOSPC)
+		if (tgt->event_errno == ENOSPC && tgt->event_write)
 			ret = (DMEMIT("event_ENOSPC\n")) ? 1 : 0;
 		else
 			ret = (DMEMIT("event_io_error %s %d\n",
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index b2962c77cc15..adbebe728f99 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4572,8 +4572,14 @@ static bool qcow2_try_hold_error(struct qcow2_target *tgt, struct qcow2_rq *qrq,
 	bool write = op_is_write(qio->bi_op) || qio->bi_op == REQ_OP_FLUSH;
 	bool held = true, first = false;
 	unsigned long flags;
+	u8 policy;
 
-	if (bi_status != BLK_STS_NOSPC)
+	if (bi_status == BLK_STS_NOTSUPP)
+		return false;
+
+	policy = write ? tgt->write_policy : tgt->read_policy;
+	if (policy == QCOW2_ERROR_REPORT ||
+	    (policy == QCOW2_ERROR_ENOSPC && bi_status != BLK_STS_NOSPC))
 		return false;
 
 	spin_lock_irqsave(&tgt->event_lock, flags);
@@ -4585,14 +4591,23 @@ static bool qcow2_try_hold_error(struct qcow2_target *tgt, struct qcow2_rq *qrq,
 	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));
-	tgt->event_io_error = true;
+	if (bi_status == BLK_STS_NOSPC)
+		pr_err_once(QCOW2_FMT("underlying disk is almost full"),
+				qcow2_device_name(tgt->ti));
+	else
+		pr_err_ratelimited(QCOW2_FMT("holding failed request, status %d"),
+				   qcow2_device_name(tgt->ti),
+				   blk_status_to_errno(bi_status));
 	first = list_empty(&tgt->held_qios);
-	if (first) {
-		tgt->event_uevent = true;
+	if (!tgt->event_io_error) {
 		tgt->event_write = write;
 		tgt->event_errno = -blk_status_to_errno(bi_status);
+		tgt->event_io_error = true;
+	}
+	if (first) {
+		tgt->event_uevent = true;
+		tgt->uevent_write = write;
+		tgt->uevent_errno = -blk_status_to_errno(bi_status);
 	}
 	list_add_tail(&qio->link, &tgt->held_qios);
 unlock:
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 590c2e6a4bec..b3365f92c7dd 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -513,8 +513,8 @@ static void qcow2_event_work(struct work_struct *ws)
 	spin_lock_irq(&tgt->event_lock);
 	uevent = tgt->event_uevent;
 	tgt->event_uevent = false;
-	write = tgt->event_write;
-	err = tgt->event_errno;
+	write = tgt->uevent_write;
+	err = tgt->uevent_errno;
 	spin_unlock_irq(&tgt->event_lock);
 
 	dm_table_event(tgt->ti->table);
@@ -559,6 +559,8 @@ static struct qcow2_target *alloc_qcow2_target(struct dm_target *ti)
 	}
 
 	init_completion(&tgt->inflight_ref_comp);
+	tgt->read_policy = QCOW2_ERROR_REPORT;
+	tgt->write_policy = QCOW2_ERROR_ENOSPC;
 	spin_lock_init(&tgt->event_lock);
 	mutex_init(&tgt->ctl_mutex);
 	init_rwsem(&tgt->seek_rwsem);
@@ -1029,6 +1031,32 @@ static int qcow2_parse_metadata(struct dm_target *ti, struct qcow2_target *tgt)
 	return ret;
 }
 
+static const char * const qcow2_error_policy_names[] = {
+	[QCOW2_ERROR_REPORT] = "report",
+	[QCOW2_ERROR_ENOSPC] = "enospc",
+	[QCOW2_ERROR_STOP] = "stop",
+};
+
+static int qcow2_parse_error_policy(struct qcow2_target *tgt, const char *arg)
+{
+	char rd[8], wr[8], end;
+	int r, w;
+
+	if (sscanf(arg, "error_policy=%7[^,],%7s%c", rd, wr, &end) != 2)
+		return -EINVAL;
+
+	r = match_string(qcow2_error_policy_names,
+			 ARRAY_SIZE(qcow2_error_policy_names), rd);
+	w = match_string(qcow2_error_policy_names,
+			 ARRAY_SIZE(qcow2_error_policy_names), wr);
+	if (r < 0 || w < 0)
+		return -EINVAL;
+
+	tgt->read_policy = r;
+	tgt->write_policy = w;
+	return 0;
+}
+
 static int qcow2_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 {
 	struct qcow2 *qcow2, *upper = NULL;
@@ -1041,6 +1069,17 @@ static int qcow2_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	tgt = alloc_qcow2_target(ti);
 	if (!tgt)
 		return -ENOMEM;
+
+	if (str_has_prefix(argv[0], "error_policy=")) {
+		ret = qcow2_parse_error_policy(tgt, argv[0]);
+		if (ret || argc < 2) {
+			ti->error = "Wrong error_policy";
+			ret = -EINVAL;
+			goto err;
+		}
+		argc--;
+		argv++;
+	}
 	/*
 	 * Userspace passes deltas in bottom, ..., top order,
 	 * but we attach it vise versa: from top to bottom.
@@ -1173,6 +1212,11 @@ static void qcow2_status(struct dm_target *ti, status_type_t type,
 	case STATUSTYPE_TABLE:
 		DMEMIT("%u v%u %llu", qcow2->img_id + 1, hdr->version,
 				      to_sector(qcow2->clu_size));
+		if (tgt->read_policy != QCOW2_ERROR_REPORT ||
+		    tgt->write_policy != QCOW2_ERROR_ENOSPC)
+			DMEMIT(" error_policy=%s,%s",
+			       qcow2_error_policy_names[tgt->read_policy],
+			       qcow2_error_policy_names[tgt->write_policy]);
 		break;
 	case STATUSTYPE_IMA:
 		result[0] = '\0';
@@ -1259,7 +1303,7 @@ static void qcow2_resume(struct dm_target *ti)
 
 static struct target_type qcow2_target = {
 	.name = "qcow2",
-	.version = {1, 0, 0},
+	.version = {1, 1, 0},
 	.features = DM_TARGET_SINGLETON,
 	.module = THIS_MODULE,
 	.ctr = qcow2_ctr,
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index df20826c6060..cd73314ee28c 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -188,6 +188,12 @@ struct qcow2_backward_merge {
 	long long max_progress;
 };
 
+enum qcow2_error_policy {
+	QCOW2_ERROR_REPORT = 0,
+	QCOW2_ERROR_ENOSPC,
+	QCOW2_ERROR_STOP,
+};
+
 struct qcow2_target {
 	struct dm_target *ti;
 #define QCOW2_QRQ_POOL_SIZE 512 /* Twice nr_requests from blk_mq_init_sched() */
@@ -213,6 +219,10 @@ struct qcow2_target {
 	bool event_uevent;
 	bool event_write;
 	int event_errno;
+	bool uevent_write;
+	int uevent_errno;
+	u8 read_policy;
+	u8 write_policy;
 
 	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: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 ` Alexander Ivanov [this message]
2026-11-17 10:34   ` [Devel] [PATCH hci-8.1 v2 7/9] drivers/md/dm-qcow2: add the error_policy table argument 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-8-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