In qemuConnectGetAllDomainStats() there a loop that iterates over
all domains that stats are to be fetched for. Within this loop
the qemuDomainGetStats() is called which is responsible for
fetching stats for an individual domain. Now, the code that
handles successful and failure cases is almost the same. Rework
it, so that the code is deduplicated. Note, that the check for
!tmp is dropped because upon successful return from
qemuDomainGetStats() it is always allocated.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_driver.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f12a5aef11..6333d0af36 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18830,6 +18830,10 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
unsigned int privflags = 0;
unsigned int requestedStats = stats;
unsigned int domflags = 0;
+ int rc;
+
+ if (flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING)
+ domflags |= QEMU_DOMAIN_STATS_BACKING;
virObjectLock(vm);
@@ -18854,23 +18858,17 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
}
/* else: without a job it's still possible to gather some data */
- if (flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING)
- domflags |= QEMU_DOMAIN_STATS_BACKING;
- if (qemuDomainGetStats(conn, vm, requestedStats, &tmp, domflags) < 0) {
- if (HAVE_JOB(domflags) && vm)
- qemuDomainObjEndJob(driver, vm);
-
- virObjectUnlock(vm);
- goto cleanup;
- }
-
- if (tmp)
- tmpstats[nstats++] = tmp;
+ rc = qemuDomainGetStats(conn, vm, requestedStats, &tmp, domflags);
if (HAVE_JOB(domflags))
qemuDomainObjEndJob(driver, vm);
virObjectUnlock(vm);
+
+ if (rc < 0)
+ goto cleanup;
+
+ tmpstats[nstats++] = tmp;
}
*retStats = g_steal_pointer(&tmpstats);
--
2.32.0