mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-05 12:35:20 +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))
|
if (nodeGetInfo(&nodeinfo))
|
||||||
return -1;
|
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 -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -362,6 +362,8 @@ virCPUDataFree(virCPUDataPtr data)
|
|||||||
* @arch: CPU architecture
|
* @arch: CPU architecture
|
||||||
* @type: requested type of the CPU
|
* @type: requested type of the CPU
|
||||||
* @nodeInfo: simplified CPU topology (optional)
|
* @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.
|
* 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
|
* 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.
|
* 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.
|
* Returns host CPU definition or NULL on error.
|
||||||
*/
|
*/
|
||||||
virCPUDefPtr
|
virCPUDefPtr
|
||||||
virCPUGetHost(virArch arch,
|
virCPUGetHost(virArch arch,
|
||||||
virCPUType type,
|
virCPUType type,
|
||||||
virNodeInfoPtr nodeInfo)
|
virNodeInfoPtr nodeInfo,
|
||||||
|
const char **models,
|
||||||
|
unsigned int nmodels)
|
||||||
{
|
{
|
||||||
struct cpuArchDriver *driver;
|
struct cpuArchDriver *driver;
|
||||||
virCPUDefPtr cpu = NULL;
|
virCPUDefPtr cpu = NULL;
|
||||||
|
|
||||||
VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p",
|
VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p, models=%p, nmodels=%u",
|
||||||
virArchToString(arch), virCPUTypeToString(type), nodeInfo);
|
virArchToString(arch), virCPUTypeToString(type), nodeInfo,
|
||||||
|
models, nmodels);
|
||||||
|
|
||||||
if (!(driver = cpuGetSubDriver(arch)))
|
if (!(driver = cpuGetSubDriver(arch)))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -431,7 +441,8 @@ virCPUGetHost(virArch arch,
|
|||||||
* filled in.
|
* filled in.
|
||||||
*/
|
*/
|
||||||
if (driver->getHost) {
|
if (driver->getHost) {
|
||||||
if (driver->getHost(cpu) < 0 && !nodeInfo)
|
if (driver->getHost(cpu, models, nmodels) < 0 &&
|
||||||
|
!nodeInfo)
|
||||||
goto error;
|
goto error;
|
||||||
} else if (nodeInfo) {
|
} else if (nodeInfo) {
|
||||||
VIR_DEBUG("cannot detect host CPU model for %s architecture",
|
VIR_DEBUG("cannot detect host CPU model for %s architecture",
|
||||||
|
@ -71,7 +71,9 @@ typedef void
|
|||||||
(*cpuArchDataFree) (virCPUDataPtr data);
|
(*cpuArchDataFree) (virCPUDataPtr data);
|
||||||
|
|
||||||
typedef int
|
typedef int
|
||||||
(*virCPUArchGetHost)(virCPUDefPtr cpu);
|
(*virCPUArchGetHost)(virCPUDefPtr cpu,
|
||||||
|
const char **models,
|
||||||
|
unsigned int nmodels);
|
||||||
|
|
||||||
typedef virCPUDefPtr
|
typedef virCPUDefPtr
|
||||||
(*cpuArchBaseline) (virCPUDefPtr *cpus,
|
(*cpuArchBaseline) (virCPUDefPtr *cpus,
|
||||||
@ -171,7 +173,9 @@ virCPUDataFree(virCPUDataPtr data);
|
|||||||
virCPUDefPtr
|
virCPUDefPtr
|
||||||
virCPUGetHost(virArch arch,
|
virCPUGetHost(virArch arch,
|
||||||
virCPUType type,
|
virCPUType type,
|
||||||
virNodeInfoPtr nodeInfo);
|
virNodeInfoPtr nodeInfo,
|
||||||
|
const char **models,
|
||||||
|
unsigned int nmodels);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
cpuBaselineXML(const char **xmlCPUs,
|
cpuBaselineXML(const char **xmlCPUs,
|
||||||
|
@ -716,7 +716,9 @@ virCPUppc64DataFree(virCPUDataPtr data)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virCPUppc64GetHost(virCPUDefPtr cpu)
|
virCPUppc64GetHost(virCPUDefPtr cpu,
|
||||||
|
const char **models,
|
||||||
|
unsigned int nmodels)
|
||||||
{
|
{
|
||||||
virCPUDataPtr cpuData = NULL;
|
virCPUDataPtr cpuData = NULL;
|
||||||
virCPUppc64Data *data;
|
virCPUppc64Data *data;
|
||||||
@ -738,7 +740,7 @@ virCPUppc64GetHost(virCPUDefPtr cpu)
|
|||||||
#endif
|
#endif
|
||||||
data->pvr[0].mask = 0xfffffffful;
|
data->pvr[0].mask = 0xfffffffful;
|
||||||
|
|
||||||
ret = ppc64DriverDecode(cpu, cpuData, NULL, 0, NULL, 0);
|
ret = ppc64DriverDecode(cpu, cpuData, models, nmodels, NULL, 0);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCPUppc64DataFree(cpuData);
|
virCPUppc64DataFree(cpuData);
|
||||||
|
@ -2438,7 +2438,9 @@ cpuidSet(uint32_t base, virCPUDataPtr data)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virCPUx86GetHost(virCPUDefPtr cpu)
|
virCPUx86GetHost(virCPUDefPtr cpu,
|
||||||
|
const char **models,
|
||||||
|
unsigned int nmodels)
|
||||||
{
|
{
|
||||||
virCPUDataPtr cpuData = NULL;
|
virCPUDataPtr cpuData = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -2450,7 +2452,7 @@ virCPUx86GetHost(virCPUDefPtr cpu)
|
|||||||
cpuidSet(CPUX86_EXTENDED, cpuData) < 0)
|
cpuidSet(CPUX86_EXTENDED, cpuData) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = x86DecodeCPUData(cpu, cpuData, NULL, 0, NULL, 0);
|
ret = x86DecodeCPUData(cpu, cpuData, models, nmodels, NULL, 0);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCPUx86DataFree(cpuData);
|
virCPUx86DataFree(cpuData);
|
||||||
|
@ -1070,7 +1070,8 @@ virQEMUCapsInitCPU(virCapsPtr caps,
|
|||||||
if (nodeGetInfo(&nodeinfo))
|
if (nodeGetInfo(&nodeinfo))
|
||||||
return -1;
|
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 -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -82,7 +82,8 @@ vmwareCapsInit(void)
|
|||||||
NULL, NULL, 0, NULL) == NULL)
|
NULL, NULL, 0, NULL) == NULL)
|
||||||
goto error;
|
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;
|
goto error;
|
||||||
|
|
||||||
/* x86_64 guests are supported if
|
/* x86_64 guests are supported if
|
||||||
|
@ -130,7 +130,7 @@ vzBuildCapabilities(void)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
|
if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
|
||||||
&nodeinfo)))
|
&nodeinfo, NULL, 0)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
|
if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user