Commit fa82f460 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

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: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/396584


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatar <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 23077383
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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,
+6 −5
Original line number Diff line number Diff line
@@ -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;
+1 −7
Original line number Diff line number Diff line
@@ -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);
+4 −5
Original line number Diff line number Diff line
@@ -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) {
+2 −1
Original line number Diff line number Diff line
@@ -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;
Loading