All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: andrey.drobyshev@virtuozzo.com, svt-core@virtuozzo.com
Subject: [PATCH hci-8.2 v3 4/4] vhost-blk: fail realize when the kernel lacks write zeroes or discard
Date: Fri, 27 Nov 2026 13:46:58 +0100	[thread overview]
Message-ID: <20261127124658.1180997-5-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261127124658.1180997-1-alexander.ivanov@virtuozzo.com>

With the write-zeroes or discard property on, a kernel without that
feature in vhost-blk silently does not offer it to the guest. A
migration from a node that does offer it then fails only in
virtio_load() with a generic "Features ... unsupported".

Fail realize instead and name the missing feature. A backend that
lacks the feature still only gets a warning.

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

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

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index a2d5cfe9ea1..0e17b949726 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -702,6 +702,18 @@ fail:
     return false;
 }
 
+static bool vhost_blk_check_feature(VHostBlk *s, bool offered,
+                                    unsigned int bit, const char *name,
+                                    Error **errp)
+{
+    if (offered && !virtio_has_feature(s->dev.features, bit)) {
+        error_setg(errp, "vhost-blk: kernel does not support %s", name);
+        return false;
+    }
+
+    return true;
+}
+
 static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -781,6 +793,15 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp)
         goto cleanup;
     }
 
+    if (!vhost_blk_check_feature(s, s->write_zeroes, VIRTIO_BLK_F_WRITE_ZEROES,
+                                 "write zeroes", errp) ||
+        !vhost_blk_check_feature(s, s->discard, VIRTIO_BLK_F_DISCARD,
+                                 "discard", errp)) {
+        vhost_dev_cleanup(&s->dev);
+        s->vhostfd = -1;
+        goto cleanup;
+    }
+
     return;
 
 cleanup:
-- 
2.53.0


  parent reply	other threads:[~2026-11-27 12:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 12:46 [PATCH hci-8.2 v3 0/4] vhost-blk: support discard Alexander Ivanov
2026-11-27 12:46 ` [PATCH hci-8.2 v3 1/4] vhost-blk: read any queue attribute of the backend from sysfs Alexander Ivanov
2026-11-27 12:46 ` [PATCH hci-8.2 v3 2/4] vhost-blk: factor out the sysfs probe of the backend Alexander Ivanov
2026-11-27 12:46 ` [PATCH hci-8.2 v3 3/4] vhost-blk: advertise discard on a backend that supports it Alexander Ivanov
2026-11-27 12:46 ` Alexander Ivanov [this message]
2026-11-27 15:24 ` [PATCH hci-8.2 v3 0/4] vhost-blk: support discard Andrey Drobyshev
2026-11-30 14:09 ` Andrey Zhadchenko

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=20261127124658.1180997-5-alexander.ivanov@virtuozzo.com \
    --to=alexander.ivanov@virtuozzo.com \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=svt-core@virtuozzo.com \
    /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.