Commit 061959e8 authored by Max Reitz's avatar Max Reitz Committed by Kevin Wolf
Browse files

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: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 281d22d8
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -872,7 +872,11 @@ void blk_error_action(BlockBackend *blk, BlockErrorAction action,

int blk_is_read_only(BlockBackend *blk)
{
    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)
{
    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)
{
    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)
{
    if (blk->bs) {
        return bdrv_get_flags(blk->bs);
    } else {
        return blk->root_state.open_flags;
    }
}

int blk_get_max_transfer_length(BlockBackend *blk)