void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)

{



    if (bs->backing_hd) {

        assert(bs->backing_blocker);

        bdrv_op_unblock_all(bs->backing_hd, bs->backing_blocker);

    } else if (backing_hd) {

        error_setg(&bs->backing_blocker,

                   "device is used as backing hd of '%s'",

                   bdrv_get_device_name(bs));

    }



    bs->backing_hd = backing_hd;

    if (!backing_hd) {

        error_free(bs->backing_blocker);

        bs->backing_blocker = NULL;

        goto out;

    }

    bs->open_flags &= ~BDRV_O_NO_BACKING;

    pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_hd->filename);

    pstrcpy(bs->backing_format, sizeof(bs->backing_format),

            backing_hd->drv ? backing_hd->drv->format_name : "");



    bdrv_op_block_all(bs->backing_hd, bs->backing_blocker);

    /* Otherwise we won't be able to commit due to check in bdrv_commit */

    bdrv_op_unblock(bs->backing_hd, BLOCK_OP_TYPE_COMMIT,

                    bs->backing_blocker);

out:

    bdrv_refresh_limits(bs, NULL);

}

void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)

{



    if (bs->backing_hd) {

        assert(bs->backing_blocker);

        bdrv_op_unblock_all(bs->backing_hd, bs->backing_blocker);

    } else if (backing_hd) {

        error_setg(&bs->backing_blocker,

                   "device is used as backing hd of '%s'",

                   bdrv_get_device_name(bs));

    }



    bs->backing_hd = backing_hd;

    if (!backing_hd) {

        error_free(bs->backing_blocker);

        bs->backing_blocker = NULL;

        goto out;

    }

    bs->open_flags &= ~BDRV_O_NO_BACKING;

    pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_hd->filename);

    pstrcpy(bs->backing_format, sizeof(bs->backing_format),

            backing_hd->drv ? backing_hd->drv->format_name : "");



    bdrv_op_block_all(bs->backing_hd, bs->backing_blocker);

    

    bdrv_op_unblock(bs->backing_hd, BLOCK_OP_TYPE_COMMIT,

                    bs->backing_blocker);

out:

    bdrv_refresh_limits(bs, NULL);

}

    bdrv_op_unblock(bs->backing_hd, BLOCK_OP_TYPE_COMMIT,
void FUNC_0(BlockDriverState *VAR_0, BlockDriverState *VAR_1)

{



    if (VAR_0->VAR_1) {

        assert(VAR_0->backing_blocker);

        bdrv_op_unblock_all(VAR_0->VAR_1, VAR_0->backing_blocker);

    } else if (VAR_1) {

        error_setg(&VAR_0->backing_blocker,

                   "device is used as backing hd of '%s'",

                   bdrv_get_device_name(VAR_0));

    }



    VAR_0->VAR_1 = VAR_1;

    if (!VAR_1) {

        error_free(VAR_0->backing_blocker);

        VAR_0->backing_blocker = NULL;

        goto out;

    }

    VAR_0->open_flags &= ~BDRV_O_NO_BACKING;

    pstrcpy(VAR_0->backing_file, sizeof(VAR_0->backing_file), VAR_1->filename);

    pstrcpy(VAR_0->backing_format, sizeof(VAR_0->backing_format),

            VAR_1->drv ? VAR_1->drv->format_name : "");



    bdrv_op_block_all(VAR_0->VAR_1, VAR_0->backing_blocker);

    

    bdrv_op_unblock(VAR_0->VAR_1, BLOCK_OP_TYPE_COMMIT,

                    VAR_0->backing_blocker);

out:

    bdrv_refresh_limits(VAR_0, NULL);

}

void FUNC_0(BlockDriverState *VAR_0, BlockDriverState *VAR_1)
{ if (VAR_0->VAR_1) { assert(VAR_0->backing_blocker); bdrv_op_unblock_all(VAR_0->VAR_1, VAR_0->backing_blocker); } else if (VAR_1) { error_setg(&VAR_0->backing_blocker,
"device is used as backing hd of '%s'",
bdrv_get_device_name(VAR_0)); } VAR_0->VAR_1 = VAR_1; if (!VAR_1) { error_free(VAR_0->backing_blocker); VAR_0->backing_blocker = NULL; goto out; } VAR_0->open_flags &= ~BDRV_O_NO_BACKING; pstrcpy(VAR_0->backing_file, sizeof(VAR_0->backing_file), VAR_1->filename); pstrcpy(VAR_0->backing_format, sizeof(VAR_0->backing_format),
VAR_1->drv ? VAR_1->drv->format_name : ""); bdrv_op_block_all(VAR_0->VAR_1, VAR_0->backing_blocker); bdrv_op_unblock(VAR_0->VAR_1, BLOCK_OP_TYPE_COMMIT,
VAR_0->backing_blocker); out:
bdrv_refresh_limits(VAR_0, NULL); }