diff mbox

[2/9] block/qapi: Add qdev device name to query-block

Message ID 1499864249-26305-3-git-send-email-kwolf@redhat.com
State New
Headers show

Commit Message

Kevin Wolf July 12, 2017, 12:57 p.m. UTC
With -blockdev/-device, users can indirectly create anonymous
BlockBackends, in the state of which they are still interested. As a
preparation for making such BBs visible in query-block, make sure that
they can be identified even without a name by adding the ID/QOM path of
their qdev device to BlockInfo.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qapi.c               | 10 ++++++++++
 hmp.c                      |  3 +++
 qapi/block-core.json       |  5 ++++-
 tests/qemu-iotests/067.out |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)

Comments

Eric Blake July 12, 2017, 3:06 p.m. UTC | #1
On 07/12/2017 07:57 AM, Kevin Wolf wrote:
> With -blockdev/-device, users can indirectly create anonymous
> BlockBackends, in the state of which they are still interested. As a

Reads awkwardly.  Maybe:

BlockBackends, although it is still of interest to learn the state of
such backends.

> preparation for making such BBs visible in query-block, make sure that
> they can be identified even without a name by adding the ID/QOM path of
> their qdev device to BlockInfo.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---

> +++ b/qapi/block-core.json
> @@ -433,6 +433,9 @@
>  #
>  # @device: The device name associated with the virtual device.
>  #
> +# @qdev: The qdev ID, or if no ID is assigned the QOM path, of the block

s/assigned the QOM path, of/assigned, the QOM path of/

> +#        device.

Missing a (since 2.10) tag.

> +#
>  # @type: This field is returned only for compatibility reasons, it should
>  #        not be used (always returns 'unknown')
>  #
> @@ -458,7 +461,7 @@
>  # Since:  0.14.0
>  ##
>  { 'struct': 'BlockInfo',
> -  'data': {'device': 'str', 'type': 'str', 'removable': 'bool',
> +  'data': {'device': 'str', '*qdev': 'str', 'type': 'str', 'removable': 'bool',
>             'locked': 'bool', '*inserted': 'BlockDeviceInfo',
>             '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus',
>             '*dirty-bitmaps': ['BlockDirtyInfo'] } }

Besides the testsuite, are there any example outputs that need to be
adjusted?

> diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out
> index 782eae2..e3c4496 100644
> --- a/tests/qemu-iotests/067.out
> +++ b/tests/qemu-iotests/067.out
> @@ -57,6 +57,7 @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti
>                  "file": "TEST_DIR/t.qcow2",
>                  "encryption_key_missing": false
>              },
> +            "qdev": "/machine/peripheral/virtio0/virtio-backend",
>              "type": "unknown"
>          }
>      ]
>
diff mbox

Patch

diff --git a/block/qapi.c b/block/qapi.c
index 0a41d59..705cd11 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -322,11 +322,21 @@  static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
 {
     BlockInfo *info = g_malloc0(sizeof(*info));
     BlockDriverState *bs = blk_bs(blk);
+    char *qdev;
+
     info->device = g_strdup(blk_name(blk));
     info->type = g_strdup("unknown");
     info->locked = blk_dev_is_medium_locked(blk);
     info->removable = blk_dev_has_removable_media(blk);
 
+    qdev = blk_get_attached_dev_id(blk);
+    if (qdev && *qdev) {
+        info->has_qdev = true;
+        info->qdev = qdev;
+    } else {
+        g_free(qdev);
+    }
+
     if (blk_dev_has_tray(blk)) {
         info->has_tray_open = true;
         info->tray_open = blk_dev_is_tray_open(blk);
diff --git a/hmp.c b/hmp.c
index dee4028..d1d769e 100644
--- a/hmp.c
+++ b/hmp.c
@@ -425,6 +425,9 @@  static void print_block_info(Monitor *mon, BlockInfo *info,
     }
 
     if (info) {
+        if (info->has_qdev) {
+            monitor_printf(mon, "    Attached to:      %s\n", info->qdev);
+        }
         if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
             monitor_printf(mon, "    I/O status:       %s\n",
                            BlockDeviceIoStatus_lookup[info->io_status]);
diff --git a/qapi/block-core.json b/qapi/block-core.json
index f85c223..69b3c3c 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -433,6 +433,9 @@ 
 #
 # @device: The device name associated with the virtual device.
 #
+# @qdev: The qdev ID, or if no ID is assigned the QOM path, of the block
+#        device.
+#
 # @type: This field is returned only for compatibility reasons, it should
 #        not be used (always returns 'unknown')
 #
@@ -458,7 +461,7 @@ 
 # Since:  0.14.0
 ##
 { 'struct': 'BlockInfo',
-  'data': {'device': 'str', 'type': 'str', 'removable': 'bool',
+  'data': {'device': 'str', '*qdev': 'str', 'type': 'str', 'removable': 'bool',
            'locked': 'bool', '*inserted': 'BlockDeviceInfo',
            '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus',
            '*dirty-bitmaps': ['BlockDirtyInfo'] } }
diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out
index 782eae2..e3c4496 100644
--- a/tests/qemu-iotests/067.out
+++ b/tests/qemu-iotests/067.out
@@ -57,6 +57,7 @@  Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti
                 "file": "TEST_DIR/t.qcow2",
                 "encryption_key_missing": false
             },
+            "qdev": "/machine/peripheral/virtio0/virtio-backend",
             "type": "unknown"
         }
     ]