vhost: set supported features based on backend

In vhost-blk, choose supported features based on what
 backend bdev supports instead of disabling not supported features.
This will prevent from enabling not supported feature in runtime.

Change-Id: Ie9453c7c02eb6d0a0ff0f1887048f4092cb7b14f
Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/476617
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.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>
This commit is contained in:
Vitaliy Mysak 2019-12-03 22:17:35 +01:00 committed by Tomasz Zawadzki
parent 5ffe337846
commit dda7375177

View File

@ -45,16 +45,13 @@
#include "vhost_internal.h" #include "vhost_internal.h"
/* Supported features for every SPDK VHOST-blk driver instance /* Minimal set of features supported by every SPDK VHOST-BLK device */
* Some of these get disabled depending on backend bdev */ #define SPDK_VHOST_BLK_FEATURES_BASE (SPDK_VHOST_FEATURES | \
#define SPDK_VHOST_BLK_SUPPORTED_FEATURES (SPDK_VHOST_FEATURES | \
(1ULL << VIRTIO_BLK_F_SIZE_MAX) | (1ULL << VIRTIO_BLK_F_SEG_MAX) | \ (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_GEOMETRY) | (1ULL << VIRTIO_BLK_F_BLK_SIZE) | \
(1ULL << VIRTIO_BLK_F_BLK_SIZE) | (1ULL << VIRTIO_BLK_F_TOPOLOGY) | \ (1ULL << VIRTIO_BLK_F_TOPOLOGY) | (1ULL << VIRTIO_BLK_F_BARRIER) | \
(1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI) | \ (1ULL << VIRTIO_BLK_F_SCSI) | (1ULL << VIRTIO_BLK_F_CONFIG_WCE) | \
(1ULL << VIRTIO_BLK_F_FLUSH) | (1ULL << VIRTIO_BLK_F_CONFIG_WCE) | \ (1ULL << VIRTIO_BLK_F_MQ))
(1ULL << VIRTIO_BLK_F_MQ) | (1ULL << VIRTIO_BLK_F_DISCARD) | \
(1ULL << VIRTIO_BLK_F_WRITE_ZEROES))
/* Not supported features */ /* Not supported features */
#define SPDK_VHOST_BLK_DISABLED_FEATURES (SPDK_VHOST_DISABLED_FEATURES | \ #define SPDK_VHOST_BLK_DISABLED_FEATURES (SPDK_VHOST_DISABLED_FEATURES | \
@ -979,20 +976,20 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
} }
vdev = &bvdev->vdev; vdev = &bvdev->vdev;
vdev->virtio_features = SPDK_VHOST_BLK_SUPPORTED_FEATURES; vdev->virtio_features = SPDK_VHOST_BLK_FEATURES_BASE;
vdev->disabled_features = SPDK_VHOST_BLK_DISABLED_FEATURES; vdev->disabled_features = SPDK_VHOST_BLK_DISABLED_FEATURES;
if (!spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) { if (spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) {
vdev->disabled_features |= (1ULL << VIRTIO_BLK_F_DISCARD); vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_DISCARD);
} }
if (!spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_WRITE_ZEROES)) { if (spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_WRITE_ZEROES)) {
vdev->disabled_features |= (1ULL << VIRTIO_BLK_F_WRITE_ZEROES); vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_WRITE_ZEROES);
} }
if (!readonly) { if (readonly) {
vdev->disabled_features |= (1ULL << VIRTIO_BLK_F_RO); vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_RO);
} }
if (!spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_FLUSH)) { if (spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_FLUSH)) {
vdev->disabled_features |= (1ULL << VIRTIO_BLK_F_FLUSH); vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_FLUSH);
} }
ret = spdk_bdev_open(bdev, true, bdev_remove_cb, bvdev, &bvdev->bdev_desc); ret = spdk_bdev_open(bdev, true, bdev_remove_cb, bvdev, &bvdev->bdev_desc);