From patchwork Wed Mar 14 01:20:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: junyan.he@hotmail.com X-Patchwork-Id: 10281349 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 899B8601A0 for ; Wed, 14 Mar 2018 01:29:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A315285EE for ; Wed, 14 Mar 2018 01:29:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F1522863B; Wed, 14 Mar 2018 01:29:26 +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,FREEMAIL_FROM, 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 44EF3285EE for ; Wed, 14 Mar 2018 01:29:25 +0000 (UTC) Received: from localhost ([::1]:43937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evvEK-0007sQ-H1 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Mar 2018 21:29:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evv5q-0000Tx-Vp for qemu-devel@nongnu.org; Tue, 13 Mar 2018 21:20:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evv5p-0006UC-ED for qemu-devel@nongnu.org; Tue, 13 Mar 2018 21:20:38 -0400 Received: from mga18.intel.com ([134.134.136.126]:28906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evv5p-0006Hx-5u for qemu-devel@nongnu.org; Tue, 13 Mar 2018 21:20:37 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Mar 2018 18:20:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,466,1515484800"; d="scan'208";a="38632863" Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by orsmga001.jf.intel.com with ESMTP; 13 Mar 2018 18:20:34 -0700 From: junyan.he@hotmail.com To: qemu-devel@nongnu.org Date: Wed, 14 Mar 2018 09:20:15 +0800 Message-Id: <1520990418-28258-8-git-send-email-junyan.he@hotmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520990418-28258-1-git-send-email-junyan.he@hotmail.com> References: <1520990418-28258-1-git-send-email-junyan.he@hotmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 Subject: [Qemu-devel] [PATCH 07/10] RFC: Add get_current_snapshot_info to get the snapshot state. 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: kwolf@redhat.com, famz@redhat.com, crosthwaite.peter@gmail.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, Junyan He , pbonzini@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Junyan He We need to know the snapshot saving information when we do dependent snapshot saving, e.g the name of previous snapshot. Add this global function to query the snapshot status is usable. Signed-off-by: Junyan He --- include/migration/snapshot.h | 3 +++ migration/savevm.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/migration/snapshot.h b/include/migration/snapshot.h index c85b6ec..0b950ce 100644 --- a/include/migration/snapshot.h +++ b/include/migration/snapshot.h @@ -15,7 +15,10 @@ #ifndef QEMU_MIGRATION_SNAPSHOT_H #define QEMU_MIGRATION_SNAPSHOT_H +#include "block/snapshot.h" + int save_snapshot(const char *name, Error **errp); int load_snapshot(const char *name, Error **errp); +int get_current_snapshot_info(QEMUSnapshotInfo *sn); #endif diff --git a/migration/savevm.c b/migration/savevm.c index 1bbd6aa..3a9b904 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2212,6 +2212,29 @@ int qemu_loadvm_state(QEMUFile *f) return ret; } +static int in_snap_saving; +static QEMUSnapshotInfo in_snap_saving_sn; + +int get_current_snapshot_info(QEMUSnapshotInfo *sn) +{ + if (in_snap_saving && sn) { + memcpy(sn, &in_snap_saving_sn, sizeof(QEMUSnapshotInfo)); + } + + return in_snap_saving; +} + +static void set_current_snapshot_info(QEMUSnapshotInfo *sn) +{ + if (sn) { + memcpy(&in_snap_saving_sn, sn, sizeof(QEMUSnapshotInfo)); + in_snap_saving = 1; + } else { + memset(&in_snap_saving_sn, 0, sizeof(QEMUSnapshotInfo)); + in_snap_saving = 0; + } +} + int save_snapshot(const char *name, Error **errp) { BlockDriverState *bs, *bs1; @@ -2282,6 +2305,8 @@ int save_snapshot(const char *name, Error **errp) strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm); } + set_current_snapshot_info(sn); + /* save the VM state */ f = qemu_fopen_bdrv(bs, 1); if (!f) { @@ -2313,6 +2338,8 @@ int save_snapshot(const char *name, Error **errp) ret = 0; the_end: + set_current_snapshot_info(NULL); + if (aio_context) { aio_context_release(aio_context); }