block/qapi: Add qdev device name to query-block
With -blockdev/-device, users can indirectly create anonymous BlockBackends, while the state of such backends is still of interest. 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> Reviewed-by: John Snow <jsnow@redhat.com>
This commit is contained in:
		
							parent
							
								
									77beef8365
								
							
						
					
					
						commit
						46eade7be8
					
				
							
								
								
									
										10
									
								
								block/qapi.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								block/qapi.c
									
									
									
									
									
								
							@ -322,11 +322,21 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    BlockInfo *info = g_malloc0(sizeof(*info));
 | 
					    BlockInfo *info = g_malloc0(sizeof(*info));
 | 
				
			||||||
    BlockDriverState *bs = blk_bs(blk);
 | 
					    BlockDriverState *bs = blk_bs(blk);
 | 
				
			||||||
 | 
					    char *qdev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    info->device = g_strdup(blk_name(blk));
 | 
					    info->device = g_strdup(blk_name(blk));
 | 
				
			||||||
    info->type = g_strdup("unknown");
 | 
					    info->type = g_strdup("unknown");
 | 
				
			||||||
    info->locked = blk_dev_is_medium_locked(blk);
 | 
					    info->locked = blk_dev_is_medium_locked(blk);
 | 
				
			||||||
    info->removable = blk_dev_has_removable_media(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)) {
 | 
					    if (blk_dev_has_tray(blk)) {
 | 
				
			||||||
        info->has_tray_open = true;
 | 
					        info->has_tray_open = true;
 | 
				
			||||||
        info->tray_open = blk_dev_is_tray_open(blk);
 | 
					        info->tray_open = blk_dev_is_tray_open(blk);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								hmp.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								hmp.c
									
									
									
									
									
								
							@ -425,6 +425,9 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (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) {
 | 
					        if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
 | 
				
			||||||
            monitor_printf(mon, "    I/O status:       %s\n",
 | 
					            monitor_printf(mon, "    I/O status:       %s\n",
 | 
				
			||||||
                           BlockDeviceIoStatus_lookup[info->io_status]);
 | 
					                           BlockDeviceIoStatus_lookup[info->io_status]);
 | 
				
			||||||
 | 
				
			|||||||
@ -457,6 +457,9 @@
 | 
				
			|||||||
#
 | 
					#
 | 
				
			||||||
# @device: The device name associated with the virtual device.
 | 
					# @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. (since 2.10)
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
# @type: This field is returned only for compatibility reasons, it should
 | 
					# @type: This field is returned only for compatibility reasons, it should
 | 
				
			||||||
#        not be used (always returns 'unknown')
 | 
					#        not be used (always returns 'unknown')
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
@ -482,7 +485,7 @@
 | 
				
			|||||||
# Since:  0.14.0
 | 
					# Since:  0.14.0
 | 
				
			||||||
##
 | 
					##
 | 
				
			||||||
{ 'struct': 'BlockInfo',
 | 
					{ 'struct': 'BlockInfo',
 | 
				
			||||||
  'data': {'device': 'str', 'type': 'str', 'removable': 'bool',
 | 
					  'data': {'device': 'str', '*qdev': 'str', 'type': 'str', 'removable': 'bool',
 | 
				
			||||||
           'locked': 'bool', '*inserted': 'BlockDeviceInfo',
 | 
					           'locked': 'bool', '*inserted': 'BlockDeviceInfo',
 | 
				
			||||||
           '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus',
 | 
					           '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus',
 | 
				
			||||||
           '*dirty-bitmaps': ['BlockDirtyInfo'] } }
 | 
					           '*dirty-bitmaps': ['BlockDirtyInfo'] } }
 | 
				
			||||||
@ -577,6 +580,7 @@
 | 
				
			|||||||
#                   }
 | 
					#                   }
 | 
				
			||||||
#                }
 | 
					#                }
 | 
				
			||||||
#             },
 | 
					#             },
 | 
				
			||||||
 | 
					#             "qdev": "ide_disk",
 | 
				
			||||||
#             "type":"unknown"
 | 
					#             "type":"unknown"
 | 
				
			||||||
#          },
 | 
					#          },
 | 
				
			||||||
#          {
 | 
					#          {
 | 
				
			||||||
@ -584,12 +588,15 @@
 | 
				
			|||||||
#             "device":"ide1-cd0",
 | 
					#             "device":"ide1-cd0",
 | 
				
			||||||
#             "locked":false,
 | 
					#             "locked":false,
 | 
				
			||||||
#             "removable":true,
 | 
					#             "removable":true,
 | 
				
			||||||
 | 
					#             "qdev": "/machine/unattached/device[23]",
 | 
				
			||||||
 | 
					#             "tray_open": false,
 | 
				
			||||||
#             "type":"unknown"
 | 
					#             "type":"unknown"
 | 
				
			||||||
#          },
 | 
					#          },
 | 
				
			||||||
#          {
 | 
					#          {
 | 
				
			||||||
#             "device":"floppy0",
 | 
					#             "device":"floppy0",
 | 
				
			||||||
#             "locked":false,
 | 
					#             "locked":false,
 | 
				
			||||||
#             "removable":true,
 | 
					#             "removable":true,
 | 
				
			||||||
 | 
					#             "qdev": "/machine/unattached/device[20]",
 | 
				
			||||||
#             "type":"unknown"
 | 
					#             "type":"unknown"
 | 
				
			||||||
#          },
 | 
					#          },
 | 
				
			||||||
#          {
 | 
					#          {
 | 
				
			||||||
 | 
				
			|||||||
@ -57,6 +57,7 @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti
 | 
				
			|||||||
                "file": "TEST_DIR/t.qcow2",
 | 
					                "file": "TEST_DIR/t.qcow2",
 | 
				
			||||||
                "encryption_key_missing": false
 | 
					                "encryption_key_missing": false
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            "qdev": "/machine/peripheral/virtio0/virtio-backend",
 | 
				
			||||||
            "type": "unknown"
 | 
					            "type": "unknown"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user