]> xenbits.xensource.com Git - libvirt.git/commitdiff
getstats: start giving offline block stats
authorEric Blake <eblake@redhat.com>
Tue, 25 Nov 2014 00:12:30 +0000 (17:12 -0700)
committerEric Blake <eblake@redhat.com>
Mon, 8 Dec 2014 18:55:12 +0000 (11:55 -0700)
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@redhat.com>
src/qemu/qemu_driver.c

index ed8e140790d0e972f1c344b6046316a964ecd101..d87ea98fd91f46e7cdc9d6ee86f23edef2f6dd8a 100644 (file)
@@ -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 */
-
-    qemuDomainObjEnterMonitor(driver, dom);
-    rc = qemuMonitorGetAllBlockStatsInfo(priv->mon, &stats);
-    ignore_value(qemuMonitorBlockStatsUpdateCapacity(priv->mon, stats));
-    qemuDomainObjExitMonitor(driver, dom);
+    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);
 
-    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);