[libvirt] [PATCH 11/11] qemu: bulk stats: implement blockinfo group

Francesco Romani fromani at redhat.com
Fri Aug 29 07:15:32 UTC 2014


This patch implements the VIR_DOMAIN_STATS_BLOCK_INFO
group of statistics.

This is different from the VIR_DOMAIN_STATS_BLOCK
group because represents the information about the
block device.
Most notably, this group export the allocation information
which is used by monitoring applications to detect
the space exaustion on the block devices.

Signed-off-by: Francesco Romani <fromani at redhat.com>
---
 include/libvirt/libvirt.h.in |  1 +
 src/qemu/qemu_driver.c       | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 372e098..c0b695d 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2516,6 +2516,7 @@ typedef enum {
     VIR_DOMAIN_STATS_VCPU = (1 << 3), /* return domain virtual CPU info */
     VIR_DOMAIN_STATS_INTERFACE = (1 << 4), /* return domain interfaces info */
     VIR_DOMAIN_STATS_BLOCK = (1 << 5), /* return domain block info */
+    VIR_DOMAIN_STATS_BLOCK_INFO = (1 << 6), /* return domain block layout */
 } virDomainStatsTypes;
 
 typedef enum {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 344b02e..564f1e1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17604,6 +17604,49 @@ qemuDomainGetStatsBlock(virConnectPtr conn ATTRIBUTE_UNUSED,
 
 #undef QEMU_ADD_BLOCK_PARAM
 
+#define QEMU_ADD_BLOCK_INFO_PARAM(RECORD, MAXPARAMS, BLOCK, NAME, VALUE) \
+do { \
+    char param_name[NAME_MAX]; \
+    snprintf(param_name, NAME_MAX, "block.%s.%s", BLOCK, NAME); \
+    if (virTypedParamsAddULLong(&RECORD->params, \
+                                &RECORD->nparams, \
+                                MAXPARAMS, \
+                                param_name, \
+                                VALUE) < 0) \
+        return -1; \
+} while (0)
+
+static int
+qemuDomainGetStatsBlockInfo(virConnectPtr conn,
+                            virDomainObjPtr dom,
+                            virDomainStatsRecordPtr record,
+                            int *maxparams,
+                            unsigned int privflags ATTRIBUTE_UNUSED)
+{
+    virQEMUDriverPtr driver = conn->privateData;
+    virDomainBlockInfo info;
+    size_t i;
+
+    for (i = 0; i < dom->def->ndisks; i++) {
+        memset(&info, 0, sizeof(info));
+
+        if (qemuDiskGetBlockInfo(driver, dom, dom->def->disks[i],
+                                 dom->def->disks[i]->dst, &info) < 0)
+            continue;
+
+        QEMU_ADD_BLOCK_INFO_PARAM(record, maxparams, dom->def->disks[i]->dst,
+                                 "capacity", info.capacity);
+        QEMU_ADD_BLOCK_INFO_PARAM(record, maxparams, dom->def->disks[i]->dst,
+                                 "allocation", info.allocation);
+        QEMU_ADD_BLOCK_INFO_PARAM(record, maxparams, dom->def->disks[i]->dst,
+                                 "physical", info.physical);
+    }
+
+    return 0;
+}
+
+#undef QEMU_ADD_BLOCK_PARAM
+
 
 typedef int
 (*qemuDomainGetStatsFunc)(virConnectPtr conn,
@@ -17624,6 +17667,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
     { qemuDomainGetStatsVcpu, VIR_DOMAIN_STATS_VCPU },
     { qemuDomainGetStatsInterface, VIR_DOMAIN_STATS_INTERFACE },
     { qemuDomainGetStatsBlock, VIR_DOMAIN_STATS_BLOCK },
+    { qemuDomainGetStatsBlockInfo, VIR_DOMAIN_STATS_BLOCK_INFO },
     { NULL, 0 }
 };
 
-- 
1.9.3




More information about the libvir-list mailing list