vhost: remove vdev->type field

This field was only required to check
if we can safely upcast vdev object.
We can just as well check vdev->backend
instead. The vdev->type is not needed here.

Change-Id: I525350957406d4299151e0557b9025ca7bea5371
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/396584
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2018-01-26 15:29:20 +01:00 committed by Jim Harris
parent 2307738334
commit fa82f460d1
8 changed files with 23 additions and 28 deletions

View File

@ -610,7 +610,7 @@ spdk_vhost_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
int int
spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str, spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
enum spdk_vhost_dev_type type, const struct spdk_vhost_dev_backend *backend) const struct spdk_vhost_dev_backend *backend)
{ {
unsigned ctrlr_num; unsigned ctrlr_num;
char path[PATH_MAX]; char path[PATH_MAX];
@ -708,7 +708,6 @@ spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const cha
vdev->lcore = -1; vdev->lcore = -1;
vdev->cpumask = cpumask; vdev->cpumask = cpumask;
vdev->registered = true; vdev->registered = true;
vdev->type = type;
vdev->backend = backend; vdev->backend = backend;
spdk_vhost_set_coalescing(vdev, SPDK_VHOST_COALESCING_DELAY_BASE_US, spdk_vhost_set_coalescing(vdev, SPDK_VHOST_COALESCING_DELAY_BASE_US,

View File

@ -71,6 +71,9 @@ struct spdk_vhost_blk_dev {
bool readonly; bool readonly;
}; };
/* forward declaration */
static const struct spdk_vhost_dev_backend vhost_blk_device_backend;
static void static void
blk_task_finish(struct spdk_vhost_blk_task *task) blk_task_finish(struct spdk_vhost_blk_task *task)
{ {
@ -377,9 +380,8 @@ to_blk_dev(struct spdk_vhost_dev *vdev)
return NULL; return NULL;
} }
if (vdev->type != SPDK_VHOST_DEV_T_BLK) { if (vdev->backend != &vhost_blk_device_backend) {
SPDK_ERRLOG("Controller %s: expected block controller (%d) but got %d\n", SPDK_ERRLOG("%s: not a vhost-blk device\n", vdev->name);
vdev->name, SPDK_VHOST_DEV_T_BLK, vdev->type);
return NULL; return NULL;
} }
@ -705,8 +707,7 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
bvdev->bdev = bdev; bvdev->bdev = bdev;
bvdev->readonly = readonly; bvdev->readonly = readonly;
ret = spdk_vhost_dev_register(&bvdev->vdev, name, cpumask, SPDK_VHOST_DEV_T_BLK, ret = spdk_vhost_dev_register(&bvdev->vdev, name, cpumask, &vhost_blk_device_backend);
&vhost_blk_device_backend);
if (ret != 0) { if (ret != 0) {
spdk_bdev_close(bvdev->bdev_desc); spdk_bdev_close(bvdev->bdev_desc);
ret = -1; ret = -1;

View File

@ -93,11 +93,6 @@
#define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \ #define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \
(1ULL << VIRTIO_RING_F_INDIRECT_DESC)) (1ULL << VIRTIO_RING_F_INDIRECT_DESC))
enum spdk_vhost_dev_type {
SPDK_VHOST_DEV_T_SCSI,//!< SPDK_VHOST_DEV_T_SCSI
SPDK_VHOST_DEV_T_BLK, //!< SPDK_VHOST_DEV_T_BLK
};
struct spdk_vhost_virtqueue { struct spdk_vhost_virtqueue {
struct rte_vhost_vring vring; struct rte_vhost_vring vring;
void *tasks; void *tasks;
@ -148,7 +143,6 @@ struct spdk_vhost_dev {
struct spdk_cpuset *cpumask; struct spdk_cpuset *cpumask;
bool registered; bool registered;
enum spdk_vhost_dev_type type;
const struct spdk_vhost_dev_backend *backend; const struct spdk_vhost_dev_backend *backend;
uint32_t coalescing_delay_time_base; uint32_t coalescing_delay_time_base;
@ -241,7 +235,7 @@ int spdk_vhost_vring_desc_to_iov(struct spdk_vhost_dev *vdev, struct iovec *iov,
bool spdk_vhost_dev_has_feature(struct spdk_vhost_dev *vdev, unsigned feature_id); bool spdk_vhost_dev_has_feature(struct spdk_vhost_dev *vdev, unsigned feature_id);
int spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str, int spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
enum spdk_vhost_dev_type type, const struct spdk_vhost_dev_backend *backend); const struct spdk_vhost_dev_backend *backend);
int spdk_vhost_dev_unregister(struct spdk_vhost_dev *vdev); int spdk_vhost_dev_unregister(struct spdk_vhost_dev *vdev);
int spdk_vhost_scsi_controller_construct(void); int spdk_vhost_scsi_controller_construct(void);

View File

@ -677,13 +677,12 @@ to_scsi_dev(struct spdk_vhost_dev *ctrlr)
return NULL; return NULL;
} }
if (ctrlr->type != SPDK_VHOST_DEV_T_SCSI) { if (ctrlr->backend != &spdk_vhost_scsi_device_backend) {
SPDK_ERRLOG("Controller %s: expected SCSI controller (%d) but got %d\n", SPDK_ERRLOG("%s: not a vhost-scsi device.\n", ctrlr->name);
ctrlr->name, SPDK_VHOST_DEV_T_SCSI, ctrlr->type);
return NULL; return NULL;
} }
return (struct spdk_vhost_scsi_dev *)ctrlr; return SPDK_CONTAINEROF(ctrlr, struct spdk_vhost_scsi_dev, vdev);
} }
int int
@ -698,7 +697,7 @@ spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask)
} }
spdk_vhost_lock(); spdk_vhost_lock();
rc = spdk_vhost_dev_register(&svdev->vdev, name, cpumask, SPDK_VHOST_DEV_T_SCSI, rc = spdk_vhost_dev_register(&svdev->vdev, name, cpumask,
&spdk_vhost_scsi_device_backend); &spdk_vhost_scsi_device_backend);
if (rc) { if (rc) {

View File

@ -108,12 +108,13 @@ DEFINE_STUB(spdk_vhost_dev_register_fail, bool, (void), false);
static struct spdk_vhost_dev *g_spdk_vhost_device; static struct spdk_vhost_dev *g_spdk_vhost_device;
int int
spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str, spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
enum spdk_vhost_dev_type type, const struct spdk_vhost_dev_backend *backend) const struct spdk_vhost_dev_backend *backend)
{ {
if (spdk_vhost_dev_register_fail()) { if (spdk_vhost_dev_register_fail()) {
return -1; return -1;
} }
vdev->backend = backend;
g_spdk_vhost_device = vdev; g_spdk_vhost_device = vdev;
vdev->registered = true; vdev->registered = true;
return 0; return 0;

View File

@ -222,25 +222,25 @@ create_controller_test(void)
/* Create device with no name */ /* Create device with no name */
vdev = alloc_vdev(); vdev = alloc_vdev();
ret = spdk_vhost_dev_register(vdev, NULL, "0x1", SPDK_VHOST_DEV_T_BLK, &backend); ret = spdk_vhost_dev_register(vdev, NULL, "0x1", &backend);
CU_ASSERT(ret != 0); CU_ASSERT(ret != 0);
/* Create device with incorrect cpumask */ /* Create device with incorrect cpumask */
ret = spdk_vhost_dev_register(vdev, "vdev_name_0", "0x2", SPDK_VHOST_DEV_T_BLK, &backend); ret = spdk_vhost_dev_register(vdev, "vdev_name_0", "0x2", &backend);
CU_ASSERT(ret != 0); CU_ASSERT(ret != 0);
/* Create device with too long name and path */ /* Create device with too long name and path */
memset(long_name, 'x', sizeof(long_name)); memset(long_name, 'x', sizeof(long_name));
long_name[PATH_MAX - 1] = 0; long_name[PATH_MAX - 1] = 0;
snprintf(dev_dirname, sizeof(dev_dirname), "some_path/"); snprintf(dev_dirname, sizeof(dev_dirname), "some_path/");
ret = spdk_vhost_dev_register(vdev, long_name, "0x1", SPDK_VHOST_DEV_T_BLK, &backend); ret = spdk_vhost_dev_register(vdev, long_name, "0x1", &backend);
CU_ASSERT(ret != 0); CU_ASSERT(ret != 0);
dev_dirname[0] = 0; dev_dirname[0] = 0;
/* Create device when device name is already taken */ /* Create device when device name is already taken */
vdev->name = strdup("vdev_name_0"); vdev->name = strdup("vdev_name_0");
g_spdk_vhost_devices[0] = vdev; g_spdk_vhost_devices[0] = vdev;
ret = spdk_vhost_dev_register(vdev, "vdev_name_0", "0x1", SPDK_VHOST_DEV_T_BLK, &backend); ret = spdk_vhost_dev_register(vdev, "vdev_name_0", "0x1", &backend);
CU_ASSERT(ret != 0); CU_ASSERT(ret != 0);
/* Create device when max number of devices is reached */ /* Create device when max number of devices is reached */
@ -248,7 +248,7 @@ create_controller_test(void)
g_spdk_vhost_devices[ctrlr_num] = vdev; g_spdk_vhost_devices[ctrlr_num] = vdev;
} }
ret = spdk_vhost_dev_register(vdev, "vdev_name_1", "0x1", SPDK_VHOST_DEV_T_BLK, &backend); ret = spdk_vhost_dev_register(vdev, "vdev_name_1", "0x1", &backend);
CU_ASSERT(ret != 0); CU_ASSERT(ret != 0);
free_vdev(vdev); free_vdev(vdev);

