[Libvirt-cim] [PATCH V2] Fix kvm support check logic

Xu Wang cngesaint at gmail.com
Thu Jun 27 07:22:19 UTC 2013


Kvm support check function should return domain type of guest which
arch name same with host. This patch add arch name comparation and
return the domain type of right guest.

Signed-off-by: Xu Wang <cngesaint at gmail.com>
---
 libxkutil/device_parsing.c |   51 +++++++++++++++++++++++++++++++++----------
 1 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 16195da..2f39af3 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -396,31 +396,58 @@ err:
         return 0;
 }
 
+static xmlNodePtr seek_subNode(xmlNodePtr node, char *tag)
+{
+        xmlNodePtr child = node->children;
+        xmlNodePtr ret = NULL;
+
+        if (child == NULL) {
+                return NULL;
+        }
+
+        while (child) {
+                if (XSTREQ(child->name, tag)) {
+                        return child;
+                }
+
+                ret = seek_subNode(child, tag);
+                if (ret) {
+                        return ret;
+                }
+
+                child = child->next;
+        }
+
+        return NULL;
+}
+
 int parse_domain_type(xmlNodePtr node, char **value)
 {
         xmlNodePtr child = NULL;
+        xmlNodePtr seek_node = NULL;
         char *type = NULL;
+        char *host_arch = NULL;
+        char *guest_arch = NULL;
 
         child = node->children;
-        while (child != NULL) {
-                if (XSTREQ(child->name, "domain")) {
-                        type = get_attr_value(child, "type");
-                        if (type != NULL) {
+        while (child) {
+                if (XSTREQ(child->name, "host")) {
+                        seek_node = seek_subNode(child, "arch");
+                        host_arch = get_node_content(seek_node);
+                } else if (XSTREQ(child->name, "guest")) {
+                        seek_node = seek_subNode(child, "arch");
+                        guest_arch = get_attr_value(seek_node, "name");
+                        if (XSTREQ(host_arch, guest_arch)) {
+                                seek_node = seek_subNode(child, "domain");
+                                type = get_attr_value(seek_node, "type");
                                 *value = strdup(type);
-                                goto out;
+                                return 1;
                         }
                 }
-
-                if (parse_domain_type(child, value) == 1) {
-                        goto out;
-                }
-
                 child = child->next;
         }
 
         return 0;
-out:
-        return 1;
 }
 
 static int parse_net_device(xmlNode *inode, struct virt_device **vdevs)
-- 
1.7.1




More information about the Libvirt-cim mailing list