From patchwork Thu Oct 6 02:54:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 9363621 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 2C9B3600C8 for ; Thu, 6 Oct 2016 02:57:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E6FD28DAF for ; Thu, 6 Oct 2016 02:57:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 132D028DB2; Thu, 6 Oct 2016 02:57:04 +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 0902528DAF for ; Thu, 6 Oct 2016 02:57:02 +0000 (UTC) Received: from localhost ([::1]:52615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bryrl-0006Qx-UE for patchwork-qemu-devel@patchwork.kernel.org; Wed, 05 Oct 2016 22:57:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bryrL-0006Qg-Mu for qemu-devel@nongnu.org; Wed, 05 Oct 2016 22:56:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bryrI-0000L3-H6 for qemu-devel@nongnu.org; Wed, 05 Oct 2016 22:56:35 -0400 Received: from [59.151.112.132] (port=19055 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bryrH-0000Ka-QL for qemu-devel@nongnu.org; Wed, 05 Oct 2016 22:56:32 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="11673065" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 06 Oct 2016 10:56:31 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id DC5AE4623498; Thu, 6 Oct 2016 10:56:28 +0800 (CST) Received: from G08FNSTD140138.localdomain (10.167.226.45) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Thu, 6 Oct 2016 10:56:28 +0800 From: Li Zhijian To: , , Date: Thu, 6 Oct 2016 10:54:19 +0800 Message-ID: <1475722460-22185-1-git-send-email-lizhijian@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.45] X-yoursite-MailScanner-ID: DC5AE4623498.AF32E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lizhijian@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH 1/2] migration: add qemu_loadvm_section_header() helper 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: Li Zhijian Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP no fuctional changes Signed-off-by: Li Zhijian --- migration/savevm.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 33a2911..c36a675 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1729,48 +1729,65 @@ void loadvm_free_handlers(MigrationIncomingState *mis) } } + static int -qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) +qemu_loadvm_section_header(QEMUFile *f, MigrationIncomingState *mis, + SaveStateEntry **se, + uint32_t *version_id, uint32_t *section_id) { - uint32_t instance_id, version_id, section_id; - SaveStateEntry *se; - LoadStateEntry *le; + uint32_t instance_id; char idstr[256]; - int ret; /* Read section start */ - section_id = qemu_get_be32(f); + *section_id = qemu_get_be32(f); if (!qemu_get_counted_string(f, idstr)) { error_report("Unable to read ID string for section %u", - section_id); + *section_id); return -EINVAL; } instance_id = qemu_get_be32(f); - version_id = qemu_get_be32(f); + *version_id = qemu_get_be32(f); - trace_qemu_loadvm_state_section_startfull(section_id, idstr, - instance_id, version_id); + trace_qemu_loadvm_state_section_startfull(*section_id, idstr, + instance_id, *version_id); /* Find savevm section */ - se = find_se(idstr, instance_id); - if (se == NULL) { + *se = find_se(idstr, instance_id); + if (*se == NULL) { error_report("Unknown savevm section or instance '%s' %d", idstr, instance_id); return -EINVAL; } /* Validate version */ - if (version_id > se->version_id) { + if (*version_id > (*se)->version_id) { error_report("savevm: unsupported version %d for '%s' v%d", - version_id, idstr, se->version_id); + *version_id, idstr, (*se)->version_id); return -EINVAL; } /* Validate if it is a device's state */ - if (xen_enabled() && se->is_ram) { + if (xen_enabled() && (*se)->is_ram) { error_report("loadvm: %s RAM loading not allowed on Xen", idstr); return -EINVAL; } + return 0; +} + +static int +qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) +{ + uint32_t version_id, section_id; + SaveStateEntry *se; + LoadStateEntry *le; + char idstr[256]; + int ret; + + ret = qemu_loadvm_section_header(f, mis, &se, &version_id, §ion_id); + if (ret) { + return ret; + } + /* Add entry */ le = g_malloc0(sizeof(*le)); @@ -1781,8 +1798,8 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) ret = vmstate_load(f, le->se, le->version_id); if (ret < 0) { - error_report("error while loading state for instance 0x%x of" - " device '%s'", instance_id, idstr); + error_report("error while loading state for" + " device '%s'", idstr); return ret; } if (!check_section_footer(f, le)) {