mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
Introduce virCPUProbeHost
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>
This commit is contained in:
parent
532788a840
commit
272d78a5ef
@ -41,21 +41,6 @@
|
||||
|
||||
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;
|
||||
|
||||
|
@ -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:
|
||||
*
|
||||
|
@ -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,
|
||||
|
@ -1018,6 +1018,7 @@ virCPUDataNew;
|
||||
virCPUDataParse;
|
||||
virCPUGetHost;
|
||||
virCPUGetModels;
|
||||
virCPUProbeHost;
|
||||
virCPUTranslate;
|
||||
virCPUUpdate;
|
||||
virCPUUpdateLive;
|
||||
|
@ -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 */
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user