Blob Blame History Raw
From d2d674cf41b0560e187cb836b81e3c5f9684c29c Mon Sep 17 00:00:00 2001
Message-Id: <d2d674cf41b0560e187cb836b81e3c5f9684c29c@dist-git>
From: Eric Blake <eblake@redhat.com>
Date: Wed, 17 Dec 2014 03:09:06 -0700
Subject: [PATCH] getstats: prepare for dynamic block.count stat

https://bugzilla.redhat.com/show_bug.cgi?id=1041569

A coming patch will make it optionally possible to list backing
chain block stats; in this mode of operation, block.counts is no
longer the number of <disks> in the domain, but the number of
blocks in the array being reported.  We still want block.count
listed first, but rather than iterate the tree twice (once to
count, and once to list stats), it's easier to just touch things
up after the fact.

* src/qemu/qemu_driver.c (qemuDomainGetStatsBlock): Compute count
after the fact.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 14ef1f62e3429face36ac1e6f5665e97e53a328d)

Conflicts:
	src/qemu/qemu_driver.c - no offline stats (commit 596a137)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_driver.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8376486..6be180e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18020,6 +18020,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
     virHashTablePtr stats = NULL;
     qemuDomainObjPrivatePtr priv = dom->privateData;
     bool abbreviated = false;
+    int count_index = -1;
 
     if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) {
         abbreviated = true; /* it's ok, just go ahead silently */
@@ -18036,7 +18037,11 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
         }
     }
 
-    QEMU_ADD_COUNT_PARAM(record, maxparams, "block", dom->def->ndisks);
+    /* When listing backing chains, it's easier to fix up the count
+     * after the iteration than it is to iterate twice; but we still
+     * want count listed first.  */
+    count_index = record->nparams;
+    QEMU_ADD_COUNT_PARAM(record, maxparams, "block", 0);
 
     for (i = 0; i < dom->def->ndisks; i++) {
         qemuBlockStats *entry;
@@ -18083,6 +18088,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 
     }
 
+    record->params[count_index].value.ui = i;
     ret = 0;
 
  cleanup:
-- 
2.2.0