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

[Xen-devel] [RFC PATCH 7/7] libxl: add APIs to delete internal/external disk snapshots



Currently this group of APIs are not used by xl toolstack since xl
doesn't maintain domain snapshot info and so depends on user to
delete things.

But for libvirt, they are very useful since libvirt maintains domain
snapshot info itself and needs these APIs to delete
internal/external disk snapshots.

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 tools/libxl/libxl.h          |  28 ++++++++++++
 tools/libxl/libxl_snapshot.c | 102 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 130 insertions(+)

diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 412a42f..1383b92 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1752,6 +1752,34 @@ int libxl_disk_snapshot_create(libxl_ctx *ctx, uint32_t 
domid,
 int libxl_disk_snapshot_revert(libxl_ctx *ctx, uint32_t domid,
                                libxl_disk_snapshot *snapshot, int nb);
 
+/* delete internal disk snapshot */
+int libxl_disk_snapshot_delete(libxl_ctx *ctx, uint32_t domid,
+                               libxl_disk_snapshot *snapshot, int nb);
+/* next 4 functions deal with external disk snapshot */
+/* shorten backing file chain. Merge from top to base */
+int libxl_domain_block_rebase(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_disk *disk,
+                              const char *base,
+                              const char *backing_file,
+                              unsigned long long bandwidth);
+/* shorten backing file chain. Merge from base to top */
+int libxl_domain_block_commit(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_disk *disk,
+                              const char *top,
+                              const char *base,
+                              const char *backing_file,
+                              unsigned long long bandwidth);
+/* query a block job status, can get job type, speed, progress status */
+int libxl_domain_block_job_query(libxl_ctx *ctx, uint32_t domid,
+                                 libxl_device_disk *disk,
+                                 libxl_block_job_info *info);
+/* abort a block job. If the job is finished, complete it.
+ * otherwise, cancel it.
+ */
+int libxl_domain_block_job_abort(libxl_ctx *ctx, uint32_t domid,
+                                 libxl_device_disk *disk,
+                                 bool force);
+
 /* misc */
 
 /* Each of these sets or clears the flag according to whether the
diff --git a/tools/libxl/libxl_snapshot.c b/tools/libxl/libxl_snapshot.c
index 34d36ef..9b139e6 100644
--- a/tools/libxl/libxl_snapshot.c
+++ b/tools/libxl/libxl_snapshot.c
@@ -217,3 +217,105 @@ int libxl_disk_snapshot_revert(libxl_ctx *ctx, uint32_t 
domid,
     }
     return rc;
 }
+
+int libxl_disk_snapshot_delete(libxl_ctx *ctx, uint32_t domid,
+                               libxl_disk_snapshot *snapshot, int nb)
+{
+    int rc = 0;
+    int i;
+
+    GC_INIT(ctx);
+    for(i = 0; i < nb; i++ ) {
+        if (snapshot[i].type == LIBXL_DISK_SNAPSHOT_TYPE_EXTERNAL) {
+            LOG(WARN, "libxl_disk_snapshot_delete: external disk snapshot "
+                "cannot be deleted. Please use libxl_domain_block_commit and "
+                "libxl_domain_block_rebase to handle that.");
+            continue;
+        }
+
+        rc = libxl__qmp_disk_snapshot_delete(gc, domid, &snapshot[i]);
+        if ( rc )
+            goto err;
+    }
+err:
+    if (rc)
+        LOG(ERROR, "domain disk snapshot delete fail\n");
+
+    GC_FREE;
+    return rc;
+}
+
+int libxl_domain_block_rebase(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_disk *disk,
+                              const char *base,
+                              const char *backing_file,
+                              unsigned long long bandwidth)
+{
+    GC_INIT(ctx);
+    int rc;
+
+    rc = libxl__qmp_block_stream(gc, domid, disk, base,
+                                 backing_file, bandwidth, NULL);
+    GC_FREE;
+    return rc;
+}
+
+int libxl_domain_block_commit(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_disk *disk,
+                              const char *top,
+                              const char *base,
+                              const char *backing_file,
+                              unsigned long long bandwidth)
+
+{
+    GC_INIT(ctx);
+    int rc;
+
+    rc = libxl__qmp_block_commit(gc, domid, disk, top, base,
+                                 backing_file, bandwidth);
+
+    GC_FREE;
+    return rc;
+}
+
+/* query block job status */
+int libxl_domain_block_job_query(libxl_ctx *ctx, uint32_t domid,
+                                 libxl_device_disk *disk,
+                                 libxl_block_job_info *info)
+{
+    GC_INIT(ctx);
+    int rc;
+
+    rc = libxl__qmp_query_block_job(gc, domid, disk, info);
+
+    GC_FREE;
+    return rc;
+}
+
+/* Abort block job:
+ * If block job is already finished, call "block_job_complete" qmp;
+ * otherwise, call "block_job_cancel" qmp command.
+ */
+int libxl_domain_block_job_abort(libxl_ctx *ctx, uint32_t domid,
+                                 libxl_device_disk *disk,
+                                 bool force)
+{
+    GC_INIT(ctx);
+    libxl_block_job_info info;
+    int rc;
+
+    /* query block job info */
+    if (libxl_domain_block_job_query(ctx, domid, disk, &info) < 0) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if (info.current == info.end)
+        rc = libxl__qmp_block_job_complete(gc, domid, disk);
+    else
+        rc = libxl__qmp_block_job_cancel(gc, domid, disk, force);
+
+out:
+    GC_FREE;
+    return rc;
+}
-- 
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®.