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

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


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

diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 8e793f9..cbc69be 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -1564,10 +1564,11 @@ static const char *cputune_xml(xmlNodePtr root, struct domain *dominfo)
 static const char *mem_xml(xmlNodePtr root, struct domain *dominfo)
 {
         struct mem_device *mem;
-        xmlNodePtr tmp = NULL;
         int ret;
         char *string = NULL;
 
+        CU_DEBUG("Enter mem_xml()");
+
         if (dominfo->dev_mem == NULL)
                 return NULL;
 
@@ -1576,39 +1577,60 @@ static const char *mem_xml(xmlNodePtr root, struct domain *dominfo)
         ret = asprintf(&string, "%" PRIu64, mem->size);
         if (ret == -1)
                 goto out;
-        tmp = xmlNewChild(root,
-                          NULL,
-                          BAD_CAST "currentMemory",
-                          BAD_CAST string);
-        if (tmp == NULL)
+
+        mem->others = add_node_to_others(mem->others,
+                                         0,
+                                         "currentMemory",
+                                         string,
+                                         TYPE_NODE,
+                                         0,
+                                         "domain");
+
+        if (mem->others == NULL) {
+                CU_DEBUG("add node <currentMemory> failed.");
                 return XML_ERROR;
+        }
 
         free(string);
-        tmp = NULL;
 
         ret = asprintf(&string, "%" PRIu64, mem->maxsize);
         if (ret == -1)
                 goto out;
-        tmp = xmlNewChild(root,
-                          NULL,
-                          BAD_CAST "memory",
-                          BAD_CAST string);
+
+        mem->others = add_node_to_others(mem->others,
+                                         0,
+                                         "memory",
+                                         string,
+                                         TYPE_NODE,
+                                         0,
+                                         "domain");
 
         free(string);
 
-        if (tmp == NULL)
-                return XML_ERROR;
         if (mem->dumpCore == MEM_DUMP_CORE_ON) {
-                xmlNewProp(tmp, BAD_CAST "dumpCore", BAD_CAST "on");
+                mem->others = add_node_to_others(mem->others,
+                                                 0,
+                                                 "dumpCore",
+                                                 "on",
+                                                 TYPE_PROP,
+                                                 0,
+                                                 "memory");
         } else if (mem->dumpCore == MEM_DUMP_CORE_OFF) {
-                xmlNewProp(tmp, BAD_CAST "dumpCore", BAD_CAST "off");
+                mem->others = add_node_to_others(mem->others,
+                                                 0,
+                                                 "dumpCore",
+                                                 "off",
+                                                 TYPE_PROP,
+                                                 0,
+                                                 "memory");
         }
 
+        dominfo->others = combine_others(dominfo->others, mem->others);
+        mem->others = NULL;
+
+        return NULL;
  out:
-        if (tmp == NULL)
-                return XML_ERROR;
-        else
-                return NULL;
+        return XML_ERROR;
 }
 
 static const char *emu_xml(xmlNodePtr root, struct domain *dominfo)
-- 
1.7.1




More information about the Libvirt-cim mailing list