[Libvirt-cim] [PATCH 08/20] Fix xml parsing algorithm for parse_vcpu_device()

John Ferlan jferlan at redhat.com
Fri Nov 15 00:23:57 UTC 2013


From: Xu Wang <cngesaint at gmail.com>

Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
---
 libxkutil/device_parsing.c | 35 ++++++++++++++++++++++++++++++-----
 libxkutil/device_parsing.h |  1 +
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 8b39cda..8082b37 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -151,6 +151,14 @@ static void cleanup_net_device(struct net_device *dev)
         cleanup_others(dev->others);
 }
 
+static void cleanup_vcpu_device(struct vcpu_device *dev)
+{
+        if (dev == NULL)
+                return;
+
+        cleanup_others(dev->others);
+}
+
 static void cleanup_emu_device(struct emu_device *dev)
 {
         if (dev == NULL)
@@ -339,6 +347,8 @@ void cleanup_virt_device(struct virt_device *dev)
                 cleanup_disk_device(&dev->dev.disk);
         else if (dev->type == CIM_RES_TYPE_NET)
                 cleanup_net_device(&dev->dev.net);
+        else if (dev->type == CIM_RES_TYPE_PROC)
+                cleanup_vcpu_device(&dev->dev.vcpu);
         else if (dev->type == CIM_RES_TYPE_EMU)
                 cleanup_emu_device(&dev->dev.emu);
         else if (dev->type == CIM_RES_TYPE_GRAPHICS)
@@ -1450,7 +1460,26 @@ static int parse_vcpu_device(xmlNode *node, struct virt_device **vdevs)
         char *count_str;
         int count;
 
-        count_str = get_node_content(node);
+        CU_DEBUG("Enter parse_vcpu_device().");
+
+        list = calloc(1, sizeof(*list));
+        if (list == NULL) {
+                CU_DEBUG("calloc failed.");
+                goto err;
+        }
+
+        list->dev.vcpu.others = parse_data_to_others(list->dev.vcpu.others,
+                                                     node,
+                                                     0,
+                                                     BAD_CAST "domain");
+
+        count_str = fetch_from_others(&list->dev.vcpu.others,
+                                      -1,
+                                      "vcpu",
+                                      TYPE_NODE,
+                                      -1,
+                                      "domain");
+
         if (count_str == NULL)
                 count = 1; /* Default to 1 VCPU if non specified */
         else if (sscanf(count_str, "%i", &count) != 1)
@@ -1458,10 +1487,6 @@ static int parse_vcpu_device(xmlNode *node, struct virt_device **vdevs)
 
         free(count_str);
 
-        list = calloc(1, sizeof(*list));
-        if (list == NULL)
-                goto err;
-        
         list->dev.vcpu.quantity = count;
 
         list->type = CIM_RES_TYPE_PROC;
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index 4d26fc8..c9e2b29 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -115,6 +115,7 @@ struct vcpu_device {
         uint64_t quantity;
         uint32_t weight;
         uint64_t limit;
+        struct others *others;
 };
 
 struct emu_device {
-- 
1.8.3.1




More information about the Libvirt-cim mailing list