lib/nvmf: modify add_ns rpc to roll back changes in failure.

This can happen and we should make a best effort to return
the subsystem to a coherent state when it does.

maybe fixes: issue #1416

Signed-off-by: Seth Howell <seth.howell@intel.com>
Change-Id: Ic3d0376984733e6664295305be82fca678c515b3
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3437
Community-CI: Broadcom CI
Reviewed-by: Michael Haeuptle <michaelhaeuptle@gmail.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Seth Howell 2020-07-17 11:38:09 -07:00 committed by Tomasz Zawadzki
parent 1e337a1eb2
commit 1b249c38ad

View File

@ -962,6 +962,24 @@ nvmf_rpc_ns_ctx_free(struct nvmf_rpc_ns_ctx *ctx)
free(ctx); free(ctx);
} }
static void
nvmf_rpc_ns_failback_resumed(struct spdk_nvmf_subsystem *subsystem,
void *cb_arg, int status)
{
struct nvmf_rpc_ns_ctx *ctx = cb_arg;
struct spdk_jsonrpc_request *request = ctx->request;
if (status) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"Unable to add ns, subsystem in invalid state");
} else {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"Unable to add ns, subsystem in active state");
}
nvmf_rpc_ns_ctx_free(ctx);
}
static void static void
nvmf_rpc_ns_resumed(struct spdk_nvmf_subsystem *subsystem, nvmf_rpc_ns_resumed(struct spdk_nvmf_subsystem *subsystem,
void *cb_arg, int status) void *cb_arg, int status)
@ -971,6 +989,27 @@ nvmf_rpc_ns_resumed(struct spdk_nvmf_subsystem *subsystem,
uint32_t nsid = ctx->ns_params.nsid; uint32_t nsid = ctx->ns_params.nsid;
bool response_sent = ctx->response_sent; bool response_sent = ctx->response_sent;
struct spdk_json_write_ctx *w; struct spdk_json_write_ctx *w;
int rc;
/* The case where the call to add the namespace was successful, but the subsystem couldn't be resumed. */
if (status && !ctx->response_sent) {
rc = spdk_nvmf_subsystem_remove_ns(subsystem, nsid);
if (rc != 0) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"Unable to add ns, subsystem in invalid state");
nvmf_rpc_ns_ctx_free(ctx);
return;
}
rc = spdk_nvmf_subsystem_resume(subsystem, nvmf_rpc_ns_failback_resumed, ctx);
if (rc != 0) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
nvmf_rpc_ns_ctx_free(ctx);
return;
}
return;
}
nvmf_rpc_ns_ctx_free(ctx); nvmf_rpc_ns_ctx_free(ctx);