From patchwork Wed Aug 19 02:07:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 31623 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 39790B7B68 for ; Wed, 19 Aug 2009 12:44:33 +1000 (EST) Received: from localhost ([127.0.0.1]:36353 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MdbA3-0004h3-Um for incoming@patchwork.ozlabs.org; Tue, 18 Aug 2009 22:44:27 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mdb2H-0002m9-GD for qemu-devel@nongnu.org; Tue, 18 Aug 2009 22:36:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mdb2C-0002iP-A0 for qemu-devel@nongnu.org; Tue, 18 Aug 2009 22:36:24 -0400 Received: from [199.232.76.173] (port=37503 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mdb2C-0002iM-4A for qemu-devel@nongnu.org; Tue, 18 Aug 2009 22:36:20 -0400 Received: from [66.187.237.31] (port=53936 helo=mx2.redhat.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mdb2B-0004SU-G8 for qemu-devel@nongnu.org; Tue, 18 Aug 2009 22:36:19 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7J2A8UQ026678 for ; Tue, 18 Aug 2009 22:10:08 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7J2A6oh001613; Tue, 18 Aug 2009 22:10:07 -0400 Received: from localhost.localdomain (vpn1-4-108.ams2.redhat.com [10.36.4.108]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7J2A1t2004927; Tue, 18 Aug 2009 22:10:05 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 19 Aug 2009 04:07:46 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH 3/6] split do_loadvm() into do_loadvm() and load_vmstate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org do_loadvm() is now called from the monitor. load_vmstate() is called by do_loadvm() and when -loadvm command line is used. Command line don't have to play games with vmstop()/vmstart() Signed-off-by: Juan Quintela --- savevm.c | 22 +++++++++++++--------- sysemu.h | 1 + vl.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/savevm.c b/savevm.c index 570377f..a321136 100644 --- a/savevm.c +++ b/savevm.c @@ -1145,14 +1145,13 @@ void do_savevm(Monitor *mon, const char *name) vm_start(); } -void do_loadvm(Monitor *mon, const char *name) +void load_vmstate(Monitor *mon, const char *name) { DriveInfo *dinfo; BlockDriverState *bs, *bs1; QEMUSnapshotInfo sn; QEMUFile *f; int ret; - int saved_vm_running; bs = get_bs_snapshots(); if (!bs) { @@ -1163,9 +1162,6 @@ void do_loadvm(Monitor *mon, const char *name) /* Flush all IO requests so they don't interfere with the new state. */ qemu_aio_flush(); - saved_vm_running = vm_running; - vm_stop(0); - TAILQ_FOREACH(dinfo, &drives, next) { bs1 = dinfo->bdrv; if (bdrv_has_snapshot(bs1)) { @@ -1191,7 +1187,7 @@ void do_loadvm(Monitor *mon, const char *name) } /* fatal on snapshot block device */ if (bs == bs1) - goto the_end; + return; } } } @@ -1199,20 +1195,28 @@ void do_loadvm(Monitor *mon, const char *name) /* Don't even try to load empty VM states */ ret = bdrv_snapshot_find(bs, &sn, name); if ((ret >= 0) && (sn.vm_state_size == 0)) - goto the_end; + return; /* restore the VM state */ f = qemu_fopen_bdrv(bs, 0); if (!f) { monitor_printf(mon, "Could not open VM state file\n"); - goto the_end; + return; } ret = qemu_loadvm_state(f); qemu_fclose(f); if (ret < 0) { monitor_printf(mon, "Error %d while loading VM state\n", ret); } - the_end: +} + +void do_loadvm(Monitor *mon, const char *name) +{ + int saved_vm_running = vm_running; + + vm_stop(0); + + load_vmstate(mon, name); if (saved_vm_running) vm_start(); } diff --git a/sysemu.h b/sysemu.h index dffb2f1..a20025d 100644 --- a/sysemu.h +++ b/sysemu.h @@ -52,6 +52,7 @@ void qemu_system_reset(void); void do_savevm(Monitor *mon, const char *name); void do_loadvm(Monitor *mon, const char *name); +void load_vmstate(Monitor *mon, const char *name); void do_delvm(Monitor *mon, const char *name); void do_info_snapshots(Monitor *mon); diff --git a/vl.c b/vl.c index e86bdce..4d585b0 100644 --- a/vl.c +++ b/vl.c @@ -6037,7 +6037,7 @@ int main(int argc, char **argv, char **envp) } if (loadvm) - do_loadvm(cur_mon, loadvm); + load_vmstate(cur_mon, loadvm); if (incoming) { qemu_start_incoming_migration(incoming);