From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: [PATCH v1 01/10] libxl: libxl-json format and internal functions to get / set it Date: Thu, 10 Jul 2014 15:32:16 +0100 Message-ID: <1405002745-5034-2-git-send-email-wei.liu2@citrix.com> References: <1405002745-5034-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1405002745-5034-1-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Wei Liu , ian.jackson@eu.citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org Introduce a new format in libxl userdata store called "libxl-json". This file format contains JSON version of libxl_domain_config, generated by libxl. Two internal functions to get and set libxl_domain_configuration are also introduced. Signed-off-by: Wei Liu --- tools/libxl/libxl.h | 2 ++ tools/libxl/libxl_internal.c | 56 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 10 ++++++++ 3 files changed, 68 insertions(+) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index e6e0301..2dc6a51 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1182,6 +1182,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" libxl_domain_config object 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 diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 81f8985..dc47177 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -381,6 +381,62 @@ out: return rc; } +int libxl__get_domain_configuration(libxl__gc *gc, uint32_t domid, + libxl_domain_config *d_config) +{ + uint8_t *data = NULL; + int rc, len; + + rc = libxl_userdata_retrieve(CTX, domid, "libxl-json", &data, &len); + if (rc) { + LOGEV(ERROR, rc, + "failed to retrieve domain configuration for domain %d", domid); + rc = ERROR_FAIL; + goto out; + } + + if (len == 0) { + LOGE(ERROR, "configuration data stream empty for domain %d", domid); + rc = ERROR_FAIL; + goto out; + } + rc = libxl_domain_config_from_json(CTX, d_config, (const char *)data); + +out: + free(data); + return rc; +} + +int libxl__set_domain_configuration(libxl__gc *gc, uint32_t domid, + libxl_domain_config *d_config) +{ + char *d_config_json; + int rc; + + d_config_json = libxl_domain_config_to_json(CTX, d_config); + if (!d_config_json) { + LOGE(ERROR, "failed to convert domain configuration to JSON for domain %d", + domid); + rc = ERROR_FAIL; + goto out; + } + + rc = libxl_userdata_store(CTX, domid, "libxl-json", + (const uint8_t *)d_config_json, + strlen(d_config_json) + 1 /* include '\0' */); + if (rc) { + LOGEV(ERROR, rc, "failed to store domain configuration for domain %d", + domid); + rc = ERROR_FAIL; + goto out; + } + +out: + free(d_config_json); + return rc; +} + + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index beb052e..ef2111b 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3219,6 +3219,16 @@ static inline int libxl__key_value_list_is_empty(libxl_key_value_list *pkvl) int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl); +/* + * Retrieve / store domain configuration from / to libxl private + * data store. The registry entry in libxl private data store + * is "libxl-json". + */ +int libxl__get_domain_configuration(libxl__gc *gc, uint32_t domid, + libxl_domain_config *d_config); +int libxl__set_domain_configuration(libxl__gc *gc, uint32_t domid, + libxl_domain_config *d_config); + #endif /* -- 1.7.10.4