void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)

{

    BlockDriver *drv = bs->drv;

    Error *local_err = NULL;



    memset(&bs->bl, 0, sizeof(bs->bl));



    if (!drv) {

        return;

    }



    /* Default alignment based on whether driver has byte interface */

    bs->request_alignment = drv->bdrv_co_preadv ? 1 : 512;



    /* Take some limits from the children as a default */

    if (bs->file) {

        bdrv_refresh_limits(bs->file->bs, &local_err);

        if (local_err) {

            error_propagate(errp, local_err);

            return;

        }

        bs->bl.opt_transfer = bs->file->bs->bl.opt_transfer;

        bs->bl.max_transfer = bs->file->bs->bl.max_transfer;

        bs->bl.min_mem_alignment = bs->file->bs->bl.min_mem_alignment;

        bs->bl.opt_mem_alignment = bs->file->bs->bl.opt_mem_alignment;

        bs->bl.max_iov = bs->file->bs->bl.max_iov;

    } else {

        bs->bl.min_mem_alignment = 512;

        bs->bl.opt_mem_alignment = getpagesize();



        /* Safe default since most protocols use readv()/writev()/etc */

        bs->bl.max_iov = IOV_MAX;

    }



    if (bs->backing) {

        bdrv_refresh_limits(bs->backing->bs, &local_err);

        if (local_err) {

            error_propagate(errp, local_err);

            return;

        }

        bs->bl.opt_transfer = MAX(bs->bl.opt_transfer,

                                  bs->backing->bs->bl.opt_transfer);

        bs->bl.max_transfer = MIN_NON_ZERO(bs->bl.max_transfer,

                                           bs->backing->bs->bl.max_transfer);

        bs->bl.opt_mem_alignment =

            MAX(bs->bl.opt_mem_alignment,

                bs->backing->bs->bl.opt_mem_alignment);

        bs->bl.min_mem_alignment =

            MAX(bs->bl.min_mem_alignment,

                bs->backing->bs->bl.min_mem_alignment);

        bs->bl.max_iov =

            MIN(bs->bl.max_iov,

                bs->backing->bs->bl.max_iov);

    }



    /* Then let the driver override it */

    if (drv->bdrv_refresh_limits) {

        drv->bdrv_refresh_limits(bs, errp);

    }

}

void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)

{

    BlockDriver *drv = bs->drv;

    Error *local_err = NULL;



    memset(&bs->bl, 0, sizeof(bs->bl));



    if (!drv) {

        return;

    }



    

    bs->request_alignment = drv->bdrv_co_preadv ? 1 : 512;



    

    if (bs->file) {

        bdrv_refresh_limits(bs->file->bs, &local_err);

        if (local_err) {

            error_propagate(errp, local_err);

            return;

        }

        bs->bl.opt_transfer = bs->file->bs->bl.opt_transfer;

        bs->bl.max_transfer = bs->file->bs->bl.max_transfer;

        bs->bl.min_mem_alignment = bs->file->bs->bl.min_mem_alignment;

        bs->bl.opt_mem_alignment = bs->file->bs->bl.opt_mem_alignment;

        bs->bl.max_iov = bs->file->bs->bl.max_iov;

    } else {

        bs->bl.min_mem_alignment = 512;

        bs->bl.opt_mem_alignment = getpagesize();



        

        bs->bl.max_iov = IOV_MAX;

    }



    if (bs->backing) {

        bdrv_refresh_limits(bs->backing->bs, &local_err);

        if (local_err) {

            error_propagate(errp, local_err);

            return;

        }

        bs->bl.opt_transfer = MAX(bs->bl.opt_transfer,

                                  bs->backing->bs->bl.opt_transfer);

        bs->bl.max_transfer = MIN_NON_ZERO(bs->bl.max_transfer,

                                           bs->backing->bs->bl.max_transfer);

        bs->bl.opt_mem_alignment =

            MAX(bs->bl.opt_mem_alignment,

                bs->backing->bs->bl.opt_mem_alignment);

        bs->bl.min_mem_alignment =

            MAX(bs->bl.min_mem_alignment,

                bs->backing->bs->bl.min_mem_alignment);

        bs->bl.max_iov =

            MIN(bs->bl.max_iov,

                bs->backing->bs->bl.max_iov);

    }



    

    if (drv->bdrv_refresh_limits) {

        drv->bdrv_refresh_limits(bs, errp);

    }

}

void FUNC_0(BlockDriverState *VAR_0, Error **VAR_1)

