qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH V2 10/10] snapshot: hmp add internal snapshot suppor


From: Wenchao Xia
Subject: [Qemu-devel] [PATCH V2 10/10] snapshot: hmp add internal snapshot support for block device
Date: Mon, 7 Jan 2013 15:28:09 +0800

  Now hmp can take snapshot for a single block device.

v2:
  Removed option -n in internal snapshot case.
  Better tips.

Signed-off-by: Wenchao Xia <address@hidden>
---
 hmp-commands.hx |   28 +++++++++++++++++-----------
 hmp.c           |   25 +++++++++++++++----------
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 010b8c9..bd10349 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -983,17 +983,23 @@ ETEXI
 
     {
         .name       = "snapshot_blkdev",
-        .args_type  = "reuse:-n,device:B,snapshot-file:s?,format:s?",
-        .params     = "[-n] device [new-image-file] [format]",
-        .help       = "initiates a live snapshot\n\t\t\t"
-                      "of device. If a new image file is specified, 
the\n\t\t\t"
-                      "new image file will become the new root image.\n\t\t\t"
-                      "If format is specified, the snapshot file will\n\t\t\t"
-                      "be created in that format. Otherwise the\n\t\t\t"
-                      "snapshot will be internal! (currently 
unsupported).\n\t\t\t"
-                      "The default format is qcow2.  The -n flag requests 
QEMU\n\t\t\t"
-                      "to reuse the image found in new-image-file, instead 
of\n\t\t\t"
-                      "recreating it from scratch.",
+        .args_type  = "internal:-i,reuse:-n,device:B,name:s?,format:s?",
+        .params     = "[-i] [-n] device [name] [format]",
+        .help       = "initiates a live snapshot of device.\n\t\t\t"
+                      "  The -i flag requests QEMU to create internal 
snapshot\n\t\t\t"
+                      "instead of external one.\n\t\t\t"
+                      "  The -n flag requests QEMU to reuse the image found 
in\n\t\t\t"
+                      "in name, instead of recreating it from scratch. Only 
valid\n\t\t\t"
+                      "for external case.\n\t\t\t"
+                      "  The name is the snapshot's name. In external 
case\n\t\t\t"
+                      "it is the new image's name which will become the new 
root\n\t\t\t"
+                      "image and must be specified. In internal case it is 
the\n\t\t\t"
+                      "record's name and if not specified QEMU will 
create\n\t\t\t"
+                      "internal snapshot with name generated according to 
time.\n\t\t\t"
+                      "Any existing internal snapshot with name will be 
overwritten.\n\t\t\t"
+                      "  The format is the new snapshot image's format. If 
not\n\t\t\t"
+                      "sepcified, the default format is qcow2. Only valid for 
external\n\t\t\t"
+                      "case.",
         .mhandler.cmd = hmp_snapshot_blkdev,
     },
 
diff --git a/hmp.c b/hmp.c
index 9e9e624..d78d55f 100644
--- a/hmp.c
+++ b/hmp.c
@@ -804,23 +804,28 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
 {
     const char *device = qdict_get_str(qdict, "device");
-    const char *filename = qdict_get_try_str(qdict, "snapshot-file");
+    const char *name = qdict_get_try_str(qdict, "name");
     const char *format = qdict_get_try_str(qdict, "format");
     int reuse = qdict_get_try_bool(qdict, "reuse", 0);
+    int internal = qdict_get_try_bool(qdict, "internal", 0);
     enum NewImageMode mode;
+
     Error *errp = NULL;
 
-    if (!filename) {
-        /* In the future, if 'snapshot-file' is not specified, the snapshot
-           will be taken internally. Today it's actually required. */
-        error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
-        hmp_handle_error(mon, &errp);
-        return;
+    if (internal) {
+        qmp_blockdev_snapshot_internal_sync(device, !!name, name, &errp);
+    } else {
+        if (!name) {
+            /* Name must be specified for external case */
+            error_set(&errp, QERR_MISSING_PARAMETER, "name");
+            hmp_handle_error(mon, &errp);
+            return;
+        }
+        mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
+        qmp_blockdev_snapshot_sync(device, name, !!format, format,
+                                   true, mode, &errp);
     }
 
-    mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
-    qmp_blockdev_snapshot_sync(device, filename, !!format, format,
-                               true, mode, &errp);
     hmp_handle_error(mon, &errp);
 }
 
-- 
1.7.1





reply via email to

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