[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 39/76] qmp: fill in the image field in BlockDeviceInf
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 39/76] qmp: fill in the image field in BlockDeviceInfo |
Date: |
Tue, 28 Apr 2015 17:00:21 +0200 |
From: Alberto Garcia <address@hidden>
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().
Signed-off-by: Alberto Garcia <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
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(-)
diff --git a/block.c b/block.c
index 002972a..101b50c 100644
--- a/block.c
+++ b/block.c
@@ -3897,15 +3897,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;
}
diff --git a/block/qapi.c b/block/qapi.c
index 8a19aed..063dd1b 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -31,8 +31,10 @@
#include "qapi/qmp/types.h"
#include "sysemu/block-backend.h"
-BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs)
+BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp)
{
+ ImageInfo **p_image_info;
+ BlockDriverState *bs0;
BlockDeviceInfo *info = g_malloc0(sizeof(*info));
info->file = g_strdup(bs->filename);
@@ -92,6 +94,25 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs)
info->write_threshold = bdrv_write_threshold_get(bs);
+ bs0 = bs;
+ p_image_info = &info->image;
+ while (1) {
+ Error *local_err = NULL;
+ bdrv_query_image_info(bs0, p_image_info, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ qapi_free_BlockDeviceInfo(info);
+ return NULL;
+ }
+ if (bs0->drv && bs0->backing_hd) {
+ bs0 = bs0->backing_hd;
+ (*p_image_info)->has_backing_image = true;
+ p_image_info = &((*p_image_info)->backing_image);
+ } else {
+ break;
+ }
+ }
+
return info;
}
@@ -264,9 +285,6 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo
**p_info,
{
BlockInfo *info = g_malloc0(sizeof(*info));
BlockDriverState *bs = blk_bs(blk);
- BlockDriverState *bs0;
- ImageInfo **p_image_info;
- Error *local_err = NULL;
info->device = g_strdup(blk_name(blk));
info->type = g_strdup("unknown");
info->locked = blk_dev_is_medium_locked(blk);
@@ -289,23 +307,9 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo
**p_info,
if (bs->drv) {
info->has_inserted = true;
- info->inserted = bdrv_block_device_info(bs);
-
- bs0 = bs;
- p_image_info = &info->inserted->image;
- while (1) {
- bdrv_query_image_info(bs0, p_image_info, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- goto err;
- }
- if (bs0->drv && bs0->backing_hd) {
- bs0 = bs0->backing_hd;
- (*p_image_info)->has_backing_image = true;
- p_image_info = &((*p_image_info)->backing_image);
- } else {
- break;
- }
+ info->inserted = bdrv_block_device_info(bs, errp);
+ if (info->inserted == NULL) {
+ goto err;
}
}
diff --git a/blockdev.c b/blockdev.c
index e67c701..a136b2e 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2392,7 +2392,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,
diff --git a/include/block/block.h b/include/block/block.h
index b285e0d..d79714a 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -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);
diff --git a/include/block/qapi.h b/include/block/qapi.h
index 168d788..327549d 100644
--- a/include/block/qapi.h
+++ b/include/block/qapi.h
@@ -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);
--
1.8.3.1
- [Qemu-block] [PULL 31/76] virtio_blk: comment fix, (continued)
- [Qemu-block] [PULL 31/76] virtio_blk: comment fix, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 29/76] blockjob: Update function name in comments, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 32/76] m25p80: add missing blk_attach_dev_nofail, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 30/76] block: avoid unnecessary bottom halves, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 33/76] m25p80: fix s->blk usage before assignment, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 34/76] block: document block-stream in qmp-commands.hx, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 35/76] block: add bdrv_get_device_or_node_name(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 36/76] block: use bdrv_get_device_or_node_name() in error messages, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 37/76] block: add 'node-name' field to BLOCK_IMAGE_CORRUPTED, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 38/76] Revert "hmp: fix crash in 'info block -n -v'", Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 39/76] qmp: fill in the image field in BlockDeviceInfo,
Kevin Wolf <=
- [Qemu-block] [PULL 40/76] block/iscsi: do not forget to logout from target, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 41/76] block/iscsi: change all iscsilun properties from uint8_t to bool, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 42/76] block/iscsi: rename iscsi_write_protected and let it return void, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 43/76] block/iscsi: store DPOFUA bit from the modesense command, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 44/76] block/iscsi: optimize WRITE10/16 if cache.writeback is not set, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 45/76] block/iscsi: increase retry count, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 46/76] block/iscsi: handle SCSI_STATUS_TASK_SET_FULL, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 47/76] block/iscsi: bump year in copyright notice, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 48/76] block/iscsi: use the allocationmap also if cache.direct=on, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 49/76] docs: incremental backup documentation, Kevin Wolf, 2015/04/28