Skip to content

Commit

Permalink
vhost: do not close a closed connfd
Browse files Browse the repository at this point in the history
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 <wanghonghui@ucloud.cn>
Change-Id: Ic3fd938892f004c18fb38d4594c006c40a01efaa
Reviewed-on: https://review.gerrithub.io/c/439851
Reviewed-by: GangCao <gang.cao@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: Changpeng Liu <changpeng.liu@intel.com>
  • Loading branch information
wanghonghui authored and changpe1 committed Jan 16, 2019
1 parent 0e46c8f commit 3eb66ba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/vhost/rte_vhost/socket.c
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3eb66ba

Please sign in to comment.