All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies
@ 2026-11-17 10:50 Alexander Ivanov
  2026-11-17 10:50 ` [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Alexander Ivanov @ 2026-11-17 10:50 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

A vhost-blk disk completes requests to the guest from the kernel, so
QEMU never sees an I/O error and the werror/rerror policies cannot
work the usual way. The dm-qcow2 series holds a failed request
according to the policy and reports it with an IO_ERROR change
uevent. This series makes QEMU accept the policies and pause the VM
on that uevent.

Patch 1 adds the werror and rerror properties, which libvirt passes
when the disk has error_policy or rerror_policy set. Without them
QEMU refuses to start such a VM.

Patch 2 parses the IO_ERROR uevent and stops the VM with the io-error
reason and a BLOCK_IO_ERROR event when the policy says so. Migration
and savevm are blocked while requests are held in the kernel.

! Don't apply this patchset before the kernel patchset is applied.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Alexander Ivanov (2):
  vhost-blk: add the werror and rerror properties #VSTOR-152175
  vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2
    #VSTOR-152175

 hw/block/vhost-blk.c          | 112 +++++++++++++++++++++++++++++++++-
 include/hw/virtio/vhost-blk.h |   2 +
 2 files changed, 111 insertions(+), 3 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175
  2026-11-17 10:50 [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies Alexander Ivanov
@ 2026-11-17 10:50 ` Alexander Ivanov
  2026-11-17 11:03   ` no-reply
  2026-11-17 18:12   ` Andrey Drobyshev
  2026-11-17 10:50 ` [PATCH hci-8.1 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175 Alexander Ivanov
  2026-11-17 10:59 ` [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies Andrey Drobyshev
  2 siblings, 2 replies; 9+ messages in thread
From: Alexander Ivanov @ 2026-11-17 10:50 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

libvirt passes werror and rerror to the device when the disk has
error_policy or rerror_policy set, and QEMU refuses to start such a VM
with vhost-blk.

Accept them with the defaults of other block devices: enospc for
writes and report for reads. dm-qcow2 holds the failed requests under
the same policy, which libvirt loads into its table. It has no ignore
policy, and enospc makes no sense for reads, so reject both.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 hw/block/vhost-blk.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index abddff02c6d..354111a1b41 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -617,6 +617,24 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    if (conf->conf.werror == BLOCKDEV_ON_ERROR_AUTO) {
+        conf->conf.werror = BLOCKDEV_ON_ERROR_ENOSPC;
+    }
+    if (conf->conf.rerror == BLOCKDEV_ON_ERROR_AUTO) {
+        conf->conf.rerror = BLOCKDEV_ON_ERROR_REPORT;
+    }
+
+    if (conf->conf.werror == BLOCKDEV_ON_ERROR_IGNORE ||
+        conf->conf.rerror == BLOCKDEV_ON_ERROR_IGNORE) {
+        error_setg(errp, "vhost-blk: 'ignore' error policy is not supported");
+        return;
+    }
+
+    if (conf->conf.rerror == BLOCKDEV_ON_ERROR_ENOSPC) {
+        error_setg(errp, "vhost-blk: 'enospc' is not supported as rerror");
+        return;
+    }
+
     if (!vhost_blk_open_backend(s, errp)) {
         return;
     }
@@ -795,6 +813,7 @@ static const Property vhost_blk_properties[] = {
     DEFINE_PROP_BIT64("write-zeroes", VHostBlk, host_features,
                       VIRTIO_BLK_F_WRITE_ZEROES, false),
     DEFINE_PROP_STRING("serial", VHostBlk, conf.serial),
+    DEFINE_BLOCK_ERROR_PROPERTIES(VHostBlk, conf.conf),
 };
 
 static const VMStateDescription vmstate_vhost_blk = {
-- 
2.53.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH hci-8.1 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175
  2026-11-17 10:50 [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies Alexander Ivanov
  2026-11-17 10:50 ` [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
@ 2026-11-17 10:50 ` Alexander Ivanov
  2026-11-17 11:05   ` no-reply
  2026-11-17 18:12   ` Andrey Drobyshev
  2026-11-17 10:59 ` [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies Andrey Drobyshev
  2 siblings, 2 replies; 9+ messages in thread
From: Alexander Ivanov @ 2026-11-17 10:50 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

vhost-blk completes requests to the guest in the kernel, so werror and
rerror had no effect: dm-qcow2 held the failed write under the enospc
or stop policy, but the VM kept running with the request stuck.

dm-qcow2 reports a held request with a change uevent carrying
IO_ERROR=1, IO_ERROR_OP=read|write and IO_ERROR_ERRNO=<errno>. Parse it
on the uevent socket and, if the policy of the device says so, stop
the VM with the io-error reason and emit BLOCK_IO_ERROR, as the block
layer does for other devices. The device field is the id of the proxy,
which is the disk alias libvirt looks the disk up by.

The VM stops with RUN_STATE_IO_ERROR, on which vhost-blk keeps running,
so the held requests survive the pause. libvirt resubmits them before
cont. dm-qcow2 repeats the event on every failed retry, so ignore it
unless the VM is running.

Migration and savevm from IO_ERROR do not notify the VM state handlers,
so vhost-blk would keep running and its vring state would be saved
stale. The held requests cannot be migrated either, so block migration
until the VM runs again, and fail it in pre_save for a migration that
was already running when the error came.

Reject the stop policy without the ueventfd property: without the
socket QEMU never learns about the held request.

https://virtuozzo.atlassian.net/browse/VSTOR-152175

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 hw/block/vhost-blk.c          | 93 +++++++++++++++++++++++++++++++++--
 include/hw/virtio/vhost-blk.h |  2 +
 2 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 354111a1b41..6775a561eab 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -32,6 +32,7 @@
 #include "migration/blocker.h"
 #include "migration/cpr.h"
 #include "system/runstate.h"
+#include "qapi/qapi-events-block-core.h"
 
 static int vhost_blk_start(VirtIODevice *vdev)
 {
@@ -205,6 +206,10 @@ static void vhost_blk_vm_state(void *opaque, bool running, RunState state)
         vhost_blk_stop(vdev);
         vhost_blk_reset(vdev);
     } else if (state == RUN_STATE_RUNNING) {
+        VHostBlk *s = VHOST_BLK(vdev);
+
+        s->io_error_held = false;
+        migrate_del_blocker(&s->io_error_blocker);
         vhost_blk_start(vdev);
     }
 }
@@ -293,6 +298,45 @@ static void vhost_blk_block_cpr(VHostBlk *s)
     }
 }
 
+static void vhost_blk_io_error(VHostBlk *s, bool is_read, int error)
+{
+    DeviceState *dev = DEVICE(s);
+    DeviceState *proxy = dev->parent_bus ? dev->parent_bus->parent : NULL;
+    BlockdevOnError on_err = is_read ? s->conf.conf.rerror
+                                     : s->conf.conf.werror;
+    g_autofree char *path = NULL;
+
+    if (on_err != BLOCKDEV_ON_ERROR_STOP &&
+        (on_err != BLOCKDEV_ON_ERROR_ENOSPC || error != ENOSPC)) {
+        return;
+    }
+
+    /* dm-qcow2 repeats the event on every failed retry of a held request */
+    if (!runstate_is_running()) {
+        return;
+    }
+
+    path = object_get_canonical_path(OBJECT(dev));
+
+    s->io_error_held = true;
+    if (!s->io_error_blocker) {
+        error_setg(&s->io_error_blocker,
+                   "vhost-blk: '%s' has requests held in the kernel after "
+                   "an I/O error", path);
+        migrate_add_blocker_internal(&s->io_error_blocker, NULL);
+    }
+
+    qemu_system_vmstop_request_prepare();
+    qapi_event_send_block_io_error(path,
+                                   proxy && proxy->id ? proxy->id : "",
+                                   NULL,
+                                   is_read ? IO_OPERATION_TYPE_READ
+                                           : IO_OPERATION_TYPE_WRITE,
+                                   BLOCK_ERROR_ACTION_STOP, true,
+                                   error == ENOSPC, strerror(error), 0, 0);
+    qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
+}
+
 /*
  * The uevent socket is created, bound and filtered by the management
  * layer and passed to us via the "ueventfd" property.
@@ -310,6 +354,9 @@ static void vhost_blk_uevent_read(void *opaque)
         bool action_change = false;
         bool subsystem_block = false;
         bool resize = false;
+        bool io_error = false;
+        bool io_error_read = false;
+        int io_error_errno = EIO;
         char *field;
         char *end;
         ssize_t len;
@@ -351,6 +398,17 @@ static void vhost_blk_uevent_read(void *opaque)
                 subsystem_block = true;
             } else if (!strcmp(field, "RESIZE=1")) {
                 resize = true;
+            } else if (!strcmp(field, "IO_ERROR=1")) {
+                io_error = true;
+            } else if (!strcmp(field, "IO_ERROR_OP=read")) {
+                io_error_read = true;
+            } else if (g_str_has_prefix(field, "IO_ERROR_ERRNO=")) {
+                int value;
+
+                if (!qemu_strtoi(field + strlen("IO_ERROR_ERRNO="), NULL, 10,
+                                 &value) && value > 0) {
+                    io_error_errno = value;
+                }
             } else if (g_str_has_prefix(field, "MAJOR=")) {
                 uint64_t value;
 
@@ -373,11 +431,18 @@ static void vhost_blk_uevent_read(void *opaque)
             field += field_len + 1;
         }
 
-        if (action_change && subsystem_block && resize &&
-            event_major == major(s->backend_rdev) &&
-            event_minor == minor(s->backend_rdev)) {
+        if (!action_change || !subsystem_block ||
+            event_major != major(s->backend_rdev) ||
+            event_minor != minor(s->backend_rdev)) {
+            continue;
+        }
+
+        if (resize) {
             qemu_bh_schedule(s->resize_bh);
         }
+        if (io_error) {
+            vhost_blk_io_error(s, io_error_read, io_error_errno);
+        }
     }
 }
 
@@ -635,6 +700,14 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    if (!conf->ueventfd &&
+        (conf->conf.werror == BLOCKDEV_ON_ERROR_STOP ||
+         conf->conf.rerror == BLOCKDEV_ON_ERROR_STOP)) {
+        error_setg(errp, "vhost-blk: 'stop' error policy requires the "
+                   "'ueventfd' property");
+        return;
+    }
+
     if (!vhost_blk_open_backend(s, errp)) {
         return;
     }
@@ -709,6 +782,7 @@ static void vhost_blk_device_unrealize(DeviceState *dev)
     VHostBlk *s = VHOST_BLK(dev);
 
     vhost_blk_uevent_detach(s);
+    migrate_del_blocker(&s->io_error_blocker);
     qemu_del_vm_change_state_handler(s->mighand);
     vhost_blk_set_status(vdev, 0);
     vhost_dev_cleanup(&s->dev);
@@ -816,10 +890,23 @@ static const Property vhost_blk_properties[] = {
     DEFINE_BLOCK_ERROR_PROPERTIES(VHostBlk, conf.conf),
 };
 
+static int vhost_blk_pre_save(void *opaque)
+{
+    VHostBlk *s = opaque;
+
+    if (s->io_error_held) {
+        error_report("vhost-blk: requests are held in the kernel after an "
+                     "I/O error, resubmit or fail them first");
+        return -EBUSY;
+    }
+    return 0;
+}
+
 static const VMStateDescription vmstate_vhost_blk = {
     .name = "vhost-blk",
     .minimum_version_id = 1,
     .version_id = 1,
+    .pre_save = vhost_blk_pre_save,
     .fields = (VMStateField[]) {
         VMSTATE_VIRTIO_DEVICE,
         VMSTATE_END_OF_LIST()
diff --git a/include/hw/virtio/vhost-blk.h b/include/hw/virtio/vhost-blk.h
index 059f1ebc701..935b35f6d6b 100644
--- a/include/hw/virtio/vhost-blk.h
+++ b/include/hw/virtio/vhost-blk.h
@@ -48,6 +48,8 @@ typedef struct VHostBlk {
     uint64_t backend_rdev;
     QEMUBH *resize_bh;
     Error *cpr_blocker;
+    Error *io_error_blocker;
+    bool io_error_held;
 } VHostBlk;
 
 #endif
-- 
2.53.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies
  2026-11-17 10:50 [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies Alexander Ivanov
  2026-11-17 10:50 ` [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
  2026-11-17 10:50 ` [PATCH hci-8.1 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175 Alexander Ivanov
@ 2026-11-17 10:59 ` Andrey Drobyshev
  2026-11-17 18:14   ` Denis V. Lunev
  2 siblings, 1 reply; 9+ messages in thread
From: Andrey Drobyshev @ 2026-11-17 10:59 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: svt-core

AFAIU vhost-blk is targeted for hci-8.2, and therefore these patches are
NOT meant for hci-8.1 (despite what subject line suggests).  Please confirm.

On 11/17/26 12:50 PM, Alexander Ivanov wrote:
> A vhost-blk disk completes requests to the guest from the kernel, so
> QEMU never sees an I/O error and the werror/rerror policies cannot
> work the usual way. The dm-qcow2 series holds a failed request
> according to the policy and reports it with an IO_ERROR change
> uevent. This series makes QEMU accept the policies and pause the VM
> on that uevent.
> 
> Patch 1 adds the werror and rerror properties, which libvirt passes
> when the disk has error_policy or rerror_policy set. Without them
> QEMU refuses to start such a VM.
> 
> Patch 2 parses the IO_ERROR uevent and stops the VM with the io-error
> reason and a BLOCK_IO_ERROR event when the policy says so. Migration
> and savevm are blocked while requests are held in the kernel.
> 
> ! Don't apply this patchset before the kernel patchset is applied.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-152175
> 
> Alexander Ivanov (2):
>   vhost-blk: add the werror and rerror properties #VSTOR-152175
>   vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2
>     #VSTOR-152175
> 
>  hw/block/vhost-blk.c          | 112 +++++++++++++++++++++++++++++++++-
>  include/hw/virtio/vhost-blk.h |   2 +
>  2 files changed, 111 insertions(+), 3 deletions(-)
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175
  2026-11-17 10:50 ` [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
@ 2026-11-17 11:03   ` no-reply
  2026-11-17 18:12   ` Andrey Drobyshev
  1 sibling, 0 replies; 9+ messages in thread
From: no-reply @ 2026-11-17 11:03 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

> libvirt passes werror and rerror to the device when the disk has
> error_policy or rerror_policy set, and QEMU refuses to start such a VM
> with vhost-blk.
> 
> Accept them with the defaults of other block devices: enospc for
> writes and report for reads. dm-qcow2 holds the failed requests under
> the same policy, which libvirt loads into its table. It has no ignore
> policy, and enospc makes no sense for reads, so reject both.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-152175
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261117105003.3082044-1-alexander.ivanov@virtuozzo.com?part=1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH hci-8.1 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175
  2026-11-17 10:50 ` [PATCH hci-8.1 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175 Alexander Ivanov
@ 2026-11-17 11:05   ` no-reply
  2026-11-17 18:12   ` Andrey Drobyshev
  1 sibling, 0 replies; 9+ messages in thread
From: no-reply @ 2026-11-17 11:05 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: andrey.drobyshev, svt-core

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] vhost-blk: IO_ERROR outside RUNNING skips io_error_held and
  migration blocker
- [Low] vhost-blk: realize rejects only stop policy without ueventfd,
  not enospc
- [Low] vhost-blk: runstate_is_running() guard lets duplicate
  BLOCK_IO_ERROR events through
- [Low] vhost-blk: ENOBUFS recovery in uevent_read() ignores dropped
  IO_ERROR events
--

commit 678e0f871c6d292d376eb1ea266d4ee9fc2f8511
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175

The patch parses the IO_ERROR change uevent from dm-qcow2 on the uevent
socket. If the werror or rerror policy asks for it, QEMU emits
BLOCK_IO_ERROR and stops the VM with RUN_STATE_IO_ERROR. It also blocks
migration while requests are held, fails pre_save in that state, and
rejects the stop policy when no ueventfd is given.

> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index 354111a1b41a..6775a561eabb 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c

[ ... ]

> +static void vhost_blk_io_error(VHostBlk *s, bool is_read, int error)
> +{
> +    DeviceState *dev = DEVICE(s);
> +    DeviceState *proxy = dev->parent_bus ? dev->parent_bus->parent : NULL;
> +    BlockdevOnError on_err = is_read ? s->conf.conf.rerror
> +                                     : s->conf.conf.werror;
> +    g_autofree char *path = NULL;
> +
> +    if (on_err != BLOCKDEV_ON_ERROR_STOP &&
> +        (on_err != BLOCKDEV_ON_ERROR_ENOSPC || error != ENOSPC)) {
> +        return;
> +    }
> +
> +    /* dm-qcow2 repeats the event on every failed retry of a held request */
> +    if (!runstate_is_running()) {
> +        return;
> +    }
> +
> +    path = object_get_canonical_path(OBJECT(dev));
> +
> +    s->io_error_held = true;
> +    if (!s->io_error_blocker) {

[Severity: Medium]
Does this early return drop the first IO_ERROR event when the VM is in
PAUSED, FINISH_MIGRATE or SAVE_VM?

vhost_blk_vm_state() has already run vhost_blk_stop() and
vhost_blk_reset() in those states. A request that fails afterwards can
be held by dm-qcow2, but its event returns here before io_error_held is
set or the blocker is added. vhost_blk_pre_save() then returns 0, so
savevm or migration can complete while dm-qcow2 still holds a request
the guest has submitted.

The comment only justifies skipping repeats once the VM is already in
IO_ERROR. Would it work to set io_error_held and add the blocker before
this check, and skip only the vmstop and the event here?

[Severity: Low]
Does this check dedupe anything inside the drain loop of
vhost_blk_uevent_read()? qemu_system_vmstop_request() only records the
request and wakes the main loop. The run state stays RUNNING until the
main loop runs vm_stop(). Several queued IO_ERROR datagrams read in one
pass all get through, so management sees duplicate BLOCK_IO_ERROR events
and repeated vmstop requests. The comment and commit message say repeats
are ignored, which only holds after the stop has been processed.
Checking s->io_error_held here would close the window.

[ ... ]

> @@ -373,11 +431,18 @@ static void vhost_blk_uevent_read(void *opaque)
>              field += field_len + 1;
>          }
>  
> -        if (action_change && subsystem_block && resize &&
> -            event_major == major(s->backend_rdev) &&
> -            event_minor == minor(s->backend_rdev)) {
> +        if (!action_change || !subsystem_block ||
> +            event_major != major(s->backend_rdev) ||
> +            event_minor != minor(s->backend_rdev)) {
> +            continue;
> +        }
> +
> +        if (resize) {
>              qemu_bh_schedule(s->resize_bh);
>          }
> +        if (io_error) {
> +            vhost_blk_io_error(s, io_error_read, io_error_errno);
> +        }
>      }
>  }

[Severity: Low]
Is a lost IO_ERROR event recoverable? The ENOBUFS branch earlier in this
function only schedules resize_bh, which re-reads the capacity. If the
netlink socket overruns and the IO_ERROR datagram is among those
dropped, QEMU never stops the VM and never emits BLOCK_IO_ERROR. The
guest keeps running with a request held in the kernel, and nothing
re-queries that state.

[ ... ]

> @@ -635,6 +700,14 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
>          return;
>      }
>  
> +    if (!conf->ueventfd &&
> +        (conf->conf.werror == BLOCKDEV_ON_ERROR_STOP ||
> +         conf->conf.rerror == BLOCKDEV_ON_ERROR_STOP)) {
> +        error_setg(errp, "vhost-blk: 'stop' error policy requires the "
> +                   "'ueventfd' property");
> +        return;
> +    }

[Severity: Low]
Should enospc also require ueventfd here? The commit message says the
enospc or stop policy is affected, but only stop is checked. The default
werror (auto) is mapped to enospc earlier in realize. Without ueventfd, a
held ENOSPC write never reaches vhost_blk_io_error(), so the VM keeps
running with the request stuck. Either check werror == ENOSPC as well or
document the limitation.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261117105003.3082044-1-alexander.ivanov@virtuozzo.com?part=2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175
  2026-11-17 10:50 ` [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
  2026-11-17 11:03   ` no-reply
@ 2026-11-17 18:12   ` Andrey Drobyshev
  1 sibling, 0 replies; 9+ messages in thread
From: Andrey Drobyshev @ 2026-11-17 18:12 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: svt-core

On 11/17/26 12:50 PM, Alexander Ivanov wrote:
> libvirt passes werror and rerror to the device when the disk has
> error_policy or rerror_policy set, and QEMU refuses to start such a VM
> with vhost-blk.
> 
> Accept them with the defaults of other block devices: enospc for
> writes and report for reads. dm-qcow2 holds the failed requests under
> the same policy, which libvirt loads into its table. It has no ignore
> policy, and enospc makes no sense for reads, so reject both.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-152175
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>  hw/block/vhost-blk.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index abddff02c6d..354111a1b41 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c
> @@ -617,6 +617,24 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
>          return;
>      }
>  
> +    if (conf->conf.werror == BLOCKDEV_ON_ERROR_AUTO) {
> +        conf->conf.werror = BLOCKDEV_ON_ERROR_ENOSPC;
> +    }
> +    if (conf->conf.rerror == BLOCKDEV_ON_ERROR_AUTO) {
> +        conf->conf.rerror = BLOCKDEV_ON_ERROR_REPORT;
> +    }
> +
> +    if (conf->conf.werror == BLOCKDEV_ON_ERROR_IGNORE ||
> +        conf->conf.rerror == BLOCKDEV_ON_ERROR_IGNORE) {
> +        error_setg(errp, "vhost-blk: 'ignore' error policy is not supported");
> +        return;
> +    }
> +
> +    if (conf->conf.rerror == BLOCKDEV_ON_ERROR_ENOSPC) {
> +        error_setg(errp, "vhost-blk: 'enospc' is not supported as rerror");
> +        return;
> +    }

AFAICT this last if condition is dead code since XML parser in libvirt
currently refuses rerror_policy='enospace'.  Correct me if I'm wrong.

Otherwise LGTM.

Reviewed-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH hci-8.1 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175
  2026-11-17 10:50 ` [PATCH hci-8.1 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175 Alexander Ivanov
  2026-11-17 11:05   ` no-reply
@ 2026-11-17 18:12   ` Andrey Drobyshev
  1 sibling, 0 replies; 9+ messages in thread
From: Andrey Drobyshev @ 2026-11-17 18:12 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: svt-core

On 11/17/26 12:50 PM, Alexander Ivanov wrote:
> vhost-blk completes requests to the guest in the kernel, so werror and
> rerror had no effect: dm-qcow2 held the failed write under the enospc
> or stop policy, but the VM kept running with the request stuck.
> 
> dm-qcow2 reports a held request with a change uevent carrying
> IO_ERROR=1, IO_ERROR_OP=read|write and IO_ERROR_ERRNO=<errno>. Parse it
> on the uevent socket and, if the policy of the device says so, stop
> the VM with the io-error reason and emit BLOCK_IO_ERROR, as the block
> layer does for other devices. The device field is the id of the proxy,
> which is the disk alias libvirt looks the disk up by.
> 
> The VM stops with RUN_STATE_IO_ERROR, on which vhost-blk keeps running,
> so the held requests survive the pause. libvirt resubmits them before
> cont. dm-qcow2 repeats the event on every failed retry, so ignore it
> unless the VM is running.
> 
> Migration and savevm from IO_ERROR do not notify the VM state handlers,
> so vhost-blk would keep running and its vring state would be saved
> stale. The held requests cannot be migrated either, so block migration
> until the VM runs again, and fail it in pre_save for a migration that
> was already running when the error came.
> 
> Reject the stop policy without the ueventfd property: without the
> socket QEMU never learns about the held request.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-152175
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>  hw/block/vhost-blk.c          | 93 +++++++++++++++++++++++++++++++++--
>  include/hw/virtio/vhost-blk.h |  2 +
>  2 files changed, 92 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index 354111a1b41..6775a561eab 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c
> @@ -32,6 +32,7 @@
>  #include "migration/blocker.h"
>  #include "migration/cpr.h"
>  #include "system/runstate.h"
> +#include "qapi/qapi-events-block-core.h"
>  
>  static int vhost_blk_start(VirtIODevice *vdev)
>  {
> @@ -205,6 +206,10 @@ static void vhost_blk_vm_state(void *opaque, bool running, RunState state)
>          vhost_blk_stop(vdev);
>          vhost_blk_reset(vdev);
>      } else if (state == RUN_STATE_RUNNING) {
> +        VHostBlk *s = VHOST_BLK(vdev);
> +
> +        s->io_error_held = false;
> +        migrate_del_blocker(&s->io_error_blocker);
>          vhost_blk_start(vdev);
>      }
>  }
> @@ -293,6 +298,45 @@ static void vhost_blk_block_cpr(VHostBlk *s)
>      }
>  }
>  
> +static void vhost_blk_io_error(VHostBlk *s, bool is_read, int error)
> +{
> +    DeviceState *dev = DEVICE(s);
> +    DeviceState *proxy = dev->parent_bus ? dev->parent_bus->parent : NULL;
> +    BlockdevOnError on_err = is_read ? s->conf.conf.rerror
> +                                     : s->conf.conf.werror;
> +    g_autofree char *path = NULL;
> +
> +    if (on_err != BLOCKDEV_ON_ERROR_STOP &&
> +        (on_err != BLOCKDEV_ON_ERROR_ENOSPC || error != ENOSPC)) {
> +        return;
> +    }

IIUC libvirt gets rerror/werror policies from XML, then sets them in
dm-qcow2 table and provides to QEMU via conf settings.  If so, they
can't mismatch.  Therefore:

1. Returning on this mismatch is wrong. This way requests stay parked in
the kernel, nobody's told and libvirt never sends resubmit.
2. This mismatch shouldn't happen in the 1st place, so let's at least
add warn_report() on it.

> +
> +    /* dm-qcow2 repeats the event on every failed retry of a held request */
> +    if (!runstate_is_running()) {
> +        return;
> +    }

What if a VM is stopped for another reason (e.g. IO error on another
disk)?  We return here and don't set the migration blocker.  Maybe
instead return on:

>     if (!s->vhost_started || runstate_check(RUN_STATE_SUSPENDED))


> +
> +    path = object_get_canonical_path(OBJECT(dev));
> +
> +    s->io_error_held = true;
> +    if (!s->io_error_blocker) {
> +        error_setg(&s->io_error_blocker,
> +                   "vhost-blk: '%s' has requests held in the kernel after "
> +                   "an I/O error", path);
> +        migrate_add_blocker_internal(&s->io_error_blocker, NULL);
> +    }

And then here after the mig blocker is already set, once again check:

>     if (!runstate_is_running()) {                                               
>         return;                                                                 
>     }

So that we don't request stop of an already stopped VM.

Andrey

> +    qemu_system_vmstop_request_prepare();
> +    qapi_event_send_block_io_error(path,
> +                                   proxy && proxy->id ? proxy->id : "",
> +                                   NULL,
> +                                   is_read ? IO_OPERATION_TYPE_READ
> +                                           : IO_OPERATION_TYPE_WRITE,
> +                                   BLOCK_ERROR_ACTION_STOP, true,
> +                                   error == ENOSPC, strerror(error), 0, 0);
> +    qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
> +}
> +
>  /*
>   * The uevent socket is created, bound and filtered by the management
>   * layer and passed to us via the "ueventfd" property.
> @@ -310,6 +354,9 @@ static void vhost_blk_uevent_read(void *opaque)
>          bool action_change = false;
>          bool subsystem_block = false;
>          bool resize = false;
> +        bool io_error = false;
> +        bool io_error_read = false;
> +        int io_error_errno = EIO;
>          char *field;
>          char *end;
>          ssize_t len;
> @@ -351,6 +398,17 @@ static void vhost_blk_uevent_read(void *opaque)
>                  subsystem_block = true;
>              } else if (!strcmp(field, "RESIZE=1")) {
>                  resize = true;
> +            } else if (!strcmp(field, "IO_ERROR=1")) {
> +                io_error = true;
> +            } else if (!strcmp(field, "IO_ERROR_OP=read")) {
> +                io_error_read = true;
> +            } else if (g_str_has_prefix(field, "IO_ERROR_ERRNO=")) {
> +                int value;
> +
> +                if (!qemu_strtoi(field + strlen("IO_ERROR_ERRNO="), NULL, 10,
> +                                 &value) && value > 0) {
> +                    io_error_errno = value;
> +                }
>              } else if (g_str_has_prefix(field, "MAJOR=")) {
>                  uint64_t value;
>  
> @@ -373,11 +431,18 @@ static void vhost_blk_uevent_read(void *opaque)
>              field += field_len + 1;
>          }
>  
> -        if (action_change && subsystem_block && resize &&
> -            event_major == major(s->backend_rdev) &&
> -            event_minor == minor(s->backend_rdev)) {
> +        if (!action_change || !subsystem_block ||
> +            event_major != major(s->backend_rdev) ||
> +            event_minor != minor(s->backend_rdev)) {
> +            continue;
> +        }
> +
> +        if (resize) {
>              qemu_bh_schedule(s->resize_bh);
>          }
> +        if (io_error) {
> +            vhost_blk_io_error(s, io_error_read, io_error_errno);
> +        }
>      }
>  }
>  
> @@ -635,6 +700,14 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
>          return;
>      }
>  
> +    if (!conf->ueventfd &&
> +        (conf->conf.werror == BLOCKDEV_ON_ERROR_STOP ||
> +         conf->conf.rerror == BLOCKDEV_ON_ERROR_STOP)) {
> +        error_setg(errp, "vhost-blk: 'stop' error policy requires the "
> +                   "'ueventfd' property");
> +        return;
> +    }
> +
>      if (!vhost_blk_open_backend(s, errp)) {
>          return;
>      }
> @@ -709,6 +782,7 @@ static void vhost_blk_device_unrealize(DeviceState *dev)
>      VHostBlk *s = VHOST_BLK(dev);
>  
>      vhost_blk_uevent_detach(s);
> +    migrate_del_blocker(&s->io_error_blocker);
>      qemu_del_vm_change_state_handler(s->mighand);
>      vhost_blk_set_status(vdev, 0);
>      vhost_dev_cleanup(&s->dev);
> @@ -816,10 +890,23 @@ static const Property vhost_blk_properties[] = {
>      DEFINE_BLOCK_ERROR_PROPERTIES(VHostBlk, conf.conf),
>  };
>  
> +static int vhost_blk_pre_save(void *opaque)
> +{
> +    VHostBlk *s = opaque;
> +
> +    if (s->io_error_held) {
> +        error_report("vhost-blk: requests are held in the kernel after an "
> +                     "I/O error, resubmit or fail them first");
> +        return -EBUSY;
> +    }
> +    return 0;
> +}
> +
>  static const VMStateDescription vmstate_vhost_blk = {
>      .name = "vhost-blk",
>      .minimum_version_id = 1,
>      .version_id = 1,
> +    .pre_save = vhost_blk_pre_save,
>      .fields = (VMStateField[]) {
>          VMSTATE_VIRTIO_DEVICE,
>          VMSTATE_END_OF_LIST()
> diff --git a/include/hw/virtio/vhost-blk.h b/include/hw/virtio/vhost-blk.h
> index 059f1ebc701..935b35f6d6b 100644
> --- a/include/hw/virtio/vhost-blk.h
> +++ b/include/hw/virtio/vhost-blk.h
> @@ -48,6 +48,8 @@ typedef struct VHostBlk {
>      uint64_t backend_rdev;
>      QEMUBH *resize_bh;
>      Error *cpr_blocker;
> +    Error *io_error_blocker;
> +    bool io_error_held;
>  } VHostBlk;
>  
>  #endif


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies
  2026-11-17 10:59 ` [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies Andrey Drobyshev
@ 2026-11-17 18:14   ` Denis V. Lunev
  0 siblings, 0 replies; 9+ messages in thread
From: Denis V. Lunev @ 2026-11-17 18:14 UTC (permalink / raw)
  To: Andrey Drobyshev, Alexander Ivanov, andrey.zhadchenko; +Cc: svt-core

On 11/17/26 11:59, Andrey Drobyshev wrote:
> AFAIU vhost-blk is targeted for hci-8.2, and therefore these patches are
> NOT meant for hci-8.1 (despite what subject line suggests).  Please confirm.
>
> On 11/17/26 12:50 PM, Alexander Ivanov wrote:
>> A vhost-blk disk completes requests to the guest from the kernel, so
>> QEMU never sees an I/O error and the werror/rerror policies cannot
>> work the usual way. The dm-qcow2 series holds a failed request
>> according to the policy and reports it with an IO_ERROR change
>> uevent. This series makes QEMU accept the policies and pause the VM
>> on that uevent.
>>
>> Patch 1 adds the werror and rerror properties, which libvirt passes
>> when the disk has error_policy or rerror_policy set. Without them
>> QEMU refuses to start such a VM.
>>
>> Patch 2 parses the IO_ERROR uevent and stops the VM with the io-error
>> reason and a BLOCK_IO_ERROR event when the policy says so. Migration
>> and savevm are blocked while requests are held in the kernel.
>>
>> ! Don't apply this patchset before the kernel patchset is applied.
>>
>> https://virtuozzo.atlassian.net/browse/VSTOR-152175
>>
>> Alexander Ivanov (2):
>>   vhost-blk: add the werror and rerror properties #VSTOR-152175
>>   vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2
>>     #VSTOR-152175
>>
>>  hw/block/vhost-blk.c          | 112 +++++++++++++++++++++++++++++++++-
>>  include/hw/virtio/vhost-blk.h |   2 +
>>  2 files changed, 111 insertions(+), 3 deletions(-)
>>
question is correct. Anyway, we are to rebuild 8.1 for LA57.

@Andrey Drobyshev - if this is safe (not very dangerous) - take.
If not - 8.2

Den

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-17 18:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 10:50 [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies Alexander Ivanov
2026-11-17 10:50 ` [PATCH hci-8.1 1/2] vhost-blk: add the werror and rerror properties #VSTOR-152175 Alexander Ivanov
2026-11-17 11:03   ` no-reply
2026-11-17 18:12   ` Andrey Drobyshev
2026-11-17 10:50 ` [PATCH hci-8.1 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175 Alexander Ivanov
2026-11-17 11:05   ` no-reply
2026-11-17 18:12   ` Andrey Drobyshev
2026-11-17 10:59 ` [PATCH hci-8.1 0/2] vhost-blk: support the werror/rerror policies Andrey Drobyshev
2026-11-17 18:14   ` Denis V. Lunev

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.