Skip to contentSkip to conversation

savevm/loadvm to/from a file

Qemu-devel Uri Lublin 2 participants 2 messages Jan 20, 2009

lore
Share & tools
lore

Uri Lublin

author
#0 lore raw

Sometimes we do not want to save VM state internally (within the image). For example raw images (and any other non qcow images) are not capable of savevm'ing.

This patch enables saving/loading the VM state in/from a file.

It introduces two monitor commands savevm_file and loadvm_file (should I just add flags or add prefix to savevm/loadvm ?).
When saving VM state, upon successful operation, the VM is left in stopped mode (such that it does not change the disk image).
When loading VM state, upon a failure, the VM is left in stopped mode; The user or a management-app should send a quit command, as otherwise the VM state may be inconsistent.

---
 monitor.c |    4 ++++
 savevm.c  |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sysemu.h  |    2 ++
 3 files changed, 64 insertions(+), 0 deletions(-)
monitor.c +4 -0
index 7ff9890..02274bc 100644
@@ -1454,6 +1454,10 @@ static const term_cmd_t term_cmds[] = {
       "tag|id", "restore a VM snapshot from its tag or id" },
     { "delvm", "s", do_delvm,
       "tag|id", "delete a VM snapshot from its tag or id" },
+    { "savevm_file", "F", do_savevm_file,
+      "filename", "save a VM state in a file." },
+    { "loadvm_file", "F", do_loadvm_file,
+      "filename", "load a VM state from a file" },
     { "stop", "", do_stop,
       "", "stop emulation", },
     { "c|cont", "", do_cont,
savevm.c +58 -0

70 lines not on this page · raw message

sysemu.h +2 -0
index 56eb9b3..f27058b 100644
@@ -47,6 +47,8 @@ void do_savevm(const char *name);
 void do_loadvm(const char *name);
 void do_delvm(const char *name);
 void do_info_snapshots(void);
+void do_savevm_file(const char *filename);
+void do_loadvm_file(const char *filename);
 
 void qemu_announce_self(void);
 
Signature · 1 line
1.6.0.6
#1 lore raw

Uri Lublin writes ("[Qemu-devel] [MIGRATION_TO_FILE_ALTERNATIVE] savevm/loadvm to/from a file"):

Quoted 3 lines

Sometimes we do not want to save VM state internally (within the image). For example raw images (and any other non qcow images) are not capable of savevm'ing.

This code is almost identical to the same code in our qemu-dm Xen tree. The only real difference is the umask call, and that our code takes its snapshot of vm_running after calling qemu_aio_flush.

Ie, in our version the assignment I mark here as A is at location B:

A > + int saved_vm_running = vm_running;
...

Quoted 1 line

+ f = qemu_fopen(filename, "wb");

...

Quoted 1 line

+ qemu_aio_flush();

B

Quoted 1 line

+ vm_stop(0);

I'm not sure exactly how relevant that is but it seems possible that qemu_aio_flush could stop the VM (eg due to the forthcoming stop-on-enospc patch).

Modulo this one tiny change, I'm keen to see this go into qemu upstream.

Ian.