diff options
author | Kevin Wolf <kwolf@redhat.com> | 2016-09-20 13:38:40 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-09-23 13:36:10 +0200 |
commit | 1c89e1fa2fb1414f4485a01924032ad9cdb9073d (patch) | |
tree | 881fd516e4ec8e932fc74613c02ead9da8c6a5c8 /block/block-backend.c | |
parent | 6bed02805666035a59daa6a46935074f6f6d507d (diff) |
block: Add blk_by_dev()
This finds a BlockBackend given the device model that is attached to it.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'block/block-backend.c')
-rw-r--r-- | block/block-backend.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/block/block-backend.c b/block/block-backend.c index d1349d90e5..0bd19abdfb 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -560,6 +560,25 @@ void *blk_get_attached_dev(BlockBackend *blk) } /* + * Return the BlockBackend which has the device model @dev attached if it + * exists, else null. + * + * @dev must not be null. + */ +BlockBackend *blk_by_dev(void *dev) +{ + BlockBackend *blk = NULL; + + assert(dev != NULL); + while ((blk = blk_all_next(blk)) != NULL) { + if (blk->dev == dev) { + return blk; + } + } + return NULL; +} + +/* * Set @blk's device model callbacks to @ops. * @opaque is the opaque argument to pass to the callbacks. * This is for use by device models. |