From: Sasha Levin Subject: [PATCH 1/2] kvm tools: Handle only relevant events in epoll Date: Fri, 28 Oct 2011 11:01:54 +0200 Message-ID: <1319792515-15642-1-git-send-email-levinsasha928@gmail.com> Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, Sasha Levin , Osier Yang To: penberg@cs.helsinki.fi Return-path: Received: from mail-fx0-f46.google.com ([209.85.161.46]:36605 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751115Ab1J1JCJ (ORCPT ); Fri, 28 Oct 2011 05:02:09 -0400 Received: by faan17 with SMTP id n17so3434950faa.19 for ; Fri, 28 Oct 2011 02:02:07 -0700 (PDT) Sender: kvm-owner@vger.kernel.org List-ID: Handle only new incoming data for listener and stop fds, treat all other events as error events which close the socket. This fixes the bug where a 'kvm list' could have hanged because a close event in the listener fd have been treated as a new connection. Cc: Osier Yang Signed-off-by: Sasha Levin --- tools/kvm/kvm-ipc.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c index 3131fe8..40ab457 100644 --- a/tools/kvm/kvm-ipc.c +++ b/tools/kvm/kvm-ipc.c @@ -112,7 +112,7 @@ static void *kvm_ipc__thread(void *param) if (nfds > 0) { int fd = event.data.fd; - if (fd == stop_fd) { + if (fd == stop_fd && event.events & EPOLLIN) { break; } else if (fd == server_fd) { int client; @@ -138,13 +138,13 @@ int kvm_ipc__start(int sock) epoll_fd = epoll_create(KVM_IPC_MAX_MSGS); - ev.events = EPOLLIN | EPOLLOUT | EPOLLPRI; + ev.events = EPOLLIN | EPOLLET; ev.data.fd = sock; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) < 0) die("Failed starting IPC thread"); stop_fd = eventfd(0, 0); - ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET; + ev.events = EPOLLIN | EPOLLET; ev.data.fd = stop_fd; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_fd, &ev) < 0) die("Failed adding stop event to epoll"); -- 1.7.7.1