From 56b21dfe0c12867fa1dc3715145a61017e6928f1 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 24 Nov 2014 17:12:30 -0700 Subject: [PATCH] getstats: start giving offline block stats I noticed that for an offline domain, 'virsh domstats --block $dom' was producing just the domain name, with no stats. But the older 'virsh domblkinfo' works just fine on offline domains. This patch starts to get us closer, by at least reporting the disk names for an offline domain. With this patch, I now see the following for an offline domain with one qcow2 disk and an empty cdrom drive: $ virsh domstats --block foo Domain: 'foo' block.count=2 block.0.name=hda block.1.name=hdc * src/qemu/qemu_driver.c (qemuDomainGetStatsBlock): Don't short-circuit output of block name. Signed-off-by: Eric Blake --- src/qemu/qemu_driver.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ed8e140790..d87ea98fd9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18495,19 +18495,20 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, int rc; virHashTablePtr stats = NULL; qemuDomainObjPrivatePtr priv = dom->privateData; + bool abbreviated = false; - if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) - return 0; /* it's ok, just go ahead silently */ + if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) { + abbreviated = true; /* it's ok, just go ahead silently */ + } else { + qemuDomainObjEnterMonitor(driver, dom); + rc = qemuMonitorGetAllBlockStatsInfo(priv->mon, &stats); + ignore_value(qemuMonitorBlockStatsUpdateCapacity(priv->mon, stats)); + qemuDomainObjExitMonitor(driver, dom); - qemuDomainObjEnterMonitor(driver, dom); - rc = qemuMonitorGetAllBlockStatsInfo(priv->mon, &stats); - ignore_value(qemuMonitorBlockStatsUpdateCapacity(priv->mon, stats)); - qemuDomainObjExitMonitor(driver, dom); - - if (rc < 0) { - virResetLastError(); - ret = 0; /* still ok, again go ahead silently */ - goto cleanup; + if (rc < 0) { + virResetLastError(); + abbreviated = true; /* still ok, again go ahead silently */ + } } QEMU_ADD_COUNT_PARAM(record, maxparams, "block", dom->def->ndisks); @@ -18518,9 +18519,12 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, QEMU_ADD_NAME_PARAM(record, maxparams, "block", i, disk->dst); - if (!disk->info.alias || - !(entry = virHashLookup(stats, disk->info.alias))) + if (abbreviated || !disk->info.alias || + !(entry = virHashLookup(stats, disk->info.alias))) { + /* FIXME: we could still look up sizing by sharing code + * with qemuDomainGetBlockInfo */ continue; + } QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, i, "rd.reqs", entry->rd_req);