qemu: Convert qemuConnectGetAllDomainStats to use new helpers

Use the new domain list collection helpers to avoid going through
virDomainPtrs.

This additionally implements filter capability when called through the
api that accepts domain list filters.
This commit is contained in:
Peter Krempa 2015-04-29 16:41:20 +02:00
parent 83726a14d2
commit 85d8ede9eb

View File

@ -19807,26 +19807,25 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
unsigned int flags) unsigned int flags)
{ {
virQEMUDriverPtr driver = conn->privateData; virQEMUDriverPtr driver = conn->privateData;
virDomainPtr *domlist = NULL; virDomainObjPtr *vms = NULL;
virDomainObjPtr dom = NULL; virDomainObjPtr vm;
size_t nvms;
virDomainStatsRecordPtr *tmpstats = NULL; virDomainStatsRecordPtr *tmpstats = NULL;
bool enforce = !!(flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS); bool enforce = !!(flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS);
int ntempdoms;
int nstats = 0; int nstats = 0;
size_t i; size_t i;
int ret = -1; int ret = -1;
unsigned int privflags = 0; unsigned int privflags = 0;
unsigned int domflags = 0; unsigned int domflags = 0;
unsigned int lflags = flags & (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE |
VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT |
VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE);
if (ndoms) virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE |
virCheckFlags(VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING | VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT |
VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS, -1); VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE |
else VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING |
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE | VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS, -1);
VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT |
VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE |
VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING |
VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS, -1);
if (virConnectGetAllDomainStatsEnsureACL(conn) < 0) if (virConnectGetAllDomainStatsEnsureACL(conn) < 0)
return -1; return -1;
@ -19834,58 +19833,53 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
if (qemuDomainGetStatsCheckSupport(&stats, enforce) < 0) if (qemuDomainGetStatsCheckSupport(&stats, enforce) < 0)
return -1; return -1;
if (!ndoms) { if (ndoms) {
unsigned int lflags = flags & (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE | if (virDomainObjListConvert(driver->domains, conn, doms, ndoms, &vms,
VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT | &nvms, virConnectGetAllDomainStatsCheckACL,
VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE); lflags, true) < 0)
return -1;
if ((ntempdoms = virDomainObjListExport(driver->domains, } else {
conn, if (virDomainObjListCollect(driver->domains, conn, &vms, &nvms,
&domlist, virConnectGetAllDomainStatsCheckACL,
virConnectGetAllDomainStatsCheckACL, lflags) < 0)
lflags)) < 0) return -1;
goto cleanup;
ndoms = ntempdoms;
doms = domlist;
} }
if (VIR_ALLOC_N(tmpstats, ndoms + 1) < 0) if (VIR_ALLOC_N(tmpstats, nvms + 1) < 0)
goto cleanup; return -1;
if (qemuDomainGetStatsNeedMonitor(stats)) if (qemuDomainGetStatsNeedMonitor(stats))
privflags |= QEMU_DOMAIN_STATS_HAVE_JOB; privflags |= QEMU_DOMAIN_STATS_HAVE_JOB;
for (i = 0; i < ndoms; i++) { for (i = 0; i < nvms; i++) {
virDomainStatsRecordPtr tmp = NULL; virDomainStatsRecordPtr tmp = NULL;
domflags = 0; domflags = 0;
vm = vms[i];
if (!(dom = qemuDomObjFromDomain(doms[i]))) virObjectLock(vm);
continue;
if (doms != domlist &&
!virConnectGetAllDomainStatsCheckACL(conn, dom->def)) {
virDomainObjEndAPI(&dom);
continue;
}
if (HAVE_JOB(privflags) && if (HAVE_JOB(privflags) &&
qemuDomainObjBeginJob(driver, dom, QEMU_JOB_QUERY) == 0) qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) == 0)
domflags |= QEMU_DOMAIN_STATS_HAVE_JOB; domflags |= QEMU_DOMAIN_STATS_HAVE_JOB;
/* else: without a job it's still possible to gather some data */ /* else: without a job it's still possible to gather some data */
if (flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING) if (flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING)
domflags |= QEMU_DOMAIN_STATS_BACKING; domflags |= QEMU_DOMAIN_STATS_BACKING;
if (qemuDomainGetStats(conn, dom, stats, &tmp, domflags) < 0) if (qemuDomainGetStats(conn, vm, stats, &tmp, domflags) < 0) {
goto endjob; if (HAVE_JOB(domflags) && vm)
qemuDomainObjEndJob(driver, vm);
virObjectUnlock(vm);
goto cleanup;
}
if (tmp) if (tmp)
tmpstats[nstats++] = tmp; tmpstats[nstats++] = tmp;
if (HAVE_JOB(domflags)) if (HAVE_JOB(domflags))
qemuDomainObjEndJob(driver, dom); qemuDomainObjEndJob(driver, vm);
virDomainObjEndAPI(&dom); virObjectUnlock(vm);
} }
*retStats = tmpstats; *retStats = tmpstats;
@ -19893,15 +19887,9 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
ret = nstats; ret = nstats;
endjob:
if (HAVE_JOB(domflags) && dom)
qemuDomainObjEndJob(driver, dom);
cleanup: cleanup:
virDomainObjEndAPI(&dom);
virDomainStatsRecordListFree(tmpstats); virDomainStatsRecordListFree(tmpstats);
virObjectListFree(domlist); virObjectListFreeCount(vms, nvms);
return ret; return ret;
} }