Skip to content

Commit

Permalink
block: Prepare for NULL BDS
Browse files Browse the repository at this point in the history
blk_bs() will not necessarily return a non-NULL value any more (unless
blk_is_available() is true or it can be assumed to otherwise, e.g.
because it is called immediately after a successful blk_new_with_bs() or
blk_new_open()).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed Oct 23, 2015
1 parent 0c3c36d commit 5433c24
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 72 deletions.
5 changes: 5 additions & 0 deletions block.c
Expand Up @@ -2683,6 +2683,11 @@ BlockDriverState *bdrv_lookup_bs(const char *device,
blk = blk_by_name(device);

if (blk) {
if (!blk_bs(blk)) {
error_setg(errp, "Device '%s' has no medium", device);
return NULL;
}

return blk_bs(blk);
}
}
Expand Down
4 changes: 2 additions & 2 deletions block/qapi.c
Expand Up @@ -306,12 +306,12 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
info->io_status = blk_iostatus(blk);
}

if (!QLIST_EMPTY(&bs->dirty_bitmaps)) {
if (bs && !QLIST_EMPTY(&bs->dirty_bitmaps)) {
info->has_dirty_bitmaps = true;
info->dirty_bitmaps = bdrv_query_dirty_bitmaps(bs);
}

if (bs->drv) {
if (bs && bs->drv) {
info->has_inserted = true;
info->inserted = bdrv_block_device_info(bs, errp);
if (info->inserted == NULL) {
Expand Down

0 comments on commit 5433c24

Please sign in to comment.