From 576dba88356f4e9e02344590ffec4ca865caa725 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Wed, 2 Oct 2019 15:15:51 +0200 Subject: [PATCH] vhost: move feature fields from backend to vdev structure This will enable us to make features dynamic, dependent on underlying backend device, and to remove usage of rte_vhost functions in vhost-blk implementation which will improve encapsulation and enable us to write tests that use vhost-blk functions directly. Dynamic features are used in vhost_blk, but backend structure is assumed to be static, so we had to call rte_vhost_driver_enable_features() after registering it with some features initially disabled. This patch moves feature fields to vdev structure where it can be set dynamically. Change-Id: Icd76bdd76a3d67ec74e0ac992d8da639beead593 Signed-off-by: Vitaliy Mysak Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470460 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Community-CI: SPDK CI Jenkins --- lib/vhost/vhost.c | 2 +- lib/vhost/vhost_blk.c | 25 +++++++++++++------------ lib/vhost/vhost_internal.h | 6 +++--- lib/vhost/vhost_scsi.c | 5 +++-- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 899182142..4420a6249 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -640,7 +640,7 @@ vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *ma vhost_dev_set_coalescing(vdev, SPDK_VHOST_COALESCING_DELAY_BASE_US, SPDK_VHOST_VQ_IOPS_COALESCING_THRESHOLD); - if (vhost_register_unix_socket(path, name, backend->virtio_features, backend->disabled_features)) { + if (vhost_register_unix_socket(path, name, vdev->virtio_features, vdev->disabled_features)) { TAILQ_REMOVE(&g_vhost_devices, vdev, tailq); free(vdev->name); free(vdev->path); diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 3d45c93e1..531e93f2b 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -887,18 +887,6 @@ vhost_blk_get_config(struct spdk_vhost_dev *vdev, uint8_t *config, } static const struct spdk_vhost_dev_backend vhost_blk_device_backend = { - .virtio_features = SPDK_VHOST_FEATURES | - (1ULL << VIRTIO_BLK_F_SIZE_MAX) | (1ULL << VIRTIO_BLK_F_SEG_MAX) | - (1ULL << VIRTIO_BLK_F_GEOMETRY) | (1ULL << VIRTIO_BLK_F_RO) | - (1ULL << VIRTIO_BLK_F_BLK_SIZE) | (1ULL << VIRTIO_BLK_F_TOPOLOGY) | - (1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI) | - (1ULL << VIRTIO_BLK_F_FLUSH) | (1ULL << VIRTIO_BLK_F_CONFIG_WCE) | - (1ULL << VIRTIO_BLK_F_MQ) | (1ULL << VIRTIO_BLK_F_DISCARD) | - (1ULL << VIRTIO_BLK_F_WRITE_ZEROES), - .disabled_features = SPDK_VHOST_DISABLED_FEATURES | (1ULL << VIRTIO_BLK_F_GEOMETRY) | - (1ULL << VIRTIO_BLK_F_RO) | (1ULL << VIRTIO_BLK_F_FLUSH) | (1ULL << VIRTIO_BLK_F_CONFIG_WCE) | - (1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI) | (1ULL << VIRTIO_BLK_F_DISCARD) | - (1ULL << VIRTIO_BLK_F_WRITE_ZEROES), .session_ctx_size = sizeof(struct spdk_vhost_blk_session) - sizeof(struct spdk_vhost_session), .start_session = vhost_blk_start, .stop_session = vhost_blk_stop, @@ -974,6 +962,19 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_ goto out; } + bvdev->vdev.virtio_features = SPDK_VHOST_FEATURES | + (1ULL << VIRTIO_BLK_F_SIZE_MAX) | (1ULL << VIRTIO_BLK_F_SEG_MAX) | + (1ULL << VIRTIO_BLK_F_GEOMETRY) | (1ULL << VIRTIO_BLK_F_RO) | + (1ULL << VIRTIO_BLK_F_BLK_SIZE) | (1ULL << VIRTIO_BLK_F_TOPOLOGY) | + (1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI) | + (1ULL << VIRTIO_BLK_F_FLUSH) | (1ULL << VIRTIO_BLK_F_CONFIG_WCE) | + (1ULL << VIRTIO_BLK_F_MQ) | (1ULL << VIRTIO_BLK_F_DISCARD) | + (1ULL << VIRTIO_BLK_F_WRITE_ZEROES); + bvdev->vdev.disabled_features = SPDK_VHOST_DISABLED_FEATURES | (1ULL << VIRTIO_BLK_F_GEOMETRY) | + (1ULL << VIRTIO_BLK_F_RO) | (1ULL << VIRTIO_BLK_F_FLUSH) | (1ULL << VIRTIO_BLK_F_CONFIG_WCE) | + (1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI) | (1ULL << VIRTIO_BLK_F_DISCARD) | + (1ULL << VIRTIO_BLK_F_WRITE_ZEROES); + ret = spdk_bdev_open(bdev, true, bdev_remove_cb, bvdev, &bvdev->bdev_desc); if (ret != 0) { SPDK_ERRLOG("%s: could not open bdev '%s', error=%d\n", diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index c81409e55..921459548 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -156,6 +156,9 @@ struct spdk_vhost_dev { struct spdk_cpuset *cpumask; bool registered; + uint64_t virtio_features; + uint64_t disabled_features; + const struct spdk_vhost_dev_backend *backend; /* Saved orginal values used to setup coalescing to avoid integer @@ -199,9 +202,6 @@ typedef int (*spdk_vhost_session_fn)(struct spdk_vhost_dev *vdev, typedef void (*spdk_vhost_dev_fn)(struct spdk_vhost_dev *vdev, void *arg); struct spdk_vhost_dev_backend { - uint64_t virtio_features; - uint64_t disabled_features; - /** * Size of additional per-session context data * allocated whenever a new client connects. diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index 2fa099974..2d611cb19 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -151,8 +151,6 @@ static void vhost_scsi_write_config_json(struct spdk_vhost_dev *vdev, static int vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev); const struct spdk_vhost_dev_backend spdk_vhost_scsi_device_backend = { - .virtio_features = SPDK_VHOST_SCSI_FEATURES, - .disabled_features = SPDK_VHOST_SCSI_DISABLED_FEATURES, .session_ctx_size = sizeof(struct spdk_vhost_scsi_session) - sizeof(struct spdk_vhost_session), .start_session = vhost_scsi_start, .stop_session = vhost_scsi_stop, @@ -836,6 +834,9 @@ spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask) return -ENOMEM; } + svdev->vdev.virtio_features = SPDK_VHOST_SCSI_FEATURES; + svdev->vdev.disabled_features = SPDK_VHOST_SCSI_DISABLED_FEATURES; + spdk_vhost_lock(); rc = vhost_dev_register(&svdev->vdev, name, cpumask, &spdk_vhost_scsi_device_backend);