mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-08-23 05:50:03 +03:00
qemu: Refactor virQEMUCapsInitHostCPUModel
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
@ -3048,37 +3048,36 @@ virQEMUCapsCPUFilterFeatures(const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
/**
|
||||||
virQEMUCapsCopyCPUModelFromQEMU(virQEMUCapsPtr qemuCaps)
|
* Returns 0 when host CPU model provided by QEMU was filled in qemuCaps,
|
||||||
|
* 1 when the caller should fall back to using virCapsPtr->host.cpu,
|
||||||
|
* -1 on error.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
|
||||||
|
virCPUDefPtr cpu)
|
||||||
{
|
{
|
||||||
virCPUDefPtr cpu = NULL;
|
qemuMonitorCPUModelInfoPtr modelInfo = qemuCaps->hostCPUModelInfo;
|
||||||
qemuMonitorCPUModelInfoPtr modelInfo = NULL;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!(modelInfo = qemuCaps->hostCPUModelInfo)) {
|
if (!modelInfo) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("missing host CPU model info from QEMU capabilities"
|
_("missing host CPU model info from QEMU capabilities "
|
||||||
" for binary %s"), qemuCaps->binary);
|
"for binary %s"),
|
||||||
goto error;
|
qemuCaps->binary);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(cpu) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 ||
|
if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 ||
|
||||||
VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0)
|
VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0)
|
||||||
goto error;
|
return -1;
|
||||||
|
|
||||||
cpu->nfeatures_max = modelInfo->nprops;
|
cpu->nfeatures_max = modelInfo->nprops;
|
||||||
cpu->nfeatures = 0;
|
cpu->nfeatures = 0;
|
||||||
cpu->sockets = cpu->cores = cpu->threads = 0;
|
|
||||||
cpu->type = VIR_CPU_TYPE_GUEST;
|
|
||||||
cpu->mode = VIR_CPU_MODE_CUSTOM;
|
|
||||||
cpu->match = VIR_CPU_MATCH_EXACT;
|
|
||||||
|
|
||||||
for (i = 0; i < modelInfo->nprops; i++) {
|
for (i = 0; i < modelInfo->nprops; i++) {
|
||||||
if (VIR_STRDUP(cpu->features[i].name, modelInfo->props[i].name) < 0)
|
if (VIR_STRDUP(cpu->features[i].name, modelInfo->props[i].name) < 0)
|
||||||
goto error;
|
return -1;
|
||||||
|
|
||||||
if (modelInfo->props[i].supported)
|
if (modelInfo->props[i].supported)
|
||||||
cpu->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
|
cpu->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
|
||||||
@ -3088,30 +3087,52 @@ virQEMUCapsCopyCPUModelFromQEMU(virQEMUCapsPtr qemuCaps)
|
|||||||
cpu->nfeatures++;
|
cpu->nfeatures++;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemuCaps->hostCPUModel = cpu;
|
return 0;
|
||||||
return;
|
|
||||||
|
|
||||||
error:
|
|
||||||
virCPUDefFree(cpu);
|
|
||||||
qemuCaps->hostCPUModel = NULL;
|
|
||||||
virResetLastError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
/**
|
||||||
virQEMUCapsCopyCPUModelFromHost(virQEMUCapsPtr qemuCaps,
|
* Returns 0 when host CPU model provided by QEMU was filled in qemuCaps,
|
||||||
|
* 1 when the caller should fall back to using virCapsPtr->host.cpu,
|
||||||
|
* -1 on error.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
|
||||||
|
virCPUDefPtr cpu)
|
||||||
|
{
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
|
if (ARCH_IS_S390(qemuCaps->arch))
|
||||||
|
ret = virQEMUCapsInitCPUModelS390(qemuCaps, cpu);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
|
||||||
virCapsPtr caps)
|
virCapsPtr caps)
|
||||||
{
|
{
|
||||||
virCPUDefPtr cpu = NULL;
|
virCPUDefPtr cpu = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
|
||||||
|
return;
|
||||||
|
|
||||||
if (caps->host.cpu && caps->host.cpu->model) {
|
|
||||||
if (VIR_ALLOC(cpu) < 0)
|
if (VIR_ALLOC(cpu) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
cpu->sockets = cpu->cores = cpu->threads = 0;
|
|
||||||
cpu->type = VIR_CPU_TYPE_GUEST;
|
cpu->type = VIR_CPU_TYPE_GUEST;
|
||||||
cpu->mode = VIR_CPU_MODE_CUSTOM;
|
cpu->mode = VIR_CPU_MODE_CUSTOM;
|
||||||
cpu->match = VIR_CPU_MATCH_EXACT;
|
cpu->match = VIR_CPU_MATCH_EXACT;
|
||||||
|
cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
|
||||||
|
|
||||||
|
if ((rc = virQEMUCapsInitCPUModel(qemuCaps, cpu)) < 0) {
|
||||||
|
goto error;
|
||||||
|
} else if (rc == 1) {
|
||||||
|
VIR_DEBUG("No host CPU model info from QEMU; using host capabilities");
|
||||||
|
if (!caps->host.cpu || !caps->host.cpu->model)
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (virCPUDefCopyModelFilter(cpu, caps->host.cpu, true,
|
if (virCPUDefCopyModelFilter(cpu, caps->host.cpu, true,
|
||||||
virQEMUCapsCPUFilterFeatures,
|
virQEMUCapsCPUFilterFeatures,
|
||||||
@ -3124,30 +3145,10 @@ virQEMUCapsCopyCPUModelFromHost(virQEMUCapsPtr qemuCaps,
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
virCPUDefFree(cpu);
|
virCPUDefFree(cpu);
|
||||||
qemuCaps->hostCPUModel = NULL;
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
|
|
||||||
virCapsPtr caps)
|
|
||||||
{
|
|
||||||
if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (qemuCaps->arch) {
|
|
||||||
case VIR_ARCH_S390:
|
|
||||||
case VIR_ARCH_S390X:
|
|
||||||
virQEMUCapsCopyCPUModelFromQEMU(qemuCaps);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
virQEMUCapsCopyCPUModelFromHost(qemuCaps, caps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
|
virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
|
||||||
xmlXPathContextPtr ctxt)
|
xmlXPathContextPtr ctxt)
|
||||||
|
Reference in New Issue
Block a user