From patchwork Mon Dec 2 09:19:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 295838 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 8DC932C0097 for ; Mon, 2 Dec 2013 20:22:46 +1100 (EST) Received: from localhost ([::1]:34606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnPiF-0002Dq-LS for incoming@patchwork.ozlabs.org; Mon, 02 Dec 2013 04:22:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnPfX-0006sA-U6 for qemu-devel@nongnu.org; Mon, 02 Dec 2013 04:20:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VnPfO-0002Uo-V1 for qemu-devel@nongnu.org; Mon, 02 Dec 2013 04:19:55 -0500 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:35358) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnPfO-0002UV-Cz for qemu-devel@nongnu.org; Mon, 02 Dec 2013 04:19:46 -0500 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Dec 2013 14:49:44 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp09.in.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 2 Dec 2013 14:49:43 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id DD475125805A for ; Mon, 2 Dec 2013 14:50:44 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rB29JdOZ46071840 for ; Mon, 2 Dec 2013 14:49:39 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rB29Jfoa001223 for ; Mon, 2 Dec 2013 14:49:41 +0530 Received: from localhost.localdomain.cn.ibm.com ([9.115.122.11]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rB29JI4s032476; Mon, 2 Dec 2013 14:49:39 +0530 From: Lei Li To: qemu-devel@nongnu.org Date: Mon, 2 Dec 2013 17:19:08 +0800 Message-Id: <1385975957-22941-9-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1385975957-22941-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1385975957-22941-1-git-send-email-lilei@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13120209-2674-0000-0000-00000BB9B54D X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.9 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..9453ec8 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 move pages rather than + * copying, previously unused. + * + * If a move is not possible the kernel will transparently fall + * 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 = size; + } + 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)