nvmf/rpc: Don't stop listener if it was failed to remove

nvmf_subsystem_remove_listener RPC handler may fail to remove
the listener (e.g. it doesn't exist) but in eror case we
spdk_nvmf_transport_stop_listen_async and send an error
response. In a completion callback passed to
spdk_nvmf_transport_stop_listen_async we try to send a
response again but the response handler had already been
released and we dereference a NULL pointer.

The fix is to skip spdk_nvmf_transport_stop_listen_async
in error case and continue with the subsystem resuming.

Fixes github issue #1821

Change-Id: I8d96b943cca25d9f95d19e8ea600242f019e6b21
Signed-off-by: Alexey Marchuk <alexeymar@mellanox.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6699
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Alexey Marchuk 2021-03-04 18:26:16 +03:00 committed by Tomasz Zawadzki
parent 191e6ab8d2
commit f209637c9d

View File

@ -725,15 +725,16 @@ nvmf_rpc_listen_paused(struct spdk_nvmf_subsystem *subsystem,
ctx->response_sent = true;
}
} else if (ctx->op == NVMF_RPC_LISTEN_REMOVE) {
if (spdk_nvmf_subsystem_remove_listener(subsystem, &ctx->trid)) {
SPDK_ERRLOG("Unable to remove listener.\n");
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"Invalid parameters");
ctx->response_sent = true;
rc = spdk_nvmf_subsystem_remove_listener(subsystem, &ctx->trid);
if (rc == 0) {
spdk_nvmf_transport_stop_listen_async(ctx->transport, &ctx->trid, nvmf_rpc_stop_listen_async_done,
ctx);
return;
}
spdk_nvmf_transport_stop_listen_async(ctx->transport, &ctx->trid, nvmf_rpc_stop_listen_async_done,
ctx);
return;
SPDK_ERRLOG("Unable to remove listener, rc %d\n", rc);
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"Invalid parameters");
ctx->response_sent = true;
} else if (ctx->op == NVMF_RPC_LISTEN_SET_ANA_STATE) {
nvmf_subsystem_set_ana_state(subsystem, &ctx->trid, ctx->ana_state,
nvmf_rpc_set_ana_state_done, ctx);