Skip to content

Commit

Permalink
block: Make some BB functions fall back to BBRS
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
XanClic authored and kevmw committed Oct 23, 2015
1 parent 281d22d commit 061959e
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions block/block-backend.c
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 061959e

Please sign in to comment.