[Libvirt-cim] [PATCH 04/47] Fix xml parsing algorithm for parse_fs_device()

Xu Wang gesaint at linux.vnet.ibm.com
Tue Oct 8 06:13:38 UTC 2013


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

diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 09dab97..d29a09a 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -454,7 +454,8 @@ static int parse_fs_device(xmlNode *dnode, struct virt_device **vdevs)
 {
         struct virt_device *vdev = NULL;
         struct disk_device *ddev = NULL;
-        xmlNode *child = NULL;
+
+        CU_DEBUG("Enter parse_fs_device().");
 
         vdev = calloc(1, sizeof(*vdev));
         if (vdev == NULL)
@@ -462,35 +463,72 @@ static int parse_fs_device(xmlNode *dnode, struct virt_device **vdevs)
 
         ddev = (&vdev->dev.disk);
 
-        ddev->type = get_attr_value(dnode, "type");
+        ddev->others = parse_data_to_others(dnode, BAD_CAST "devices");
+        if (ddev->others == NULL) {
+                CU_DEBUG("parse xml failed.");
+                goto err;
+        }
+
+        /* fetch out <disk> tag from others. It will be removed
+         * after others management finished. */
+        fetch_from_others(&ddev->others,
+                          "filesystem",
+                          TYPE_NODE,
+                          "devices");
+
+        ddev->type = fetch_from_others(&ddev->others,
+                                       "type",
+                                       TYPE_PROP,
+                                       (char *)dnode->name);
         if (ddev->type == NULL) {
                 CU_DEBUG("No type");
                 goto err;
         }
 
-        ddev->access_mode = get_attr_value(dnode, "accessmode");
+        ddev->access_mode = fetch_from_others(&ddev->others,
+                                              "accessmode",
+                                              TYPE_PROP,
+                                              (char *)dnode->name);
 
-        for (child = dnode->children; child != NULL; child = child->next) {
-                if (XSTREQ(child->name, "source")) {
-                        ddev->source = get_attr_value(child, "dir");
-                        if (ddev->source == NULL) {
-                                CU_DEBUG("No source dir");
-                                goto err;
-                        }
-                } else if (XSTREQ(child->name, "target")) {
-                        ddev->virtual_dev = get_attr_value(child, "dir");
-                        if (ddev->virtual_dev == NULL) {
-                                CU_DEBUG("No target dir");
-                                goto err;
-                        }
-                } else if (XSTREQ(child->name, "driver")) {
-                       ddev->driver_type = get_attr_value(child, "type");
+        if (seek_in_others(&ddev->others,
+                           "source",
+                           TYPE_NODE,
+                           (char *)dnode->name)) {
+                ddev->source = fetch_from_others(&ddev->others,
+                                                 "dir",
+                                                 TYPE_PROP,
+                                                 "source");
+
+
+                if (ddev->source == NULL) {
+                        CU_DEBUG("no source dir");
+                        goto err;
                 }
         }
 
-        if ((ddev->source == NULL) || (ddev->virtual_dev == NULL)) {
-                CU_DEBUG("S: %s D: %s", ddev->source, ddev->virtual_dev);
-                goto err;
+        if (seek_in_others(&ddev->others,
+                           "target",
+                           TYPE_NODE,
+                           (char *)dnode->name)) {
+                ddev->virtual_dev = fetch_from_others(&ddev->others,
+                                                      "dir",
+                                                      TYPE_PROP,
+                                                      "target");
+
+                if (ddev->virtual_dev == NULL) {
+                        CU_DEBUG("no target dir");
+                        goto err;
+                }
+        }
+
+        if (seek_in_others(&ddev->others,
+                           "driver",
+                           TYPE_NODE,
+                           (char *)dnode->name)) {
+                ddev->driver_type = fetch_from_others(&ddev->others,
+                                                      "type",
+                                                      TYPE_PROP,
+                                                      "driver");
         }
 
         ddev->disk_type = DISK_FS;
-- 
1.7.1




More information about the Libvirt-cim mailing list