From patchwork Fri Nov 29 10:06:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 295207 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 1512F2C00A7 for ; Fri, 29 Nov 2013 21:12:39 +1100 (EST) Received: from localhost ([::1]:46438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmL3s-0006QP-GN for incoming@patchwork.ozlabs.org; Fri, 29 Nov 2013 05:12:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmKyY-0007qy-3b for qemu-devel@nongnu.org; Fri, 29 Nov 2013 05:07:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VmKyP-0007wr-6S for qemu-devel@nongnu.org; Fri, 29 Nov 2013 05:07:06 -0500 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:53489) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmKyO-0007wY-Dk for qemu-devel@nongnu.org; Fri, 29 Nov 2013 05:06:57 -0500 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 29 Nov 2013 20:06:54 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 29 Nov 2013 20:06:53 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id CC97E2BB0052 for ; Fri, 29 Nov 2013 21:06:52 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rATA6e6Q65994962 for ; Fri, 29 Nov 2013 21:06:40 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rATA6qKl012450 for ; Fri, 29 Nov 2013 21:06:52 +1100 Received: from localhost.cn.ibm.com ([9.115.122.11]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rATA6P14011813; Fri, 29 Nov 2013 21:06:50 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Fri, 29 Nov 2013 18:06:15 +0800 Message-Id: <1385719584-21114-9-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1385719584-21114-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1385719584-21114-1-git-send-email-lilei@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13112910-9264-0000-0000-00000505CD63 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.146 Cc: aarcange@redhat.com, Lei Li , quintela@redhat.com, mrhines@linux.vnet.ibm.com, aliguori@amazon.com, lagarcia@br.ibm.com, pbonzini@redhat.com, rcj@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 08/17] migration-local: override save_page for page transmit 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 implements save_page callback for the outside of page flipping. It will write the address of the page on the Unix socket and flip the page data on pipe by vmsplice(). Every page address would have a header flag RAM_SAVE_FLAG_HOOK, which will trigger the load hook to receive it in incoming side as well. Signed-off-by: Lei Li --- migration-local.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) diff --git a/migration-local.c b/migration-local.c index f479530..0a41c69 100644 --- a/migration-local.c +++ b/migration-local.c @@ -116,6 +116,68 @@ static int qemu_local_close(void *opaque) return 0; } +static int send_pipefd(int sockfd, int pipefd); + +static size_t qemu_local_save_ram(QEMUFile *f, void *opaque, + MemoryRegion *mr, ram_addr_t offset, + size_t size, int *bytes_sent) +{ + QEMUFileLocal *s = opaque; + ram_addr_t current_addr = mr->ram_addr + offset; + void *ram_addr; + ssize_t ret; + + if (s->unix_page_flipping) { + qemu_put_be64(s->file, current_addr | RAM_SAVE_FLAG_HOOK); + qemu_fflush(s->file); + + if (!s->pipefd_passed) { + ret = send_pipefd(s->sockfd, s->pipefd[0]); + if (ret < 0) { + fprintf(stderr, "failed to pass PIPE\n"); + return ret; + } + s->pipefd_passed = true; + } + + ram_addr = memory_region_get_ram_ptr(mr) + offset; + + /* vmsplice page data to pipe */ + struct iovec iov = { + .iov_base = ram_addr, + .iov_len = size, + }; + + /* + * The flag SPLICE_F_MOVE is introduced in kernel for the page + * flipping feature in QEMU, which will movie pages rather than + * copying, previously unused. + * + * If a move is not possible the kernel will transparently falls + * back to copying data. + * + * For older kernels the SPLICE_F_MOVE would be ignored and a copy + * would occur. + */ + + ret = vmsplice(s->pipefd[1], &iov, 1, SPLICE_F_GIFT | SPLICE_F_MOVE); + if (ret == -1) { + if (errno != EAGAIN && errno != EINTR) { + fprintf(stderr, "vmsplice save error: %s\n", strerror(errno)); + return ret; + } + } else { + if (bytes_sent) { + *bytes_sent = 1; + } + DPRINTF("block_offset: %lu, offset: %lu\n", mr->ram_addr, offset); + return 0; + } + } + + return RAM_SAVE_CONTROL_NOT_SUPP; +} + static const QEMUFileOps pipe_read_ops = { .get_fd = qemu_local_get_sockfd, .get_buffer = qemu_local_get_buffer, @@ -126,6 +188,7 @@ static const QEMUFileOps pipe_write_ops = { .get_fd = qemu_local_get_sockfd, .writev_buffer = qemu_local_writev_buffer, .close = qemu_local_close, + .save_page = qemu_local_save_ram }; QEMUFile *qemu_fopen_socket_local(int sockfd, const char *mode)