qemu: Explicitly find disks for stats totals

Rather than totalling every entry from 'query-block' for stats provided
by qemuDomainBlocksStatsGather total only stats for known disks. This
will allow to return data for nodenames and qdevs in the same hash so
that we can use them with -blockdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2018-08-03 15:30:13 +02:00
parent 93fad53d3e
commit b222ce3075

View File

@ -11021,13 +11021,9 @@ qemuDomainBlockResize(virDomainPtr dom,
static int
qemuDomainBlockStatsGatherTotals(void *payload,
const void *name ATTRIBUTE_UNUSED,
void *opaque)
qemuDomainBlockStatsGatherTotals(qemuBlockStatsPtr data,
qemuBlockStatsPtr total)
{
qemuBlockStatsPtr data = payload;
qemuBlockStatsPtr total = opaque;
#define QEMU_BLOCK_STAT_TOTAL(NAME) \
if (data->NAME > 0) \
total->NAME += data->NAME
@ -11068,6 +11064,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk;
virHashTablePtr blockstats = NULL;
qemuBlockStatsPtr stats;
size_t i;
int nstats;
const char *entryname = NULL;
int ret = -1;
@ -11109,7 +11106,21 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
**retstats = *stats;
} else {
virHashForEach(blockstats, qemuDomainBlockStatsGatherTotals, *retstats);
for (i = 0; i < vm->def->ndisks; i++) {
disk = vm->def->disks[i];
entryname = disk->info.alias;
if (!entryname)
continue;
if (!(stats = virHashLookup(blockstats, entryname))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot find statistics for device '%s'"), entryname);
goto cleanup;
}
qemuDomainBlockStatsGatherTotals(stats, *retstats);
}
}
ret = nstats;