Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/xmlgen.c | 137 +++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 110 insertions(+), 27 deletions(-)
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 60aa9c3..5c151d3 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -309,26 +309,66 @@ static char *disk_block_xml(xmlNodePtr root, struct disk_device
*dev)
static const char *disk_file_xml(xmlNodePtr root, struct disk_device *dev)
{
- xmlNodePtr disk;
- xmlNodePtr tmp;
+ CU_DEBUG("Enter disk_file_xml()");
- disk = xmlNewChild(root, NULL, BAD_CAST "disk", NULL);
- if (disk == NULL)
+ dev->others = add_node_to_others(dev->others,
+ "disk",
+ NULL,
+ TYPE_NODE,
+ "devices");
+
+ if (dev->others == NULL) {
+ CU_DEBUG("add tag <disk> failed.");
return XML_ERROR;
- xmlNewProp(disk, BAD_CAST "type", BAD_CAST "file");
- if (dev->device)
- xmlNewProp(disk, BAD_CAST "device", BAD_CAST dev->device);
+ }
+
+ dev->others = add_node_to_others(dev->others,
+ "type",
+ "file",
+ TYPE_PROP,
+ "disk");
+
+ if (dev->device) {
+ dev->others = add_node_to_others(dev->others,
+ "device",
+ dev->device,
+ TYPE_PROP,
+ "disk");
+ }
if (dev->driver) {
- tmp = xmlNewChild(disk, NULL, BAD_CAST "driver", NULL);
- if (tmp == NULL)
+ dev->others = add_node_to_others(dev->others,
+ "driver",
+ NULL,
+ TYPE_NODE,
+ "disk");
+
+ if (dev->others == NULL) {
+ CU_DEBUG("add node <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,
+ "name",
+ dev->driver,
+ TYPE_PROP,
+ "driver");
+
+ if (dev->driver_type) {
+ dev->others = add_node_to_others(dev->others,
+ "type",
+ dev->driver_type,
+ TYPE_PROP,
+ "driver");
+ }
+
+ if (dev->cache) {
+ dev->others = add_node_to_others(dev->others,
+ "cache",
+ dev->cache,
+ TYPE_PROP,
+ "driver");
+ }
}
if (dev->device != NULL && XSTREQ(dev->device, "cdrom")
&&
@@ -338,26 +378,69 @@ static const char *disk_file_xml(xmlNodePtr root, struct disk_device
*dev)
xml defination for libvirt should not have this defined in this
situation. */
} else {
- tmp = xmlNewChild(disk, NULL, BAD_CAST "source", NULL);
- if (tmp == NULL)
+ dev->others = add_node_to_others(dev->others,
+ "source",
+ NULL,
+ TYPE_NODE,
+ "disk");
+
+ if (dev->others == NULL) {
+ CU_DEBUG("add node <source> failed.");
return XML_ERROR;
- xmlNewProp(tmp, BAD_CAST "file", BAD_CAST dev->source);
+ }
+
+ dev->others = add_node_to_others(dev->others,
+ "file",
+ dev->source,
+ TYPE_PROP,
+ "source");
}
- tmp = xmlNewChild(disk, NULL, BAD_CAST "target", NULL);
- if (tmp == NULL)
+ dev->others = add_node_to_others(dev->others,
+ "target",
+ NULL,
+ TYPE_NODE,
+ "disk");
+
+ if (dev->others == NULL) {
+ CU_DEBUG("add node <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);
+ }
+
+ dev->others = add_node_to_others(dev->others,
+ "dev",
+ dev->virtual_dev,
+ TYPE_PROP,
+ "target");
+ if (dev->bus_type) {
+ dev->others = add_node_to_others(dev->others,
+ "bus",
+ dev->bus_type,
+ TYPE_PROP,
+ "target");
+ }
- if (dev->readonly)
- xmlNewChild(disk, NULL, BAD_CAST "readonly", NULL);
+ if (dev->readonly) {
+ dev->others = add_node_to_others(dev->others,
+ "readonly",
+ NULL,
+ TYPE_NODE,
+ "disk");
+ }
- if (dev->shareable)
- xmlNewChild(disk, NULL, BAD_CAST "shareable", NULL);
+ if (dev->shareable) {
+ dev->others = add_node_to_others(dev->others,
+ "shareable",
+ NULL,
+ TYPE_NODE,
+ "disk");
+ }
+ dev->others = others_to_xml(root, dev->others, "devices");
+ if (dev->others) {
+ CU_DEBUG("others_to_xml error.");
+ }
return NULL;
}
--
1.7.1