From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 36008817C6 for ; Tue, 17 Nov 2026 10:12:11 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AHAB0xB007840; Tue, 17 Nov 2026 13:11:01 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AHAB0xB007840 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="VqSO1iQ6" Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AHAAVh1007770 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 17 Nov 2026 13:10:32 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AHAAVh1007770 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4a204f135ffso22726165e9.1 for ; Tue, 17 Nov 2026 02:10:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHPNB/3zKQgc3dyrNEtxOfe2vhGsjzFAI7/zgrfG8AI3dsz6W6ILze83frEyL2S6jXV3vjuiQ==@openvz.org X-Gm-Message-State: APuU4Z+NgD30UskRRLO3LMsTLrASMC3yzCctFWHegQU0WkWbhQ5CUwCP C5ZFYCWXttOrgImcL+3mIr2X4twqXJSgSsjVVx0ECUgBuT+BFASoPUgMeLKsGIA7dWB5H7yBYwm X0MsW68mpyeIlS8vAZ8dHflEu47fPef/llEqFNkHIgLOUnWg7C+4qPQ== X-Gm-Gg: AYBFou2J4HDaAmn/fesfIxwPrRS1bO7b1MyNYucjsCvm0ejzhqgJwu/CZe0aEXcumFe mhx7YMpEWC43e3H9afMECUmn6lm36DclwLw47yzBhrKHpMgIZL+BrBGYjnkoj2fFejiu5f426q0 TyBlrM65OB2bOtk5qKrEm+p/0P39rjNDl7xrWYUHQpW6LGWn+mYAMTVdnRRpOH8NBXCLgknaAVW csM+MuMPKxxpjgTpeGDQi2E9bFcdMOXo/f31vxXZT6HOvjmcJjxk0f7gGdjLJVe1OfTnp5IfsLl cJmTOuJC9AVSQz7dBn3y50KRzj9c20j0ImlnYrZKq3g5fcBpx+6NMe3K67noozNn4bC5oUFyLYZ w8iTrGeh0FD0DlF//qFBJG90GZyiS X-Received: by 2002:a05:600c:6286:b0:4a1:7e77:c382 with SMTP id 5b1f17b1804b1-4bb55a5d634mr260804845e9.5.1794910231484; Tue, 17 Nov 2026 02:10:31 -0800 (PST) X-Received: by 2002:a05:600c:6286:b0:4a1:7e77:c382 with SMTP id 5b1f17b1804b1-4bb55a5d634mr260803815e9.5.1794910230683; Tue, 17 Nov 2026 02:10:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794910230; cv=none; d=google.com; s=arc-20260327; b=acUTgWSJpthP/xj8KNQilrPorM1ffeP1CruHQNr1Ky4HRhdyXoox0za1/0xGc7l4LG vTbrctNgqsQlGa9eE2qgqq5b+3+yKpUPQLFdcIOHvJSJKAg1oXDA4nkclw6pyZfi40U/ xyAkWWQVFkfbQi7v0lPHHDBEyb8u4I1oDH9DOPKrTjlQZP8w4yJsotqgJBXaUE+yWS/B FfwtOqOdT09hrDpn1xWYJeD7FmmrGtylFrdJgWFvyUJEJYofh0CVTaAMUZ5MFkKKWgax 4W+gfPbr7q/7+nZV7p+jtPCaMUEhYYnXaWogH9Pj1rwrvHkrbSK2TEiiJUUohrZOLPz1 61zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=17GpKSjZceQJTuClxCnKxdl46E4mCjRULgF2uj4fRDU=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=bGKstZV+zfvD6zg8SwNiPHjYzkYE7XzQbTqZXJnilcH6IMWsZ4xeyW71WYxHr0gfgg Rae5b68VF+E/L4BaWoXVbGEsMp0XFs3AwU9PCterSLyBzXy3gsSCa4x0NrA6xyWrhWMV udqh4IWtI/24qBPpZqW6FDz06rYnI1GgWw4Xq61jKe7ER3mCZSy6E8xASegIpyIeESSp pcYX40SefO2GvWnmVAol7LfPPjGjaECA0qph2X/7X1tbnz9t16NCGxq0erDr/3NOk15d lz+32oru8DGEodjj9KREA46XI30Us+0X+8MOPM3vkCt4skE1aTCe6VdAO5HzCgaal1u2 pcww==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=VqSO1iQ6; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id 5b1f17b1804b1-4bb784405e3si45580255e9.14.2026.11.17.02.10.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2026 02:10:30 -0800 (PST) Received-SPF: pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=VqSO1iQ6; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=17GpKSjZceQJTuClxCnKxdl46E4mCjRULgF2uj4fRDU=; b=VqSO1iQ6W0Ww zmtX2cUTDiNjMIKNuKfKVzDWYvmhkz3h+bJU7XpYJh/4iTPbPFqPNxyc7FC0mffPXTBnW5O/ZqM1s xog2oeO3BN/bsf7ykoHsGNWCl8B818+elvRSUjdOXfbDPO6ULro9mOSYD0+Asrhut/nST5R67hp/U tfl8DxHD2WgaTo4lvUWoCcRhgFYdTNT8mV9/IS7AuJMNEhns2RFJVKf7a+DUbbi9uEChaGAFIb/H3 MXXVOMIqHWNk/+AXQ2m9TRQadNQk97t/wi90dzP0AIseojRrfF7AzE4mBEe3rzgPqJhJBoHP+oN3K aQ1U04dmSZqoVDOaN3XV1g==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=sky) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xTG4j-009Isp-39; Tue, 17 Nov 2026 11:10:20 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Tue, 17 Nov 2026 11:10:24 +0100 Message-ID: <20261117101026.3071579-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261117101026.3071579-1-alexander.ivanov@virtuozzo.com> References: <20261117101026.3071579-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v2 7/9] drivers/md/dm-qcow2: add the error_policy table argument X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org 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=, 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 --- 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