Commit f766d1e4 authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Tomasz Zawadzki
Browse files

nvmf: let transports parse transport opts from JSON themselves



There are more transport on the way and we don't want to add
all their various opts into the single, generic structure.
We'll pass the JSON structure to transports instead. Then
the transport code can custom pull from the JSON any param
it wants.

To complement that, transports will now also have their own
JSON config dump callback. This was only done in the generic
nvmf.c so far, with conditions for RDMA and TCP.

Change-Id: I33115a8d56cec829b1c51311a318e0333cc64920
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Signed-off-by: default avatarjiaqizho <jiaqi.zhou@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2761


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJacek Kalwas <jacek.kalwas@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 9ae19a41
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -71,6 +71,11 @@ receive the notification when the scsi bdev has been resized.
The `spdk_scsi_dev_construct` and `spdk_scsi_dev_add_lun` eventually may be
deprecated and removed.

### nvmf

NVMf Target transports can now parse any additional JSON params in the nvmf_create_transport RPC
through the JSON context provided via spdk_nvmf_target_opts->transport_specific.

## v20.07: SPDK CSI driver, new accel_fw commands, I/O abort support

### accel
+4 −5
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ struct spdk_nvmf_host;
struct spdk_nvmf_subsystem_listener;
struct spdk_nvmf_poll_group;
struct spdk_json_write_ctx;
struct spdk_json_val;
struct spdk_nvmf_transport;

