Blame SOURCES/libvirt-cim-0.6.3-117dabb9.patch

c55d09
From 117dabb96ff85f41d05ab841df02c02a09ff73d7 Mon Sep 17 00:00:00 2001
c55d09
From: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
c55d09
Date: Thu, 29 Aug 2013 17:18:53 +0200
c55d09
Subject: [PATCH 11/60] VSSM: Set default values based on libvirt capabilities
c55d09
 on DefineSystem calls
c55d09
c55d09
In the DefineSystem call the architecture, machine and emulator for KVM are set
c55d09
to the hypervisor-specific default values if they did not get provided.
c55d09
This now allows architecture based decision making in the CIM providers to
c55d09
work for all platforms.
c55d09
c55d09
Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
c55d09
Reviewed-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
c55d09
Signed-off-by: John Ferlan <jferlan@redhat.com>
c55d09
---
c55d09
 src/Virt_VirtualSystemManagementService.c | 162 +++++++++++++++---------------
c55d09
 1 file changed, 79 insertions(+), 83 deletions(-)
c55d09
c55d09
diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c
c55d09
index 301f046..79dec73 100644
c55d09
--- a/src/Virt_VirtualSystemManagementService.c
c55d09
+++ b/src/Virt_VirtualSystemManagementService.c
c55d09
@@ -35,6 +35,7 @@
c55d09
 #include "cs_util.h"
c55d09
 #include "misc_util.h"
c55d09
 #include "device_parsing.h"
c55d09
+#include "capability_parsing.h"
c55d09
 #include "xmlgen.h"
c55d09
 
c55d09
 #include <libcmpiutil/libcmpiutil.h>
c55d09
@@ -388,59 +389,6 @@ static bool fv_set_emulator(struct domain *domain,
c55d09
         return true;
c55d09
 }
c55d09
 
c55d09
-static bool system_has_kvm(const char *pfx)
c55d09
-{
c55d09
-        CMPIStatus s;
c55d09
-        virConnectPtr conn = NULL;
c55d09
-        char *caps = NULL;
c55d09
-        bool disable_kvm = get_disable_kvm();
c55d09
-        xmlDocPtr doc = NULL;
c55d09
-        xmlNodePtr node = NULL;
c55d09
-        int len;
c55d09
-        bool kvm = false;
c55d09
-
c55d09
-        /* sometimes disable KVM to avoid problem in nested KVM */
c55d09
-        if (disable_kvm) {
c55d09
-                CU_DEBUG("Enter disable kvm mode!");
c55d09
-                goto out;
c55d09
-        }
c55d09
-
c55d09
-        conn = connect_by_classname(_BROKER, pfx, &s);
c55d09
-        if ((conn == NULL) || (s.rc != CMPI_RC_OK)) {
c55d09
-                goto out;
c55d09
-        }
c55d09
-
c55d09
-        caps = virConnectGetCapabilities(conn);
c55d09
-        if (caps != NULL) {
c55d09
-            len = strlen(caps) + 1;
c55d09
-
c55d09
-            doc = xmlParseMemory(caps, len);
c55d09
-            if (doc == NULL) {
c55d09
-                CU_DEBUG("xmlParseMemory() call failed!");
c55d09
-                goto out;
c55d09
-            }
c55d09
-
c55d09
-            node = xmlDocGetRootElement(doc);
c55d09
-            if (node == NULL) {
c55d09
-                CU_DEBUG("xmlDocGetRootElement() call failed!");
c55d09
-                goto out;
c55d09
-            }
c55d09
-
c55d09
-            if (has_kvm_domain_type(node)) {
c55d09
-                    CU_DEBUG("The system support kvm!");
c55d09
-                    kvm = true;
c55d09
-            }
c55d09
-        }
c55d09
-
c55d09
-out:
c55d09
-        free(caps);
c55d09
-        free(doc);
c55d09
-
c55d09
-        virConnectClose(conn);
c55d09
-
c55d09
-        return kvm;
c55d09
-}
c55d09
-
c55d09
 static int bootord_vssd_to_domain(CMPIInstance *inst,
c55d09
                                   struct domain *domain)
