[PATCH 0 of 2] Add support for generating image XML

# HG changeset patch # User Kaitlin Rupert <karupert@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@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 */ + + 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

On 08/11/2009 05:19 PM, Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert<karupert@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@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@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com

+ 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?
Right now, the StorageVolRASD doesn't have attributes that allow the user to set the permissions and flags they want for the image. This is something I'll need to add in the future, but it isn't needed to get the initial image creation support working. Plus, it's a lot of additional code, and I wanted to make the patches small enough that they were easy and quick to review. Once all the patches for initial image creation are in the tree, my plan is to do the following: 1) Add a method that will allow the user to delete the image 2) Improve the image creation support so that users can specify permissions, flags, anything else I've missed/neglected. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

On 08/11/2009 05:19 PM, Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert<karupert@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@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 */ + + 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";
Since you're using the same message, why not assign the value and use it?
+ 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@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
Only a small comment on the style above. Overall, the code is fine. -- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1245187550 25200 # Node ID 2fb0663546797c7781119063dc6ad3af2c090e83 # Parent ffc93d36908aa5fca483fc650393802383409890 Image creation: Add support for CreateResourceInPool() method Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r ffc93d36908a -r 2fb066354679 src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Tue Jun 16 14:25:50 2009 -0700 +++ b/src/Virt_ResourcePoolConfigurationService.c Tue Jun 16 14:25:50 2009 -0700 @@ -784,6 +784,9 @@ CMPIObjectPath *pool; struct virt_pool_res *res = NULL; const char* msg = NULL; + const char *id = NULL; + char *pool_id = NULL; + char *xml = NULL; CU_DEBUG("CreateResourceInPool"); @@ -808,12 +811,44 @@ goto out; } + if (cu_get_str_path(pool, "InstanceID", &id) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing InstanceID in resource pool"); + goto out; + } + + pool_id = name_from_pool_id(id); + if (pool_id == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_INVALID_PARAMETER, + "Pool has invalid InstanceID"); + goto out; + } + + free(res->pool_id); + res->pool_id = strdup(pool_id); + + xml = res_to_xml(res); + if (xml == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to generate XML for new resource"); + goto out; + } + + CU_DEBUG("New resource XML:\n%s", xml); + + /*FIXME: Add resource here */ + + out: + free(pool_id); + free(xml); + if (s.rc == CMPI_RC_OK) rc = CIM_SVPC_RETURN_COMPLETED; CMReturnData(results, &rc, CMPI_uint32); - out: - return s; }
participants (2)
-
Kaitlin Rupert
-
Richard Maciel