{

    BlockDriver *drv = VAR_0->drv;

    Error *local_err = NULL;



    memset(&VAR_0->bl, 0, sizeof(VAR_0->bl));



    if (!drv) {

        return;

    }



    

    VAR_0->request_alignment = drv->bdrv_co_preadv ? 1 : 512;



    

    if (VAR_0->file) {

        FUNC_0(VAR_0->file->VAR_0, &local_err);

        if (local_err) {

            error_propagate(VAR_1, local_err);

            return;

        }

        VAR_0->bl.opt_transfer = VAR_0->file->VAR_0->bl.opt_transfer;

        VAR_0->bl.max_transfer = VAR_0->file->VAR_0->bl.max_transfer;

        VAR_0->bl.min_mem_alignment = VAR_0->file->VAR_0->bl.min_mem_alignment;

        VAR_0->bl.opt_mem_alignment = VAR_0->file->VAR_0->bl.opt_mem_alignment;

        VAR_0->bl.max_iov = VAR_0->file->VAR_0->bl.max_iov;

    } else {

        VAR_0->bl.min_mem_alignment = 512;

        VAR_0->bl.opt_mem_alignment = getpagesize();



        

        VAR_0->bl.max_iov = IOV_MAX;

    }



    if (VAR_0->backing) {

        FUNC_0(VAR_0->backing->VAR_0, &local_err);

        if (local_err) {

            error_propagate(VAR_1, local_err);

            return;

        }

        VAR_0->bl.opt_transfer = MAX(VAR_0->bl.opt_transfer,

                                  VAR_0->backing->VAR_0->bl.opt_transfer);

        VAR_0->bl.max_transfer = MIN_NON_ZERO(VAR_0->bl.max_transfer,

                                           VAR_0->backing->VAR_0->bl.max_transfer);

        VAR_0->bl.opt_mem_alignment =

            MAX(VAR_0->bl.opt_mem_alignment,

                VAR_0->backing->VAR_0->bl.opt_mem_alignment);

        VAR_0->bl.min_mem_alignment =

            MAX(VAR_0->bl.min_mem_alignment,

                VAR_0->backing->VAR_0->bl.min_mem_alignment);

        VAR_0->bl.max_iov =

            MIN(VAR_0->bl.max_iov,

                VAR_0->backing->VAR_0->bl.max_iov);

    }



    

    if (drv->FUNC_0) {

        drv->FUNC_0(VAR_0, VAR_1);

    }

}

void FUNC_0(BlockDriverState *VAR_0, Error **VAR_1)
{ BlockDriver *drv = VAR_0->drv; Error *local_err = NULL; memset(&VAR_0->bl, 0, sizeof(VAR_0->bl)); if (!drv) { return; } VAR_0->request_alignment = drv->bdrv_co_preadv ? 1 : 512; if (VAR_0->file) { FUNC_0(VAR_0->file->VAR_0, &local_err); if (local_err) { error_propagate(VAR_1, local_err); return; } VAR_0->bl.opt_transfer = VAR_0->file->VAR_0->bl.opt_transfer; VAR_0->bl.max_transfer = VAR_0->file->VAR_0->bl.max_transfer; VAR_0->bl.min_mem_alignment = VAR_0->file->VAR_0->bl.min_mem_alignment; VAR_0->bl.opt_mem_alignment = VAR_0->file->VAR_0->bl.opt_mem_alignment; VAR_0->bl.max_iov = VAR_0->file->VAR_0->bl.max_iov; } else { VAR_0->bl.min_mem_alignment = 512; VAR_0->bl.opt_mem_alignment = getpagesize(); VAR_0->bl.max_iov = IOV_MAX; } if (VAR_0->backing) { FUNC_0(VAR_0->backing->VAR_0, &local_err); if (local_err) { error_propagate(VAR_1, local_err); return; } VAR_0->bl.opt_transfer = MAX(VAR_0->bl.opt_transfer,
VAR_0->backing->VAR_0->bl.opt_transfer); VAR_0->bl.max_transfer = MIN_NON_ZERO(VAR_0->bl.max_transfer,
VAR_0->backing->VAR_0->bl.max_transfer); VAR_0->bl.opt_mem_alignment =
MAX(VAR_0->bl.opt_mem_alignment,
VAR_0->backing->VAR_0->bl.opt_mem_alignment); VAR_0->bl.min_mem_alignment =
MAX(VAR_0->bl.min_mem_alignment,
VAR_0->backing->VAR_0->bl.min_mem_alignment); VAR_0->bl.max_iov =
MIN(VAR_0->bl.max_iov,
VAR_0->backing->VAR_0->bl.max_iov); } if (drv->FUNC_0) { drv->FUNC_0(VAR_0, VAR_1); } }