diff mbox

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

Message ID 20170525152628.37628-6-vsementsov@virtuozzo.com
State New
Headers show

Commit Message

Vladimir Sementsov-Ogievskiy May 25, 2017, 3:26 p.m. UTC
Shows format 'sparseness' of the image top level.

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

Comments

Eric Blake May 25, 2017, 5:59 p.m. UTC | #1
On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
> Shows format 'sparseness' of the image top level.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  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'} }

Missing documentation (including a since 2.10 blurb).
diff mbox

Patch

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;
 }