]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Introduce virCPUProbeHost
authorMartin Kletzander <mkletzan@redhat.com>
Wed, 15 Mar 2017 08:07:38 +0000 (09:07 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Mon, 27 Mar 2017 11:13:29 +0000 (13:13 +0200)
Both QEMU and bhyve are using the same function for setting up the CPU
in virCapabilities, so de-duplicate it, save code and time, and help
other drivers adopt it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/bhyve/bhyve_capabilities.c
src/cpu/cpu.c
src/cpu/cpu.h
src/libvirt_private.syms
src/qemu/qemu_capabilities.c
src/vmware/vmware_conf.c

index f97834242d512c95012537effc1194ad67b4981d..875ee4ad5d2708e657af7f3cdd764f88d4f944b7 100644 (file)
 
 VIR_LOG_INIT("bhyve.bhyve_capabilities");
 
-static int
-virBhyveCapsInitCPU(virCapsPtr caps,
-                    virArch arch)
-{
-    virNodeInfo nodeinfo;
-
-    if (nodeGetInfo(&nodeinfo))
-        return -1;
-
-    if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST,
-                                         &nodeinfo, NULL, 0)))
-        return -1;
-
-    return 0;
-}
 
 virCapsPtr
 virBhyveCapsBuild(void)
@@ -77,8 +62,8 @@ virBhyveCapsBuild(void)
                                       NULL, NULL, 0, NULL) == NULL)
         goto error;
 
-    if (virBhyveCapsInitCPU(caps, virArchFromHost()) < 0)
-        VIR_WARN("Failed to get host CPU: %s", virGetLastErrorMessage());
+    if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch)))
+        VIR_WARN("Failed to get host CPU");
 
     return caps;
 
index 1461190bac2a08541804c4d5961ac65136ddbc1b..1bbc2b2f849e4c0d938ec8cd6bf49897a3fc82d8 100644 (file)
@@ -26,6 +26,7 @@
 #include "virlog.h"
 #include "viralloc.h"
 #include "virxml.h"
+#include "nodeinfo.h"
 #include "cpu.h"
 #include "cpu_map.h"
 #include "cpu_x86.h"
@@ -462,6 +463,18 @@ virCPUGetHost(virArch arch,
 }
 
 
+virCPUDefPtr
+virCPUProbeHost(virArch arch)
+{
+    virNodeInfo nodeinfo;
+
+    if (nodeGetInfo(&nodeinfo))
+        return NULL;
+
+    return virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo, NULL, 0);
+}
+
+
 /**
  * cpuBaselineXML:
  *
index d23409a4f0684499a47386d62f9ac16e89790508..c8e6b18463821000d19ac351aa05a0fd676b0ea5 100644 (file)
@@ -183,6 +183,9 @@ virCPUGetHost(virArch arch,
               const char **models,
               unsigned int nmodels);
 
+virCPUDefPtr
+virCPUProbeHost(virArch arch);
+
 char *
 cpuBaselineXML(const char **xmlCPUs,
                unsigned int ncpus,
index ec3deb4afcdaf31b057b69b42bac19339d615cd2..9dc374173212c3e3b67e781a00044f3aa2be9d8a 100644 (file)
@@ -1018,6 +1018,7 @@ virCPUDataNew;
 virCPUDataParse;
 virCPUGetHost;
 virCPUGetModels;
+virCPUProbeHost;
 virCPUTranslate;
 virCPUUpdate;
 virCPUUpdateLive;
index 9ac3d93c395341ca0b409afc5ade257f6ff2b5eb..3d00debc52c8941993ea782316d3ade8066f1fe9 100644 (file)
@@ -1067,19 +1067,6 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
 }
 
 
-static virCPUDefPtr
-virQEMUCapsProbeHostCPU(virCapsPtr caps)
-{
-    virNodeInfo nodeinfo;
-
-    if (nodeGetInfo(&nodeinfo))
-        return NULL;
-
-    return virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
-                         &nodeinfo, NULL, 0);
-}
-
-
 virCPUDefPtr
 virQEMUCapsProbeHostCPUForEmulator(virCapsPtr caps,
                                    virQEMUCapsPtr qemuCaps,
@@ -1142,7 +1129,7 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
 
-    if (!(caps->host.cpu = virQEMUCapsProbeHostCPU(caps)))
+    if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch)))
         VIR_WARN("Failed to get host CPU");
 
     /* Add the power management features of the host */
index 659c4737a30166870a52abe941959a8d4461f05b..0c2b0f4c0be3c654fbcc5947f33da019ef5218d9 100644 (file)
@@ -61,7 +61,6 @@ vmwareCapsInit(void)
 {
     virCapsPtr caps = NULL;
     virCapsGuestPtr guest = NULL;
-    virCPUDefPtr cpu = NULL;
 
     if ((caps = virCapabilitiesNew(virArchFromHost(),
                                    false, false)) == NULL)
@@ -81,9 +80,9 @@ vmwareCapsInit(void)
                                       VIR_DOMAIN_VIRT_VMWARE,
                                       NULL, NULL, 0, NULL) == NULL)
         goto error;
+    guest = NULL;
 
-    if (!(cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
-                              NULL, NULL, 0)))
+    if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch)))
         goto error;
 
     /* x86_64 guests are supported if
@@ -92,9 +91,9 @@ vmwareCapsInit(void)
      *  - Host CPU is x86_64 with virtualization extensions
      */
     if (caps->host.arch == VIR_ARCH_X86_64 ||
-        (virCPUCheckFeature(cpu->arch, cpu, "lm") &&
-         (virCPUCheckFeature(cpu->arch, cpu, "vmx") ||
-          virCPUCheckFeature(cpu->arch, cpu, "svm")))) {
+        (virCPUCheckFeature(caps->host.cpu->arch, caps->host.cpu, "lm") &&
+         (virCPUCheckFeature(caps->host.cpu->arch, caps->host.cpu, "vmx") ||
+          virCPUCheckFeature(caps->host.cpu->arch, caps->host.cpu, "svm")))) {
 
         if ((guest = virCapabilitiesAddGuest(caps,
                                              VIR_DOMAIN_OSTYPE_HVM,
@@ -109,7 +108,6 @@ vmwareCapsInit(void)
     }
 
  cleanup:
-    virCPUDefFree(cpu);
     return caps;
 
  error: