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>
This commit is contained in:
Max Reitz 2015-10-19 17:53:25 +02:00 committed by Kevin Wolf
parent 281d22d86c
commit 061959e8da
1 changed files with 24 additions and 4 deletions

View File

@ -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)