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:
parent
2307738334
commit
fa82f460d1
@ -610,7 +610,7 @@ spdk_vhost_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
|
||||
|
||||
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)
|
||||
{
|
||||
unsigned ctrlr_num;
|
||||
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->cpumask = cpumask;
|
||||
vdev->registered = true;
|
||||
vdev->type = type;
|
||||
vdev->backend = backend;
|
||||
|
||||
spdk_vhost_set_coalescing(vdev, SPDK_VHOST_COALESCING_DELAY_BASE_US,
|
||||
|
@ -71,6 +71,9 @@ struct spdk_vhost_blk_dev {
|
||||
bool readonly;
|
||||
};
|
||||
|
||||
/* forward declaration */
|
||||
static const struct spdk_vhost_dev_backend vhost_blk_device_backend;
|
||||
|
||||
static void
|
||||
blk_task_finish(struct spdk_vhost_blk_task *task)
|
||||
{
|
||||
@ -377,9 +380,8 @@ to_blk_dev(struct spdk_vhost_dev *vdev)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vdev->type != SPDK_VHOST_DEV_T_BLK) {
|
||||
SPDK_ERRLOG("Controller %s: expected block controller (%d) but got %d\n",
|
||||
vdev->name, SPDK_VHOST_DEV_T_BLK, vdev->type);
|
||||
if (vdev->backend != &vhost_blk_device_backend) {
|
||||
SPDK_ERRLOG("%s: not a vhost-blk device\n", vdev->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -705,8 +707,7 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
|
||||
|
||||
bvdev->bdev = bdev;
|
||||
bvdev->readonly = readonly;
|
||||
ret = spdk_vhost_dev_register(&bvdev->vdev, name, cpumask, SPDK_VHOST_DEV_T_BLK,
|
||||
&vhost_blk_device_backend);
|
||||
ret = spdk_vhost_dev_register(&bvdev->vdev, name, cpumask, &vhost_blk_device_backend);
|
||||
if (ret != 0) {
|
||||
spdk_bdev_close(bvdev->bdev_desc);
|
||||
ret = -1;
|
||||
|
@ -93,11 +93,6 @@
|
||||
#define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \
|
||||
(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 rte_vhost_vring vring;
|
||||
void *tasks;
|
||||
@ -148,7 +143,6 @@ struct spdk_vhost_dev {
|
||||
struct spdk_cpuset *cpumask;
|
||||
bool registered;
|
||||
|
||||
enum spdk_vhost_dev_type type;
|
||||
const struct spdk_vhost_dev_backend *backend;
|
||||
|
||||
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);
|
||||
|
||||
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_scsi_controller_construct(void);
|
||||
|
@ -677,13 +677,12 @@ to_scsi_dev(struct spdk_vhost_dev *ctrlr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ctrlr->type != SPDK_VHOST_DEV_T_SCSI) {
|
||||
SPDK_ERRLOG("Controller %s: expected SCSI controller (%d) but got %d\n",
|
||||
ctrlr->name, SPDK_VHOST_DEV_T_SCSI, ctrlr->type);
|
||||
if (ctrlr->backend != &spdk_vhost_scsi_device_backend) {
|
||||
SPDK_ERRLOG("%s: not a vhost-scsi device.\n", ctrlr->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct spdk_vhost_scsi_dev *)ctrlr;
|
||||
return SPDK_CONTAINEROF(ctrlr, struct spdk_vhost_scsi_dev, vdev);
|
||||
}
|
||||
|
||||
int
|
||||
@ -698,7 +697,7 @@ spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask)
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (rc) {
|
||||
|
@ -108,12 +108,13 @@ DEFINE_STUB(spdk_vhost_dev_register_fail, bool, (void), false);
|
||||
static struct spdk_vhost_dev *g_spdk_vhost_device;
|
||||
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)
|
||||
{
|
||||
if (spdk_vhost_dev_register_fail()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
vdev->backend = backend;
|
||||
g_spdk_vhost_device = vdev;
|
||||
vdev->registered = true;
|
||||
return 0;
|
||||
|
@ -222,25 +222,25 @@ create_controller_test(void)
|
||||
|
||||
/* Create device with no name */
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Create device with too long name and path */
|
||||
memset(long_name, 'x', sizeof(long_name));
|
||||
long_name[PATH_MAX - 1] = 0;
|
||||
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);
|
||||
dev_dirname[0] = 0;
|
||||
|
||||
/* Create device when device name is already taken */
|
||||
vdev->name = strdup("vdev_name_0");
|
||||
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);
|
||||
|
||||
/* Create device when max number of devices is reached */
|
||||
@ -248,7 +248,7 @@ create_controller_test(void)
|
||||
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);
|
||||
|
||||
free_vdev(vdev);
|
||||
|
@ -88,7 +88,7 @@ alloc_bvdev(void)
|
||||
SPDK_CACHE_LINE_SIZE, NULL);
|
||||
|
||||
SPDK_CU_ASSERT_FATAL(bvdev != NULL);
|
||||
bvdev->vdev.type = SPDK_VHOST_DEV_T_BLK;
|
||||
bvdev->vdev.backend = &vhost_blk_device_backend;
|
||||
return bvdev;
|
||||
}
|
||||
|
||||
@ -138,12 +138,12 @@ vhost_blk_destroy_test(void)
|
||||
bvdev = alloc_bvdev();
|
||||
|
||||
/* Device has an incorrect type */
|
||||
bvdev->vdev.type = SPDK_VHOST_DEV_T_SCSI;
|
||||
bvdev->vdev.backend = NULL;;
|
||||
rc = spdk_vhost_blk_destroy(&bvdev->vdev);
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
|
||||
/* 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);
|
||||
rc = spdk_vhost_blk_destroy(&bvdev->vdev);
|
||||
CU_ASSERT(rc == -1);
|
||||
|
@ -105,6 +105,7 @@ alloc_svdev(void)
|
||||
|
||||
SPDK_CU_ASSERT_FATAL(svdev != NULL);
|
||||
svdev->vdev.registered = true;
|
||||
svdev->vdev.backend = &spdk_vhost_scsi_device_backend;
|
||||
return svdev;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user