Use the 'qdev' instead of the disk alias to lookup the stats and
transfer the capacity from the appropriate node name so that the
function works with -blockdev.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_driver.c | 48 +++++++++++++++++++++++++++++++++++++-----------
1 file changed, 37 insertions(+), 11 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a97235614b..dfb06bed80 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11063,11 +11063,13 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
qemuBlockStatsPtr *retstats)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- virDomainDiskDefPtr disk;
+ bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
+ virDomainDiskDefPtr disk = NULL;
virHashTablePtr blockstats = NULL;
qemuBlockStatsPtr stats;
size_t i;
int nstats;
+ int rc = 0;
const char *entryname = NULL;
int ret = -1;
@@ -11077,23 +11079,30 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
goto cleanup;
}
- if (!disk->info.alias) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("missing disk device alias name for %s"),
disk->dst);
- goto cleanup;
- }
+ if (blockdev) {
+ entryname = QEMU_DOMAIN_DISK_PRIVATE(disk)->backendQomName;
+ } else {
+ if (!disk->info.alias) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("missing disk device alias name for %s"),
disk->dst);
+ goto cleanup;
+ }
- entryname = disk->info.alias;
+ entryname = disk->info.alias;
+ }
}
qemuDomainObjEnterMonitor(driver, vm);
nstats = qemuMonitorGetAllBlockStatsInfo(priv->mon, &blockstats, false);
- if (capacity && nstats >= 0 &&
- qemuMonitorBlockStatsUpdateCapacity(priv->mon, blockstats, false) < 0)
- nstats = -1;
+ if (capacity && nstats >= 0) {
+ if (blockdev)
+ rc = qemuMonitorBlockStatsUpdateCapacityBlockdev(priv->mon, blockstats);
+ else
+ rc = qemuMonitorBlockStatsUpdateCapacity(priv->mon, blockstats, false);
+ }
- if (qemuDomainObjExitMonitor(driver, vm) < 0 || nstats < 0)
+ if (qemuDomainObjExitMonitor(driver, vm) < 0 || nstats < 0 || rc < 0)
goto cleanup;
if (VIR_ALLOC(*retstats) < 0)
@@ -11106,12 +11115,29 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
goto cleanup;
}
+ if (blockdev) {
+ /* capacity are reported only per node-name so we need to transfer them */
+ qemuBlockStatsPtr capstats;
+
+ if (disk && disk->src &&
+ (capstats = virHashLookup(blockstats, disk->src->nodeformat))) {
+ (*retstats)->capacity = capstats->capacity;
+ (*retstats)->physical = capstats->physical;
+ (*retstats)->wr_highest_offset = capstats->wr_highest_offset;
+ (*retstats)->wr_highest_offset_valid =
capstats->wr_highest_offset_valid;
+ (*retstats)->write_threshold = capstats->write_threshold;
+ }
+ }
+
**retstats = *stats;
} else {
for (i = 0; i < vm->def->ndisks; i++) {
disk = vm->def->disks[i];
entryname = disk->info.alias;
+ if (blockdev)
+ entryname = QEMU_DOMAIN_DISK_PRIVATE(disk)->backendQomName;
+
if (!entryname)
continue;
--
2.16.2