[PATCH] Fix kvm support check logic

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@gmail.com> --- libxkutil/device_parsing.c | 49 +++++++++++++++++++++++++++++++++---------- 1 files changed, 37 insertions(+), 12 deletions(-) diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c index 16195da..184627f 100644 --- a/libxkutil/device_parsing.c +++ b/libxkutil/device_parsing.c @@ -396,31 +396,56 @@ 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; + } +} + 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

于 2013年06月27日 14:55, Xu Wang 写道:
+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; if (ret == NULL) and (child = (child->next ) ==NULL)
what would seek_subNode return ? should return a NULL when quit from while loop.
+ } +}
-- Thanks Eli.(Li Yong Qiao/qiaoly@cn.ibm.com Chinese Name:乔立勇) LTC, Chian CSTL
participants (2)
-
Eli Qiao(Li Yong Qiao)
-
Xu Wang