Commit 63dab844 authored by Changpeng Liu's avatar Changpeng Liu Committed by Jim Harris
Browse files

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 376c25ed
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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