From fd948954329e749506823ef7213a1adeaebe3ded Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 4 Sep 2018 11:37:31 -0700 Subject: [PATCH] nvmf: Require qpair disconnect to be performed from owning thread I observed that spdk_nvmf_qpair_disconnect is only ever called from the thread that owns the qpair - i.e. the one associated with the poll group - with only one exception where the qpair wasn't fully initialized. Add a check that enforces this condition, as it will allow some major simplifications. Change-Id: Ied434c9ea63fd4f2a6f9eacdf8f3f26a7b6bcf3f Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/424591 Reviewed-by: Seth Howell Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System --- lib/nvmf/nvmf.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index ecf4b61e8..4e133f64b 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -723,16 +723,10 @@ _spdk_nvmf_qpair_deactivate(void *ctx) int spdk_nvmf_qpair_disconnect(struct spdk_nvmf_qpair *qpair, nvmf_qpair_disconnect_cb cb_fn, void *ctx) { - struct nvmf_qpair_disconnect_ctx *qpair_ctx = calloc(1, sizeof(struct nvmf_qpair_disconnect_ctx)); - - if (!qpair_ctx) { - SPDK_ERRLOG("Unable to allocate context for nvmf_qpair_disconnect\n"); - return -ENOMEM; - } + struct nvmf_qpair_disconnect_ctx *qpair_ctx; /* If we get a qpair in the uninitialized state, we can just destroy it immediately */ if (qpair->state == SPDK_NVMF_QPAIR_UNINITIALIZED) { - free(qpair_ctx); spdk_nvmf_transport_qpair_fini(qpair); if (cb_fn) { cb_fn(ctx); @@ -740,6 +734,16 @@ spdk_nvmf_qpair_disconnect(struct spdk_nvmf_qpair *qpair, nvmf_qpair_disconnect_ return 0; } + /* The queue pair must be disconnected from the thread that owns it */ + assert(qpair->group->thread == spdk_get_thread()); + + qpair_ctx = calloc(1, sizeof(struct nvmf_qpair_disconnect_ctx)); + + if (!qpair_ctx) { + SPDK_ERRLOG("Unable to allocate context for nvmf_qpair_disconnect\n"); + return -ENOMEM; + } + qpair_ctx->qpair = qpair; qpair_ctx->cb_fn = cb_fn; qpair_ctx->thread = qpair->group->thread;