struct spdk_nvmf_target_opts {
@@ -80,15 +81,13 @@ struct spdk_nvmf_transport_opts {
	uint32_t	max_aq_depth;
	uint32_t	num_shared_buffers;
	uint32_t	buf_cache_size;
	uint32_t	max_srq_depth;
	bool		no_srq;
	bool		c2h_success;
	bool		dif_insert_or_strip;
	uint32_t	sock_priority;
	int		acceptor_backlog;

	uint32_t	abort_timeout_sec;
	/* ms */
	uint32_t	association_timeout;

	const struct spdk_json_val *transport_specific;
};

struct spdk_nvmf_poll_group_stat {
+6 −0
Original line number Diff line number Diff line
@@ -224,6 +224,12 @@ struct spdk_nvmf_transport_ops {
	 */
	struct spdk_nvmf_transport *(*create)(struct spdk_nvmf_transport_opts *opts);

	/**
	 * Dump transport-specific opts into JSON
	 */
	void (*dump_opts)(struct spdk_nvmf_transport *transport,
			  struct spdk_json_write_ctx *w);

	/**
	 * Destroy the transport
	 */
+2 −2
Original line number Diff line number Diff line
@@ -576,8 +576,8 @@ spdk_nvmf_tgt_write_config_json(struct spdk_json_write_ctx *w, struct spdk_nvmf_
		spdk_json_write_named_uint32(w, "max_io_size", transport->opts.max_io_size);
		spdk_json_write_named_uint32(w, "io_unit_size", transport->opts.io_unit_size);
		spdk_json_write_named_uint32(w, "max_aq_depth", transport->opts.max_aq_depth);
		if (transport->ops->type == SPDK_NVME_TRANSPORT_RDMA) {
			spdk_json_write_named_uint32(w, "max_srq_depth", transport->opts.max_srq_depth);
		if (transport->ops->dump_opts) {
			transport->ops->dump_opts(transport, w);
		}
		spdk_json_write_named_uint32(w, "abort_timeout_sec", transport->opts.abort_timeout_sec);
		spdk_json_write_object_end(w);
+15 −36
Original line number Diff line number Diff line
@@ -1869,30 +1869,10 @@ static const struct spdk_json_object_decoder nvmf_rpc_create_transport_decoder[]
		"buf_cache_size", offsetof(struct nvmf_rpc_create_transport_ctx, opts.buf_cache_size),
		spdk_json_decode_uint32, true
	},
	{
		"max_srq_depth", offsetof(struct nvmf_rpc_create_transport_ctx, opts.max_srq_depth),
		spdk_json_decode_uint32, true
	},
	{
		"no_srq", offsetof(struct nvmf_rpc_create_transport_ctx, opts.no_srq),
		spdk_json_decode_bool, true
	},
	{
		"c2h_success", offsetof(struct nvmf_rpc_create_transport_ctx, opts.c2h_success),
		spdk_json_decode_bool, true
	},
	{
		"dif_insert_or_strip", offsetof(struct nvmf_rpc_create_transport_ctx, opts.dif_insert_or_strip),
		spdk_json_decode_bool, true
	},
	{
		"sock_priority", offsetof(struct nvmf_rpc_create_transport_ctx, opts.sock_priority),
		spdk_json_decode_uint32, true
	},
	{
		"acceptor_backlog", offsetof(struct nvmf_rpc_create_transport_ctx, opts.acceptor_backlog),
		spdk_json_decode_int32, true
	},
	{
		"abort_timeout_sec", offsetof(struct nvmf_rpc_create_transport_ctx, opts.abort_timeout_sec),
		spdk_json_decode_uint32, true
@@ -1950,10 +1930,10 @@ rpc_nvmf_create_transport(struct spdk_jsonrpc_request *request,
	}

	/* Decode parameters the first time to get the transport type */
	if (spdk_json_decode_object(params, nvmf_rpc_create_transport_decoder,
	if (spdk_json_decode_object_relaxed(params, nvmf_rpc_create_transport_decoder,
					    SPDK_COUNTOF(nvmf_rpc_create_transport_decoder),
					    ctx)) {
		SPDK_ERRLOG("spdk_json_decode_object failed\n");
		SPDK_ERRLOG("spdk_json_decode_object_relaxed failed\n");
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
		nvmf_rpc_create_transport_ctx_free(ctx);
		return;
@@ -1990,10 +1970,10 @@ rpc_nvmf_create_transport(struct spdk_jsonrpc_request *request,
		return;
	}

	if (spdk_json_decode_object(params, nvmf_rpc_create_transport_decoder,
	if (spdk_json_decode_object_relaxed(params, nvmf_rpc_create_transport_decoder,
					    SPDK_COUNTOF(nvmf_rpc_create_transport_decoder),
					    ctx)) {
		SPDK_ERRLOG("spdk_json_decode_object failed\n");
		SPDK_ERRLOG("spdk_json_decode_object_relaxed failed\n");
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
		nvmf_rpc_create_transport_ctx_free(ctx);
		return;
@@ -2007,6 +1987,9 @@ rpc_nvmf_create_transport(struct spdk_jsonrpc_request *request,
		return;
	}

	/* Transport can parse additional params themselves */
	ctx->opts.transport_specific = params;

	transport = spdk_nvmf_transport_create(ctx->trtype, &ctx->opts);

	if (!transport) {
@@ -2027,7 +2010,6 @@ static void
dump_nvmf_transport(struct spdk_json_write_ctx *w, struct spdk_nvmf_transport *transport)
{
	const struct spdk_nvmf_transport_opts *opts = spdk_nvmf_get_transport_opts(transport);
	spdk_nvme_transport_type_t type = spdk_nvmf_get_transport_type(transport);

	spdk_json_write_object_begin(w);

@@ -2041,14 +2023,11 @@ dump_nvmf_transport(struct spdk_json_write_ctx *w, struct spdk_nvmf_transport *t
	spdk_json_write_named_uint32(w, "num_shared_buffers", opts->num_shared_buffers);
	spdk_json_write_named_uint32(w, "buf_cache_size", opts->buf_cache_size);
	spdk_json_write_named_bool(w, "dif_insert_or_strip", opts->dif_insert_or_strip);
	if (type == SPDK_NVME_TRANSPORT_RDMA) {
		spdk_json_write_named_uint32(w, "max_srq_depth", opts->max_srq_depth);
		spdk_json_write_named_bool(w, "no_srq", opts->no_srq);
		spdk_json_write_named_int32(w, "acceptor_backlog", opts->acceptor_backlog);
	} else if (type == SPDK_NVME_TRANSPORT_TCP) {
		spdk_json_write_named_bool(w, "c2h_success", opts->c2h_success);
		spdk_json_write_named_uint32(w, "sock_priority", opts->sock_priority);

	if (transport->ops->dump_opts) {
		transport->ops->dump_opts(transport, w);
	}

	spdk_json_write_named_uint32(w, "abort_timeout_sec", opts->abort_timeout_sec);

	spdk_json_write_object_end(w);
Loading