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

[Xen-devel] [PATCH V5 27/32] libxl: libxl-json format and load/store configuration functions



Introduce a new format in libxl userdata store called "libxl-json". This
format contains the deserialized version of domain configuration of a
domain.

Two libxl functions to load and store domain configuration are also
introduced. They use the new "libxl-json" format.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/libxl/libxl.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl.h |   10 ++++++++
 2 files changed, 78 insertions(+)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index c9475d7..b578a5c 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -5751,6 +5751,74 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, 
libxl_mac *src)
     for (i = 0; i < 6; i++)
         (*dst)[i] = (*src)[i];
 }
+
+int libxl_load_domain_configuration(libxl_ctx *ctx, uint32_t domid,
+                                    libxl_domain_config *d_config)
+{
+    GC_INIT(ctx);
+    uint8_t *data;
+    int rc, len;
+
+    rc = libxl_userdata_retrieve(ctx, domid, "libxl-json", &data, &len);
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+                            "Failed to retrieve domain configuration for 
domain %d",
+                            domid);
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if (len == 0) {
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
+                         "Configuration data stream empty for domain %d",
+                         domid);
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    /* Make sure this string ends with \0 -- the parser expects a NULL
+     * terminated string.
+     */
+    if (data[len-1] != '\0') {
+        data = libxl__realloc(gc, data, len + 1);
+        data[len] = '\0';
+    }
+
+    rc = libxl_domain_config_from_json(ctx, d_config, (const char *)data);
+
+out:
+    free(data);
+    GC_FREE;
+    return rc;
+}
+
+int libxl_store_domain_configuration(libxl_ctx *ctx, uint32_t domid,
+                                     libxl_domain_config *d_config)
+{
+    GC_INIT(ctx);
+    char *d_config_json;
+    int rc;
+
+    d_config_json = libxl_domain_config_to_json(ctx, d_config);
+
+    rc = libxl_userdata_store(ctx, domid, "libxl-json",
+                              (const uint8_t *)d_config_json,
+                              strlen(d_config_json));
+    if (rc) {
+        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
+                            "Failed to store domain configuration for domain 
%d",
+                            domid);
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    free(d_config_json);
+
+out:
+    GC_FREE;
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index d5dfe2e..be722b6 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1140,6 +1140,8 @@ void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid,
  *  "xl"          domain config file in xl format, Unix line endings
  *  "libvirt-xml" domain config file in libvirt XML format.  See
  *                http://libvirt.org/formatdomain.html
+ *  "libxl-json"  domain config file in JSON format, generated by
+ *                libxl
  *
  * libxl does not enforce the registration of userdata userids or the
  * semantics of the data.  For specifications of the data formats
@@ -1251,6 +1253,14 @@ int libxl_flask_loadpolicy(libxl_ctx *ctx, void *policy, 
uint32_t size);
 int libxl_fd_set_cloexec(libxl_ctx *ctx, int fd, int cloexec);
 int libxl_fd_set_nonblock(libxl_ctx *ctx, int fd, int nonblock);
 
+/* Load / save domain configuration. The domain configuration is
+ * stored in libxl userdata store.
+ */
+int libxl_load_domain_configuration(libxl_ctx *ctx, uint32_t domid,
+                                    libxl_domain_config *d_config);
+int libxl_store_domain_configuration(libxl_ctx *ctx, uint32_t domid,
+                                     libxl_domain_config *d_config);
+
 #include <libxl_event.h>
 
 #endif /* LIBXL_H */
-- 
1.7.10.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®.