qmp: fill in the image field in BlockDeviceInfo
PATCH 1/1 qmp: fill in the image field in BlockDeviceInfo
The image field in BlockDeviceInfo is supposed to contain an ImageInfo object. However that is being filled in by bdrv_query_info(), not by bdrv_block_device_info(), which is where BlockDeviceInfo is actually created.
Anyone calling bdrv_block_device_info() directly will get a null image field. As a consequence of this, the HMP command 'info block -n -v' crashes QEMU.
This patch moves the code that fills in that field from bdrv_query_info() to bdrv_block_device_info().
--- block.c | 9 +++++++-- block/qapi.c | 46 +++++++++++++++++++++++++--------------------- blockdev.c | 2 +- include/block/block.h | 2 +- include/block/qapi.h | 2 +- 5 files changed, 35 insertions(+), 26 deletions(-)
block.c +7 -2
@@ -3870,15 +3870,20 @@ BlockDriverState *bdrv_find_node(const char *node_name) }/* Put this QMP function here so it can access the static graph_bdrv_states. */ -BlockDeviceInfoList *bdrv_named_nodes_list (void ) +BlockDeviceInfoList *bdrv_named_nodes_list (Error **errp) {BlockDeviceInfoList *list, *entry;BlockDriverState *bs; list =NULL ; QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) { +BlockDeviceInfo *info =bdrv_block_device_info (bs, errp); +if (!info) { +qapi_free_BlockDeviceInfoList (list); +return NULL ; + } entry =g_malloc0 (sizeof (*entry)); - entry->value =bdrv_block_device_info (bs); + entry->value = info; entry->next = list; list = entry; }
block/qapi.c +25 -21
71 lines not on this page · raw message
blockdev.c +1 -1
@@ -2391,7 +2391,7 @@ out:BlockDeviceInfoList *qmp_query_named_block_nodes (Error **errp) { -return bdrv_named_nodes_list (); +return bdrv_named_nodes_list (errp); } void qmp_blockdev_backup(const char *device, const char *target,
include/block/block.h +1 -1
@@ -382,7 +382,7 @@ void bdrv_lock_medium(BlockDriverState *bs, bool locked);void bdrv_eject (BlockDriverState *bs,bool eject_flag);const char *bdrv_get_format_name (BlockDriverState *bs);BlockDriverState *bdrv_find_node (const char *node_name); -BlockDeviceInfoList *bdrv_named_nodes_list (void ); +BlockDeviceInfoList *bdrv_named_nodes_list (Error **errp);BlockDriverState *bdrv_lookup_bs (const char *device,const char *node_name,Error **errp);
include/block/qapi.h +1 -1
@@ -29,7 +29,7 @@#include "block/block.h" #include "block/snapshot.h" -BlockDeviceInfo *bdrv_block_device_info (BlockDriverState *bs); +BlockDeviceInfo *bdrv_block_device_info (BlockDriverState *bs,Error **errp);int bdrv_query_snapshot_info_list (BlockDriverState *bs,SnapshotInfoList **p_list,Error **errp);
Signature · 1 line
2.1.4
Quoted 6 lines · Alberto Garcia
Anyone calling
bdrv_block_device_info()directly will get a null image field. As a consequence of this, the HMP command 'info block -n -v' crashes QEMU.This patch moves the code that fills in that field from
bdrv_query_info()tobdrv_block_device_info().
And in case this change is too big/risky for 2.3, there's also the simple workaround for the crash:
hmp.c +1 -1
@@ -391,7 +391,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info, inserted->iops_size); } -if (verbose) { +if (verbose && inserted->image) {monitor_printf (mon,"\nImages:\n" ); image_info = inserted->image;while (1 ) {
Berto
Quoted 12 lines · Alberto Garcia
The image field in BlockDeviceInfo is supposed to contain an ImageInfo object. However that is being filled in by
bdrv_query_info(), not bybdrv_block_device_info(), which is where BlockDeviceInfo is actually created.Anyone calling
bdrv_block_device_info()directly will get a null image field. As a consequence of this, the HMP command 'info block -n -v' crashes QEMU.This patch moves the code that fills in that field from
bdrv_query_info()tobdrv_block_device_info().
Quoted 8 lines
Signed-off-by Alberto Garcia <[email protected]>--- block.c | 9 +++++++-- block/qapi.c | 46 +++++++++++++++++++++++++--------------------- blockdev.c | 2 +- include/block/block.h | 2 +- include/block/qapi.h | 2 +- 5 files changed, 35 insertions(+), 26 deletions(-)
For the record, the following patch has been merged instead:
[PATCH for-2.3] hmp: fix crash in 'info block -n -v'
Am 21.04.2015 um 15:28 hat Stefan Hajnoczi geschrieben:
Quoted 22 lines · Alberto Garcia
Quoted 12 lines
The image field in BlockDeviceInfo is supposed to contain an ImageInfo object. However that is being filled in by
bdrv_query_info(), not bybdrv_block_device_info(), which is where BlockDeviceInfo is actually created.Anyone calling
bdrv_block_device_info()directly will get a null image field. As a consequence of this, the HMP command 'info block -n -v' crashes QEMU.This patch moves the code that fills in that field from
bdrv_query_info()tobdrv_block_device_info().Quoted 8 lines
Signed-off-by Alberto Garcia <[email protected]>--- block.c | 9 +++++++-- block/qapi.c | 46 +++++++++++++++++++++++++--------------------- blockdev.c | 2 +- include/block/block.h | 2 +- include/block/qapi.h | 2 +- 5 files changed, 35 insertions(+), 26 deletions(-)
Quoted 2 lines
For the record, the following patch has been merged instead:
[PATCH for-2.3] hmp: fix crash in 'info block -n -v'
That was just a minimal stopgap solution that could still be applied after -rc3. We should revert it in block-next and apply this one as a replacement (after proper review, of course).
Kevin
Stefan Hajnoczi
AppliedQuoted 12 lines · Alberto Garcia
The image field in BlockDeviceInfo is supposed to contain an ImageInfo object. However that is being filled in by
bdrv_query_info(), not bybdrv_block_device_info(), which is where BlockDeviceInfo is actually created.Anyone calling
bdrv_block_device_info()directly will get a null image field. As a consequence of this, the HMP command 'info block -n -v' crashes QEMU.This patch moves the code that fills in that field from
bdrv_query_info()tobdrv_block_device_info().
Quoted 8 lines
Signed-off-by Alberto Garcia <[email protected]>--- block.c | 9 +++++++-- block/qapi.c | 46 +++++++++++++++++++++++++--------------------- blockdev.c | 2 +- include/block/block.h | 2 +- include/block/qapi.h | 2 +- 5 files changed, 35 insertions(+), 26 deletions(-)
Reverted the QEMU 2.3 fix and replaced it with this commit.
Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next
Stefan