View File

@ -88,7 +88,7 @@ alloc_bvdev(void)
SPDK_CACHE_LINE_SIZE, NULL); SPDK_CACHE_LINE_SIZE, NULL);
SPDK_CU_ASSERT_FATAL(bvdev != NULL); SPDK_CU_ASSERT_FATAL(bvdev != NULL);
bvdev->vdev.type = SPDK_VHOST_DEV_T_BLK; bvdev->vdev.backend = &vhost_blk_device_backend;
return bvdev; return bvdev;
} }
@ -138,12 +138,12 @@ vhost_blk_destroy_test(void)
bvdev = alloc_bvdev(); bvdev = alloc_bvdev();
/* Device has an incorrect type */ /* Device has an incorrect type */
bvdev->vdev.type = SPDK_VHOST_DEV_T_SCSI; bvdev->vdev.backend = NULL;;
rc = spdk_vhost_blk_destroy(&bvdev->vdev); rc = spdk_vhost_blk_destroy(&bvdev->vdev);
CU_ASSERT(rc == -EINVAL); CU_ASSERT(rc == -EINVAL);
/* Failed to remove device */ /* Failed to remove device */
bvdev->vdev.type = SPDK_VHOST_DEV_T_BLK; bvdev->vdev.backend = &vhost_blk_device_backend;
MOCK_SET(spdk_vhost_dev_unregister_fail, bool, true); MOCK_SET(spdk_vhost_dev_unregister_fail, bool, true);
rc = spdk_vhost_blk_destroy(&bvdev->vdev); rc = spdk_vhost_blk_destroy(&bvdev->vdev);
CU_ASSERT(rc == -1); CU_ASSERT(rc == -1);

View File

@ -105,6 +105,7 @@ alloc_svdev(void)
SPDK_CU_ASSERT_FATAL(svdev != NULL); SPDK_CU_ASSERT_FATAL(svdev != NULL);
svdev->vdev.registered = true; svdev->vdev.registered = true;
svdev->vdev.backend = &spdk_vhost_scsi_device_backend;
return svdev; return svdev;
} }