mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-31 18:15:25 +00:00
cpu: Add list of allowed CPU models to virCPUGetHost
When creating host CPU definition usable with a given emulator, the CPU should not be defined using an unsupported CPU model. The new @models and @nmodels parameters can be used to limit CPU models which can be used in the result. Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
5677b9b336
commit
79a78c13ec
@ -50,7 +50,8 @@ virBhyveCapsInitCPU(virCapsPtr caps,
|
||||
if (nodeGetInfo(&nodeinfo))
|
||||
return -1;
|
||||
|
||||
if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo)))
|
||||
if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST,
|
||||
&nodeinfo, NULL, 0)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
@ -362,6 +362,8 @@ virCPUDataFree(virCPUDataPtr data)
|
||||
* @arch: CPU architecture
|
||||
* @type: requested type of the CPU
|
||||
* @nodeInfo: simplified CPU topology (optional)
|
||||
* @models: list of CPU models that can be considered for host CPU
|
||||
* @nmodels: number of CPU models in @models
|
||||
*
|
||||
* Create CPU definition describing the host's CPU.
|
||||
*
|
||||
@ -378,18 +380,26 @@ virCPUDataFree(virCPUDataPtr data)
|
||||
* host CPU model. In other words, a CPU definition containing just the
|
||||
* topology is a successful result even if detecting the host CPU model fails.
|
||||
*
|
||||
* It possible to limit the CPU model which may appear in the created CPU
|
||||
* definition by passing non-NULL @models list. This is useful when requesting
|
||||
* a CPU model usable on a specific hypervisor. If @models is NULL, any CPU
|
||||
* model known to libvirt may appear in the result.
|
||||
*
|
||||
* Returns host CPU definition or NULL on error.
|
||||
*/
|
||||
virCPUDefPtr
|
||||
virCPUGetHost(virArch arch,
|
||||
virCPUType type,
|
||||
virNodeInfoPtr nodeInfo)
|
||||
virNodeInfoPtr nodeInfo,
|
||||
const char **models,
|
||||
unsigned int nmodels)
|
||||
{
|
||||
struct cpuArchDriver *driver;
|
||||
virCPUDefPtr cpu = NULL;
|
||||
|
||||
VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p",
|
||||
virArchToString(arch), virCPUTypeToString(type), nodeInfo);
|
||||
VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p, models=%p, nmodels=%u",
|
||||
virArchToString(arch), virCPUTypeToString(type), nodeInfo,
|
||||
models, nmodels);
|
||||
|
||||
if (!(driver = cpuGetSubDriver(arch)))
|
||||
return NULL;
|
||||
@ -431,7 +441,8 @@ virCPUGetHost(virArch arch,
|
||||
* filled in.
|
||||
*/
|
||||
if (driver->getHost) {
|
||||
if (driver->getHost(cpu) < 0 && !nodeInfo)
|
||||
if (driver->getHost(cpu, models, nmodels) < 0 &&
|
||||
!nodeInfo)
|
||||
goto error;
|
||||
} else if (nodeInfo) {
|
||||
VIR_DEBUG("cannot detect host CPU model for %s architecture",
|
||||
|
@ -71,7 +71,9 @@ typedef void
|
||||
(*cpuArchDataFree) (virCPUDataPtr data);
|
||||
|
||||
typedef int
|
||||
(*virCPUArchGetHost)(virCPUDefPtr cpu);
|
||||
(*virCPUArchGetHost)(virCPUDefPtr cpu,
|
||||
const char **models,
|
||||
unsigned int nmodels);
|
||||
|
||||
typedef virCPUDefPtr
|
||||
(*cpuArchBaseline) (virCPUDefPtr *cpus,
|
||||
@ -171,7 +173,9 @@ virCPUDataFree(virCPUDataPtr data);
|
||||
virCPUDefPtr
|
||||
virCPUGetHost(virArch arch,
|
||||
virCPUType type,
|
||||
virNodeInfoPtr nodeInfo);
|
||||
virNodeInfoPtr nodeInfo,
|
||||
const char **models,
|
||||
unsigned int nmodels);
|
||||
|
||||
char *
|
||||
cpuBaselineXML(const char **xmlCPUs,
|
||||
|
@ -716,7 +716,9 @@ virCPUppc64DataFree(virCPUDataPtr data)
|
||||
|
||||
|
||||
static int
|
||||
virCPUppc64GetHost(virCPUDefPtr cpu)
|
||||
virCPUppc64GetHost(virCPUDefPtr cpu,
|
||||
const char **models,
|
||||
unsigned int nmodels)
|
||||
{
|
||||
virCPUDataPtr cpuData = NULL;
|
||||
virCPUppc64Data *data;
|
||||
@ -738,7 +740,7 @@ virCPUppc64GetHost(virCPUDefPtr cpu)
|
||||
#endif
|
||||
data->pvr[0].mask = 0xfffffffful;
|
||||
|
||||
ret = ppc64DriverDecode(cpu, cpuData, NULL, 0, NULL, 0);
|
||||
ret = ppc64DriverDecode(cpu, cpuData, models, nmodels, NULL, 0);
|
||||
|
||||
cleanup:
|
||||
virCPUppc64DataFree(cpuData);
|
||||
|
@ -2438,7 +2438,9 @@ cpuidSet(uint32_t base, virCPUDataPtr data)
|
||||
|
||||
|
||||
static int
|
||||
virCPUx86GetHost(virCPUDefPtr cpu)
|
||||
virCPUx86GetHost(virCPUDefPtr cpu,
|
||||
const char **models,
|
||||
unsigned int nmodels)
|
||||
{
|
||||
virCPUDataPtr cpuData = NULL;
|
||||
int ret = -1;
|
||||
@ -2450,7 +2452,7 @@ virCPUx86GetHost(virCPUDefPtr cpu)
|
||||
cpuidSet(CPUX86_EXTENDED, cpuData) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = x86DecodeCPUData(cpu, cpuData, NULL, 0, NULL, 0);
|
||||
ret = x86DecodeCPUData(cpu, cpuData, models, nmodels, NULL, 0);
|
||||
|
||||
cleanup:
|
||||
virCPUx86DataFree(cpuData);
|
||||
|
@ -1070,7 +1070,8 @@ virQEMUCapsInitCPU(virCapsPtr caps,
|
||||
if (nodeGetInfo(&nodeinfo))
|
||||
return -1;
|
||||
|
||||
if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo)))
|
||||
if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST,
|
||||
&nodeinfo, NULL, 0)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
@ -82,7 +82,8 @@ vmwareCapsInit(void)
|
||||
NULL, NULL, 0, NULL) == NULL)
|
||||
goto error;
|
||||
|
||||
if (!(cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST, NULL)))
|
||||
if (!(cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
|
||||
NULL, NULL, 0)))
|
||||
goto error;
|
||||
|
||||
/* x86_64 guests are supported if
|
||||
|
@ -130,7 +130,7 @@ vzBuildCapabilities(void)
|
||||
goto error;
|
||||
|
||||
if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
|
||||
&nodeinfo)))
|
||||
&nodeinfo, NULL, 0)))
|
||||
goto error;
|
||||
|
||||
if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user