[Libvirt-cim] [PATCH V2 06/48] Fix xml parsing algorithm for parse_vsi_device()

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


Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
---
 libxkutil/device_parsing.c |   89 ++++++++++++++++++++++++++++++++-----------
 1 files changed, 66 insertions(+), 23 deletions(-)

diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 6ab8131..bc6c649 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -1014,40 +1014,83 @@ static int parse_disk_device(xmlNode *dnode, struct virt_device **vdevs)
         }
 }
 
-static int parse_vsi_device(xmlNode *dnode, struct net_device *vdevs)
+static int parse_vsi_device(struct others **others, struct net_device *vdevs)
 {
         struct vsi_device *vsi_dev = NULL;
-        xmlNode * child = NULL;
+
+        CU_DEBUG("Enter parse_vsi_device().");
 
         vsi_dev = calloc(1, sizeof(*vsi_dev));
-        if (vsi_dev == NULL)
+        if (vsi_dev == NULL) {
+                CU_DEBUG("calloc failed.");
                 goto err;
+        }
 
-        vsi_dev->vsi_type = get_attr_value(dnode, "type");
-        if (vsi_dev->vsi_type == NULL)
+        vsi_dev->vsi_type = fetch_from_others(others,
+                                              -1,
+                                              "type",
+                                              TYPE_PROP,
+                                              -1,
+                                              "virtualport");
+        if (vsi_dev->vsi_type == NULL) {
+                CU_DEBUG("no vsi type");
                 goto err;
+        }
 
-        for (child = dnode->children; child != NULL; child = child->next) {
-                if (XSTREQ(child->name, "parameters")) {
-                        vsi_dev->manager_id = get_attr_value(child, 
-                                                             "managerid");
-                        if (vsi_dev->manager_id == NULL)
-                                goto err;
+        if (seek_in_others(others,
+                           -1,
+                           "parameters",
+                           TYPE_NODE,
+                           -1,
+                           "virtualport")) {
+                vsi_dev->manager_id = fetch_from_others(others,
+                                                        -1,
+                                                        "managerid",
+                                                        TYPE_PROP,
+                                                        -1,
+                                                        "parameters");
+
+                if (vsi_dev->manager_id == NULL) {
+                        CU_DEBUG("no managerid");
+                        goto err;
+                }
 
-                        vsi_dev->type_id = get_attr_value(child, "typeid");
-                        if (vsi_dev->type_id == NULL)
-                                goto err;
+                vsi_dev->type_id = fetch_from_others(others,
+                                                     -1,
+                                                     "typeid",
+                                                     TYPE_PROP,
+                                                     -1,
+                                                     "parameters");
+                if (vsi_dev->type_id == NULL) {
+                        CU_DEBUG("no typeid");
+                        goto err;
+                }
 
-                        vsi_dev->type_id_version = 
-                                get_attr_value(child, "typeidversion");
-                        if (vsi_dev->type_id_version == NULL)
-                                goto err;
+                vsi_dev->type_id_version = fetch_from_others(others,
+                                                             -1,
+                                                             "typeidversion",
+                                                             TYPE_PROP,
+                                                             -1,
+                                                             "parameters");
 
-                        vsi_dev->instance_id = get_attr_value(child, 
-                                                              "instanceid");
-                        vsi_dev->profile_id = get_attr_value(child, 
-                                                             "profileid");
-                 }
+                if (vsi_dev->type_id_version == NULL) {
+                        CU_DEBUG("no typeidversion");
+                        goto err;
+                }
+
+                vsi_dev->instance_id = fetch_from_others(others,
+                                                         -1,
+                                                         "instanceid",
+                                                         TYPE_PROP,
+                                                         -1,
+                                                         "parameters");
+
+                vsi_dev->profile_id = fetch_from_others(others,
+                                                        -1,
+                                                        "profileid",
+                                                        TYPE_PROP,
+                                                        -1,
+                                                        "parameters");
         }
 
         memcpy(&(vdevs->vsi), vsi_dev, sizeof(*vsi_dev));
-- 
1.7.1




More information about the Libvirt-cim mailing list