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 <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470460
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Vitaliy Mysak 2019-10-02 15:15:51 +02:00 committed by Tomasz Zawadzki
parent 26a02f72e8
commit 576dba8835
4 changed files with 20 additions and 18 deletions

View File

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

View File

@ -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",

View File

@ -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.

View File

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