qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-block] [PATCH 5/7] qemu-img check: add format unallocated size


From: Vladimir Sementsov-Ogievskiy
Subject: [Qemu-block] [PATCH 5/7] qemu-img check: add format unallocated size
Date: Thu, 25 May 2017 18:26:26 +0300

Shows format 'sparseness' of the image top level.

Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
 qapi/block-core.json |  3 ++-
 qemu-img.c           | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index ea0b3e8b13..c7ed5dc970 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -185,7 +185,8 @@
            '*image-end-offset': 'int', '*corruptions': 'int', '*leaks': 'int',
            '*corruptions-fixed': 'int', '*leaks-fixed': 'int',
            '*total-clusters': 'int', '*allocated-clusters': 'int',
-           '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } }
+           '*fragmented-clusters': 'int', '*compressed-clusters': 'int',
+           '*format-unallocated-size': 'uint64'} }
 
 ##
 # @MapEntry:
diff --git a/qemu-img.c b/qemu-img.c
index b506839ef0..cbd09148d2 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -601,6 +601,13 @@ static void dump_human_image_check(ImageCheck *check, bool 
quiet)
         qprintf(quiet,
                 "Image end offset: %" PRId64 "\n", check->image_end_offset);
     }
+
+    if (check->has_format_unallocated_size) {
+        char u_buf[128];
+        qprintf(quiet, "Format unallocated size: %s\n",
+                get_human_readable_size(u_buf, sizeof(u_buf),
+                                        check->format_unallocated_size));
+    }
 }
 
 static int collect_image_check(BlockDriverState *bs,
@@ -639,6 +646,18 @@ static int collect_image_check(BlockDriverState *bs,
     check->compressed_clusters      = result.bfi.compressed_clusters;
     check->has_compressed_clusters  = result.bfi.compressed_clusters != 0;
 
+    if (bs->file) {
+        int64_t file_size = bdrv_getlength(bs->file->bs);
+        if (file_size >= 0) {
+            int64_t format_allocated_size = bdrv_get_format_allocated_size(bs);
+            if (format_allocated_size >= 0) {
+                check->format_unallocated_size =
+                    file_size - format_allocated_size;
+                check->has_format_unallocated_size = true;
+            }
+        }
+    }
+
     return 0;
 }
 
-- 
2.11.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]