virsh-domain.c: modernize cmdVcpuinfo()

Use g_auto* pointers to avoid the need for the cleanup label. The
type of the pointer 'virDomainPtr dom' was changed to its alias
'virshDomainPtr' to allow the use of g_autoptr().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Daniel Henrique Barboza 2020-06-26 19:10:41 -03:00 committed by Michal Privoznik
parent a3a628f54c
commit 9d31433483

View File

@ -6928,12 +6928,11 @@ static bool
cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd) cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainInfo info; virDomainInfo info;
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
virVcpuInfoPtr cpuinfo = NULL; g_autofree virVcpuInfoPtr cpuinfo = NULL;
unsigned char *cpumaps = NULL; g_autofree unsigned char *cpumaps = NULL;
int ncpus, maxcpu; int ncpus, maxcpu;
size_t cpumaplen; size_t cpumaplen;
bool ret = false;
bool pretty = vshCommandOptBool(cmd, "pretty"); bool pretty = vshCommandOptBool(cmd, "pretty");
int n; int n;
virshControlPtr priv = ctl->privData; virshControlPtr priv = ctl->privData;
@ -6942,10 +6941,10 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if ((maxcpu = virshNodeGetCPUCount(priv->conn)) < 0) if ((maxcpu = virshNodeGetCPUCount(priv->conn)) < 0)
goto cleanup; return false;
if (virDomainGetInfo(dom, &info) != 0) if (virDomainGetInfo(dom, &info) != 0)
goto cleanup; return false;
cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu); cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu);
cpumaplen = VIR_CPU_MAPLEN(maxcpu); cpumaplen = VIR_CPU_MAPLEN(maxcpu);
@ -6955,13 +6954,12 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
cpuinfo, info.nrVirtCpu, cpuinfo, info.nrVirtCpu,
cpumaps, cpumaplen)) < 0) { cpumaps, cpumaplen)) < 0) {
if (info.state != VIR_DOMAIN_SHUTOFF) if (info.state != VIR_DOMAIN_SHUTOFF)
goto cleanup; return false;
vshResetLibvirtError(); vshResetLibvirtError();
/* for offline VMs we can return pinning information */ /* for offline VMs we can return pinning information */
ret = virshVcpuinfoInactive(ctl, dom, maxcpu, pretty); return virshVcpuinfoInactive(ctl, dom, maxcpu, pretty);
goto cleanup;
} }
for (n = 0; n < ncpus; n++) { for (n = 0; n < ncpus; n++) {
@ -6979,19 +6977,13 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
if (virshVcpuinfoPrintAffinity(ctl, VIR_GET_CPUMAP(cpumaps, cpumaplen, n), if (virshVcpuinfoPrintAffinity(ctl, VIR_GET_CPUMAP(cpumaps, cpumaplen, n),
maxcpu, pretty) < 0) maxcpu, pretty) < 0)
goto cleanup; return false;
if (n < (ncpus - 1)) if (n < (ncpus - 1))
vshPrint(ctl, "\n"); vshPrint(ctl, "\n");
} }
ret = true; return true;
cleanup:
VIR_FREE(cpumaps);
VIR_FREE(cpuinfo);
virshDomainFree(dom);
return ret;
} }
/* /*