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

[Xen-devel] [RFC PATCH 3/7] libxl: save disk format to xenstore



Disk snapshot handling depends on disk format. Currently since disk
format is not saved into xenstore, when getting device disk list,
disk->format is LIBXL_DISK_FORMAT_UNKNOWN. Disk snapshot cannot
continue without correct disk format information, so adding code
to save disk format to xenstore so that when getting device disk
list, disk->format contains correct information.

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 tools/libxl/libxl.c       | 10 +++++++++-
 tools/libxl/libxl_utils.c | 16 ++++++++++++++++
 tools/libxl/libxl_utils.h |  1 +
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 083f099..dce43d6 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2524,6 +2524,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t 
domid,
                 goto out;
         }
 
+        flexarray_append(back, "format");
+        flexarray_append(back, 
libxl__device_disk_string_of_format(disk->format));
         flexarray_append(back, "frontend-id");
         flexarray_append(back, libxl__sprintf(gc, "%d", domid));
         flexarray_append(back, "online");
@@ -2682,7 +2684,13 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc,
     }
     disk->is_cdrom = !strcmp(tmp, "cdrom");
 
-    disk->format = LIBXL_DISK_FORMAT_UNKNOWN;
+    tmp = libxl__xs_read(gc, XBT_NULL,
+                         libxl__sprintf(gc, "%s/format", be_path));
+    if (!tmp) {
+        LOG(ERROR, "Missing xenstore node %s/format", be_path);
+        goto cleanup;
+    }
+    libxl_string_to_format(ctx, tmp, &(disk->format));
 
     return 0;
 cleanup:
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index bfc9699..067a9fc 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -322,6 +322,22 @@ out:
     return rc;
 }
 
+int libxl_string_to_format(libxl_ctx *ctx, char *s, libxl_disk_format *format)
+{
+    int rc = 0;
+
+    if (!strcmp(s, "aio")) {
+        *format = LIBXL_DISK_FORMAT_RAW;
+    } else if (!strcmp(s, "vhd")) {
+        *format = LIBXL_DISK_FORMAT_VHD;
+    } else if (!strcmp(s, "qcow")) {
+        *format = LIBXL_DISK_FORMAT_QCOW;
+    } else if (!strcmp(s, "qcow2")) {
+        *format = LIBXL_DISK_FORMAT_QCOW2;
+    }
+    return rc;
+}
+
 int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
                              void **data_r, int *datalen_r) {
     GC_INIT(ctx);
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 1e5ca8a..0897069 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -37,6 +37,7 @@ int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid);
 int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid);
 int libxl_create_logfile(libxl_ctx *ctx, const char *name, char **full_name);
 int libxl_string_to_backend(libxl_ctx *ctx, char *s, libxl_disk_backend 
*backend);
+int libxl_string_to_format(libxl_ctx *ctx, char *s, libxl_disk_format *format);
 
 int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
                              void **data_r, int *datalen_r);
-- 
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®.