Commit fd53562a authored by sberbz's avatar sberbz Committed by Tomasz Zawadzki
Browse files

vhost: parse JSON vhost_blk devices specific params



Separate parsing generic rpc vhost params form device specific,
this solution allow to create various device which share
common parameters.

Change-Id: I50b1a89a8260fb1394880a750591e95539995288
Signed-off-by: default avatarSebastian Brzezinka <sebastian.brzezinka@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12026


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 5d4b553c
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -312,14 +312,16 @@ int spdk_vhost_scsi_dev_remove_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tg
 * is allowed but not required. The mask itself can be constructed as:
 * ((1 << cpu0) | (1 << cpu1) | ... | (1 << cpuN)).
 * \param dev_name bdev name to associate with this vhost device
 * \param readonly if set, all writes to the device will fail with
 * \param params JSON value object containing variables:
 * readonly if set, all writes to the device will fail with
 * \c VIRTIO_BLK_S_IOERR error code.
 * \param packed_ring this controller supports packed ring if set.
 * packed_ring this controller supports packed ring if set.
 * packed_ring_recovery
 *
 * \return 0 on success, negative errno on error.
 */
int spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name,
			     bool readonly, bool packed_ring);
			     const struct spdk_json_val *params);

/**
 * Remove a vhost device. The device must not have any open connections on it's socket.
+26 −4
Original line number Diff line number Diff line
@@ -107,6 +107,18 @@ struct spdk_vhost_blk_session {
	struct spdk_poller *stop_poller;
};

struct rpc_vhost_blk {
	bool readonly;
	bool packed_ring;
	bool packed_ring_recovery;
};

static const struct spdk_json_object_decoder rpc_construct_vhost_blk[] = {
	{"readonly", offsetof(struct rpc_vhost_blk, readonly), spdk_json_decode_bool, true},
	{"packed_ring", offsetof(struct rpc_vhost_blk, packed_ring), spdk_json_decode_bool, true},
	{"packed_ring_recovery", offsetof(struct rpc_vhost_blk, packed_ring_recovery), spdk_json_decode_bool, true},
};

/* forward declaration */
static const struct spdk_vhost_dev_backend vhost_blk_device_backend;

@@ -1534,8 +1546,9 @@ static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {

int
spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_name,
			 bool readonly, bool packed_ring)
			 const struct spdk_json_val *params)
{
	struct rpc_vhost_blk req = {0};
	struct spdk_vhost_blk_dev *bvdev = NULL;
	struct spdk_vhost_dev *vdev;
	struct spdk_bdev *bdev;
@@ -1543,6 +1556,15 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_

	spdk_vhost_lock();

	if (spdk_json_decode_object_relaxed(params, rpc_construct_vhost_blk,
					    SPDK_COUNTOF(rpc_construct_vhost_blk),
					    &req)) {
		SPDK_DEBUGLOG(vhost_blk, "spdk_json_decode_object failed\n");
		ret = -EINVAL;
		goto out;
	}
	g_packed_ring_recovery = req.packed_ring_recovery;

	bvdev = calloc(1, sizeof(*bvdev));
	if (bvdev == NULL) {
		ret = -ENOMEM;
@@ -1562,7 +1584,7 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
	vdev->disabled_features = SPDK_VHOST_BLK_DISABLED_FEATURES;
	vdev->protocol_features = SPDK_VHOST_BLK_PROTOCOL_FEATURES;

	vdev->virtio_features |= (uint64_t)packed_ring << VIRTIO_F_RING_PACKED;
	vdev->virtio_features |= (uint64_t)req.packed_ring << VIRTIO_F_RING_PACKED;

	if (spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) {
		vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_DISCARD);
@@ -1570,7 +1592,7 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
	if (spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_WRITE_ZEROES)) {
		vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_WRITE_ZEROES);
	}
	if (readonly) {
	if (req.readonly) {
		vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_RO);
	}
	if (spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_FLUSH)) {
@@ -1591,7 +1613,7 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
	bvdev->dummy_io_channel = spdk_bdev_get_io_channel(bvdev->bdev_desc);

	bvdev->bdev = bdev;
	bvdev->readonly = readonly;
	bvdev->readonly = req.readonly;
	ret = vhost_dev_register(vdev, name, cpumask, &vhost_blk_device_backend);
	if (ret != 0) {
		spdk_put_io_channel(bvdev->dummy_io_channel);
+4 −13
Original line number Diff line number Diff line
@@ -235,18 +235,12 @@ struct rpc_vhost_blk_ctrlr {
	char *ctrlr;
	char *dev_name;
	char *cpumask;
	bool readonly;
	bool packed_ring;
	bool packed_ring_recovery;
};

static const struct spdk_json_object_decoder rpc_construct_vhost_blk_ctrlr[] = {
	{"ctrlr", offsetof(struct rpc_vhost_blk_ctrlr, ctrlr), spdk_json_decode_string },
	{"dev_name", offsetof(struct rpc_vhost_blk_ctrlr, dev_name), spdk_json_decode_string },
	{"cpumask", offsetof(struct rpc_vhost_blk_ctrlr, cpumask), spdk_json_decode_string, true},
	{"readonly", offsetof(struct rpc_vhost_blk_ctrlr, readonly), spdk_json_decode_bool, true},
	{"packed_ring", offsetof(struct rpc_vhost_blk_ctrlr, packed_ring), spdk_json_decode_bool, true},
	{"packed_ring_recovery", offsetof(struct rpc_vhost_blk_ctrlr, packed_ring_recovery), spdk_json_decode_bool, true},
};

static void
@@ -264,7 +258,7 @@ rpc_vhost_create_blk_controller(struct spdk_jsonrpc_request *request,
	struct rpc_vhost_blk_ctrlr req = {0};
	int rc;

	if (spdk_json_decode_object(params, rpc_construct_vhost_blk_ctrlr,
	if (spdk_json_decode_object_relaxed(params, rpc_construct_vhost_blk_ctrlr,
					    SPDK_COUNTOF(rpc_construct_vhost_blk_ctrlr),
					    &req)) {
		SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
@@ -272,10 +266,7 @@ rpc_vhost_create_blk_controller(struct spdk_jsonrpc_request *request,
		goto invalid;
	}

	g_packed_ring_recovery = req.packed_ring_recovery;

	rc = spdk_vhost_blk_construct(req.ctrlr, req.cpumask, req.dev_name,
				      req.readonly, req.packed_ring);
	rc = spdk_vhost_blk_construct(req.ctrlr, req.cpumask, req.dev_name, params);
	if (rc < 0) {
		goto invalid;
	}