mirror of https://github.com/proxmox/mirror_qemu
block: Add bdrv_has_blk()
In many cases we just want to know whether a BDS has at least one BB attached, without needing to know the exact BB that is attached. In contrast to bs->blk, this is still a valid question when more than one BB can be attached, so just answer it by checking the parents list. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>master
parent
91c6e4b7bb
commit
dde33812a8
|
@ -394,6 +394,23 @@ BlockDriverState *blk_bs(BlockBackend *blk)
|
||||||
return blk->root ? blk->root->bs : NULL;
|
return blk->root ? blk->root->bs : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns true if @bs has an associated BlockBackend.
|
||||||
|
*/
|
||||||
|
bool bdrv_has_blk(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
BdrvChild *child;
|
||||||
|
QLIST_FOREACH(child, &bs->parents, next_parent) {
|
||||||
|
if (child->role == &child_root) {
|
||||||
|
assert(bs->blk);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(!bs->blk);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return @blk's DriveInfo if any, else null.
|
* Return @blk's DriveInfo if any, else null.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -99,6 +99,7 @@ BlockBackend *blk_by_public(BlockBackendPublic *public);
|
||||||
BlockDriverState *blk_bs(BlockBackend *blk);
|
BlockDriverState *blk_bs(BlockBackend *blk);
|
||||||
void blk_remove_bs(BlockBackend *blk);
|
void blk_remove_bs(BlockBackend *blk);
|
||||||
void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs);
|
void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs);
|
||||||
|
bool bdrv_has_blk(BlockDriverState *bs);
|
||||||
|
|
||||||
void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
|
void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
|
||||||
void blk_iostatus_enable(BlockBackend *blk);
|
void blk_iostatus_enable(BlockBackend *blk);
|
||||||
|
|
Loading…
Reference in New Issue