9119d9
From d2d674cf41b0560e187cb836b81e3c5f9684c29c Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <d2d674cf41b0560e187cb836b81e3c5f9684c29c@dist-git>
9119d9
From: Eric Blake <eblake@redhat.com>
9119d9
Date: Wed, 17 Dec 2014 03:09:06 -0700
9119d9
Subject: [PATCH] getstats: prepare for dynamic block.count stat
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1041569
9119d9
9119d9
A coming patch will make it optionally possible to list backing
9119d9
chain block stats; in this mode of operation, block.counts is no
9119d9
longer the number of <disks> in the domain, but the number of
9119d9
blocks in the array being reported.  We still want block.count
9119d9
listed first, but rather than iterate the tree twice (once to
9119d9
count, and once to list stats), it's easier to just touch things
9119d9
up after the fact.
9119d9
9119d9
* src/qemu/qemu_driver.c (qemuDomainGetStatsBlock): Compute count
9119d9
after the fact.
9119d9
9119d9
Signed-off-by: Eric Blake <eblake@redhat.com>
9119d9
(cherry picked from commit 14ef1f62e3429face36ac1e6f5665e97e53a328d)
9119d9
9119d9
Conflicts:
9119d9
	src/qemu/qemu_driver.c - no offline stats (commit 596a137)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/qemu/qemu_driver.c | 8 +++++++-
9119d9
 1 file changed, 7 insertions(+), 1 deletion(-)
9119d9
9119d9
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
9119d9
index 8376486..6be180e 100644
9119d9
--- a/src/qemu/qemu_driver.c
9119d9
+++ b/src/qemu/qemu_driver.c
9119d9
@@ -18020,6 +18020,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
9119d9
     virHashTablePtr stats = NULL;
9119d9
     qemuDomainObjPrivatePtr priv = dom->privateData;
9119d9
     bool abbreviated = false;
9119d9
+    int count_index = -1;
9119d9
 
9119d9
     if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) {
9119d9
         abbreviated = true; /* it's ok, just go ahead silently */
9119d9
@@ -18036,7 +18037,11 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
9119d9
         }
9119d9
     }
9119d9
 
9119d9
-    QEMU_ADD_COUNT_PARAM(record, maxparams, "block", dom->def->ndisks);
9119d9
+    /* When listing backing chains, it's easier to fix up the count
9119d9
+     * after the iteration than it is to iterate twice; but we still
9119d9
+     * want count listed first.  */
9119d9
+    count_index = record->nparams;
9119d9
+    QEMU_ADD_COUNT_PARAM(record, maxparams, "block", 0);
9119d9
 
9119d9
     for (i = 0; i < dom->def->ndisks; i++) {
9119d9
         qemuBlockStats *entry;
9119d9
@@ -18083,6 +18088,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
9119d9
 
9119d9
     }
9119d9
 
9119d9
+    record->params[count_index].value.ui = i;
9119d9
     ret = 0;
9119d9
 
9119d9
  cleanup:
9119d9
-- 
9119d9
2.2.0
9119d9