mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-28 07:25:17 +00:00
cpu_ppc64.c: use g_autoptr() whenever possible
Using g_autoptr() in virCPUDef pointers allows for more cleanups in ppc64Compute() and virCPUppc64Baseline() Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
c9491341af
commit
ddbff7e3ee
@ -421,15 +421,14 @@ ppc64Compute(virCPUDefPtr host,
|
|||||||
g_autoptr(virCPUppc64Map) map = NULL;
|
g_autoptr(virCPUppc64Map) map = NULL;
|
||||||
g_autoptr(virCPUppc64Model) host_model = NULL;
|
g_autoptr(virCPUppc64Model) host_model = NULL;
|
||||||
g_autoptr(virCPUppc64Model) guest_model = NULL;
|
g_autoptr(virCPUppc64Model) guest_model = NULL;
|
||||||
virCPUDefPtr cpu = NULL;
|
g_autoptr(virCPUDef) cpu = NULL;
|
||||||
virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR;
|
|
||||||
virArch arch;
|
virArch arch;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* Ensure existing configurations are handled correctly */
|
/* Ensure existing configurations are handled correctly */
|
||||||
if (!(cpu = virCPUDefCopy(other)) ||
|
if (!(cpu = virCPUDefCopy(other)) ||
|
||||||
virCPUppc64ConvertLegacy(cpu) < 0)
|
virCPUppc64ConvertLegacy(cpu) < 0)
|
||||||
goto cleanup;
|
return VIR_CPU_COMPARE_ERROR;
|
||||||
|
|
||||||
if (cpu->arch != VIR_ARCH_NONE) {
|
if (cpu->arch != VIR_ARCH_NONE) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
@ -448,8 +447,7 @@ ppc64Compute(virCPUDefPtr host,
|
|||||||
*message = g_strdup_printf(_("CPU arch %s does not match host arch"),
|
*message = g_strdup_printf(_("CPU arch %s does not match host arch"),
|
||||||
virArchToString(cpu->arch));
|
virArchToString(cpu->arch));
|
||||||
|
|
||||||
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
|
return VIR_CPU_COMPARE_INCOMPATIBLE;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
arch = cpu->arch;
|
arch = cpu->arch;
|
||||||
} else {
|
} else {
|
||||||
@ -466,16 +464,15 @@ ppc64Compute(virCPUDefPtr host,
|
|||||||
cpu->vendor);
|
cpu->vendor);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
|
return VIR_CPU_COMPARE_INCOMPATIBLE;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(map = ppc64LoadMap()))
|
if (!(map = ppc64LoadMap()))
|
||||||
goto cleanup;
|
return VIR_CPU_COMPARE_ERROR;
|
||||||
|
|
||||||
/* Host CPU information */
|
/* Host CPU information */
|
||||||
if (!(host_model = ppc64ModelFromCPU(host, map)))
|
if (!(host_model = ppc64ModelFromCPU(host, map)))
|
||||||
goto cleanup;
|
return VIR_CPU_COMPARE_ERROR;
|
||||||
|
|
||||||
if (cpu->type == VIR_CPU_TYPE_GUEST) {
|
if (cpu->type == VIR_CPU_TYPE_GUEST) {
|
||||||
/* Guest CPU information */
|
/* Guest CPU information */
|
||||||
@ -485,10 +482,8 @@ ppc64Compute(virCPUDefPtr host,
|
|||||||
/* host-model only:
|
/* host-model only:
|
||||||
* we need to take compatibility modes into account */
|
* we need to take compatibility modes into account */
|
||||||
tmp = ppc64CheckCompatibilityMode(host->model, cpu->model);
|
tmp = ppc64CheckCompatibilityMode(host->model, cpu->model);
|
||||||
if (tmp != VIR_CPU_COMPARE_IDENTICAL) {
|
if (tmp != VIR_CPU_COMPARE_IDENTICAL)
|
||||||
ret = tmp;
|
return tmp;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
G_GNUC_FALLTHROUGH;
|
G_GNUC_FALLTHROUGH;
|
||||||
|
|
||||||
case VIR_CPU_MODE_HOST_PASSTHROUGH:
|
case VIR_CPU_MODE_HOST_PASSTHROUGH:
|
||||||
@ -509,7 +504,7 @@ ppc64Compute(virCPUDefPtr host,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!guest_model)
|
if (!guest_model)
|
||||||
goto cleanup;
|
return VIR_CPU_COMPARE_ERROR;
|
||||||
|
|
||||||
if (STRNEQ(guest_model->name, host_model->name)) {
|
if (STRNEQ(guest_model->name, host_model->name)) {
|
||||||
VIR_DEBUG("host CPU model does not match required CPU model %s",
|
VIR_DEBUG("host CPU model does not match required CPU model %s",
|
||||||
@ -520,19 +515,14 @@ ppc64Compute(virCPUDefPtr host,
|
|||||||
guest_model->name);
|
guest_model->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = VIR_CPU_COMPARE_INCOMPATIBLE;
|
return VIR_CPU_COMPARE_INCOMPATIBLE;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guestData)
|
if (guestData)
|
||||||
if (!(*guestData = ppc64MakeCPUData(arch, &guest_model->data)))
|
if (!(*guestData = ppc64MakeCPUData(arch, &guest_model->data)))
|
||||||
goto cleanup;
|
return VIR_CPU_COMPARE_ERROR;
|
||||||
|
|
||||||
ret = VIR_CPU_COMPARE_IDENTICAL;
|
return VIR_CPU_COMPARE_IDENTICAL;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCPUDefFree(cpu);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static virCPUCompareResult
|
static virCPUCompareResult
|
||||||
@ -666,16 +656,16 @@ virCPUppc64Baseline(virCPUDefPtr *cpus,
|
|||||||
g_autoptr(virCPUppc64Map) map = NULL;
|
g_autoptr(virCPUppc64Map) map = NULL;
|
||||||
const virCPUppc64Model *model;
|
const virCPUppc64Model *model;
|
||||||
const virCPUppc64Vendor *vendor = NULL;
|
const virCPUppc64Vendor *vendor = NULL;
|
||||||
virCPUDefPtr cpu = NULL;
|
g_autoptr(virCPUDef) cpu = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!(map = ppc64LoadMap()))
|
if (!(map = ppc64LoadMap()))
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (!(model = ppc64ModelFind(map, cpus[0]->model))) {
|
if (!(model = ppc64ModelFind(map, cpus[0]->model))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unknown CPU model %s"), cpus[0]->model);
|
_("Unknown CPU model %s"), cpus[0]->model);
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ncpus; i++) {
|
for (i = 0; i < ncpus; i++) {
|
||||||
@ -695,7 +685,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus,
|
|||||||
if (STRNEQ(cpus[i]->model, model->name)) {
|
if (STRNEQ(cpus[i]->model, model->name)) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("CPUs are incompatible"));
|
_("CPUs are incompatible"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cpus[i]->vendor)
|
if (!cpus[i]->vendor)
|
||||||
@ -704,7 +694,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus,
|
|||||||
if (!(vnd = ppc64VendorFind(map, cpus[i]->vendor))) {
|
if (!(vnd = ppc64VendorFind(map, cpus[i]->vendor))) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("Unknown CPU vendor %s"), cpus[i]->vendor);
|
_("Unknown CPU vendor %s"), cpus[i]->vendor);
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model->vendor) {
|
if (model->vendor) {
|
||||||
@ -714,13 +704,13 @@ virCPUppc64Baseline(virCPUDefPtr *cpus,
|
|||||||
"vendor %s"),
|
"vendor %s"),
|
||||||
model->vendor->name, model->name,
|
model->vendor->name, model->name,
|
||||||
vnd->name);
|
vnd->name);
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else if (vendor) {
|
} else if (vendor) {
|
||||||
if (vendor != vnd) {
|
if (vendor != vnd) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("CPU vendors do not match"));
|
_("CPU vendors do not match"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vendor = vnd;
|
vendor = vnd;
|
||||||
@ -738,12 +728,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus,
|
|||||||
cpu->match = VIR_CPU_MATCH_EXACT;
|
cpu->match = VIR_CPU_MATCH_EXACT;
|
||||||
cpu->fallback = VIR_CPU_FALLBACK_FORBID;
|
cpu->fallback = VIR_CPU_FALLBACK_FORBID;
|
||||||
|
|
||||||
return cpu;
|
return g_steal_pointer(&cpu);
|
||||||
|
|
||||||
error:
|
|
||||||
virCPUDefFree(cpu);
|
|
||||||
cpu = NULL;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user