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

vhost: unify vdev removal



Instead of:

 * spdk_vhost_scsi_dev_remove(vdev)
 * spdk_vhost_blk_dev_remove(vdev)

we now have

 * spdk_vhost_dev_remove(vdev)

All the logic is already handled internally. This patch only
changes the API. Also, previous vhost_dev_construct()/remove()
functions have been renamed to vhost_dev_register()/unregister()
because that's what they really do.

Change-Id: I7dd0d77bc5b633bec075e0a71345ddbed62697b4
Signed-off-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/396574


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatar <shuhei.matsumoto.xt@hitachi.com>
parent 3fb4bc71
Loading
Loading
Loading
Loading
+3 −13
Original line number Diff line number Diff line
@@ -155,16 +155,6 @@ int spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_u
 */
int spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask);

/**
 * Remove an empty vhost SCSI device.  The vdev must not
 * have any SCSI devices attached nor have any open connection on
 * it's socket.
 *
 * \param vdev vhost SCSI device
 * \return 0 on success, negative errno on error.
 */
int spdk_vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev);

/**
 * Construct and attach new SCSI target to the vhost SCSI device
 * on given (unoccupied) slot.  The device will be created with a single
@@ -246,13 +236,13 @@ int spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *
			     bool readonly);

/**
 * Remove a vhost blk device. The device must not have any
 * open connections on it's socket.
 * Remove a vhost device. The device must not have any open
 * connections on it's socket.
 *
 * \param vdev vhost blk device
 * \return 0 on success, negative errno on error.
 */
int spdk_vhost_blk_destroy(struct spdk_vhost_dev *dev);
int spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev);

/**
 * Get underlying SPDK bdev from vhost blk device.  The
+5 −5
Original line number Diff line number Diff line
@@ -609,7 +609,7 @@ spdk_vhost_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
}

int
spdk_vhost_dev_construct(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)
{
	unsigned ctrlr_num;
@@ -734,7 +734,7 @@ out:
}

int
spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev)
spdk_vhost_dev_unregister(struct spdk_vhost_dev *vdev)
{
	unsigned ctrlr_num;

@@ -1197,9 +1197,9 @@ spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev,
}

int
spdk_remove_vhost_controller(struct spdk_vhost_dev *vdev)
spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev)
{
	return vdev->backend->vhost_remove_controller(vdev);
	return vdev->backend->remove_device(vdev);
}

static int
+8 −6
Original line number Diff line number Diff line
@@ -611,6 +611,8 @@ spdk_vhost_blk_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_wr
	spdk_json_write_object_end(w);
}

static int spdk_vhost_blk_destroy(struct spdk_vhost_dev *dev);

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) |
@@ -625,7 +627,7 @@ static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
	.start_device =  spdk_vhost_blk_start,
	.stop_device = spdk_vhost_blk_stop,
	.dump_config_json = spdk_vhost_blk_dump_config_json,
	.vhost_remove_controller = spdk_vhost_blk_destroy,
	.remove_device = spdk_vhost_blk_destroy,
};

int
@@ -703,7 +705,7 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_

	bvdev->bdev = bdev;
	bvdev->readonly = readonly;
	ret = spdk_vhost_dev_construct(&bvdev->vdev, name, cpumask, SPDK_VHOST_DEV_T_BLK,
	ret = spdk_vhost_dev_register(&bvdev->vdev, name, cpumask, SPDK_VHOST_DEV_T_BLK,
				      &vhost_blk_device_backend);
	if (ret != 0) {
		spdk_bdev_close(bvdev->bdev_desc);
@@ -715,7 +717,7 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
		SPDK_ERRLOG("Controller %s: failed to set as a readonly\n", name);
		spdk_bdev_close(bvdev->bdev_desc);

		if (spdk_vhost_dev_remove(&bvdev->vdev) != 0) {
		if (spdk_vhost_dev_unregister(&bvdev->vdev) != 0) {
			SPDK_ERRLOG("Controller %s: failed to remove controller\n", name);
		}

@@ -732,7 +734,7 @@ out:
	return ret;
}

int
static int
spdk_vhost_blk_destroy(struct spdk_vhost_dev *vdev)
{
	struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
@@ -742,7 +744,7 @@ spdk_vhost_blk_destroy(struct spdk_vhost_dev *vdev)
		return -EINVAL;
	}

	rc = spdk_vhost_dev_remove(&bvdev->vdev);
	rc = spdk_vhost_dev_unregister(&bvdev->vdev);
	if (rc != 0) {
		return rc;
	}
+4 −5
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ struct spdk_vhost_dev_backend {
				uint32_t offset, uint32_t size, uint32_t flags);

	void (*dump_config_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
	int (*vhost_remove_controller)(struct spdk_vhost_dev *vdev);
	int (*remove_device)(struct spdk_vhost_dev *vdev);
};

struct spdk_vhost_dev {
@@ -239,9 +239,9 @@ int spdk_vhost_vring_desc_to_iov(struct spdk_vhost_dev *vdev, struct iovec *iov,
				 uint16_t *iov_index, const struct vring_desc *desc);
bool spdk_vhost_dev_has_feature(struct spdk_vhost_dev *vdev, unsigned feature_id);

int spdk_vhost_dev_construct(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);
int spdk_vhost_dev_remove(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_blk_controller_construct(void);
@@ -249,6 +249,5 @@ void spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_w
void spdk_vhost_dev_backend_event_done(void *event_ctx, int response);
void spdk_vhost_lock(void);
void spdk_vhost_unlock(void);
int spdk_remove_vhost_controller(struct spdk_vhost_dev *vdev);

#endif /* SPDK_VHOST_INTERNAL_H */
+1 −1
Original line number Diff line number Diff line
@@ -391,7 +391,7 @@ spdk_rpc_remove_vhost_controller_cb(struct spdk_vhost_dev *vdev, void *arg)
		goto invalid;
	}

	rc = spdk_remove_vhost_controller(vdev);
	rc = spdk_vhost_dev_remove(vdev);
	if (rc < 0) {
		goto invalid;
	}
Loading