Commit a2d61900 authored by Kevin Wolf's avatar Kevin Wolf
Browse files

block-backend: Add blk_set_bs()



It allows changing the BlockDriverState that a BlockBackend points to.

Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarAlberto Garcia <berto@igalia.com>
Reviewed-by: default avatarFam Zheng <famz@redhat.com>
Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent 439db28c
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -238,6 +238,23 @@ BlockDriverState *blk_bs(BlockBackend *blk)
    return blk->bs;
}

/*
 * Changes the BlockDriverState attached to @blk
 */
void blk_set_bs(BlockBackend *blk, BlockDriverState *bs)
{
    bdrv_ref(bs);

    if (blk->bs) {
        blk->bs->blk = NULL;
        bdrv_unref(blk->bs);
    }
    assert(bs->blk == NULL);

    blk->bs = bs;
    bs->blk = blk;
}

/*
 * Return @blk's DriveInfo if any, else null.
 */
+2 −0
Original line number Diff line number Diff line
@@ -659,6 +659,8 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
                  BlockCompletionFunc *cb, void *opaque,
                  Error **errp);

void blk_set_bs(BlockBackend *blk, BlockDriverState *bs);

void blk_dev_change_media_cb(BlockBackend *blk, bool load);
bool blk_dev_has_removable_media(BlockBackend *blk);
void blk_dev_eject_request(BlockBackend *blk, bool force);