[PATCH] vhost: only emit debug log with invalid FD

Maxime Coquelin maxime.coquelin at redhat.com
Mon Jun 24 16:46:13 CEST 2024


This patch improves the FD manager logging in case
of FD removal from the epoll FD set failure.

When the FD is not more valid, like for example if it
has already been closed, only emit a debug log and not
an error one.

Fixes: 0e38b42bf61c ("vhost: manage FD with epoll")

Reported-by: David Marchand <david.marchand at redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
---
 lib/vhost/fd_man.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c
index 87a8dc3f3e..9bc7e50b93 100644
--- a/lib/vhost/fd_man.c
+++ b/lib/vhost/fd_man.c
@@ -256,9 +256,14 @@ fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat)
 static void
 fdset_del_locked(struct fdset *pfdset, struct fdentry *pfdentry)
 {
-	if (epoll_ctl(pfdset->epfd, EPOLL_CTL_DEL, pfdentry->fd, NULL) == -1)
-		VHOST_FDMAN_LOG(ERR, "could not remove %d fd from %d epfd: %s",
-			pfdentry->fd, pfdset->epfd, strerror(errno));
+	if (epoll_ctl(pfdset->epfd, EPOLL_CTL_DEL, pfdentry->fd, NULL) == -1) {
+		if (errno == EBADF) /* File might have already been closed. */
+			VHOST_FDMAN_LOG(DEBUG, "could not remove %d fd from %d epfd: %s",
+				pfdentry->fd, pfdset->epfd, strerror(errno));
+		else
+			VHOST_FDMAN_LOG(ERR, "could not remove %d fd from %d epfd: %s",
+				pfdentry->fd, pfdset->epfd, strerror(errno));
+	}
 
 	fdset_remove_entry(pfdset, pfdentry);
 }
-- 
2.45.1



More information about the dev mailing list