Commit ee9e3438 authored by Jacek Kalwas's avatar Jacek Kalwas Committed by Jim Harris
Browse files

nvmf/rpc: fix input validation for nvmf_subsystem_add_listener

In case user tries to add listener with the same parameters then error
shall be returned instead silent success.

That is more aligned with what is happening e.g. for
rpc_nvmf_create_subsystem i.e. when there is a try to create the
subsystem with the same nqn error is being returned.

Moreover, although previous behavior allows to call _add_listener with
the same parameters N times only single _remove_listener would release
allocated resources for it.

Issue was spotted earlier, however since then nobody has fixed that,
see https://review.gerrithub.io/c/spdk/spdk/+/482446

 and comments
there.

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


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
parent 79f6fb18
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8274,6 +8274,8 @@ Example response:

Add a new listen address to an NVMe-oF subsystem.

This method will fail if listener with given address already exists.

#### Parameters

Name                    | Optional | Type        | Description
+5 −10
Original line number Diff line number Diff line
@@ -756,20 +756,15 @@ nvmf_rpc_listen_paused(struct spdk_nvmf_subsystem *subsystem,
		       void *cb_arg, int status)
{
	struct nvmf_rpc_listener_ctx *ctx = cb_arg;
	struct spdk_nvmf_subsystem_listener *listener;
	int rc;

	switch (ctx->op) {
	case NVMF_RPC_LISTEN_ADD:
		listener = nvmf_subsystem_find_listener(subsystem, &ctx->trid);
		if (listener) {
			if (ctx->listener_opts.secure_channel != listener->opts.secure_channel) {
				SPDK_ERRLOG("A listener already exists with different secure channel option.");
		if (nvmf_subsystem_find_listener(subsystem, &ctx->trid)) {
			SPDK_ERRLOG("Listener already exists\n");
			spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
							 "Invalid parameters");
			ctx->response_sent = true;
			}

			break;
		}