[libvirt] [PATCH 06/12] getstats: start giving offline block stats

Eric Blake eblake at redhat.com
Sat Dec 6 08:14:14 UTC 2014


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 <eblake at redhat.com>
---
 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 1e254bc..404decd 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18529,19 +18529,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);
@@ -18552,9 +18553,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);
-- 
1.9.3




More information about the libvir-list mailing list