c55d09
 {
c55d09
@@ -511,53 +459,90 @@ static int bootord_vssd_to_domain(CMPIInstance *inst,
c55d09
 
c55d09
 static int fv_vssd_to_domain(CMPIInstance *inst,
c55d09
                              struct domain *domain,
c55d09
-                             const char *pfx)
c55d09
+                             const char *pfx,
c55d09
+                             virConnectPtr conn)
c55d09
 {
c55d09
-        int ret;
c55d09
+        int ret = 1;
c55d09
+        int retr;
c55d09
         const char *val;
c55d09
+        const char *domtype = NULL;
c55d09
+        const char *ostype = "hvm";
c55d09
+        struct capabilities *capsinfo = NULL;
c55d09
+
c55d09
+        get_capabilities(conn, &capsinfo);
c55d09
 
c55d09
         if (STREQC(pfx, "KVM")) {
c55d09
-                if (system_has_kvm(pfx))
c55d09
+                if (use_kvm(capsinfo)) {
c55d09
                         domain->type = DOMAIN_KVM;
c55d09
-                else
c55d09
+                        domtype = "kvm";
c55d09
+                } else {
c55d09
                         domain->type = DOMAIN_QEMU;
c55d09
+                        domtype = "qemu";
c55d09
+                }
c55d09
         } else if (STREQC(pfx, "Xen")) {
c55d09
                 domain->type = DOMAIN_XENFV;
c55d09
         } else {
c55d09
                 CU_DEBUG("Unknown fullvirt domain type: %s", pfx);
c55d09
-                return 0;
c55d09
+                ret = 0;
c55d09
+                goto out;
c55d09
         }
c55d09
 
c55d09
-        ret = bootord_vssd_to_domain(inst, domain);
c55d09
-        if (ret != 1)
c55d09
-                return 0;
c55d09
-
c55d09
-        ret = cu_get_str_prop(inst, "Emulator", &val;;
c55d09
-        if (ret != CMPI_RC_OK)
c55d09
-                val = NULL;
c55d09
-        else if (disk_type_from_file(val) == DISK_UNKNOWN) {
c55d09
-                CU_DEBUG("Emulator path does not exist: %s", val);
c55d09
-                return 0;
c55d09
+        retr = bootord_vssd_to_domain(inst, domain);
c55d09
+        if (retr != 1) {
c55d09
+                ret = 0;
c55d09
+                goto out;
c55d09
         }
c55d09
 
c55d09
-        if (!fv_set_emulator(domain, val))
c55d09
-                return 0;
c55d09
-
c55d09
         free(domain->os_info.fv.arch);
c55d09
-        ret = cu_get_str_prop(inst, "Arch", &val;;
c55d09
-        if (ret == CMPI_RC_OK)
c55d09
+        retr = cu_get_str_prop(inst, "Arch", &val;;
c55d09
+        if (retr != CMPI_RC_OK) {
c55d09
+                if (capsinfo != NULL) { /* set default */
c55d09
+                        val = get_default_arch(capsinfo, ostype);
c55d09
+                        CU_DEBUG("Set Arch to default: %s", val);
c55d09
+                } else
c55d09
+                        val = NULL;
c55d09
+        }
c55d09
+        if (val != NULL)
c55d09
                 domain->os_info.fv.arch = strdup(val);
c55d09
-        else
c55d09
-                domain->os_info.fv.arch = NULL;
c55d09
 
c55d09
         free(domain->os_info.fv.machine);
c55d09
-        ret = cu_get_str_prop(inst, "Machine", &val;;
c55d09
-        if (ret == CMPI_RC_OK)
c55d09
+        retr = cu_get_str_prop(inst, "Machine", &val;;
c55d09
+        if (retr != CMPI_RC_OK) {
c55d09
+                if (capsinfo != NULL && domtype != NULL) { /* set default */
c55d09
+                        val = get_default_machine(capsinfo, ostype,
c55d09
+                                                  domain->os_info.fv.arch,
c55d09
+                                                  domtype);
c55d09
+                        CU_DEBUG("Set Machine to default: %s", val);
c55d09
+                } else
c55d09
+                        val = NULL;
c55d09
+        }
c55d09
+        if (val != NULL)
c55d09
                 domain->os_info.fv.machine = strdup(val);
c55d09
-        else
c55d09
-                domain->os_info.fv.machine = NULL;
c55d09
 
c55d09
-        return 1;
c55d09
+        retr = cu_get_str_prop(inst, "Emulator", &val;;
c55d09
+        if (retr != CMPI_RC_OK) {
c55d09
+                if (capsinfo != NULL && domtype != NULL) { /* set default */
c55d09
+                        val = get_default_emulator(capsinfo, ostype,
c55d09
+                                                   domain->os_info.fv.arch,
c55d09
+                                                   domtype);
c55d09
+                        CU_DEBUG("Set Emulator to default: %s", val);
c55d09
+                } else
c55d09
+                        val = NULL;
c55d09
+        }
c55d09
+        if (val != NULL && disk_type_from_file(val) == DISK_UNKNOWN) {
c55d09
+                CU_DEBUG("Emulator path does not exist: %s", val);
c55d09
+                ret = 0;
c55d09
+                goto out;
c55d09
+        }
c55d09
+
c55d09
+        if (!fv_set_emulator(domain, val)) {
c55d09
+                ret = 0;
c55d09
+                goto out;
c55d09
+        }
c55d09
+
c55d09
+ out:
c55d09
+        cleanup_capabilities(&capsinfo);
c55d09
+        return ret;
c55d09
 }
c55d09
 
c55d09
 static int lxc_vssd_to_domain(CMPIInstance *inst,
c55d09
@@ -663,6 +648,8 @@ static int vssd_to_domain(CMPIInstance *inst,
c55d09
         bool bool_val;
c55d09
         bool fullvirt;
c55d09
         CMPIObjectPath *opathp = NULL;
c55d09
+        virConnectPtr conn = NULL;
c55d09
+        CMPIStatus s = { CMPI_RC_OK, NULL };
c55d09
 
c55d09
 
c55d09
         opathp = CMGetObjectPath(inst, NULL);
c55d09
@@ -748,9 +735,18 @@ static int vssd_to_domain(CMPIInstance *inst,
c55d09
                 }
c55d09
         }
c55d09
 
c55d09
-        if (fullvirt || STREQC(pfx, "KVM"))
c55d09
-                ret = fv_vssd_to_domain(inst, domain, pfx);
c55d09
-        else if (STREQC(pfx, "Xen"))
c55d09
+        if (fullvirt || STREQC(pfx, "KVM")) {
c55d09
+                conn = connect_by_classname(_BROKER, cn, &s);
c55d09
+                if (conn == NULL) {
c55d09
+                        cu_statusf(_BROKER, &s,
c55d09
+                                   CMPI_RC_ERR_FAILED,
c55d09
+                                   "Error connecting to libvirt");
c55d09
+                        ret = 0;
c55d09
+                        goto out;
c55d09
+                }
c55d09
+                ret = fv_vssd_to_domain(inst, domain, pfx, conn);
c55d09
+                virConnectClose(conn);
c55d09
+        } else if (STREQC(pfx, "Xen"))
c55d09
                 ret = xenpv_vssd_to_domain(inst, domain);
c55d09
         else if (STREQC(pfx, "LXC"))
c55d09
                 ret = lxc_vssd_to_domain(inst, domain);
c55d09
-- 
c55d09
2.1.0
c55d09