Patchwork [v2,4/5] qemu-img: add compressed clusters to BlockFragInfo

login
register
mail settings
Submitter Stefan Hajnoczi
Date Feb. 6, 2013, 10:58 a.m.
Message ID <1360148318-26988-5-git-send-email-stefanha@redhat.com>
Download mbox | patch
Permalink /patch/218552/
State New
Headers show

Comments

Stefan Hajnoczi - Feb. 6, 2013, 10:58 a.m.
Show how many clusters are compressed.  This can be used to monitor how
many compressed clusters remain and whether to recompress the image.

Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/block/block.h        | 1 +
 qemu-img.c                   | 5 +++--
 tests/qemu-iotests/026       | 6 +++---
 tests/qemu-iotests/036       | 2 +-
 tests/qemu-iotests/039       | 2 +-
 tests/qemu-iotests/044.out   | 1 +
 tests/qemu-iotests/common.rc | 6 +++---
 7 files changed, 13 insertions(+), 10 deletions(-)

Patch

diff --git a/include/block/block.h b/include/block/block.h
index 5c3b911..24db852 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -24,6 +24,7 @@  typedef struct BlockFragInfo {
     uint64_t allocated_clusters;
     uint64_t total_clusters;
     uint64_t fragmented_clusters;
+    uint64_t compressed_clusters;
 } BlockFragInfo;
 
 typedef struct QEMUSnapshotInfo {
diff --git a/qemu-img.c b/qemu-img.c
index 167d65f..fc98a93 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -471,10 +471,11 @@  static int img_check(int argc, char **argv)
 
     if (bfi->total_clusters != 0 && bfi->allocated_clusters != 0) {
         printf("%" PRId64 "/%" PRId64 "= %0.2f%% allocated, "
-               "%0.2f%% fragmented\n",
+               "%0.2f%% fragmented, %0.2f%% compressed clusters\n",
                bfi->allocated_clusters, bfi->total_clusters,
                bfi->allocated_clusters * 100.0 / bfi->total_clusters,
-               bfi->fragmented_clusters * 100.0 / bfi->allocated_clusters);
+               bfi->fragmented_clusters * 100.0 / bfi->allocated_clusters,
+               bfi->compressed_clusters * 100.0 / bfi->allocated_clusters);
     }
 
     bdrv_delete(bs);
diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026
index 1602ccd..32c6d32 100755
--- a/tests/qemu-iotests/026
+++ b/tests/qemu-iotests/026
@@ -102,7 +102,7 @@  if [ "$event" == "l2_load" ]; then
     $QEMU_IO -c "read $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
 fi
 
-$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
+_check_test_img | grep -v "refcount=1 reference=0"
 
 done
 done
@@ -147,7 +147,7 @@  echo
 echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
 $QEMU_IO -c "write $vmstate 0 64M" $BLKDBG_TEST_IMG | _filter_qemu_io
 
-$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
+_check_test_img | grep -v "refcount=1 reference=0"
 
 done
 done
@@ -186,7 +186,7 @@  echo
 echo "Event: $event; errno: $errno; imm: $imm; once: $once"
 $QEMU_IO -c "write -b 0 64k" $BLKDBG_TEST_IMG | _filter_qemu_io
 
-$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
+_check_test_img | grep -v "refcount=1 reference=0"
 
 done
 done
diff --git a/tests/qemu-iotests/036 b/tests/qemu-iotests/036
index 329533e..3c76d89 100755
--- a/tests/qemu-iotests/036
+++ b/tests/qemu-iotests/036
@@ -59,7 +59,7 @@  _make_test_img 64M
 echo
 echo === Repair image ===
 echo
-$QEMU_IMG check -r all $TEST_IMG
+_check_test_img -r all
 ./qcow2.py $TEST_IMG dump-header
 
 # success, all done
diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039
index c5ae806..ae35175 100755
--- a/tests/qemu-iotests/039
+++ b/tests/qemu-iotests/039
@@ -86,7 +86,7 @@  $QEMU_IO -r -c "read -P 0x5a 0 512" $TEST_IMG | _filter_qemu_io
 echo
 echo "== Repairing the image file must succeed =="
 
-$QEMU_IMG check -r all $TEST_IMG
+_check_test_img -r all
 
 # The dirty bit must not be set
 ./qcow2.py $TEST_IMG dump-header | grep incompatible_features
diff --git a/tests/qemu-iotests/044.out b/tests/qemu-iotests/044.out
index 7a40071..c58c7d5 100644
--- a/tests/qemu-iotests/044.out
+++ b/tests/qemu-iotests/044.out
@@ -1,4 +1,5 @@ 
 No errors were found on the image.
+7292415/8391499= 86.90% allocated, 0.00% fragmented, 0.00% compressed clusters
 .
 ----------------------------------------------------------------------
 Ran 1 tests
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index aef5f52..ad1a9f2 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -161,9 +161,9 @@  _cleanup_test_img()
 
 _check_test_img()
 {
-    $QEMU_IMG check -f $IMGFMT $TEST_IMG 2>&1 | \
-        grep -v "fragmented$" | \
-    	sed -e 's/qemu-img\: This image format does not support checks/No errors were found on the image./'
+    $QEMU_IMG check "$@" -f $IMGFMT $TEST_IMG 2>&1 | \
+        sed -e '/allocated.*fragmented.*compressed clusters/d' \
+            -e 's/qemu-img: This image format does not support checks/No errors were found on the image./'
 }
 
 _img_info()