lib/vhost: fix race condition when destroying a device

`rte_vhost_driver_unregister` API for removing socket is not
asynchronous, it may call SPDK ops for adding a new connection
or removing a connection, so we can't hold the user device lock
when calling this function, and reject to add a new connection
while calling `rte_vhost_driver_unregister`.

Fix issue #2748.

Change-Id: I5594224f26374b2336d64175ecd5e5ec3d545a58
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15483
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Changpeng Liu 2022-11-17 14:40:21 +08:00 committed by Jim Harris
parent 376c25ed0c
commit 63dab84449

View File

@ -929,6 +929,11 @@ new_connection(int vid)
user_dev = to_user_dev(vdev);
pthread_mutex_lock(&user_dev->lock);
if (user_dev->registered == false) {
SPDK_ERRLOG("Device %s is unregistered\n", ctrlr_name);
pthread_mutex_unlock(&user_dev->lock);
return -1;
}
/* We expect sessions inside user_dev->vsessions to be sorted in ascending
* order in regard of vsession->id. For now we always set id = vsessions_cnt++
@ -1841,6 +1846,7 @@ vhost_user_dev_unregister(struct spdk_vhost_dev *vdev)
pthread_mutex_unlock(&user_dev->lock);
return -EBUSY;
}
user_dev->registered = false;
pthread_mutex_unlock(&user_dev->lock);
/* There are no valid connections now, and it's not an error if the domain