diff mbox

[RFC,1/8] block: add virtual_size to query-block QMP output

Message ID 1362867748-30528-2-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi March 9, 2013, 10:22 p.m. UTC
There is currently no way to query the size of a drive.  Add a
'virtual_size' field to the 'query-block' QMP output.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block.c          | 1 +
 qapi-schema.json | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Eric Blake March 11, 2013, 5:35 p.m. UTC | #1
On 03/09/2013 03:22 PM, Stefan Hajnoczi wrote:
> There is currently no way to query the size of a drive.  Add a
> 'virtual_size' field to the 'query-block' QMP output.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  block.c          | 1 +
>  qapi-schema.json | 5 ++++-
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/block.c b/block.c
> index 124a9eb..0128e27 100644
> --- a/block.c
> +++ b/block.c
> @@ -2908,6 +2908,7 @@ BlockInfo *bdrv_query_info(BlockDriverState *bs)
>          info->has_inserted = true;
>          info->inserted = g_malloc0(sizeof(*info->inserted));
>          info->inserted->file = g_strdup(bs->filename);
> +        info->inserted->virtual_size = bdrv_getlength(bs);
>          info->inserted->ro = bs->read_only;
>          info->inserted->drv = g_strdup(bs->drv->format_name);
>          info->inserted->encrypted = bs->encrypted;
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 28b070f..6b64aec 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -751,6 +751,8 @@
>  #
>  # @iops_wr: write I/O operations per second is specified
>  #
> +# @virtual_size: size of block device, in bytes

It is traditional to list 'since 1.5' when adding a field that did not
appear in earlier qemu releases.

> +#
>  # Since: 0.14.0
>  #
>  # Notes: This interface is only found in @BlockInfo.
> @@ -760,7 +762,8 @@
>              '*backing_file': 'str', 'backing_file_depth': 'int',
>              'encrypted': 'bool', 'encryption_key_missing': 'bool',
>              'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
> -            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} }
> +            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
> +            'virtual_size': 'int' } }

I was about to suggest 'virtual-size' instead of 'virtual_size', since
we prefer '-' over '_' in QMP; but since this command has pre-existing
uses of '_', keeping consistency within the struct trumps consistency
with the rest of QMP.

The idea makes sense, and my only complaint was a trivial documentation
matter; so feel free to add this when re-posting without the RFC:

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index 124a9eb..0128e27 100644
--- a/block.c
+++ b/block.c
@@ -2908,6 +2908,7 @@  BlockInfo *bdrv_query_info(BlockDriverState *bs)
         info->has_inserted = true;
         info->inserted = g_malloc0(sizeof(*info->inserted));
         info->inserted->file = g_strdup(bs->filename);
+        info->inserted->virtual_size = bdrv_getlength(bs);
         info->inserted->ro = bs->read_only;
         info->inserted->drv = g_strdup(bs->drv->format_name);
         info->inserted->encrypted = bs->encrypted;
diff --git a/qapi-schema.json b/qapi-schema.json
index 28b070f..6b64aec 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -751,6 +751,8 @@ 
 #
 # @iops_wr: write I/O operations per second is specified
 #
+# @virtual_size: size of block device, in bytes
+#
 # Since: 0.14.0
 #
 # Notes: This interface is only found in @BlockInfo.
@@ -760,7 +762,8 @@ 
             '*backing_file': 'str', 'backing_file_depth': 'int',
             'encrypted': 'bool', 'encryption_key_missing': 'bool',
             'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
-            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} }
+            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
+            'virtual_size': 'int' } }
 
 ##
 # @BlockDeviceIoStatus: