nvmf/vfio-user: set endpoint's controller pointer to NULL

We can set endpoint's controller pointer to NULL before free_ctrlr, as
controller is a session in vfio-user, while endpoint is related with
Unix Domain socket.

Change-Id: If6d26c7522804029f8c2425bc478df9e2d53d32a
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7966
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Changpeng Liu 2021-05-13 18:18:49 +08:00 committed by Tomasz Zawadzki
parent 684410026b
commit 9bcafecb01

View File

@ -1862,15 +1862,11 @@ _free_ctrlr(void *ctx)
free_qp(ctrlr, i);
}
if (ctrlr->endpoint) {
ctrlr->endpoint->ctrlr = NULL;
}
spdk_poller_unregister(&ctrlr->mmio_poller);
free(ctrlr);
}
static int
static void
free_ctrlr(struct nvmf_vfio_user_ctrlr *ctrlr)
{
assert(ctrlr != NULL);
@ -1882,8 +1878,6 @@ free_ctrlr(struct nvmf_vfio_user_ctrlr *ctrlr)
} else {
spdk_thread_send_msg(ctrlr->thread, _free_ctrlr, ctrlr);
}
return 0;
}
static void
@ -1918,10 +1912,7 @@ out:
if (err != 0) {
SPDK_ERRLOG("%s: failed to create vfio-user controller: %s\n",
endpoint_id(endpoint), strerror(-err));
if (free_ctrlr(ctrlr) != 0) {
SPDK_ERRLOG("%s: failed to clean up\n",
endpoint_id(endpoint));
}
free_ctrlr(ctrlr);
}
}
@ -2019,7 +2010,6 @@ nvmf_vfio_user_stop_listen(struct spdk_nvmf_transport *transport,
{
struct nvmf_vfio_user_transport *vu_transport;
struct nvmf_vfio_user_endpoint *endpoint, *tmp;
int err;
assert(trid != NULL);
assert(trid->traddr != NULL);
@ -2034,11 +2024,7 @@ nvmf_vfio_user_stop_listen(struct spdk_nvmf_transport *transport,
if (strcmp(trid->traddr, endpoint->trid.traddr) == 0) {
TAILQ_REMOVE(&vu_transport->endpoints, endpoint, link);
if (endpoint->ctrlr) {
err = free_ctrlr(endpoint->ctrlr);
if (err != 0) {
SPDK_ERRLOG("%s: failed destroy controller: %s\n",
endpoint_id(endpoint), strerror(-err));
}
free_ctrlr(endpoint->ctrlr);
}
nvmf_vfio_user_destroy_endpoint(endpoint);
pthread_mutex_unlock(&vu_transport->lock);
@ -2184,6 +2170,7 @@ vfio_user_qpair_disconnect_cb(void *ctx)
}
if (!ctrlr->num_connected_qps) {
endpoint->ctrlr = NULL;
free_ctrlr(ctrlr);
pthread_mutex_unlock(&endpoint->lock);
return;
@ -2205,6 +2192,7 @@ vfio_user_destroy_ctrlr(struct nvmf_vfio_user_ctrlr *ctrlr)
pthread_mutex_lock(&endpoint->lock);
if (ctrlr->num_connected_qps == 0) {
endpoint->ctrlr = NULL;
free_ctrlr(ctrlr);
pthread_mutex_unlock(&endpoint->lock);
return 0;
@ -2266,6 +2254,7 @@ handle_queue_connect_rsp(struct nvmf_vfio_user_req *req, void *cb_arg)
if (spdk_nvme_cpl_is_error(&req->req.rsp->nvme_cpl)) {
SPDK_ERRLOG("SC %u, SCT %u\n", req->req.rsp->nvme_cpl.status.sc, req->req.rsp->nvme_cpl.status.sct);
endpoint->ctrlr = NULL;
free_ctrlr(ctrlr);
return -1;
}