[Libvirt-cim] [PATCH V2 25/48] Fix xml generation algorithm in disk_fs_xml()

Xu Wang cngesaint at gmail.com
Mon Oct 28 02:45:54 UTC 2013


Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
---
 libxkutil/xmlgen.c |   94 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 80 insertions(+), 14 deletions(-)

diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index f721ac7..3350e80 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -926,12 +926,20 @@ static const char *disk_file_xml(xmlNodePtr root, struct disk_device *dev)
 
 static const char *disk_fs_xml(xmlNodePtr root, struct disk_device *dev)
 {
-        xmlNodePtr fs;
-        xmlNodePtr tmp;
+        CU_DEBUG("Enter disk_fs_xml()");
 
-        fs = xmlNewChild(root, NULL, BAD_CAST "filesystem", NULL);
-        if (fs == NULL)
+        dev->others = add_node_to_others(dev->others,
+                                         0,
+                                         "filesystem",
+                                         NULL,
+                                         TYPE_NODE,
+                                         0,
+                                         "devices");
+
+        if (dev->others == NULL) {
+                CU_DEBUG("add node <filesystem> failed.");
                 return XML_ERROR;
+        }
 
         /* filesystem prop 'type' not needed to be generated, as it defaults
          to 'mount' in libvirt, the only supported value for now. */
@@ -940,25 +948,83 @@ static const char *disk_fs_xml(xmlNodePtr root, struct disk_device *dev)
          So generate here if specified by user, else leave it to libvirt. */
 
         if (dev->access_mode) {
-                xmlNewProp(fs, BAD_CAST "accessmode", BAD_CAST dev->access_mode);
+                dev->others = add_node_to_others(dev->others,
+                                                 0,
+                                                 "accessmode",
+                                                 dev->access_mode,
+                                                 TYPE_PROP,
+                                                 0,
+                                                 "filesystem");
         }
 
         if(dev->driver_type) {
-                tmp = xmlNewChild(fs, NULL, BAD_CAST "driver", NULL);
-                xmlNewProp(tmp, BAD_CAST "type", BAD_CAST dev->driver_type);
+                dev->others = add_node_to_others(dev->others,
+                                                 0,
+                                                 "driver",
+                                                 NULL,
+                                                 TYPE_NODE,
+                                                 0,
+                                                 "filesystem");
+
+                if (dev->others == NULL) {
+                        CU_DEBUG("add node <driver> failed.");
+                        return XML_ERROR;
+                }
+
+                dev->others = add_node_to_others(dev->others,
+                                                 0,
+                                                 "type",
+                                                 dev->driver_type,
+                                                 TYPE_PROP,
+                                                 0,
+                                                 "driver");
         }
 
-        tmp = xmlNewChild(fs, NULL, BAD_CAST "source", NULL);
-        if (tmp == NULL)
+        dev->others = add_node_to_others(dev->others,
+                                         0,
+                                         "source",
+                                         NULL,
+                                         TYPE_NODE,
+                                         0,
+                                         "filesystem");
+
+        if (dev->others == NULL) {
+                CU_DEBUG("add node <source> failed.");
                 return XML_ERROR;
-        xmlNewProp(tmp, BAD_CAST "dir", BAD_CAST dev->source);
+        }
 
-        tmp = xmlNewChild(fs, NULL, BAD_CAST "target", NULL);
-        if (tmp == NULL)
+        dev->others = add_node_to_others(dev->others,
+                                         0,
+                                         "dir",
+                                         dev->source,
+                                         TYPE_PROP,
+                                         0,
+                                         "source");
+
+        dev->others = add_node_to_others(dev->others,
+                                         0,
+                                         "target",
+                                         NULL,
+                                         TYPE_NODE,
+                                         0,
+                                         "filesystem");
+
+        if (dev->others == NULL) {
+                CU_DEBUG("add node <target> failed.");
                 return XML_ERROR;
-        xmlNewProp(tmp, BAD_CAST "dir", BAD_CAST dev->virtual_dev);
+        }
 
-        return NULL;
+        dev->others = add_node_to_others(dev->others,
+                                         0,
+                                         "dir",
+                                         dev->virtual_dev,
+                                         TYPE_PROP,
+                                         0,
+                                         "target");
+
+        dev->others = others_to_xml(root, dev->others, 0, "devices");
+
+        return check_others_active(dev->others);
 }
 
 static const char *disk_xml(xmlNodePtr root, struct domain *dominfo)
-- 
1.7.1




More information about the Libvirt-cim mailing list