cpu: Add virCPUType parameter to virCPUGetHost

The parameter can be used to request either VIR_CPU_TYPE_HOST (which has
been assumed so far) or VIR_CPU_TYPE_GUEST definition.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2017-03-07 11:38:38 +01:00
parent 23a3f5f50c
commit 5677b9b336
6 changed files with 42 additions and 9 deletions

View File

@ -50,7 +50,7 @@ virBhyveCapsInitCPU(virCapsPtr caps,
if (nodeGetInfo(&nodeinfo))
return -1;
if (!(caps->host.cpu = virCPUGetHost(arch, &nodeinfo)))
if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo)))
return -1;
return 0;

View File

@ -360,9 +360,18 @@ virCPUDataFree(virCPUDataPtr data)
* virCPUGetHost:
*
* @arch: CPU architecture
* @type: requested type of the CPU
* @nodeInfo: simplified CPU topology (optional)
*
* Create CPU definition describing the host's CPU. If @nodeInfo is not NULL,
* Create CPU definition describing the host's CPU.
*
* The @type (either VIR_CPU_TYPE_HOST or VIR_CPU_TYPE_GUEST) specifies what
* type of CPU definition should be created. Specifically, VIR_CPU_TYPE_HOST
* CPUs may contain only features without any policy attribute. Requesting
* VIR_CPU_TYPE_GUEST provides better results because the CPU is allowed to
* contain disabled features.
*
* If @nodeInfo is not NULL (which is only allowed for VIR_CPU_TYPE_HOST CPUs),
* the CPU definition will have topology (sockets, cores, threads) filled in
* according to the content of @nodeInfo. The function fails only if @nodeInfo
* was not passed in and the assigned CPU driver was not able to detect the
@ -373,13 +382,14 @@ virCPUDataFree(virCPUDataPtr data)
*/
virCPUDefPtr
virCPUGetHost(virArch arch,
virCPUType type,
virNodeInfoPtr nodeInfo)
{
struct cpuArchDriver *driver;
virCPUDefPtr cpu = NULL;
VIR_DEBUG("arch=%s, nodeInfo=%p",
virArchToString(arch), nodeInfo);
VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p",
virArchToString(arch), virCPUTypeToString(type), nodeInfo);
if (!(driver = cpuGetSubDriver(arch)))
return NULL;
@ -387,8 +397,29 @@ virCPUGetHost(virArch arch,
if (VIR_ALLOC(cpu) < 0)
return NULL;
cpu->arch = arch;
cpu->type = VIR_CPU_TYPE_HOST;
switch (type) {
case VIR_CPU_TYPE_HOST:
cpu->arch = arch;
cpu->type = type;
break;
case VIR_CPU_TYPE_GUEST:
if (nodeInfo) {
virReportError(VIR_ERR_INVALID_ARG,
_("cannot set topology for CPU type '%s'"),
virCPUTypeToString(type));
goto error;
}
cpu->type = type;
break;
case VIR_CPU_TYPE_AUTO:
case VIR_CPU_TYPE_LAST:
virReportError(VIR_ERR_INVALID_ARG,
_("unsupported CPU type: %s"),
virCPUTypeToString(type));
goto error;
}
if (nodeInfo) {
cpu->sockets = nodeInfo->sockets;

View File

@ -170,6 +170,7 @@ virCPUDataFree(virCPUDataPtr data);
virCPUDefPtr
virCPUGetHost(virArch arch,
virCPUType type,
virNodeInfoPtr nodeInfo);
char *

View File

@ -1070,7 +1070,7 @@ virQEMUCapsInitCPU(virCapsPtr caps,
if (nodeGetInfo(&nodeinfo))
return -1;
if (!(caps->host.cpu = virCPUGetHost(arch, &nodeinfo)))
if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo)))
return -1;
return 0;

View File

@ -82,7 +82,7 @@ vmwareCapsInit(void)
NULL, NULL, 0, NULL) == NULL)
goto error;
if (!(cpu = virCPUGetHost(caps->host.arch, NULL)))
if (!(cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST, NULL)))
goto error;
/* x86_64 guests are supported if

View File

@ -129,7 +129,8 @@ vzBuildCapabilities(void)
if (nodeGetInfo(&nodeinfo))
goto error;
if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, &nodeinfo)))
if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
&nodeinfo)))
goto error;
if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)