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 2/4] block: image fragmentation statistics for qed
Date: Wed,  7 Mar 2012 17:22:57 +0800	[thread overview]
Message-ID: <1331112179-12726-2-git-send-email-wdongxu@linux.vnet.ibm.com> (raw)
In-Reply-To: <1331112179-12726-1-git-send-email-wdongxu@linux.vnet.ibm.com>

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

Add fragmentation statistics for qed file format.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
---
 block/qed.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index a041d31..eb4dd90 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1444,6 +1444,46 @@ static int bdrv_qed_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return 0;
 }
 
+static int bdrv_qed_get_fragment(BlockDriverState *bs, BlockFragInfo *bfi)
+{
+    BDRVQEDState *s = bs->opaque;
+    uint32_t cluster_size = s->header.cluster_size;
+    uint64_t table_noffsets = s->header.table_size * cluster_size / sizeof(uint64_t);
+    uint64_t i, j;
+    uint64_t l2_offset;
+    int ret = 0;
+    uint64_t last_offset = 0;
+    uint64_t size = s->header.table_size * cluster_size;
+    uint64_t *table = qemu_blockalign(s->bs, size);
+
+    for (i = 0; i < table_noffsets; i++) {
+        l2_offset = s->l1_table->offsets[i];
+        if (l2_offset == 0) {
+            continue;
+        }
+        ret = bdrv_pread(bs->file, l2_offset, table, size);
+        if (ret < 0) {
+            qemu_vfree(table);
+            return ret;
+        }
+        for (j = 0; j < size/sizeof(uint64_t); j++) {
+            uint64_t *offset = (uint64_t *)(table + j);
+            if (*offset < cluster_size) {
+                continue;
+            }
+            bfi->allocated_clusters++;
+            if (last_offset && (last_offset + cluster_size) != *offset) {
+                bfi->fragmented_clusters++;
+            }
+            last_offset = *offset;
+        }
+    }
+    bfi->total_clusters = (s->header.image_size + s->header.cluster_size - 1) /
+                        s->header.cluster_size;
+    qemu_vfree(table);
+    return ret;
+}
+
 static int bdrv_qed_change_backing_file(BlockDriverState *bs,
                                         const char *backing_file,
                                         const char *backing_fmt)
@@ -1569,6 +1609,7 @@ static BlockDriver bdrv_qed = {
     .bdrv_get_info            = bdrv_qed_get_info,
     .bdrv_change_backing_file = bdrv_qed_change_backing_file,
     .bdrv_check               = bdrv_qed_check,
+    .bdrv_get_fragment        = bdrv_qed_get_fragment,
 };
 
 static void bdrv_qed_init(void)
-- 
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 [Qemu-devel] [PATCH 1/4] block: add image fragmentation statistics to qemu-img Dong Xu Wang
2012-03-07  9:22 ` Dong Xu Wang [this message]
2012-03-12 12:58   ` [Qemu-devel] [PATCH 2/4] block: image fragmentation statistics for qed 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-2-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).