From d50996a548861a776aecc55694b466722181824c Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <chellwig@redhat.com>
Date: Thu, 8 Sep 2011 09:20:49 -0300
Subject: [RHEL6 qemu-kvm PATCH 4/6] block: include flush requests in info blockstats

RH-Author: Christoph Hellwig <chellwig@redhat.com>
Message-id: <20110908092049.GA32028@shell.devel.redhat.com>
Patchwork-id: 32519
O-Subject: [RHEL6.2 qemu PATCH 1/3] block: include flush requests in info blockstats
Bugzilla: 715017
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

Signed-off-by: Christoph Hellwig <hch@lst.de>
BZ: 715017
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block.c         |   18 +++++++++++++-----
 block_int.h     |    1 +
 qemu-monitor.hx |    6 ++++++
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/block.c b/block.c
index 24678cf..3a5de7a 100644
--- a/block.c
+++ b/block.c
@@ -1681,11 +1681,13 @@ static void bdrv_stats_iter(QObject *data, void *opaque)
                         " wr_bytes=%" PRId64
                         " rd_operations=%" PRId64
                         " wr_operations=%" PRId64
+                        " flush_operations=%" PRId64
                         "\n",
                         qdict_get_int(qdict, "rd_bytes"),
                         qdict_get_int(qdict, "wr_bytes"),
                         qdict_get_int(qdict, "rd_operations"),
-                        qdict_get_int(qdict, "wr_operations"));
+                        qdict_get_int(qdict, "wr_operations"),
+                        qdict_get_int(qdict, "flush_operations"));
 }
 
 void bdrv_stats_print(Monitor *mon, const QObject *data)
@@ -1703,11 +1705,15 @@ static QObject* bdrv_info_stats_bs(BlockDriverState *bs)
                              "'wr_bytes': %" PRId64 ","
                              "'rd_operations': %" PRId64 ","
                              "'wr_operations': %" PRId64 ","
-                             "'wr_highest_offset': %" PRId64
+                             "'wr_highest_offset': %" PRId64 ","
+                             "'flush_operations': %" PRId64
                              "} }",
-                             bs->rd_bytes, bs->wr_bytes,
-                             bs->rd_ops, bs->wr_ops,
-                             bs->wr_highest_sector * 512);
+                             bs->rd_bytes,
+                             bs->wr_bytes,
+                             bs->rd_ops,
+                             bs->wr_ops,
+                             bs->wr_highest_sector * 512,
+                             bs->flush_ops);
     dict  = qobject_to_qdict(res);
 
     if (*bs->device_name) {
@@ -2270,6 +2276,8 @@ BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs,
 {
     BlockDriver *drv = bs->drv;
 
+    bs->flush_ops++;
+
     if (bs->open_flags & BDRV_O_NO_FLUSH) {
         return bdrv_aio_noop_em(bs, cb, opaque);
     }
diff --git a/block_int.h b/block_int.h
index 25bc818..77e4211 100644
--- a/block_int.h
+++ b/block_int.h
@@ -178,6 +178,7 @@ struct BlockDriverState {
     uint64_t wr_bytes;
     uint64_t rd_ops;
     uint64_t wr_ops;
+    uint64_t flush_ops;
     uint64_t wr_highest_sector;
 
     /* Whether the disk can expand beyond total_sectors */
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index f8fe72c..6c09002 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -2195,6 +2195,7 @@ Each json-object contain the following:
     - "wr_bytes": bytes written (json-int)
     - "rd_operations": read operations (json-int)
     - "wr_operations": write operations (json-int)
+    - "flush_operations": cache flush operations (json-int)
     - "wr_highest_offset": Highest offset of a sector written since the
                            BlockDriverState has been opened (json-int)
 - "parent": Contains recursively the statistics of the underlying
@@ -2216,6 +2217,7 @@ Example:
                   "wr_operations":751,
                   "rd_bytes":122567168,
                   "rd_operations":36772
+                  "flush_operations":61,
                }
             },
             "stats":{
@@ -2224,6 +2226,7 @@ Example:
                "wr_operations":692,
                "rd_bytes":122739200,
                "rd_operations":36604
+               "flush_operations":51,
             }
          },
          {
@@ -2234,6 +2237,7 @@ Example:
                "wr_operations":0,
                "rd_bytes":0,
                "rd_operations":0
+               "flush_operations":0,
             }
          },
          {
@@ -2244,6 +2248,7 @@ Example:
                "wr_operations":0,
                "rd_bytes":0,
                "rd_operations":0
+               "flush_operations":0,
             }
          },
          {
@@ -2254,6 +2259,7 @@ Example:
                "wr_operations":0,
                "rd_bytes":0,
                "rd_operations":0
+               "flush_operations":0,
             }
          }
       ]
-- 
1.7.3.2

