From 684410026b54f7209dedbcb8afb1f63513f556f8 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 27 Apr 2021 21:22:16 +0800 Subject: [PATCH] nvmf/vfio-user: free controller if no connected qpair The VM may already delete all queue pairs and just leave the socket when killing VM, so we can check number of connected queue pairs here, if no connected queue pairs, free the controller immediately. It's an optimization so that we don't need to loop all queue pairs below. Change-Id: Ia1be868ce2c74ce6953b1f44a81b51d605e642f0 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7625 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Reviewed-by: Jim Harris Reviewed-by: Ben Walker Community-CI: Broadcom CI Community-CI: Mellanox Build Bot --- lib/nvmf/vfio_user.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index 368614fab..1e525dad0 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -2203,6 +2203,14 @@ vfio_user_destroy_ctrlr(struct nvmf_vfio_user_ctrlr *ctrlr) endpoint = ctrlr->endpoint; assert(endpoint != NULL); + pthread_mutex_lock(&endpoint->lock); + if (ctrlr->num_connected_qps == 0) { + free_ctrlr(ctrlr); + pthread_mutex_unlock(&endpoint->lock); + return 0; + } + pthread_mutex_unlock(&endpoint->lock); + for (i = 0; i < NVMF_VFIO_USER_DEFAULT_MAX_QPAIRS_PER_CTRLR; i++) { qpair = ctrlr->qp[i]; if (qpair == NULL) {