From nobody Tue Feb 10 05:26:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527872975620752.7697854157379; Fri, 1 Jun 2018 10:09:35 -0700 (PDT) Received: from localhost ([::1]:56831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOnYM-0001bL-0I for importer@patchew.org; Fri, 01 Jun 2018 13:09:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOmts-0002iK-2H for qemu-devel@nongnu.org; Fri, 01 Jun 2018 12:27:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOmtq-0007dy-Ts for qemu-devel@nongnu.org; Fri, 01 Jun 2018 12:27:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60294 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fOmtn-0007cF-L4; Fri, 01 Jun 2018 12:27:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42B2D401EF23; Fri, 1 Jun 2018 16:27:31 +0000 (UTC) Received: from redhat.com (ovpn-121-148.rdu2.redhat.com [10.10.121.148]) by smtp.corp.redhat.com (Postfix) with SMTP id E8C852166BB2; Fri, 1 Jun 2018 16:27:28 +0000 (UTC) Date: Fri, 1 Jun 2018 19:27:28 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180601162620.32362-32-mst@redhat.com> References: <20180601162620.32362-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180601162620.32362-1-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 01 Jun 2018 16:27:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 01 Jun 2018 16:27:31 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 31/31] vhost-blk: turn on pre-defined RO feature bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Changpeng Liu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Changpeng Liu Read only feature shouldn't be negotiable, because if the backend device reported Read only feature supported, QEMU host driver shouldn't change backend's RO attribute. While here, also enable the vhost-user-blk test utility to test RO feature. Signed-off-by: Changpeng Liu Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user-blk.h | 1 - contrib/vhost-user-blk/vhost-user-blk.c | 48 ++++++++++++++++++------- hw/block/vhost-user-blk.c | 5 +-- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-u= ser-blk.h index f1258ae545..d52944aeeb 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -35,7 +35,6 @@ typedef struct VHostUserBlk { uint16_t num_queues; uint32_t queue_size; uint32_t config_wce; - uint32_t config_ro; struct vhost_dev dev; VhostUserState *vhost_user; } VHostUserBlk; diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index a6a132a492..571f114a56 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -31,6 +31,7 @@ typedef struct VubDev { VugDev parent; int blk_fd; struct virtio_blk_config blkcfg; + bool enable_ro; char *blk_name; GMainLoop *loop; } VubDev; @@ -301,14 +302,27 @@ static void vub_queue_set_started(VuDev *vu_dev, int = idx, bool started) static uint64_t vub_get_features(VuDev *dev) { - return 1ull << VIRTIO_BLK_F_SIZE_MAX | - 1ull << VIRTIO_BLK_F_SEG_MAX | - 1ull << VIRTIO_BLK_F_TOPOLOGY | - 1ull << VIRTIO_BLK_F_BLK_SIZE | - 1ull << VIRTIO_BLK_F_FLUSH | - 1ull << VIRTIO_BLK_F_CONFIG_WCE | - 1ull << VIRTIO_F_VERSION_1 | - 1ull << VHOST_USER_F_PROTOCOL_FEATURES; + uint64_t features; + VugDev *gdev; + VubDev *vdev_blk; + + gdev =3D container_of(dev, VugDev, parent); + vdev_blk =3D container_of(gdev, VubDev, parent); + + features =3D 1ull << VIRTIO_BLK_F_SIZE_MAX | + 1ull << VIRTIO_BLK_F_SEG_MAX | + 1ull << VIRTIO_BLK_F_TOPOLOGY | + 1ull << VIRTIO_BLK_F_BLK_SIZE | + 1ull << VIRTIO_BLK_F_FLUSH | + 1ull << VIRTIO_BLK_F_CONFIG_WCE | + 1ull << VIRTIO_F_VERSION_1 | + 1ull << VHOST_USER_F_PROTOCOL_FEATURES; + + if (vdev_blk->enable_ro) { + features |=3D 1ull << VIRTIO_BLK_F_RO; + } + + return features; } =20 static uint64_t @@ -476,6 +490,7 @@ vub_new(char *blk_file) vub_free(vdev_blk); return NULL; } + vdev_blk->enable_ro =3D false; vdev_blk->blkcfg.wce =3D 0; vdev_blk->blk_name =3D blk_file; =20 @@ -490,10 +505,11 @@ int main(int argc, char **argv) int opt; char *unix_socket =3D NULL; char *blk_file =3D NULL; + bool enable_ro =3D false; int lsock =3D -1, csock =3D -1; VubDev *vdev_blk =3D NULL; =20 - while ((opt =3D getopt(argc, argv, "b:s:h")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "b:rs:h")) !=3D -1) { switch (opt) { case 'b': blk_file =3D g_strdup(optarg); @@ -501,17 +517,20 @@ int main(int argc, char **argv) case 's': unix_socket =3D g_strdup(optarg); break; + case 'r': + enable_ro =3D true; + break; case 'h': default: - printf("Usage: %s [-b block device or file, -s UNIX domain soc= ket]" - " | [ -h ]\n", argv[0]); + printf("Usage: %s [ -b block device or file, -s UNIX domain so= cket" + " | -r Enable read-only ] | [ -h ]\n", argv[0]); return 0; } } =20 if (!unix_socket || !blk_file) { - printf("Usage: %s [-b block device or file, -s UNIX domain socket]= |" - " [ -h ]\n", argv[0]); + printf("Usage: %s [ -b block device or file, -s UNIX domain socket" + " | -r Enable read-only ] | [ -h ]\n", argv[0]); return -1; } =20 @@ -530,6 +549,9 @@ int main(int argc, char **argv) if (!vdev_blk) { goto err; } + if (enable_ro) { + vdev_blk->enable_ro =3D true; + } =20 vug_init(&vdev_blk->parent, csock, vub_panic_cb, &vub_iface); =20 diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 7c3fa8bb1c..d755223643 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -203,13 +203,11 @@ static uint64_t vhost_user_blk_get_features(VirtIODev= ice *vdev, virtio_add_feature(&features, VIRTIO_BLK_F_TOPOLOGY); virtio_add_feature(&features, VIRTIO_BLK_F_BLK_SIZE); virtio_add_feature(&features, VIRTIO_BLK_F_FLUSH); + virtio_add_feature(&features, VIRTIO_BLK_F_RO); =20 if (s->config_wce) { virtio_add_feature(&features, VIRTIO_BLK_F_CONFIG_WCE); } - if (s->config_ro) { - virtio_add_feature(&features, VIRTIO_BLK_F_RO); - } if (s->num_queues > 1) { virtio_add_feature(&features, VIRTIO_BLK_F_MQ); } @@ -339,7 +337,6 @@ static Property vhost_user_blk_properties[] =3D { DEFINE_PROP_UINT16("num-queues", VHostUserBlk, num_queues, 1), DEFINE_PROP_UINT32("queue-size", VHostUserBlk, queue_size, 128), DEFINE_PROP_BIT("config-wce", VHostUserBlk, config_wce, 0, true), - DEFINE_PROP_BIT("config-ro", VHostUserBlk, config_ro, 0, false), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 MST