diff options
author | Kevin Wolf <kwolf@redhat.com> | 2016-02-29 10:50:38 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-05-19 16:45:31 +0200 |
commit | dde33812a83b9c55b180a85411bfc4d6c39e8b11 (patch) | |
tree | e5beba4ece97dcd013bf25b0ad5aaa9a62eb5fd6 /block | |
parent | 91c6e4b7bba906cfb8d84481da6340957f876c90 (diff) |
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>
Diffstat (limited to 'block')
-rw-r--r-- | block/block-backend.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/block/block-backend.c b/block/block-backend.c index 8d6fc77b26..9dcac9792f 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -395,6 +395,23 @@ BlockDriverState *blk_bs(BlockBackend *blk) } /* + * 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. */ DriveInfo *blk_legacy_dinfo(BlockBackend *blk) |