Skip to content

Commit

Permalink
vhost-blk: turn on pre-defined RO feature bit
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Changpeng Liu authored and mstsirkin committed Jun 1, 2018
1 parent cab27af commit 25b1d45
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
48 changes: 35 additions & 13 deletions contrib/vhost-user-blk/vhost-user-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -490,28 +505,32 @@ 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);
break;
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;
}

Expand All @@ -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);

Expand Down
5 changes: 1 addition & 4 deletions hw/block/vhost-user-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(),
};

Expand Down
1 change: 0 additions & 1 deletion include/hw/virtio/vhost-user-blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 25b1d45

Please sign in to comment.