[PATCH V2] 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 | 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

On 06/27/2013 09:22 AM, Xu Wang wrote:
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; unfortunately this logic is still returns the first guest domain type in the capabilities XML which is "qemu". It would be necessary to iterate all guest domains to find out whether one of them is of type "kvm".
BTW: this function is leaking type, host_arch and guest_arch...
} } -
-- Mit freundlichen Grüßen/Kind Regards Viktor Mihajlovski IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martina Köderitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
participants (2)
-
Viktor Mihajlovski
-
Xu Wang