Commit 5e952d84 authored by Jacek Kalwas's avatar Jacek Kalwas Committed by Tomasz Zawadzki
Browse files

nvmf: extend _add_ns with transport specific opts



It allows custom transport specific options support. JSON values
are meant to be parsed on specific transport during subsystem_add_ns
operation.

Change-Id: I1cd7590779b4c76e9d5d22eafd7fb9608eacbe64
Signed-off-by: default avatarJacek Kalwas <jacek.kalwas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22296


Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent 0bc67673
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -927,8 +927,17 @@ struct spdk_nvmf_ns_opts {

	/* Hole at bytes 60-63. */
	uint8_t reserved60[4];

	/* Transport specific json values.
	 *
	 * If transport specific values provided then json object is valid only at the time
	 * namespace is being added. It is transport layer responsibility to maintain
	 * the copy of it or its decoding if required. When \ref spdk_nvmf_ns_get_opts used
	 * after namespace has been added object becomes invalid.
	 */
	const struct spdk_json_val *transport_specific;
} __attribute__((packed));
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_ns_opts) == 64, "Incorrect size");
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_ns_opts) == 72, "Incorrect size");

/**
 * Get default namespace creation options.
+5 −3
Original line number Diff line number Diff line
@@ -1405,6 +1405,7 @@ struct nvmf_rpc_ns_ctx {
	struct spdk_nvmf_ns_params ns_params;

	struct spdk_jsonrpc_request *request;
	const struct spdk_json_val *params;
	bool response_sent;
};

@@ -1493,6 +1494,7 @@ nvmf_rpc_ns_paused(struct spdk_nvmf_subsystem *subsystem,

	spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
	ns_opts.nsid = ctx->ns_params.nsid;
	ns_opts.transport_specific = ctx->params;

	SPDK_STATIC_ASSERT(sizeof(ns_opts.nguid) == sizeof(ctx->ns_params.nguid), "size mismatch");
	memcpy(ns_opts.nguid, ctx->ns_params.nguid, sizeof(ns_opts.nguid));
@@ -1539,9 +1541,8 @@ rpc_nvmf_subsystem_add_ns(struct spdk_jsonrpc_request *request,
		return;
	}

	if (spdk_json_decode_object(params, nvmf_rpc_subsystem_ns_decoder,
				    SPDK_COUNTOF(nvmf_rpc_subsystem_ns_decoder),
				    ctx)) {
	if (spdk_json_decode_object_relaxed(params, nvmf_rpc_subsystem_ns_decoder,
					    SPDK_COUNTOF(nvmf_rpc_subsystem_ns_decoder), ctx)) {
		SPDK_ERRLOG("spdk_json_decode_object failed\n");
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
		nvmf_rpc_ns_ctx_free(ctx);
@@ -1549,6 +1550,7 @@ rpc_nvmf_subsystem_add_ns(struct spdk_jsonrpc_request *request,
	}

	ctx->request = request;
	ctx->params = params;
	ctx->response_sent = false;

	tgt = spdk_nvmf_get_tgt(ctx->tgt_name);
+6 −1
Original line number Diff line number Diff line
@@ -1654,6 +1654,7 @@ spdk_nvmf_ns_opts_get_defaults(struct spdk_nvmf_ns_opts *opts, size_t opts_size)
		spdk_uuid_set_null(&opts->uuid);
	}
	SET_FIELD(anagrpid, 0);
	SET_FIELD(transport_specific, NULL);

#undef FIELD_OK
#undef SET_FIELD
@@ -1683,13 +1684,14 @@ nvmf_ns_opts_copy(struct spdk_nvmf_ns_opts *opts,
		spdk_uuid_copy(&opts->uuid, &user_opts->uuid);
	}
	SET_FIELD(anagrpid);
	SET_FIELD(transport_specific);

	opts->opts_size = user_opts->opts_size;

	/* We should not remove this statement, but need to update the assert statement
	 * if we add a new field, and also add a corresponding SET_FIELD statement.
	 */
	SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_ns_opts) == 64, "Incorrect size");
	SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_ns_opts) == 72, "Incorrect size");

#undef FIELD_OK
#undef SET_FIELD
@@ -1882,6 +1884,9 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
		}
	}

	/* JSON value obj is freed before sending the response. Set NULL to prevent usage of dangling pointer. */
	ns->opts.transport_specific = NULL;

	SPDK_DEBUGLOG(nvmf, "Subsystem %s: bdev %s assigned nsid %" PRIu32 "\n",
		      spdk_nvmf_subsystem_get_nqn(subsystem),
		      bdev_name,