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

[Xen-devel] [RFC PATCH 2/7] qmp: add qmp handlers to create disk snapshots



Add qmp handlers to take disk snapshots. This will be used when
creating a domain snapshots.

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 tools/libxl/libxl_internal.h |  4 +++
 tools/libxl/libxl_qmp.c      | 66 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 6ea6c83..c3dec85 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1735,6 +1735,10 @@ _hidden int libxl__qmp_set_global_dirty_log(libxl__gc 
*gc, int domid, bool enabl
 _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const 
libxl_device_disk *disk);
 /* Add a virtual CPU */
 _hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index);
+/* Create disk snapshots for a group of disks in a transaction */
+_hidden int libxl__qmp_disk_snapshot_transaction(libxl__gc *gc, int domid,
+                                                libxl_disk_snapshot *snapshot,
+                                                int nb);
 /* close and free the QMP handler */
 _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);
 /* remove the socket file, if the file has already been removed,
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 965c507..2216511 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -968,6 +968,72 @@ int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx)
     return qmp_run_command(gc, domid, "cpu-add", args, NULL, NULL);
 }
 
+/*
+ * requires QEMU version >= 1.1
+ * qmp command example:
+ * -> { "execute": "transaction",
+ *      "arguments": { "actions": [
+ *          { "type": "blockdev-snapshot-sync", "data" : { "device": "ide-hd0",
+ *                                          "snapshot-file": 
"/some/place/my-image",
+ *                                          "format": "qcow2" } },
+ *          { 'type': 'blockdev-snapshot-internal-sync', 'data' : {
+ *                                          "device": "ide-hd1",
+ *                                          "name": "snapshot0" } } ] } }
+ *          { 'type': 'blockdev-snapshot-internal-sync', 'data' : {
+ *                                          "device": "ide-hd2",
+ *                                          "name": "snapshot0" } } ] } }
+ * <- { "return": {} }
+ */
+int libxl__qmp_disk_snapshot_transaction(libxl__gc *gc, int domid,
+                                         libxl_disk_snapshot *snapshot,
+                                         int nb)
+{
+    libxl__json_object *args = NULL;
+    libxl__json_object *actions = NULL;
+    libxl__json_object **type = NULL;
+    libxl__json_object **data = NULL;
+    int i;
+
+    type = (libxl__json_object**)calloc(nb, sizeof(libxl__json_object*));
+    data = (libxl__json_object**)calloc(nb, sizeof(libxl__json_object*));
+    actions = libxl__json_object_alloc(gc, JSON_ARRAY);
+
+    for (i = 0; i < nb; i++) {
+        switch (snapshot[i].type) {
+        case LIBXL_DISK_SNAPSHOT_TYPE_INTERNAL:
+            /* internal disk snapshot */
+            qmp_parameters_add_string(gc, &type[i], "type",
+                                      "blockdev-snapshot-internal-sync");
+            qmp_parameters_add_string(gc, &data[i], "name",
+                                      snapshot[i].name);
+            qmp_parameters_add_string(gc, &data[i], "device",
+                                      snapshot[i].disk.vdev);
+            qmp_parameters_common_add(gc, &type[i], "data", data[i]);
+            flexarray_append(actions->u.array, (void*)type[i]);
+            break;
+        case LIBXL_DISK_SNAPSHOT_TYPE_EXTERNAL:
+            /* external disk snapshot */
+            qmp_parameters_add_string(gc, &type[i], "type",
+                                      "blockdev-snapshot-sync");
+            qmp_parameters_add_string(gc, &data[i], "device",
+                                      snapshot[i].disk.vdev);
+            qmp_parameters_add_string(gc, &data[i], "snapshot-file",
+                                      snapshot[i].u.external.external_path);
+            qmp_parameters_add_string(gc, &data[i], "format",
+                
libxl_disk_format_to_string(snapshot[i].u.external.external_format));
+            qmp_parameters_common_add(gc, &type[i], "data", data[i]);
+            flexarray_append(actions->u.array, (void*)type[i]);
+            break;
+        default:
+            LOG(ERROR, "Invalid disk snapshot type");
+            return -1;
+        }
+    }
+
+    qmp_parameters_common_add(gc, &args, "actions", actions);
+    return qmp_run_command(gc, domid, "transaction", args, NULL, NULL);
+}
+
 int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
                                const libxl_domain_config *guest_config)
 {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.