提交 5677b9b3 编写于 作者: J Jiri Denemark

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: NJiri Denemark <jdenemar@redhat.com>
上级 23a3f5f5
...@@ -50,7 +50,7 @@ virBhyveCapsInitCPU(virCapsPtr caps, ...@@ -50,7 +50,7 @@ virBhyveCapsInitCPU(virCapsPtr caps,
if (nodeGetInfo(&nodeinfo)) if (nodeGetInfo(&nodeinfo))
return -1; return -1;
if (!(caps->host.cpu = virCPUGetHost(arch, &nodeinfo))) if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo)))
return -1; return -1;
return 0; return 0;
......
...@@ -360,9 +360,18 @@ virCPUDataFree(virCPUDataPtr data) ...@@ -360,9 +360,18 @@ virCPUDataFree(virCPUDataPtr data)
* virCPUGetHost: * virCPUGetHost:
* *
* @arch: CPU architecture * @arch: CPU architecture
* @type: requested type of the CPU
* @nodeInfo: simplified CPU topology (optional) * @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 * the CPU definition will have topology (sockets, cores, threads) filled in
* according to the content of @nodeInfo. The function fails only if @nodeInfo * 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 * was not passed in and the assigned CPU driver was not able to detect the
...@@ -373,13 +382,14 @@ virCPUDataFree(virCPUDataPtr data) ...@@ -373,13 +382,14 @@ virCPUDataFree(virCPUDataPtr data)
*/ */
virCPUDefPtr virCPUDefPtr
virCPUGetHost(virArch arch, virCPUGetHost(virArch arch,
virCPUType type,
virNodeInfoPtr nodeInfo) virNodeInfoPtr nodeInfo)
{ {
struct cpuArchDriver *driver; struct cpuArchDriver *driver;
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
VIR_DEBUG("arch=%s, nodeInfo=%p", VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p",
virArchToString(arch), nodeInfo); virArchToString(arch), virCPUTypeToString(type), nodeInfo);
if (!(driver = cpuGetSubDriver(arch))) if (!(driver = cpuGetSubDriver(arch)))
return NULL; return NULL;
...@@ -387,8 +397,29 @@ virCPUGetHost(virArch arch, ...@@ -387,8 +397,29 @@ virCPUGetHost(virArch arch,
if (VIR_ALLOC(cpu) < 0) if (VIR_ALLOC(cpu) < 0)
return NULL; return NULL;
cpu->arch = arch; switch (type) {
cpu->type = VIR_CPU_TYPE_HOST; 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) { if (nodeInfo) {
cpu->sockets = nodeInfo->sockets; cpu->sockets = nodeInfo->sockets;
......
...@@ -170,6 +170,7 @@ virCPUDataFree(virCPUDataPtr data); ...@@ -170,6 +170,7 @@ virCPUDataFree(virCPUDataPtr data);
virCPUDefPtr virCPUDefPtr
virCPUGetHost(virArch arch, virCPUGetHost(virArch arch,
virCPUType type,
virNodeInfoPtr nodeInfo); virNodeInfoPtr nodeInfo);
char * char *
......
...@@ -1070,7 +1070,7 @@ virQEMUCapsInitCPU(virCapsPtr caps, ...@@ -1070,7 +1070,7 @@ virQEMUCapsInitCPU(virCapsPtr caps,
if (nodeGetInfo(&nodeinfo)) if (nodeGetInfo(&nodeinfo))
return -1; return -1;
if (!(caps->host.cpu = virCPUGetHost(arch, &nodeinfo))) if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo)))
return -1; return -1;
return 0; return 0;
......
...@@ -82,7 +82,7 @@ vmwareCapsInit(void) ...@@ -82,7 +82,7 @@ vmwareCapsInit(void)
NULL, NULL, 0, NULL) == NULL) NULL, NULL, 0, NULL) == NULL)
goto error; goto error;
if (!(cpu = virCPUGetHost(caps->host.arch, NULL))) if (!(cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST, NULL)))
goto error; goto error;
/* x86_64 guests are supported if /* x86_64 guests are supported if
......
...@@ -129,7 +129,8 @@ vzBuildCapabilities(void) ...@@ -129,7 +129,8 @@ vzBuildCapabilities(void)
if (nodeGetInfo(&nodeinfo)) if (nodeGetInfo(&nodeinfo))
goto error; 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; goto error;
if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0) if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册