From patchwork Thu Jul 21 05:06:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9240949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 20272607D3 for ; Thu, 21 Jul 2016 05:07:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0035527BF7 for ; Thu, 21 Jul 2016 05:07:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0DD227CF9; Thu, 21 Jul 2016 05:07:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 259F627BF7 for ; Thu, 21 Jul 2016 05:07:38 +0000 (UTC) Received: from localhost ([::1]:38272 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ6Cu-0004Et-8e for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jul 2016 01:07:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ6CV-0004Ea-Gy for qemu-devel@nongnu.org; Thu, 21 Jul 2016 01:07:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQ6CS-00015n-9m for qemu-devel@nongnu.org; Thu, 21 Jul 2016 01:07:11 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:6319) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ6CR-00011Y-LW for qemu-devel@nongnu.org; Thu, 21 Jul 2016 01:07:08 -0400 Received: from 172.24.1.36 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.36]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CFC92658; Thu, 21 Jul 2016 13:06:42 +0800 (CST) Received: from localhost (10.177.24.212) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Thu, 21 Jul 2016 13:06:35 +0800 From: zhanghailiang To: Date: Thu, 21 Jul 2016 13:06:00 +0800 Message-ID: <1469077560-20620-3-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1469077560-20620-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1469077560-20620-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.5790586C.0075, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 8a448ebf2752bd594efdba7cdeb18434 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Subject: [Qemu-devel] [RFC PATCH 2/2] migration: Allow -incoming to work on file: urls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benoit Canet , zhanghailiang , quintela@redhat.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, amit.shah@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Usage: -incoming file:/path/to/vm_statefile Besides, use qemu_strtol() instead of strtol(). Signed-off-by: zhanghailiang Signed-off-by: Benoit Canet Reviewed-by: Dr. David Alan Gilbert --- include/migration/migration.h | 2 ++ migration/fd.c | 37 +++++++++++++++++++++++++++++++------ migration/migration.c | 2 ++ migration/trace-events | 1 + 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index cc2e4f6..a7f1051 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -223,6 +223,8 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error ** void file_start_outgoing_migration(MigrationState *s, const char *filename, Error **errp); +void file_start_incoming_migration(const char *filename, Error **errp); + void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp); void rdma_start_incoming_migration(const char *host_port, Error **errp); diff --git a/migration/fd.c b/migration/fd.c index fa5df67..472876c 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -21,7 +21,7 @@ #include "monitor/monitor.h" #include "io/channel-util.h" #include "trace.h" - +#include "qemu/cutils.h" static void fd_start_outgoing_migration_core(MigrationState *s, int fd, Error **errp) @@ -73,13 +73,9 @@ static gboolean fd_accept_incoming_migration(QIOChannel *ioc, return FALSE; /* unregister */ } -void fd_start_incoming_migration(const char *infd, Error **errp) +static void fd_start_incoming_migration_core(int fd, Error **errp) { QIOChannel *ioc; - int fd; - - fd = strtol(infd, NULL, 0); - trace_migration_fd_incoming(fd); ioc = qio_channel_new_fd(fd, errp); if (!ioc) { @@ -93,3 +89,32 @@ void fd_start_incoming_migration(const char *infd, Error **errp) NULL, NULL); } + +void fd_start_incoming_migration(const char *infd, Error **errp) +{ + long fd; + int err; + + err = qemu_strtol(infd, NULL, 0, &fd); + if (err < 0) { + error_setg_errno(errp, -err, "Failed to convert string '%s'" + " to number", infd); + return; + } + + trace_migration_fd_incoming((int)fd); + fd_start_incoming_migration_core((int)fd, errp); +} + +void file_start_incoming_migration(const char *filename, Error **errp) +{ + int fd; + + fd = qemu_open(filename, O_RDONLY); + if (fd < 0) { + error_setg_errno(errp, errno, "Failed to open file:%s", filename); + return; + } + trace_migration_file_incoming(filename); + fd_start_incoming_migration_core(fd, errp); +} diff --git a/migration/migration.c b/migration/migration.c index 097adba..5ed3fea 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -315,6 +315,8 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) unix_start_incoming_migration(p, errp); } else if (strstart(uri, "fd:", &p)) { fd_start_incoming_migration(p, errp); + } else if (strstart(uri, "file:", &p)) { + file_start_incoming_migration(p, errp); } else { error_setg(errp, "unknown migration protocol: %s", uri); } diff --git a/migration/trace-events b/migration/trace-events index 4fca64c..8a76595 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -195,6 +195,7 @@ migration_exec_incoming(const char *cmd) "cmd=%s" migration_fd_outgoing(int fd) "fd=%d" migration_fd_incoming(int fd) "fd=%d" migration_file_outgoing(const char *filename) "file=%s" +migration_file_incoming(const char *filename) "file=%s" # migration/socket.c migration_socket_incoming_accepted(void) ""