From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Cc: svt-core@virtuozzo.com, den@openvz.org, andrey.drobyshev@virtuozzo.com
Subject: Re: [QEMU HCI-8.0 PATCH v2 3/5] vhost-blk: add read-only flag
Date: Fri, 04 Sep 2026 18:33:18 +0300 [thread overview]
Message-ID: <178853599893.728973.2201968989564457478.b4-review@b4> (raw)
In-Reply-To: <20260904132155.180581-4-andrey.zhadchenko@virtuozzo.com>
> and set RO respectively. Also compare BLKROGET with the selected
Please have commit message start their own sentences.
> mode and reject r/w if needed.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-143437
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
>
> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index 24f4fbe2b68..04a7013e521 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c
> @@ -24,6 +24,7 @@
> #include "system/system.h"
> #include "linux-headers/linux/vhost.h"
> #include <sys/ioctl.h>
> +#include <linux/fs.h>
Header belongs to patch 2.
> #include "system/runstate.h"
>
> static int vhost_blk_start(VirtIODevice *vdev)
> @@ -232,8 +233,9 @@ static bool vhost_blk_open_backend(VHostBlk *s, Error **errp)
> BlockConf *conf = &s->conf.conf;
> struct stat st;
> bool changed;
> + int open_flags = s->conf.readonly ? O_RDONLY : O_RDWR;
>
> - s->backend_fd = qemu_open(s->conf.devpath, O_RDWR, errp);
> + s->backend_fd = qemu_open(s->conf.devpath, open_flags, errp);
> if (s->backend_fd < 0) {
> error_prepend(errp, "vhost-blk: unable to open backend: ");
> return false;
> @@ -251,6 +253,23 @@ static bool vhost_blk_open_backend(VHostBlk *s, Error **errp)
> goto fail;
> }
>
> + if (!s->conf.readonly) {
> + int readonly;
> +
> + if (ioctl(s->backend_fd, BLKROGET, &readonly) < 0) {
> + error_setg_errno(errp, errno,
> + "vhost-blk: unable to get read-only status of "
> + "'%s'", s->conf.devpath);
> + goto fail;
> + }
> +
> + if (readonly) {
> + error_setg_errno(errp, EROFS, "vhost-blk: '%s' is not writable",
> + s->conf.devpath);
> + goto fail;
> + }
> + }
> +
> if (vhost_blk_update_size(s, &changed, errp) < 0) {
> goto fail;
> }
> @@ -406,6 +425,10 @@ static uint64_t vhost_blk_get_features(VirtIODevice *vdev,
>
> virtio_add_feature(&features, VIRTIO_F_VERSION_1);
>
> + if (s->conf.readonly) {
> + virtio_add_feature(&features, VIRTIO_BLK_F_RO);
> + }
> +
> if (s->conf.num_queues > 1) {
> virtio_add_feature(&features, VIRTIO_BLK_F_MQ);
> }
> @@ -453,6 +476,7 @@ static void vhost_blk_update_config(VirtIODevice *vdev, uint8_t *config)
>
> static const Property vhost_blk_properties[] = {
> DEFINE_PROP_STRING("devpath", VHostBlk, conf.devpath),
> + DEFINE_PROP_BOOL("read-only", VHostBlk, conf.readonly, false),
Not for this patch, but related: AFAIU currently "<readonly/>" in domain
XML is applied by libvirt to the block node. Correct? If so - we also
need to patch libvirt making sure it applies to the device.
Andrey
--
Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
next prev parent reply other threads:[~2026-09-04 15:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 13:21 [QEMU HCI-8.0 PATCH v2 0/5] vhost-blk change backend setup Andrey Zhadchenko
2026-09-04 13:21 ` [QEMU HCI-8.0 PATCH v2 1/5] vhost-blk: do not double close vhostfd Andrey Zhadchenko
2026-09-04 15:33 ` Andrey Drobyshev
2026-09-04 13:21 ` [QEMU HCI-8.0 PATCH v2 2/5] vhost-blk: change backend setup Andrey Zhadchenko
2026-09-04 15:33 ` Andrey Drobyshev
2026-09-04 13:21 ` [QEMU HCI-8.0 PATCH v2 3/5] vhost-blk: add read-only flag Andrey Zhadchenko
2026-09-04 15:33 ` Andrey Drobyshev [this message]
2026-09-04 13:21 ` [QEMU HCI-8.0 PATCH v2 4/5] vhost-blk: watch the device for resize events Andrey Zhadchenko
2026-09-04 15:33 ` Andrey Drobyshev
2026-09-04 13:21 ` [QEMU HCI-8.0 PATCH v2 5/5] vhost-blk: preserve the uevent socket across cpr-exec Andrey Zhadchenko
2026-09-04 15:33 ` Andrey Drobyshev
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=178853599893.728973.2201968989564457478.b4-review@b4 \
--to=andrey.drobyshev@virtuozzo.com \
--cc=andrey.zhadchenko@virtuozzo.com \
--cc=den@openvz.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox