[Libvirt-cim] [PATCH] Add distinction between QEMU guests and hardware accelerated KVM guests

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Mon Apr 6 19:23:03 UTC 2009


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1238533479 25200
# Node ID e5aee0f0edc128d41148ec4cedaba2bdd53cf05e
# Parent  d08b52d4da57fc8bbe946f8b4f9ddccdccf9dee6
Add distinction between QEMU guests and hardware accelerated KVM guests

If the host system doesn't support KVM guests, then the providers should
create a QEMU guest.  This code generates the proper XML for the given guest
type.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r d08b52d4da57 -r e5aee0f0edc1 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Fri Apr 03 09:38:52 2009 -0700
+++ b/libxkutil/device_parsing.c	Tue Mar 31 14:04:39 2009 -0700
@@ -827,9 +827,10 @@
         if ((STREQC(dominfo->os_info.fv.type, "hvm")) &&
             (STREQC(dominfo->typestr, "xen")))
                 dominfo->type = DOMAIN_XENFV;
-        else if ((STREQC(dominfo->typestr, "kvm")) ||
-                 (STREQC(dominfo->typestr, "qemu")))
+        else if (STREQC(dominfo->typestr, "kvm"))
                 dominfo->type = DOMAIN_KVM;
+        else if (STREQC(dominfo->typestr, "qemu"))
+                dominfo->type = DOMAIN_QEMU;
         else if (STREQC(dominfo->typestr, "lxc"))
                 dominfo->type = DOMAIN_LXC;
         else if (STREQC(dominfo->os_info.pv.type, "linux"))
@@ -994,7 +995,7 @@
                 free(dom->os_info.pv.initrd);
                 free(dom->os_info.pv.cmdline);
         } else if ((dom->type == DOMAIN_XENFV) ||
-                   (dom->type == DOMAIN_KVM)) {
+                   (dom->type == DOMAIN_KVM) || (dom->type == DOMAIN_QEMU)) {
                 free(dom->os_info.fv.type);
                 free(dom->os_info.fv.loader);
                 free(dom->os_info.fv.boot);
diff -r d08b52d4da57 -r e5aee0f0edc1 libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h	Fri Apr 03 09:38:52 2009 -0700
+++ b/libxkutil/device_parsing.h	Tue Mar 31 14:04:39 2009 -0700
@@ -107,7 +107,11 @@
 };
 
 struct domain {
-        enum { DOMAIN_XENPV, DOMAIN_XENFV, DOMAIN_KVM, DOMAIN_LXC } type;
+        enum { DOMAIN_XENPV, 
+               DOMAIN_XENFV, 
+               DOMAIN_KVM, 
+               DOMAIN_QEMU, 
+               DOMAIN_LXC } type;
         char *name;
         char *typestr; /*xen, kvm, etc */
         char *uuid;
diff -r d08b52d4da57 -r e5aee0f0edc1 libxkutil/xml_parse_test.c
--- a/libxkutil/xml_parse_test.c	Fri Apr 03 09:38:52 2009 -0700
+++ b/libxkutil/xml_parse_test.c	Tue Mar 31 14:04:39 2009 -0700
@@ -41,7 +41,7 @@
                 print_value(d, "Loader", dom->os_info.fv.loader);
                 print_value(d, "Boot", dom->os_info.fv.boot);
 
-        } else if (dom->type == DOMAIN_KVM) {
+        } else if ((dom->type == DOMAIN_KVM) || (dom->type == DOMAIN_QEMU)) {
                 print_value(d, "Domain Type", "KVM/QEMU");
                 print_value(d, "Type", dom->os_info.fv.type);
                 print_value(d, "Loader", dom->os_info.fv.loader);
diff -r d08b52d4da57 -r e5aee0f0edc1 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c	Fri Apr 03 09:38:52 2009 -0700
+++ b/libxkutil/xmlgen.c	Tue Mar 31 14:04:39 2009 -0700
@@ -545,7 +545,7 @@
                 return _xenpv_os_xml(os, domain);
         else if (domain->type == DOMAIN_XENFV)
                 return _xenfv_os_xml(os, domain);
-        else if (domain->type == DOMAIN_KVM)
+        else if ((domain->type == DOMAIN_KVM) || (domain->type == DOMAIN_QEMU))
                 return _kvm_os_xml(os, domain);
         else if (domain->type == DOMAIN_LXC)
                 return _lxc_os_xml(os, domain);
@@ -694,6 +694,8 @@
                 domtype = "xen";
         else if (dominfo->type == DOMAIN_KVM)
                 domtype = "kvm";
+        else if (dominfo->type == DOMAIN_QEMU)
+                domtype = "qemu";
         else if (dominfo->type == DOMAIN_LXC)
                 domtype = "lxc";
         else
diff -r d08b52d4da57 -r e5aee0f0edc1 src/Virt_VSSD.c
--- a/src/Virt_VSSD.c	Fri Apr 03 09:38:52 2009 -0700
+++ b/src/Virt_VSSD.c	Tue Mar 31 14:04:39 2009 -0700
@@ -144,7 +144,7 @@
 
 
         if ((dominfo->type == DOMAIN_XENFV) ||
-            (dominfo->type == DOMAIN_KVM))
+            (dominfo->type == DOMAIN_KVM) || (dominfo->type == DOMAIN_QEMU))
                 _set_fv_prop(dominfo, inst);
         else if (dominfo->type == DOMAIN_XENPV)
                 _set_pv_prop(dominfo, inst);
diff -r d08b52d4da57 -r e5aee0f0edc1 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Fri Apr 03 09:38:52 2009 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Tue Mar 31 14:04:39 2009 -0700
@@ -174,6 +174,29 @@
         return true;
 }
 
+static bool system_has_kvm(const char *pfx)
+{
+        CMPIStatus s;
+        virConnectPtr conn;
+        char *caps = NULL;
+        bool kvm = false;
+
+        conn = connect_by_classname(_BROKER, pfx, &s);
+        if ((conn == NULL) || (s.rc != CMPI_RC_OK)) {
+                return false;
+        }
+
+        caps = virConnectGetCapabilities(conn);
+        if (caps != NULL)
+                kvm = (strstr(caps, "kvm") != NULL);
+
+        free(caps);
+
+        virConnectClose(conn);
+
+        return kvm;
+}
+
 static int fv_vssd_to_domain(CMPIInstance *inst,
                              struct domain *domain,
                              const char *pfx)
@@ -182,7 +205,10 @@
         const char *val;
 
         if (STREQC(pfx, "KVM")) {
-                domain->type = DOMAIN_KVM;
+                if (system_has_kvm(pfx))
+                        domain->type = DOMAIN_KVM;
+                else
+                        domain->type = DOMAIN_QEMU;
         } else if (STREQC(pfx, "Xen")) {
                 domain->type = DOMAIN_XENFV;
         } else {




More information about the Libvirt-cim mailing list