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

Xu Wang cngesaint at gmail.com
Mon Oct 28 02:46:04 UTC 2013


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

diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 5979e96..6c4b832 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -1820,20 +1820,48 @@ static const char *input_xml(xmlNodePtr root, struct domain *dominfo)
 {
         int i;
 
+        CU_DEBUG("Enter input_xml()");
+
         for (i = 0; i < dominfo->dev_input_ct; i++) {
-                xmlNodePtr tmp;
                 struct virt_device *_dev = &dominfo->dev_input[i];
                 if (_dev->type == CIM_RES_TYPE_UNKNOWN)
                         continue;
 
                 struct input_device *dev = &_dev->dev.input;
 
-                tmp = xmlNewChild(root, NULL, BAD_CAST "input", NULL);
-                if (tmp == NULL)
+                dev->others = add_node_to_others(dev->others,
+                                                 0,
+                                                 "input",
+                                                 NULL,
+                                                 TYPE_NODE,
+                                                 0,
+                                                 "devices");
+
+                if (dev->others == NULL) {
+                        CU_DEBUG("add node <input> failed.");
                         return XML_ERROR;
+                }
 
-                xmlNewProp(tmp, BAD_CAST "type", BAD_CAST dev->type);
-                xmlNewProp(tmp, BAD_CAST "bus", BAD_CAST dev->bus);
+                dev->others = add_node_to_others(dev->others,
+                                                 0,
+                                                 "type",
+                                                 dev->type,
+                                                 TYPE_PROP,
+                                                 0,
+                                                 "input");
+
+                dev->others = add_node_to_others(dev->others,
+                                                 0,
+                                                 "bus",
+                                                 dev->bus,
+                                                 TYPE_PROP,
+                                                 0,
+                                                 "input");
+
+                dev->others = others_to_xml(root, dev->others, 0, "devices");
+                if (check_others_active(dev->others)) {
+                        return "xml generation failed.";
+                }
         }
 
         return NULL;
-- 
1.7.1




More information about the Libvirt-cim mailing list