[Libvirt-cim] [PATCH 1 of 2] Image Creation: add functions for generating a storage volume XML
Richard Maciel
rmaciel at linux.vnet.ibm.com
Wed Aug 12 03:21:16 UTC 2009
On 08/11/2009 05:19 PM, Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert<karupert at us.ibm.com>
> # Date 1245187550 25200
> # Node ID ffc93d36908aa5fca483fc650393802383409890
> # Parent 615da7491c145fa283e658df520fd9e31615f4d4
> Image Creation: add functions for generating a storage volume XML
>
> Signed-off-by: Kaitlin Rupert<karupert at us.ibm.com>
>
> diff -r 615da7491c14 -r ffc93d36908a libxkutil/xmlgen.c
> --- a/libxkutil/xmlgen.c Mon Aug 10 13:52:58 2009 -0700
> +++ b/libxkutil/xmlgen.c Tue Jun 16 14:25:50 2009 -0700
> @@ -39,6 +39,7 @@
>
> typedef const char *(*devfn_t)(xmlNodePtr node, struct domain *dominfo);
> typedef const char *(*poolfn_t)(xmlNodePtr node, struct virt_pool *pool);
> +typedef const char *(*resfn_t)(xmlNodePtr node, struct virt_pool_res *res);
>
> static char *disk_block_xml(xmlNodePtr root, struct disk_device *dev)
> {
> @@ -1056,6 +1057,133 @@
> return xml;
> }
>
> +static const char *vol_format_type_to_str(uint16_t type)
> +{
> + switch (type) {
> + case VOL_FORMAT_RAW:
> + return "raw";
> + default:
> + CU_DEBUG("Unsupported storage volume type");
> + }
> +
> + return NULL;
> +}
> +
> +static const char *storage_vol_xml(xmlNodePtr root,
> + struct virt_pool_res *res)
> +{
> + xmlNodePtr v = NULL;
> + xmlNodePtr name = NULL;
> + xmlNodePtr alloc = NULL;
> + xmlNodePtr cap = NULL;
> + xmlNodePtr target = NULL;
> + xmlNodePtr path = NULL;
> + xmlNodePtr format = NULL;
> + const char *type = NULL;
> + struct storage_vol *vol =&res->res.storage_vol;
> + char *string = NULL;
> + int ret;
> +
> + type = vol_format_type_to_str(vol->format_type);
> + if (type == NULL)
> + goto out;
> +
> + v = xmlNewChild(root, NULL, BAD_CAST "volume", NULL);
> + if (v == NULL)
> + goto out;
> +
> + name = xmlNewChild(v, NULL, BAD_CAST "name", BAD_CAST vol->vol_name);
> + if (name == NULL)
> + goto out;
> +
> + ret = asprintf(&string, "%" PRIu16, vol->alloc);
> + if (ret == -1)
> + return XML_ERROR;
> +
> + alloc = xmlNewChild(v, NULL, BAD_CAST "allocation", BAD_CAST string);
> + if (alloc == NULL)
> + goto out;
> +
> + free(string);
> + ret = asprintf(&string, "%" PRIu16, vol->cap);
> + if (ret == -1)
> + return XML_ERROR;
> +
> + cap = xmlNewChild(v, NULL, BAD_CAST "capacity", BAD_CAST string);
> + if (cap == NULL)
> + goto out;
> +
> + free(string);
> +
> + if (xmlNewProp(cap, BAD_CAST "unit", BAD_CAST vol->cap_units) == NULL)
> + goto out;
> +
> + target = xmlNewChild(v, NULL, BAD_CAST "target", NULL);
> + if (target == NULL)
> + goto out;
> +
> + path = xmlNewChild(target, NULL, BAD_CAST "path", BAD_CAST vol->path);
> + if (path == NULL)
> + goto out;
> +
> + format = xmlNewChild(target, NULL, BAD_CAST "format", NULL);
> + if (format == NULL)
> + goto out;
> +
> + if (xmlNewProp(format, BAD_CAST "type", BAD_CAST type) == NULL)
> + goto out;
> +
> + /* FIXME: Need to add permissions and label tags here */
What about this fixme?
> +
> + return NULL;
> +
> + out:
> + free(string);
> + return XML_ERROR;
> + }
> +
> +char *res_to_xml(struct virt_pool_res *res) {
> + char *xml = NULL;
> + xmlNodePtr root = NULL;
> + int type = res->type;
> + const char *msg = NULL;
> + resfn_t func;
> +
> + root = xmlNewNode(NULL, BAD_CAST "tmp");
> + if (root == NULL) {
> + msg = XML_ERROR;
> + goto out;
> + }
> +
> + switch (type) {
> + case CIM_RES_TYPE_IMAGE:
> + func = storage_vol_xml;
> + break;
> + default:
> + CU_DEBUG("res_to_xml: invalid type specified: %d", type);
> + msg = "res_to_xml: invalid type specified";
> + goto out;
> + }
> +
> + msg = func(root, res);
> + if (msg != NULL)
> + goto out;
> +
> + xml = tree_to_xml(root->children);
> + if (xml == NULL)
> + msg = "XML generation failed";
> + out:
> + if (msg != NULL) {
> + CU_DEBUG("Failed to create res XML: %s", msg);
> + } else {
> + CU_DEBUG("Created res XML:\n%s\n", xml);
> + }
> +
> + xmlFreeNode(root);
> +
> + return xml;
> +}
> +
> /*
> * Local Variables:
> * mode: C
> diff -r 615da7491c14 -r ffc93d36908a libxkutil/xmlgen.h
> --- a/libxkutil/xmlgen.h Mon Aug 10 13:52:58 2009 -0700
> +++ b/libxkutil/xmlgen.h Tue Jun 16 14:25:50 2009 -0700
> @@ -36,4 +36,6 @@
>
> char *pool_to_xml(struct virt_pool *pool);
>
> +char *res_to_xml(struct virt_pool_res *res);
> +
> #endif
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
--
Richard Maciel, MSc
IBM Linux Technology Center
rmaciel at linux.vnet.ibm.com
More information about the Libvirt-cim
mailing list