From: Xu Wang <cngesaint(a)outlook.com>
Under nested KVM environment libvirt-cim could recognize kvm support
correctly now.
Signed-off-by: Xu Wang <cngesaint(a)outlook.com>
---
libxkutil/device_parsing.c | 19 +++++++++++++++++++
libxkutil/device_parsing.h | 2 ++
src/Virt_VirtualSystemManagementService.c | 22 +++++++++++++++++++---
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 436415a..58d9094 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -396,6 +396,25 @@ err:
return 0;
}
+int parse_domain_type(xmlNodePtr node, char **value)
+{
+ xmlNodePtr child = NULL;
+
+ child = node->children;
+ while (child != NULL) {
+ if (XSTREQ(child->name, "domain")) {
+ *value = get_attr_value(child, "type");
+ }
+ if (parse_domain_type(child, value) != 1)
+ goto err;
+ child = child->next;
+ }
+
+ return 1;
+err:
+ return 0;
+}
+
static int parse_net_device(xmlNode *inode, struct virt_device **vdevs)
{
struct virt_device *vdev = NULL;
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index 6f6b0b4..733324f 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -221,6 +221,8 @@ int attach_device(virDomainPtr dom, struct virt_device *dev);
int detach_device(virDomainPtr dom, struct virt_device *dev);
int change_device(virDomainPtr dom, struct virt_device *dev);
+int parse_domain_type(xmlNodePtr node, char **value);
+
#define XSTREQ(x, y) (STREQ((char *)x, y))
#define STRPROP(d, p, n) (d->p = get_node_content(n))
diff --git a/src/Virt_VirtualSystemManagementService.c
b/src/Virt_VirtualSystemManagementService.c
index 7b7261a..5210fdf 100644
--- a/src/Virt_VirtualSystemManagementService.c
+++ b/src/Virt_VirtualSystemManagementService.c
@@ -393,8 +393,13 @@ static bool system_has_kvm(const char *pfx)
CMPIStatus s;
virConnectPtr conn;
char *caps = NULL;
- bool kvm = false;
bool disable_kvm = get_disable_kvm();
+ char *val = NULL;
+ int ret;
+ xmlDocPtr doc;
+ xmlNodePtr node;
+ int len;
+ bool kvm = false;
/* sometimes disable KVM to avoid problem in nested KVM */
if (disable_kvm) {
@@ -408,10 +413,21 @@ static bool system_has_kvm(const char *pfx)
}
caps = virConnectGetCapabilities(conn);
- if (caps != NULL)
- kvm = (strstr(caps, "kvm") != NULL);
+ if (caps != NULL) {
+ len = strlen(caps) + 1;
+ doc = xmlParseMemory(caps, len);
+ node = xmlDocGetRootElement(doc);
+ ret = parse_domain_type(node, &val);
+ CU_DEBUG("domain type is %s.", val);
+ if (ret == CMPI_RC_OK) {
+ if(STREQC(val, "kvm"))
+ kvm = true;
+ }
+ }
free(caps);
+ free(doc);
+ free(val);
virConnectClose(conn);
--
1.7.1