diff options
author | Max Reitz <mreitz@redhat.com> | 2015-10-19 17:53:25 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2015-10-23 18:18:23 +0200 |
commit | 061959e8da5af59343e2c75d55c40f366d0164f9 (patch) | |
tree | e9a15f7f0e35d1ff40344a2ebe72867c824bdb64 /block | |
parent | 281d22d86ca26bf356284719e44c4bc66b716415 (diff) |
block: Make some BB functions fall back to BBRS
If there is no BDS tree attached to a BlockBackend, functions that can
do so should fall back to the BlockBackendRootState structure.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/block-backend.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/block/block-backend.c b/block/block-backend.c index 6a3f0c7bfe..d79087029c 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -872,7 +872,11 @@ void blk_error_action(BlockBackend *blk, BlockErrorAction action, int blk_is_read_only(BlockBackend *blk) { - return bdrv_is_read_only(blk->bs); + if (blk->bs) { + return bdrv_is_read_only(blk->bs); + } else { + return blk->root_state.read_only; + } } int blk_is_sg(BlockBackend *blk) @@ -882,12 +886,24 @@ int blk_is_sg(BlockBackend *blk) int blk_enable_write_cache(BlockBackend *blk) { - return bdrv_enable_write_cache(blk->bs); + if (blk->bs) { + return bdrv_enable_write_cache(blk->bs); + } else { + return !!(blk->root_state.open_flags & BDRV_O_CACHE_WB); + } } void blk_set_enable_write_cache(BlockBackend *blk, bool wce) { - bdrv_set_enable_write_cache(blk->bs, wce); + if (blk->bs) { + bdrv_set_enable_write_cache(blk->bs, wce); + } else { + if (wce) { + blk->root_state.open_flags |= BDRV_O_CACHE_WB; + } else { + blk->root_state.open_flags &= ~BDRV_O_CACHE_WB; + } + } } void blk_invalidate_cache(BlockBackend *blk, Error **errp) @@ -917,7 +933,11 @@ void blk_eject(BlockBackend *blk, bool eject_flag) int blk_get_flags(BlockBackend *blk) { - return bdrv_get_flags(blk->bs); + if (blk->bs) { + return bdrv_get_flags(blk->bs); + } else { + return blk->root_state.open_flags; + } } int blk_get_max_transfer_length(BlockBackend *blk) |