Split out the code which converts the stats gathered in qemuDomainGetStatsBlock into typed parameters so that it will look less ugly when extending it. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 73 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b0ac5e536b..ddd991546a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20164,6 +20164,51 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver, } +static int +qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk, + virHashTablePtr stats, + virHashTablePtr nodestats, + virDomainStatsRecordPtr records, + int *nrecords, + size_t *recordnr, + bool visitBacking, + virQEMUDriverPtr driver, + virQEMUDriverConfigPtr cfg, + virDomainObjPtr dom) + +{ + char *alias = NULL; + virStorageSourcePtr src = disk->src; + int ret = -1; + + while (virStorageSourceIsBacking(src) && + (src == disk->src || visitBacking)) { + + /* alias may be NULL if the VM is not running */ + if (disk->info.alias && + !(alias = qemuDomainStorageAlias(disk->info.alias, src->id))) + goto cleanup; + + qemuDomainGetStatsOneBlockRefreshNamed(src, alias, stats, nodestats); + + if (qemuDomainGetStatsOneBlock(driver, cfg, dom, records, nrecords, + disk->dst, alias, src, *recordnr, + stats) < 0) + goto cleanup; + + VIR_FREE(alias); + (*recordnr)++; + src = src->backingStore; + } + + ret = 0; + + cleanup: + VIR_FREE(alias); + return ret; +} + + static int qemuDomainGetStatsBlock(virQEMUDriverPtr driver, virDomainObjPtr dom, @@ -20184,7 +20229,6 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, int count_index = -1; size_t visited = 0; bool visitBacking = !!(privflags & QEMU_DOMAIN_STATS_BACKING); - char *alias = NULL; if (HAVE_JOB(privflags) && virDomainObjIsActive(dom)) { qemuDomainObjEnterMonitor(driver, dom); @@ -20216,35 +20260,16 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, QEMU_ADD_COUNT_PARAM(record, maxparams, "block", 0); for (i = 0; i < dom->def->ndisks; i++) { - virDomainDiskDefPtr disk = dom->def->disks[i]; - virStorageSourcePtr src = disk->src; - - while (virStorageSourceIsBacking(src) && - (src == disk->src || visitBacking)) { - - /* alias may be NULL if the VM is not running */ - if (disk->info.alias && - !(alias = qemuDomainStorageAlias(disk->info.alias, src->id))) - goto cleanup; - - qemuDomainGetStatsOneBlockRefreshNamed(src, alias, stats, nodestats); - - if (qemuDomainGetStatsOneBlock(driver, cfg, dom, record, maxparams, - disk->dst, alias, src, visited, - stats) < 0) - goto cleanup; - - VIR_FREE(alias); - visited++; - src = src->backingStore; - } + if (qemuDomainGetStatsBlockExportDisk(dom->def->disks[i], stats, nodestats, + record, maxparams, &visited, + visitBacking, driver, cfg, dom) < 0) + goto cleanup; } record->params[count_index].value.ui = visited; ret = 0; cleanup: - VIR_FREE(alias); virHashFree(stats); virHashFree(nodestats); virJSONValueFree(nodedata); -- 2.16.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list