On 12/06/14 09:14, Eric Blake wrote:
The prior refactoring can now be put to use. With the same domain
as the previous commit (one qcow2 disk and an empty cdrom drive):
$ virsh domstats --block foo
Domain: 'foo'
block.count=2
block.0.name=hda
block.0.allocation=200704
block.0.capacity=42949672960
block.0.physical=200704
block.1.name=hdc
* src/qemu/qemu_driver.c (qemuStorageLimitsRefresh): Tweak
semantics of helper function.
(qemuDomainGetStatsBlock): Use it to report offline statistics.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/qemu/qemu_driver.c | 60 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 42 insertions(+), 18 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 404decd..723391b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10983,7 +10983,9 @@ qemuDomainMemoryPeek(virDomainPtr dom,
/* Refresh the capacity and allocation limits of a given storage
* source. Assumes that the caller has already obtained a domain job.
- * Set *activeFail to true if data cannot be obtained because a
+ * Pass NULL for path to skip any errors about an empty drive.
+ * Pass NULL for activeFail to skip any monitor attempt, otherwise,
Having a separate offline-only helper in this case would avoid us having
this argument as it would never touch the monitor.
+ * set *activeFail to true if data cannot be obtained because a
* transient guest is no longer active. */
static int
qemuStorageLimitsRefresh(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg,
@@ -11000,6 +11002,12 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
virQEMUDriverConfigPtr cfg,
char *buf = NULL;
ssize_t len;
+ if (!path) {
+ if (virStorageSourceIsEmpty(src))
+ return 0;
+ path = src->path;
+ }
Again, no need to pass path explicitly.
+
/* FIXME: For an offline domain, we always want to check current
* on-disk statistics (as users have been known to change offline
* images behind our backs). For a running domain, however, it
...
@@ -18530,6 +18542,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr
driver,
virHashTablePtr stats = NULL;
qemuDomainObjPrivatePtr priv = dom->privateData;
bool abbreviated = false;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) {
abbreviated = true; /* it's ok, just go ahead silently */
@@ -18555,8 +18568,18 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
if (abbreviated || !disk->info.alias ||
!(entry = virHashLookup(stats, disk->info.alias))) {
- /* FIXME: we could still look up sizing by sharing code
- * with qemuDomainGetBlockInfo */
+ if (qemuStorageLimitsRefresh(driver, cfg, dom,
+ disk, disk->src, NULL, NULL) < 0)
+ goto cleanup;
+ if (disk->src->allocation)
+ QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, i,
+ "allocation",
disk->src->allocation);
+ if (disk->src->capacity)
+ QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, i,
+ "capacity",
disk->src->capacity);
+ if (disk->src->physical)
+ QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, i,
+ "physical",
disk->src->physical);
continue;
}
This part looks good. Having stats for offline VMs might be useful.
@@ -18593,6 +18616,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
cleanup:
virHashFree(stats);
+ virObjectUnref(cfg);
return ret;
}
Peter