From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKWQv-0002QM-6N for qemu-devel@nongnu.org; Tue, 26 Mar 2013 12:09:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKWQp-0003AR-9i for qemu-devel@nongnu.org; Tue, 26 Mar 2013 12:09:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKWQp-0003AM-1V for qemu-devel@nongnu.org; Tue, 26 Mar 2013 12:09:03 -0400 From: Stefan Hajnoczi Date: Tue, 26 Mar 2013 17:07:48 +0100 Message-Id: <1364314072-2474-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 0/4] monitor: do not rely on O_NONBLOCK for passed file descriptors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Juan Quintela , mprivozn@redhat.com, Corey Bryant , david.pravec@nethost.cz, Stefan Hajnoczi There are several places where QEMU accidentally relies on the O_NONBLOCK state of passed file descriptors. Exposing O_NONBLOCK state makes it part of the QMP API whenever getfd or fdset_add_fd are used! Whether or not QEMU will use O_NONBLOCK is an implementation detail and should be hidden from QMP clients. This patch series addresses this in 3 steps: 1. Fix callers of monitor_handle_fd_param(), monitor_fdset_get_fd(), and monitor_get_fd() that depend on O_NONBLOCK being set. Luckily there are only two instances and they are fixed in Patches 1 & 2. 2. Rename socket_set_nonblock() to qemu_set_nonblock() just like qemu_set_cloexec(). This makes code cleaner when working with arbitrary file descriptors that may not be sockets. See Patch 3. 3. Clear O_NONBLOCK when a chardev receives file descriptors. From now on QEMU can assume that passed file descriptors are in blocking mode. Simply use qemu_set_nonblock(fd) if you want to enable O_NONBLOCK. See Patch 4. This fixes live migration with recent libvirt. Libvirt checks if QEMU supports file descriptor passing and, if yes, hands QEMU a socket with O_NONBLOCK set. The migrate fd: code assumes the socket is in blocking mode. The result is a corrupted migration stream. For more info on this bug, see: https://bugzilla.redhat.com/show_bug.cgi?id=923124 Note that Michal Privoznik also sent a libvirt patch so that old QEMUs work with new libvirts: https://www.redhat.com/archives/libvir-list/2013-March/msg01486.html My patch series fixes the QMP API and allows old libvirts to work again with new QEMUs. Stefan Hajnoczi (4): net: ensure "socket" backend uses non-blocking fds qemu-socket: set passed fd non-blocking in socket_connect() oslib-posix: rename socket_set_nonblock() to qemu_set_nonblock() chardev: clear O_NONBLOCK on SCM_RIGHTS file descriptors block/nbd.c | 2 +- block/sheepdog.c | 2 +- include/qemu/sockets.h | 4 ++-- migration.c | 2 +- nbd.c | 8 ++++---- net/socket.c | 8 +++++--- qemu-char.c | 11 +++++++---- savevm.c | 2 +- slirp/misc.c | 2 +- slirp/tcp_subr.c | 4 ++-- ui/vnc.c | 2 +- util/oslib-posix.c | 4 ++-- util/oslib-win32.c | 4 ++-- util/qemu-sockets.c | 5 +++-- 14 files changed, 33 insertions(+), 27 deletions(-) -- 1.8.1.4