Commit 9bcafecb authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

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: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7966


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatar <dongx.yi@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
parent 68441002
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -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;
	}