From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYSbm-0005D1-4n for qemu-devel@nongnu.org; Mon, 21 Oct 2013 23:26:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VYSbb-0004Wi-Qb for qemu-devel@nongnu.org; Mon, 21 Oct 2013 23:26:14 -0400 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:42872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYSbb-0004WU-6F for qemu-devel@nongnu.org; Mon, 21 Oct 2013 23:26:03 -0400 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 22 Oct 2013 08:56:00 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 58405125803F for ; Tue, 22 Oct 2013 08:56:31 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r9M3Srrl24510554 for ; Tue, 22 Oct 2013 08:58:53 +0530 Received: from d28av04.in.ibm.com (localhost [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r9M3PwTi022966 for ; Tue, 22 Oct 2013 08:55:58 +0530 From: Lei Li Date: Tue, 22 Oct 2013 11:25:29 +0800 Message-Id: <1382412341-1173-6-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1382412341-1173-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1382412341-1173-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 05/17] migration-local: add QEMUFileLocal with socket based QEMUFile List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aarcange@redhat.com, aliguori@us.ibm.com, Lei Li , quintela@redhat.com, mdroth@linux.vnet.ibm.com, mrhines@linux.vnet.ibm.com, lagarcia@br.ibm.com, pbonzini@redhat.com, rcj@linux.vnet.ibm.com This patch adds QEMUFileLocal with copy of socket based QEMUFile, will be used as the basis code for Unix socket protocol migration and page flipping migration. Signed-off-by: Lei Li --- Makefile.target | 1 + migration-local.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 0 deletions(-) create mode 100644 migration-local.c diff --git a/Makefile.target b/Makefile.target index af6ac7e..aa09960 100644 --- a/Makefile.target +++ b/Makefile.target @@ -117,6 +117,7 @@ obj-$(CONFIG_KVM) += kvm-all.o obj-y += memory.o savevm.o cputlb.o obj-y += memory_mapping.o obj-y += dump.o +obj-y += migration-local.o LIBS+=$(libs_softmmu) # xen support diff --git a/migration-local.c b/migration-local.c new file mode 100644 index 0000000..8b9e10e --- /dev/null +++ b/migration-local.c @@ -0,0 +1,121 @@ +/* + * QEMU localhost migration with page flipping + * + * Copyright IBM, Corp. 2013 + * + * Authors: + * Lei Li + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#include "config-host.h" +#include "qemu-common.h" +#include "migration/migration.h" +#include "exec/cpu-common.h" +#include "config.h" +#include "exec/cpu-all.h" +#include "exec/memory.h" +#include "exec/memory-internal.h" +#include "monitor/monitor.h" +#include "migration/qemu-file.h" +#include "qemu/iov.h" +#include "sysemu/arch_init.h" +#include "sysemu/sysemu.h" +#include "block/block.h" +#include "qemu/sockets.h" +#include "migration/block.h" +#include "qemu/thread.h" +#include "qmp-commands.h" +#include "trace.h" +#include "qemu/osdep.h" + +//#define DEBUG_MIGRATION_LOCAL + +#ifdef DEBUG_MIGRATION_LOCAL +#define DPRINTF(fmt, ...) \ + do { printf("migration-local: " fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF(fmt, ...) \ + do { } while (0) +#endif + + +typedef struct QEMUFileLocal { + QEMUFile *file; + int sockfd; + int pipefd[2]; + bool unix_page_flipping; +} QEMUFileLocal; + +static int qemu_local_get_sockfd(void *opaque) +{ + QEMUFileLocal *s = opaque; + + return s->sockfd; +} + +static int qemu_local_get_buffer(void *opaque, uint8_t *buf, + int64_t pos, int size) +{ + QEMUFileLocal *s = opaque; + ssize_t len; + + for (;;) { + len = qemu_recv(s->sockfd, buf, size, 0); + if (len != -1) { + break; + } + + if (socket_error() == EAGAIN) { + yield_until_fd_readable(s->sockfd); + } else if (socket_error() != EINTR) { + break; + } + } + + if (len == -1) { + len = -socket_error(); + } + + return len; +} + +static ssize_t qemu_local_writev_buffer(void *opaque, struct iovec *iov, + int iovcnt, int64_t pos) +{ + QEMUFileLocal *s = opaque; + ssize_t len; + ssize_t size = iov_size(iov, iovcnt); + + len = iov_send(s->sockfd, iov, iovcnt, 0, size); + if (len < size) { + len = -socket_error(); + } + + return len; +} + +static int qemu_local_close(void *opaque) +{ + QEMUFileLocal *s = opaque; + + closesocket(s->sockfd); + g_free(s); + + return 0; +} + +static const QEMUFileOps pipe_read_ops = { + .get_fd = qemu_local_get_sockfd, + .get_buffer = qemu_local_get_buffer, + .close = qemu_local_close, +}; + +static const QEMUFileOps pipe_write_ops = { + .get_fd = qemu_local_get_sockfd, + .writev_buffer = qemu_local_writev_buffer, + .close = qemu_local_close, +}; -- 1.7.7.6