From patchwork Wed Jul 15 15:03:15 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dor Laor X-Patchwork-Id: 35706 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6FF2rE8025750 for ; Wed, 15 Jul 2009 15:02:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755228AbZGOPCv (ORCPT ); Wed, 15 Jul 2009 11:02:51 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755202AbZGOPCu (ORCPT ); Wed, 15 Jul 2009 11:02:50 -0400 Received: from mx2.redhat.com ([66.187.237.31]:54289 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755191AbZGOPCu (ORCPT ); Wed, 15 Jul 2009 11:02:50 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6FF2os2012344 for ; Wed, 15 Jul 2009 11:02:50 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n6FF2nI7024696 for ; Wed, 15 Jul 2009 11:02:49 -0400 Received: from localhost.localdomain (dhcp-0-217.tlv.redhat.com [10.35.0.217]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n6FF2mec030370 for ; Wed, 15 Jul 2009 11:02:48 -0400 Message-ID: <4A5DEFB3.4060702@redhat.com> Date: Wed, 15 Jul 2009 18:03:15 +0300 From: Dor Laor Reply-To: dlaor@redhat.com User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2 MIME-Version: 1.0 To: kvm-devel Subject: Fix migration issue when the destination is loaded X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From abbe3b57af6a28bb81e5fb8b09b10802a8ccc3fe Mon Sep 17 00:00:00 2001 From: Dor Laor Date: Wed, 15 Jul 2009 17:53:16 +0300 Subject: [PATCH] Fix 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. It is solved by checking for write-readiness using select. Note that I check for select only for full 8 byte write and not for partial writes. This is because we'll break the reader otherwise. Signed-off-by: Dor Laor --- qemu-kvm.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index ed7e466..0ea67a7 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -2094,12 +2094,28 @@ void qemu_kvm_notify_work(void) uint64_t value = 1; char buffer[8]; size_t offset = 0; + fd_set wfds; + struct timeval tv; + int retval; if (io_thread_fd == -1) return; memcpy(buffer, &value, sizeof(value)); + FD_ZERO(&wfds); + FD_SET(io_thread_fd, &wfds); + tv.tv_sec = tv.tv_usec = 0; + retval = select(io_thread_fd + 1, NULL, &wfds, NULL, &tv); + if (retval == -1) { + fprintf(stderr, "failed to notify io thread due to select error\n"); + return; + } else if (retval == 0) + /* We probably ponded this pipe too much and it is full now */ + return; + + assert(FD_ISSET(io_thread_fd, &wfds)); + while (offset < 8) { ssize_t len;