Patchwork block: add apparent-size to query-block

login
register
mail settings
Submitter Federico Simoncelli
Date June 21, 2013, 4:18 p.m.
Message ID <1371831528-1128-1-git-send-email-fsimonce@redhat.com>
Download mbox | patch
Permalink /patch/253266/
State New
Headers show

Comments

Federico Simoncelli - June 21, 2013, 4:18 p.m.
This patch adds the apparent-size entry to the query-block output.
The value represents the apparent size in bytes of the image, e.g.
file size (including the blocks not yet allocated) or block device
size.

Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
---
 block/qapi.c     |    3 ++-
 qapi-schema.json |    4 +++-
 qmp-commands.hx  |    1 +
 3 files changed, 6 insertions(+), 2 deletions(-)
Eric Blake - June 21, 2013, 8:06 p.m.
On 06/21/2013 05:18 PM, Federico Simoncelli wrote:
> This patch adds the apparent-size entry to the query-block output.
> The value represents the apparent size in bytes of the image, e.g.
> file size (including the blocks not yet allocated) or block device
> size.
> 
> Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
> ---
>  block/qapi.c     |    3 ++-
>  qapi-schema.json |    4 +++-
>  qmp-commands.hx  |    1 +
>  3 files changed, 6 insertions(+), 2 deletions(-)
> 

> +++ b/qapi-schema.json
> @@ -222,6 +222,8 @@
>  #
>  # @actual-size: #optional actual size on disk in bytes of the image
>  #
> +# @apparent-size: apparent size in bytes of the image

Worth adding a '(since 1.6)' notation.  Is there any more documentation
you can list here to differentiate between the different sizes?

> +#
>  # @dirty-flag: #optional true if image is not cleanly closed
>  #
>  # @cluster-size: #optional size of a cluster in bytes
> @@ -244,7 +246,7 @@
>  
>  { 'type': 'ImageInfo',
>    'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',
> -           '*actual-size': 'int', 'virtual-size': 'int',
> +           '*actual-size': 'int', 'virtual-size': 'int', 'apparent-size': 'int',

Long line; may be worth wrapping.  Is this parameter always present,
even if it is identical to 'actual-size' for some file formats, or
should it be marked optional?

qemu-img should be enhanced to output the new information.
Kevin Wolf - June 24, 2013, 12:22 p.m.
Am 21.06.2013 um 18:18 hat Federico Simoncelli geschrieben:
> This patch adds the apparent-size entry to the query-block output.
> The value represents the apparent size in bytes of the image, e.g.
> file size (including the blocks not yet allocated) or block device
> size.
> 
> Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>

Instead of pulling one specific field up from bs->file and giving it a
non-obvious name, we should rather add something generally useful like a
field '*file': 'ImageInfo' that works as an analog to *backing-image,
just that it contains the info for bs->file instead of bs->backing_hd.

Kevin

Patch

diff --git a/block/qapi.c b/block/qapi.c
index a4bc411..ccaba67 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -119,8 +119,9 @@  void bdrv_query_image_info(BlockDriverState *bs,
 
     info->filename        = g_strdup(bs->filename);
     info->format          = g_strdup(bdrv_get_format_name(bs));
-    info->virtual_size    = total_sectors * 512;
+    info->virtual_size    = bdrv_getlength(bs);
     info->actual_size     = bdrv_get_allocated_file_size(bs);
+    info->apparent_size   = bdrv_getlength(bs->file);
     info->has_actual_size = info->actual_size >= 0;
     if (bdrv_is_encrypted(bs)) {
         info->encrypted = true;
diff --git a/qapi-schema.json b/qapi-schema.json
index a80ee40..c7403ed 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -222,6 +222,8 @@ 
 #
 # @actual-size: #optional actual size on disk in bytes of the image
 #
+# @apparent-size: apparent size in bytes of the image
+#
 # @dirty-flag: #optional true if image is not cleanly closed
 #
 # @cluster-size: #optional size of a cluster in bytes
@@ -244,7 +246,7 @@ 
 
 { 'type': 'ImageInfo',
   'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',
-           '*actual-size': 'int', 'virtual-size': 'int',
+           '*actual-size': 'int', 'virtual-size': 'int', 'apparent-size': 'int',
            '*cluster-size': 'int', '*encrypted': 'bool',
            '*backing-filename': 'str', '*full-backing-filename': 'str',
            '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'],
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8cea5e5..3f3aded 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1714,6 +1714,7 @@  Each json-object contain the following:
              - "actual-size": actual size on disk in bytes of the image, not
                               present when image does not support thin
                               provision (json-int, optional)
+             - "apparent-size": apparent size in bytes of the image
              - "cluster-size": size of a cluster in bytes, not present if image
                                format does not support it (json-int, optional)
              - "encrypted": true if the image is encrypted, not present means