Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/xmlgen.c | 172 +++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 143 insertions(+), 29 deletions(-)
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index f5fe4a4..c7dbefb 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -602,49 +602,163 @@ static const char *console_xml(xmlNodePtr root, struct domain
*dominfo)
static char *disk_block_xml(xmlNodePtr root, struct disk_device *dev)
{
- xmlNodePtr disk;
- xmlNodePtr tmp;
+ CU_DEBUG("Enter disk_block_xml()");
- disk = xmlNewChild(root, NULL, BAD_CAST "disk", NULL);
- if (disk == NULL)
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "disk",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "devices");
+
+ if (dev->others == NULL) {
+ CU_DEBUG("Add tag <disk> failed.");
return XML_ERROR;
- xmlNewProp(disk, BAD_CAST "type", BAD_CAST "block");
- if (dev->device)
- xmlNewProp(disk, BAD_CAST "device", BAD_CAST dev->device);
+ }
+
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "type",
+ "block",
+ TYPE_PROP,
+ 0,
+ "disk");
+
+ if (dev->device) {
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "device",
+ dev->device,
+ TYPE_PROP,
+ 0,
+ "disk");
+ }
if (dev->driver) {
- tmp = xmlNewChild(disk, NULL, BAD_CAST "driver", NULL);
- if (tmp == NULL)
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "driver",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "disk");
+
+ if (dev->others == NULL) {
+ CU_DEBUG("add tag <driver> failed.");
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "name", BAD_CAST dev->driver);
- if (dev->driver_type)
- xmlNewProp(tmp, BAD_CAST "type",
- BAD_CAST dev->driver_type);
- if (dev->cache)
- xmlNewProp(tmp, BAD_CAST "cache", BAD_CAST
dev->cache);
+ }
+
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "name",
+ dev->driver,
+ TYPE_PROP,
+ 0,
+ "driver");
+
+ if (dev->driver_type) {
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "type",
+ dev->driver_type,
+ TYPE_PROP,
+ 0,
+ "driver");
+ }
+
+ if (dev->cache) {
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "cache",
+ dev->cache,
+ TYPE_PROP,
+ 0,
+ "driver");
+ }
}
if ((dev->source != NULL) && (!XSTREQ(dev->source,
"/dev/null"))) {
- tmp = xmlNewChild(disk, NULL, BAD_CAST "source", NULL);
- if (tmp == NULL)
- return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "dev", BAD_CAST dev->source);
- }
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "source",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "disk");
+
+ if (dev->others == NULL) {
+ CU_DEBUG("add tag <source> failed.");
+ return XML_ERROR;
+ }
- tmp = xmlNewChild(disk, NULL, BAD_CAST "target", NULL);
- if (tmp == NULL)
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "dev",
+ dev->source,
+ TYPE_PROP,
+ 0,
+ "source");
+ }
+
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "target",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "disk");
+
+ if (dev->others == NULL) {
+ CU_DEBUG("add tag <target> failed.");
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "dev", BAD_CAST dev->virtual_dev);
- if (dev->bus_type)
- xmlNewProp(tmp, BAD_CAST "bus", BAD_CAST dev->bus_type);
+ }
- if (dev->readonly)
- xmlNewChild(disk, NULL, BAD_CAST "readonly", NULL);
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "dev",
+ dev->virtual_dev,
+ TYPE_PROP,
+ 0,
+ "target");
- if (dev->shareable)
- xmlNewChild(disk, NULL, BAD_CAST "shareable", NULL);
+ if (dev->bus_type) {
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "bus",
+ dev->bus_type,
+ TYPE_PROP,
+ 0,
+ "target");
+ }
- return NULL;
+ if (dev->readonly) {
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "readonly",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "disk");
+ }
+
+ if (dev->shareable) {
+ dev->others = add_node_to_others(dev->others,
+ 0,
+ "shareable",
+ NULL,
+ TYPE_NODE,
+ 0,
+ "disk");
+ }
+
+ dev->others = others_to_xml(root, dev->others, 0, "devices");
+
+ if (check_others_active(dev->others)) {
+ return XML_ERROR;
+ } else {
+ return NULL;
+ }
}
static const char *disk_file_xml(xmlNodePtr root, struct disk_device *dev)
--
1.7.1