qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] [RFC] savevm only saves disk state


From: disheng . su
Subject: [Qemu-devel] [PATCH] [RFC] savevm only saves disk state
Date: Thu, 9 Sep 2010 18:43:34 -0700

From: edison <address@hidden>

Add a new option when "savevm": savevm -n snapshotName, which only takes 
snapshot on disk, but doesn't save vm state(memory,cpu,devices...).
Saving vm state on QCOW2 disk will take a long time, per my test, it will take 
1~2 minutes to "savevm" on VM with 1G memory. Even worse, the VM is wholely 
stopped at that time, makes "savevm" not that useful.
All we know the side effect of it:) but does it make sense to give user the 
choice?
---
 qemu-monitor.hx |    6 +++---
 savevm.c        |   34 ++++++++++++++++++++++------------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 49bcd8d..724e0a2 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -327,9 +327,9 @@ ETEXI
 
     {
         .name       = "savevm",
-        .args_type  = "name:s?",
-        .params     = "[tag|id]",
-        .help       = "save a VM snapshot. If no tag or id are provided, a new 
snapshot is created",
+        .args_type  = "nostate:-n,name:s?",
+        .params     = "[-n] [tag|id]",
+        .help       = "save a VM snapshot. If no tag or id are provided, a new 
snapshot is created. If -n is specified, do not save vm state",
         .mhandler.cmd = do_savevm,
     },
 
diff --git a/savevm.c b/savevm.c
index 6fa7a5f..b0963b5 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1834,7 +1834,8 @@ void do_savevm(Monitor *mon, const QDict *qdict)
     int ret;
     QEMUFile *f;
     int saved_vm_running;
-    uint32_t vm_state_size;
+    uint32_t vm_state_size = 0;
+    
 #ifdef _WIN32
     struct _timeb tb;
     struct tm *ptm;
@@ -1844,6 +1845,8 @@ void do_savevm(Monitor *mon, const QDict *qdict)
 #endif
     const char *name = qdict_get_try_str(qdict, "name");
 
+    int nostate = qdict_get_try_bool(qdict, "nostate", 0);
+
     /* Verify if there is a device that doesn't support snapshots and is 
writable */
     bs = NULL;
     while ((bs = bdrv_next(bs))) {
@@ -1909,17 +1912,19 @@ void do_savevm(Monitor *mon, const QDict *qdict)
     }
 
     /* save the VM state */
-    f = qemu_fopen_bdrv(bs, 1);
-    if (!f) {
-        monitor_printf(mon, "Could not open VM state file\n");
-        goto the_end;
-    }
-    ret = qemu_savevm_state(mon, f);
-    vm_state_size = qemu_ftell(f);
-    qemu_fclose(f);
-    if (ret < 0) {
-        monitor_printf(mon, "Error %d while writing VM\n", ret);
-        goto the_end;
+    if (!nostate) {
+        f = qemu_fopen_bdrv(bs, 1);
+        if (!f) {
+            monitor_printf(mon, "Could not open VM state file\n");
+            goto the_end;
+        }
+        ret = qemu_savevm_state(mon, f);
+        vm_state_size = qemu_ftell(f);
+        qemu_fclose(f);
+        if (ret < 0) {
+            monitor_printf(mon, "Error %d while writing VM\n", ret);
+            goto the_end;
+        }
     }
 
     /* create the snapshots */
@@ -1984,6 +1989,11 @@ int load_vmstate(const char *name)
                            bdrv_get_device_name(bs), name);
             return ret;
         }
+        
+        if (sn.vm_state_size == 0) {
+            error_report("No vm state stored on snapshot: '%s'.", name);
+            return -ENOTSUP;
+        }
     }
 
     /* Flush all IO requests so they don't interfere with the new state.  */
-- 
1.7.2.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]