Commit 3eb66ba8 authored by wanghonghui's avatar wanghonghui Committed by Changpeng Liu
Browse files

vhost: do not close a closed connfd



kill a spdk process with aio bdev storage many times will get error messages:
bdev_aio.c: 244:bdev_aio_group_poll: *ERROR*: epoll_wait error(9): Bad file descriptor on ch=0x152a7f0
vhost.c:1010:_spdk_vhost_event_send: *ERROR*: Timeout waiting for event: stop device.

When spdk process exits, the connfd is closed by rte_vhost_driver_unregister, then
other function such as epoll_create1 in aio bdev may allocate the same fd,
but this fd is closed by vhost_user_read_cb again, so epoll_wait return -1

Signed-off-by: default avatarHonghui Wang <wanghonghui@ucloud.cn>
Change-Id: Ic3fd938892f004c18fb38d4594c006c40a01efaa
Reviewed-on: https://review.gerrithub.io/c/439851


Reviewed-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 0e46c8f6
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -292,7 +292,6 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)

	ret = vhost_user_msg_handler(conn->vid, connfd);
	if (ret < 0) {
		close(connfd);
		*remove = 1;
		vhost_destroy_device(conn->vid);

@@ -301,6 +300,10 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)

		pthread_mutex_lock(&vsocket->conn_mutex);
		TAILQ_REMOVE(&vsocket->conn_list, conn, next);
		if (conn->connfd != -1) {
			close(conn->connfd);
			conn->connfd = -1;
		}
		pthread_mutex_unlock(&vsocket->conn_mutex);

		free(conn);
@@ -736,6 +739,7 @@ rte_vhost_driver_unregister(const char *path)
			pthread_mutex_lock(&vsocket->conn_mutex);
			TAILQ_FOREACH(conn, &vsocket->conn_list, next) {
				close(conn->connfd);
				conn->connfd = -1;
			}
			pthread_mutex_unlock(&vsocket->conn_mutex);