int bdrv_set_key(BlockDriverState *bs, const char *key)

{

    int ret;

    if (bs->backing_hd && bs->backing_hd->encrypted) {

        ret = bdrv_set_key(bs->backing_hd, key);

        if (ret < 0)

            return ret;

        if (!bs->encrypted)

            return 0;

    }

    if (!bs->encrypted) {

        return -EINVAL;

    } else if (!bs->drv || !bs->drv->bdrv_set_key) {

        return -ENOMEDIUM;

    }

    ret = bs->drv->bdrv_set_key(bs, key);

    if (ret < 0) {

        bs->valid_key = 0;

    } else if (!bs->valid_key) {

        bs->valid_key = 1;

        if (bs->blk) {

            /* call the change callback now, we skipped it on open */

            blk_dev_change_media_cb(bs->blk, true);

        }

    }

    return ret;

}

int bdrv_set_key(BlockDriverState *bs, const char *key)

{

    int ret;

    if (bs->backing_hd && bs->backing_hd->encrypted) {

        ret = bdrv_set_key(bs->backing_hd, key);

        if (ret < 0)

            return ret;

        if (!bs->encrypted)

            return 0;

    }

    if (!bs->encrypted) {

        return -EINVAL;

    } else if (!bs->drv || !bs->drv->bdrv_set_key) {

        return -ENOMEDIUM;

    }

    ret = bs->drv->bdrv_set_key(bs, key);

    if (ret < 0) {

        bs->valid_key = 0;

    } else if (!bs->valid_key) {

        bs->valid_key = 1;

        if (bs->blk) {

            

            blk_dev_change_media_cb(bs->blk, true);

        }

    }

    return ret;

}

int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1)

{

    int VAR_2;

    if (VAR_0->backing_hd && VAR_0->backing_hd->encrypted) {

        VAR_2 = FUNC_0(VAR_0->backing_hd, VAR_1);

        if (VAR_2 < 0)

            return VAR_2;

        if (!VAR_0->encrypted)

            return 0;

    }

    if (!VAR_0->encrypted) {

        return -EINVAL;

    } else if (!VAR_0->drv || !VAR_0->drv->FUNC_0) {

        return -ENOMEDIUM;

    }

    VAR_2 = VAR_0->drv->FUNC_0(VAR_0, VAR_1);

    if (VAR_2 < 0) {

        VAR_0->valid_key = 0;

    } else if (!VAR_0->valid_key) {

        VAR_0->valid_key = 1;

        if (VAR_0->blk) {

            

            blk_dev_change_media_cb(VAR_0->blk, true);

        }

    }

    return VAR_2;

}

int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1)
{ int VAR_2; if (VAR_0->backing_hd && VAR_0->backing_hd->encrypted) { VAR_2 = FUNC_0(VAR_0->backing_hd, VAR_1); if (VAR_2 < 0)
return VAR_2; if (!VAR_0->encrypted)
return 0; } if (!VAR_0->encrypted) { return -EINVAL; } else if (!VAR_0->drv || !VAR_0->drv->FUNC_0) { return -ENOMEDIUM; } VAR_2 = VAR_0->drv->FUNC_0(VAR_0, VAR_1); if (VAR_2 < 0) { VAR_0->valid_key = 0; } else if (!VAR_0->valid_key) { VAR_0->valid_key = 1; if (VAR_0->blk) { blk_dev_change_media_cb(VAR_0->blk, true); } } return VAR_2; }