Patchwork [RFC,V5,50/62] qapi: Return virtual block device deduplication metrics in QMP

login
register
mail settings
Submitter Benoît Canet
Date Jan. 16, 2013, 3:48 p.m.
Message ID <1358351321-4891-51-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/212831/
State New
Headers show

Comments

Benoît Canet - Jan. 16, 2013, 3:48 p.m.
---
 block.c |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Patch

diff --git a/block.c b/block.c
index 4e28c55..a245653 100644
--- a/block.c
+++ b/block.c
@@ -2921,6 +2921,40 @@  BlockInfoList *qmp_query_block(Error **errp)
     return head;
 }
 
+static void bdrv_get_dedup_metrics(const BlockDriverState *bs,
+                                   BlockDeviceStats *stats)
+{
+    BlockDriverInfo bdi;
+
+    if (bdrv_get_info((BlockDriverState *) bs, &bdi) < 0) {
+        return;
+    }
+
+    if (!bdi.has_dedup) {
+        return;
+    }
+
+    stats->has_deduplication = true;
+    stats->deduplication = g_malloc0(sizeof(*stats->deduplication));
+    stats->deduplication->deduplicated_clusters =
+        bdi.dedup_metrics.deduplicated_clusters;
+    stats->deduplication->non_deduplicated_clusters =
+        bdi.dedup_metrics.non_deduplicated_clusters;
+    stats->deduplication->missing_data_reads =
+        bdi.dedup_metrics.missing_data_reads;
+    stats->deduplication->ram_hash_creations =
+        bdi.dedup_metrics.ram_hash_creations;
+    stats->deduplication->ram_hash_deletions =
+        bdi.dedup_metrics.ram_hash_deletions;
+    stats->deduplication->ram_usage =
+        bdi.dedup_metrics.ram_usage;
+    stats->deduplication->deleted_clusters =
+        bdi.dedup_metrics.deleted_clusters;
+    stats->deduplication->refcount_overflows =
+        bdi.dedup_metrics.refcount_overflows;
+    stats->deduplication->running = bdi.dedup_running;
+}
+
 BlockStats *bdrv_query_stats(const BlockDriverState *bs)
 {
     BlockStats *s;
@@ -2943,6 +2977,8 @@  BlockStats *bdrv_query_stats(const BlockDriverState *bs)
     s->stats->rd_total_time_ns = bs->total_time_ns[BDRV_ACCT_READ];
     s->stats->flush_total_time_ns = bs->total_time_ns[BDRV_ACCT_FLUSH];
 
+    bdrv_get_dedup_metrics(bs, s->stats);
+
     if (bs->file) {
         s->has_parent = true;
         s->parent = bdrv_query_stats(bs->file);