From patchwork Wed Sep 25 14:32:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 277882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B210D2C0246 for ; Thu, 26 Sep 2013 00:33:55 +1000 (EST) Received: from localhost ([::1]:53034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOqA5-0003I3-Fl for incoming@patchwork.ozlabs.org; Wed, 25 Sep 2013 10:33:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOq9R-000376-9Y for qemu-devel@nongnu.org; Wed, 25 Sep 2013 10:33:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOq9I-0006IL-AZ for qemu-devel@nongnu.org; Wed, 25 Sep 2013 10:33:13 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:41504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOq9H-0006I4-NY for qemu-devel@nongnu.org; Wed, 25 Sep 2013 10:33:04 -0400 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 25 Sep 2013 20:02:58 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 25 Sep 2013 20:02:57 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 080CEE0056 for ; Wed, 25 Sep 2013 20:04:02 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r8PEZDc035782758 for ; Wed, 25 Sep 2013 20:05:13 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r8PEWuw4003254 for ; Wed, 25 Sep 2013 20:02:56 +0530 Received: from localhost.localdomain.com ([9.77.178.88]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r8PEWo4d003070; Wed, 25 Sep 2013 20:02:54 +0530 From: Lei Li To: qemu-devel@nongnu.org Date: Wed, 25 Sep 2013 22:32:41 +0800 Message-Id: <1380119568-5530-2-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1380119568-5530-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1380119568-5530-1-git-send-email-lilei@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13092514-8256-0000-0000-00000960854E X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.5 Cc: aarcange@redhat.com, Lei Li , quintela@redhat.com, mdroth@linux.vnet.ibm.com, mrhines@linux.vnet.ibm.com, anthony@codemonkey.ws, lagarcia@br.ibm.com, pbonzini@redhat.com, rcj@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 1/8] migration-local: add pipe protocol for QEMUFileOps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds QEMUFileOps with pipe protocol, will be used to transmit RAM for localhost migration. The source process would put buffer, correspondingly the destination process would get buffer. The read side of the pipe file descriptor would be passed to destination process via SCM_RIGHTS. Signed-off-by: Lei Li --- Makefile.target | 1 + migration-local.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 migration-local.c diff --git a/Makefile.target b/Makefile.target index 9a49852..ae66fef 100644 --- a/Makefile.target +++ b/Makefile.target @@ -121,6 +121,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..1fb62b6 --- /dev/null +++ b/migration-local.c @@ -0,0 +1,114 @@ +/* + * QEMU localhost live migration + * + * 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 "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 QEMUFilePipe { + QEMUFile *file; + int pipefd; +} QEMUFilePipe; + + +static int qemu_local_get_fd(void *opaque) +{ + QEMUFilePipe *s = opaque; + + return s->pipefd; +} + +static int qemu_local_get_buffer(void *opaque, uint8_t *buf, + int64_t pos, int size) +{ + QEMUFilePipe *s = opaque; + ssize_t len; + + for (;;) { + errno = 0; + + len = read(s->pipefd, buf, size); + if (len != -1) { + break; + } + + if (errno == EAGAIN) { + yield_until_fd_readable(s->pipefd); + } else if (errno != EINTR) { + break; + } + } + + return len; +} + +static int qemu_local_put_buffer(void *opaque, const uint8_t *buf, + int64_t pos, int size) +{ + QEMUFilePipe *s = opaque; + ssize_t len; + + len = write(s->pipefd, buf, size); + if (len < size) { + len = -1; + } + + return len; +} + +static int qemu_local_close(void *opaque) +{ + QEMUFilePipe *s = opaque; + + close(s->pipefd); + g_free(s); + + return 0; +} + +static const QEMUFileOps pipe_read_ops = { + .get_fd = qemu_local_get_fd, + .get_buffer = qemu_local_get_buffer, + .close = qemu_local_close +}; + +static const QEMUFileOps pipe_write_ops = { + .put_buffer = qemu_local_put_buffer, + //.save_page = qemu_local_save_ram, + .close = qemu_local_close +};