qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Changpeng Liu <changpeng.liu@intel.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	qemu-block@nongnu.org
Subject: [Qemu-devel] [PULL 31/31] vhost-blk: turn on pre-defined RO feature bit
Date: Fri, 1 Jun 2018 19:27:28 +0300	[thread overview]
Message-ID: <20180601162620.32362-32-mst@redhat.com> (raw)
In-Reply-To: <20180601162620.32362-1-mst@redhat.com>

From: Changpeng Liu <changpeng.liu@intel.com>

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 <changpeng.liu@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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-user-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-blk/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 = container_of(dev, VugDev, parent);
+    vdev_blk = container_of(gdev, VubDev, parent);
+
+    features = 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 |= 1ull << VIRTIO_BLK_F_RO;
+    }
+
+    return features;
 }
 
 static uint64_t
@@ -476,6 +490,7 @@ vub_new(char *blk_file)
         vub_free(vdev_blk);
         return NULL;
     }
+    vdev_blk->enable_ro = false;
     vdev_blk->blkcfg.wce = 0;
     vdev_blk->blk_name = blk_file;
 
@@ -490,10 +505,11 @@ int main(int argc, char **argv)
     int opt;
     char *unix_socket = NULL;
     char *blk_file = NULL;
+    bool enable_ro = false;
     int lsock = -1, csock = -1;
     VubDev *vdev_blk = NULL;
 
-    while ((opt = getopt(argc, argv, "b:s:h")) != -1) {
+    while ((opt = getopt(argc, argv, "b:rs:h")) != -1) {
         switch (opt) {
         case 'b':
             blk_file = g_strdup(optarg);
@@ -501,17 +517,20 @@ int main(int argc, char **argv)
         case 's':
             unix_socket = g_strdup(optarg);
             break;
+        case 'r':
+            enable_ro = true;
+            break;
         case 'h':
         default:
-            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 0;
         }
     }
 
     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;
     }
 
@@ -530,6 +549,9 @@ int main(int argc, char **argv)
     if (!vdev_blk) {
         goto err;
     }
+    if (enable_ro) {
+        vdev_blk->enable_ro = true;
+    }
 
     vug_init(&vdev_blk->parent, csock, vub_panic_cb, &vub_iface);
 
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(VirtIODevice *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);
 
     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[] = {
     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(),
 };
 
-- 
MST

  parent reply	other threads:[~2018-06-01 16:27 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01 16:26 [Qemu-devel] [PULL 00/31] acpi, vhost, misc: fixes, features Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 01/31] vhost: allow backends to filter memory sections Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 02/31] vhost-user: allow slave to send fds via slave channel Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 03/31] vhost-user: introduce shared vhost-user state Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 04/31] vhost-user: support registering external host notifiers Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 05/31] libvhost-user: support host notifier Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 06/31] vhost-user-bridge: " Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 07/31] osdep: add wait.h compat macros Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 08/31] libqtest: fail if child coredumps Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 09/31] block: use local path for local headers Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 10/31] crypto: " Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 11/31] hppa: " Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 12/31] migration: drop an unused include Michael S. Tsirkin
2018-06-01 16:26 ` [Qemu-devel] [PULL 13/31] trace: use local path for local headers Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 14/31] display: " Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 15/31] ide: " Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 16/31] ioapic: fix up includes Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 17/31] e1000e: use local path for local headers Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 18/31] rocker: drop an unused include Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 19/31] ppc: use local path for local headers Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 20/31] vhost-scsi: drop an unused include Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 21/31] sd: fix up include Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 22/31] usb: use local path for local headers Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 23/31] migration: " Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 24/31] colo: " Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 25/31] qga: " Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 26/31] ui: " Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 27/31] arch_init: sort architectures Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 28/31] tests/.gitignore: add entry for generated file Michael S. Tsirkin
2018-06-01 16:27 ` [Qemu-devel] [PULL 29/31] nvdimm, acpi: support NFIT platform capabilities Michael S. Tsirkin
2018-06-01 16:27 ` Michael S. Tsirkin [this message]
2018-06-01 16:27 ` [Qemu-devel] [PULL 30/31] ACPI testing: test " Michael S. Tsirkin
2018-06-04 10:28 ` [Qemu-devel] [PULL 00/31] acpi, vhost, misc: fixes, features Peter Maydell
2018-06-08 17:52   ` Philippe Mathieu-Daudé
2018-06-08 18:47     ` Philippe Mathieu-Daudé
2018-06-09 11:38       ` Peter Maydell
2018-06-06 10:09 ` Thomas Huth

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=20180601162620.32362-32-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=changpeng.liu@intel.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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;
as well as URLs for NNTP newsgroup(s).