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.2 v3 6/7] dm-qcow2: add the report_enospc table argument
Date: Tue,  1 Dec 2026 09:50:08 +0100	[thread overview]
Message-ID: <20261201085009.1884844-7-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261201085009.1884844-1-alexander.ivanov@virtuozzo.com>

A request failing with ENOSPC is delayed in dm-qcow2 and resubmitted
every 20 seconds, and the error is reported with a dm event. A
vhost-blk disk is controlled by QEMU, which cannot wait for dm events
or send dm messages without CAP_SYS_ADMIN. So for a VM the request
just hangs until space is freed, and the VM is never paused.

vhost-blk is to hold a request failed with ENOSPC itself and let QEMU
pause the VM and resubmit it on resume, as QEMU does for its own disks
with werror=enospc. That needs the error to reach vhost-blk.

With the optional first table argument report_enospc, such a request
is completed with BLK_STS_NOSPC at once, and no dm event is raised.
Without it nothing changes, which containers rely on.

A flag set by a message would be lost on every table reload, as the
reload creates a new target. So it is a table argument, which
userspace has to pass with every table it loads: on a snapshot, a
grow, a merge, a replace and a migration.

The table status gets a flags field like the one of dm-ploop: r for
report_enospc, s for an ENOSPC event not yet read by userspace, and o
when no flag is set. The field is added to the table line of every
qcow2 device, with or without report_enospc. Userspace reads r back to
pass report_enospc again when it reloads the table.

The target version goes to 1.1.0, as an older kernel rejects the
argument as a wrong fd.

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-map.c    | 11 ++++++-----
 drivers/md/dm-qcow2-target.c | 25 ++++++++++++++++++++++---
 drivers/md/dm-qcow2.h        |  1 +
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index e0b8a805af34..2a481d50f0d3 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4727,12 +4727,13 @@ static void qrq_endio(struct qcow2_target *tgt, struct qio *qio,
 		kvfree(qrq->bvec);
 	/*
 	 * Here is exit point for rq, and here we handle ENOSPC.
-	 * Embedded qios will be reinitialized like they've just
-	 * came from upper dm level, and later resubmitted after
-	 * timeout. Note, that we do not handle merge here: merge
-	 * callers receive -ENOSPC synchronous without intermediaries.
+	 * Unless report_enospc is set, embedded qios will be
+	 * reinitialized like they've just came from upper dm level,
+	 * and later resubmitted after timeout. Note, that we do not
+	 * handle merge here: merge callers receive -ENOSPC synchronous
+	 * without intermediaries.
 	 */
-	if (unlikely(bi_status == BLK_STS_NOSPC) &&
+	if (unlikely(bi_status == BLK_STS_NOSPC) && !tgt->report_enospc &&
 	    qcow2_try_delay_enospc(tgt, qrq, qio))
 		return;
 
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index dddea4af21a4..13be646f7a64 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -1026,6 +1026,17 @@ static int qcow2_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	tgt = alloc_qcow2_target(ti);
 	if (!tgt)
 		return -ENOMEM;
+
+	if (!strcmp(argv[0], "report_enospc")) {
+		tgt->report_enospc = true;
+		argc--;
+		argv++;
+		if (!argc) {
+			ti->error = "No image";
+			ret = -EINVAL;
+			goto err;
+		}
+	}
 	/*
 	 * Userspace passes deltas in bottom, ..., top order,
 	 * but we attach it vise versa: from top to bottom.
@@ -1141,6 +1152,7 @@ static void qcow2_status(struct dm_target *ti, status_type_t type,
 {
 	struct qcow2_target *tgt = to_qcow2_target(ti);
 	struct QCowHeader *hdr;
+	char stat[4], *p = stat;
 	unsigned int sz = 0;
 	struct qcow2 *qcow2;
 	u8 ref_index;
@@ -1152,8 +1164,15 @@ static void qcow2_status(struct dm_target *ti, status_type_t type,
 		result[0] = '\0';
 		break;
 	case STATUSTYPE_TABLE:
-		DMEMIT("%u v%u %llu", qcow2->img_id + 1, hdr->version,
-				      to_sector(qcow2->clu_size));
+		if (READ_ONCE(tgt->event_enospc))
+			*p++ = 's';
+		if (tgt->report_enospc)
+			*p++ = 'r';
+		if (p == stat)
+			*p++ = 'o';
+		*p = '\0';
+		DMEMIT("%u v%u %llu %s", qcow2->img_id + 1, hdr->version,
+					 to_sector(qcow2->clu_size), stat);
 		break;
 	case STATUSTYPE_IMA:
 		result[0] = '\0';
@@ -1238,7 +1257,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 | DM_TARGET_NOWAIT,
 	.module = THIS_MODULE,
 	.ctr = qcow2_ctr,
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 6c5d3e932691..141103513bdb 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -211,6 +211,7 @@ struct qcow2_target {
 	bool md_writeback_error;
 	bool truncate_error;
 	bool event_enospc;
+	bool report_enospc;
 
 	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-12-01  8:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:50 [Devel] [PATCH hci-8.2 v3 0/7] dm-qcow2, dm-ploop: report ENOSPC at once for vhost-blk disks Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 1/7] dm-qcow2: always resubmit delayed ENOSPC requests in presuspend Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 2/7] dm-qcow2: arm the ENOSPC timer only for the first delayed request Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 3/7] dm-qcow2: drop the WARN on a read failing with ENOSPC Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 4/7] dm-ploop: arm the ENOSPC timer only for the first delayed request Alexander Ivanov
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 5/7] dm-ploop: drop the WARN on a non-write request failing with ENOSPC Alexander Ivanov
2026-12-01  8:50 ` Alexander Ivanov [this message]
2026-12-01  8:54   ` [Devel] [PATCH hci-8.2 v3 6/7] dm-qcow2: add the report_enospc table argument no-reply
2026-12-01  8:50 ` [Devel] [PATCH hci-8.2 v3 7/7] dm-ploop: " Alexander Ivanov
2026-12-01 15:28 ` [Devel] [PATCH hci-8.2 v3 0/7] dm-qcow2, dm-ploop: report ENOSPC at once for vhost-blk disks Konstantin Khorenko
2026-12-01 15:28 ` 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=20261201085009.1884844-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.