qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, Dong Xu Wang <wdongxu@linux.vnet.ibm.com>,
	stefanha@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 1/4] block: add image fragmentation statistics to qemu-img
Date: Wed,  7 Mar 2012 17:22:56 +0800	[thread overview]
Message-ID: <1331112179-12726-1-git-send-email-wdongxu@linux.vnet.ibm.com> (raw)

From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>

Discussion can be found at:
http://patchwork.ozlabs.org/patch/128730/

This patch add image fragmentation statistics while using qemu-img info.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
---
 block.c     |   13 +++++++++++++
 block.h     |    7 +++++++
 block_int.h |    1 +
 qemu-img.c  |    9 +++++++++
 4 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 52ffe14..947607b 100644
--- a/block.c
+++ b/block.c
@@ -2588,6 +2588,19 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return drv->bdrv_get_info(bs, bdi);
 }
 
+int bdrv_get_fragment(BlockDriverState *bs, BlockFragInfo *bfi)
+{
+    BlockDriver *drv = bs->drv;
+    if (!drv) {
+        return -ENOMEDIUM;
+    }
+    if (!drv->bdrv_get_fragment) {
+        return -ENOTSUP;
+    }
+    memset(bfi, 0, sizeof(*bfi));
+    return drv->bdrv_get_fragment(bs, bfi);
+}
+
 int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
                       int64_t pos, int size)
 {
diff --git a/block.h b/block.h
index 48d0bf3..d76d386 100644
--- a/block.h
+++ b/block.h
@@ -17,6 +17,12 @@ typedef struct BlockDriverInfo {
     int64_t vm_state_offset;
 } BlockDriverInfo;
 
+typedef struct BlockFragInfo {
+    uint64_t allocated_clusters;
+    uint64_t total_clusters;
+    uint64_t fragmented_clusters;
+} BlockFragInfo;
+
 typedef struct QEMUSnapshotInfo {
     char id_str[128]; /* unique snapshot id */
     /* the following fields are informative. They are not needed for
@@ -290,6 +296,7 @@ const char *bdrv_get_device_name(BlockDriverState *bs);
 int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
                           const uint8_t *buf, int nb_sectors);
 int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
+int bdrv_get_fragment(BlockDriverState *bs, BlockFragInfo *bfi);
 
 const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
 void bdrv_get_backing_filename(BlockDriverState *bs,
diff --git a/block_int.h b/block_int.h
index b460c36..339a5ac 100644
--- a/block_int.h
+++ b/block_int.h
@@ -179,6 +179,7 @@ struct BlockDriver {
     int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs,
                                   const char *snapshot_name);
     int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
+    int (*bdrv_get_fragment)(BlockDriverState *bs, BlockFragInfo *bdi);
 
     int (*bdrv_save_vmstate)(BlockDriverState *bs, const uint8_t *buf,
                              int64_t pos, int size);
diff --git a/qemu-img.c b/qemu-img.c
index 8df3564..17731a9 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1075,6 +1075,7 @@ static int img_info(int argc, char **argv)
     char backing_filename[1024];
     char backing_filename2[1024];
     BlockDriverInfo bdi;
+    BlockFragInfo bfi;
 
     fmt = NULL;
     for(;;) {
@@ -1126,6 +1127,14 @@ static int img_info(int argc, char **argv)
             printf("cluster_size: %d\n", bdi.cluster_size);
         }
     }
+    if (bdrv_get_fragment(bs, &bfi) >= 0) {
+        if (bfi.total_clusters != 0 && bfi.allocated_clusters != 0) {
+            printf("%lld/%lld = %0.2f%% allocated, %0.2f%% fragmented\n",
+                bfi.allocated_clusters, bfi.total_clusters,
+                bfi.allocated_clusters * 100.0 / bfi.total_clusters,
+                bfi.fragmented_clusters * 100.0 / bfi.allocated_clusters);
+        }
+    }
     bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename));
     if (backing_filename[0] != '\0') {
         path_combine(backing_filename2, sizeof(backing_filename2),
-- 
1.7.5.4

             reply	other threads:[~2012-03-07  9:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-07  9:22 Dong Xu Wang [this message]
2012-03-07  9:22 ` [Qemu-devel] [PATCH 2/4] block: image fragmentation statistics for qed Dong Xu Wang
2012-03-12 12:58   ` Stefan Hajnoczi
2012-03-07  9:22 ` [Qemu-devel] [PATCH 3/4 v2 RESEND] block: add dirty flag status to qemu-img Dong Xu Wang
2012-03-12 18:18   ` Stefan Hajnoczi
2012-03-13  9:03     ` Kevin Wolf
2012-03-13  9:33       ` Stefan Hajnoczi
2012-03-13 10:10         ` Kevin Wolf
2012-03-07  9:22 ` [Qemu-devel] [PATCH 4/4 v2 RESEND] block: track dirty flag status in qed Dong Xu Wang
2012-03-12 13:07 ` [Qemu-devel] [PATCH 1/4] block: add image fragmentation statistics to qemu-img Stefan Hajnoczi
2012-03-12 13:14   ` Kevin Wolf
2012-03-12 13:26     ` Stefan Hajnoczi
2012-03-12 13:36       ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1331112179-12726-1-git-send-email-wdongxu@linux.vnet.ibm.com \
    --to=wdongxu@linux.vnet.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).