提交 e20a11ee 编写于 作者: J Jiri Denemark

qemu: Copy CPU models in virQEMUCapsGetCPUDefinitions

Rather than returning a direct pointer the list stored in qemuCaps the
function now creates a new copy of the CPU models list.

The main purpose of this seemingly useless change is to update callers
to free the result returned by virQEMUCapsGetCPUDefinitions because the
internals of this function will change significantly in the following
patches.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 de0ad112
...@@ -139,6 +139,8 @@ struct _virDomainCapsCPUModels { ...@@ -139,6 +139,8 @@ struct _virDomainCapsCPUModels {
virDomainCapsCPUModelPtr models; virDomainCapsCPUModelPtr models;
}; };
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainCapsCPUModels, virObjectUnref);
typedef struct _virDomainCapsCPU virDomainCapsCPU; typedef struct _virDomainCapsCPU virDomainCapsCPU;
typedef virDomainCapsCPU *virDomainCapsCPUPtr; typedef virDomainCapsCPU *virDomainCapsCPUPtr;
struct _virDomainCapsCPU { struct _virDomainCapsCPU {
......
...@@ -1885,10 +1885,17 @@ virDomainCapsCPUModelsPtr ...@@ -1885,10 +1885,17 @@ virDomainCapsCPUModelsPtr
virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps, virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type) virDomainVirtType type)
{ {
virDomainCapsCPUModelsPtr cpuModels;
if (type == VIR_DOMAIN_VIRT_KVM) if (type == VIR_DOMAIN_VIRT_KVM)
return qemuCaps->kvmCPUModels; cpuModels = qemuCaps->kvmCPUModels;
else else
return qemuCaps->tcgCPUModels; cpuModels = qemuCaps->tcgCPUModels;
if (!cpuModels)
return NULL;
return virDomainCapsCPUModelsCopy(cpuModels);
} }
...@@ -3115,6 +3122,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps, ...@@ -3115,6 +3122,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
virCPUDefPtr cpu, virCPUDefPtr cpu,
bool migratable) bool migratable)
{ {
g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
virCPUDataPtr data = NULL; virCPUDataPtr data = NULL;
int ret = -1; int ret = -1;
...@@ -3124,7 +3132,9 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps, ...@@ -3124,7 +3132,9 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable))) if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable)))
goto cleanup; goto cleanup;
if (cpuDecode(cpu, data, virQEMUCapsGetCPUDefinitions(qemuCaps, type)) < 0) cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
if (cpuDecode(cpu, data, cpuModels) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
...@@ -3207,10 +3217,13 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, ...@@ -3207,10 +3217,13 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
if ((rc = virQEMUCapsInitCPUModel(qemuCaps, type, cpu, false)) < 0) { if ((rc = virQEMUCapsInitCPUModel(qemuCaps, type, cpu, false)) < 0) {
goto error; goto error;
} else if (rc == 1) { } else if (rc == 1) {
g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
VIR_DEBUG("No host CPU model info from QEMU; probing host CPU directly"); VIR_DEBUG("No host CPU model info from QEMU; probing host CPU directly");
hostCPU = virQEMUCapsProbeHostCPU(hostArch, cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
virQEMUCapsGetCPUDefinitions(qemuCaps, type)); hostCPU = virQEMUCapsProbeHostCPU(hostArch, cpuModels);
if (!hostCPU || if (!hostCPU ||
virCPUDefCopyModelFilter(cpu, hostCPU, true, virCPUDefCopyModelFilter(cpu, hostCPU, true,
virQEMUCapsCPUFilterFeatures, virQEMUCapsCPUFilterFeatures,
......
...@@ -13684,7 +13684,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, ...@@ -13684,7 +13684,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
g_autoptr(virQEMUCaps) qemuCaps = NULL; g_autoptr(virQEMUCaps) qemuCaps = NULL;
virArch arch; virArch arch;
virDomainVirtType virttype; virDomainVirtType virttype;
virDomainCapsCPUModelsPtr cpuModels; g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
bool migratable; bool migratable;
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
char *cpustr = NULL; char *cpustr = NULL;
......
...@@ -6040,6 +6040,8 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, ...@@ -6040,6 +6040,8 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
/* nothing to update for host-passthrough */ /* nothing to update for host-passthrough */
if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) { if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
if (def->cpu->check == VIR_CPU_CHECK_PARTIAL && if (def->cpu->check == VIR_CPU_CHECK_PARTIAL &&
virCPUCompare(caps->host.arch, virCPUCompare(caps->host.arch,
virQEMUCapsGetHostModel(qemuCaps, def->virtType, virQEMUCapsGetHostModel(qemuCaps, def->virtType,
...@@ -6052,8 +6054,9 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, ...@@ -6052,8 +6054,9 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0) VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
return -1; return -1;
if (virCPUTranslate(def->os.arch, def->cpu, cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType);
virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType)) < 0)
if (virCPUTranslate(def->os.arch, def->cpu, cpuModels) < 0)
return -1; return -1;
def->cpu->fallback = VIR_CPU_FALLBACK_FORBID; def->cpu->fallback = VIR_CPU_FALLBACK_FORBID;
......
...@@ -543,7 +543,6 @@ cpuTestGetCPUModels(const struct data *data, ...@@ -543,7 +543,6 @@ cpuTestGetCPUModels(const struct data *data,
return -1; return -1;
*models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM); *models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM);
virObjectRef(*models);
virObjectUnref(qemuCaps); virObjectUnref(qemuCaps);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册