From 61f59ea2846afefc277ed30a690c2524554e3023 Mon Sep 17 00:00:00 2001 From: Dor Laor <dlaor@redhat.com> Date: Sun, 19 Jul 2009 12:31:58 +0300 Subject: [PATCH 2/3] Set the iothread's eventfd/pipe descriptors to non-blocking It replaces the previous fix of using select. Fixes BZs: 511199, 507659 for sure, maybe 511031 Marcelo applied it to the upstream repository. >From a2567128932437d286abc82ef8f79519f9992d74 Mon Sep 17 00:00:00 2001 From: Dor Laor <dor@redhat.com> Date: Wed, 15 Jul 2009 17:53:16 +0300 Subject: [PATCH] Set the iothread's eventfd/pipe descriptors to non-blocking. It fixes migration issue when the destination is loaded. If the migration socket is full, we get EAGAIN for the write. The set_fd_handler2 defers the write for later on. The function tries to wake up the iothread by qemu_kvm_notify_work. Since this happens in a loop, multiple times, the pipe that emulates eventfd becomes full and we get a deadlock. Mark McLoughlin suggested to remove spurious wake-up of the migration code when we get EAGAIN and wait for the socket to become writeable. (+1) Nevertheless, the pipe descriptors shouldn't be blocking and the reader can also read several chunks in a time. Signed-off-by: Dor Laor <dor@redhat.com> Message-ID: <4A62E80E.6030401@redhat.com> Obsoletes: <4A5DF084.3080305@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Bugzilla: 511199 Bugzilla: 507659 Bugzilla-related: 511031 Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Mark McLoughlin <markmc@redhat.com> Acked-by: Glauber Costa <glommer@redhat.com> --- qemu/qemu-kvm.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-) diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c index f11a289..1bc9d91 100644 --- a/qemu/qemu-kvm.c +++ b/qemu/qemu-kvm.c @@ -492,14 +492,17 @@ void qemu_kvm_notify_work(void) if (len == -1 && errno == EINTR) continue; - if (len <= 0) + /* In case we have a pipe, there is not reason to insist writing + * 8 bytes + */ + if (len == -1 && errno == EAGAIN) break; + if (len <= 0) + break; + offset += len; } - - if (offset != 8) - fprintf(stderr, "failed to notify io thread\n"); } /* If we have signalfd, we mask out the signals we want to handle and then @@ -538,20 +541,18 @@ static void sigfd_handler(void *opaque) static void io_thread_wakeup(void *opaque) { int fd = (unsigned long)opaque; - char buffer[8]; - size_t offset = 0; + char buffer[4096]; - while (offset < 8) { + /* Drain the pipe/(eventfd) */ + while (1) { ssize_t len; - len = read(fd, buffer + offset, 8 - offset); + len = read(fd, buffer, sizeof(buffer)); if (len == -1 && errno == EINTR) continue; if (len <= 0) break; - - offset += len; } } @@ -569,6 +570,9 @@ int kvm_main_loop(void) return -errno; } + fcntl(fds[0], F_SETFL, O_NONBLOCK); + fcntl(fds[1], F_SETFL, O_NONBLOCK); + qemu_set_fd_handler2(fds[0], NULL, io_thread_wakeup, NULL, (void *)(unsigned long)fds[0]); -- 1.6.3.rc4.29.g8146