From 3eb66ba88edd1ad59df9c4bb2f3b031e55152303 Mon Sep 17 00:00:00 2001 From: wanghonghui Date: Thu, 10 Jan 2019 16:53:51 +0800 Subject: [PATCH] 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: Honghui Wang Change-Id: Ic3fd938892f004c18fb38d4594c006c40a01efaa Reviewed-on: https://review.gerrithub.io/c/439851 Reviewed-by: GangCao Reviewed-by: Darek Stojaczyk Reviewed-by: Pawel Wodkowski Reviewed-by: Changpeng Liu Chandler-Test-Pool: SPDK Automated Test System Tested-by: Changpeng Liu --- lib/vhost/rte_vhost/socket.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/vhost/rte_vhost/socket.c b/lib/vhost/rte_vhost/socket.c index 08a17279a..5d6959c65 100644 --- a/lib/vhost/rte_vhost/socket.c +++ b/lib/vhost/rte_vhost/socket.c @@ -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);