void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,

                               int64_t bps_wr,

                               int64_t iops,

                               int64_t iops_rd,

                               int64_t iops_wr,

                               bool has_bps_max,

                               int64_t bps_max,

                               bool has_bps_rd_max,

                               int64_t bps_rd_max,

                               bool has_bps_wr_max,

                               int64_t bps_wr_max,

                               bool has_iops_max,

                               int64_t iops_max,

                               bool has_iops_rd_max,

                               int64_t iops_rd_max,

                               bool has_iops_wr_max,

                               int64_t iops_wr_max,

                               bool has_iops_size,

                               int64_t iops_size,

                               bool has_group,

                               const char *group, Error **errp)

{

    ThrottleConfig cfg;

    BlockDriverState *bs;

    BlockBackend *blk;

    AioContext *aio_context;



    blk = blk_by_name(device);

    if (!blk) {

        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,

                  "Device '%s' not found", device);

        return;

    }



    aio_context = blk_get_aio_context(blk);

    aio_context_acquire(aio_context);



    bs = blk_bs(blk);

    if (!bs) {

        error_setg(errp, "Device '%s' has no medium", device);

        goto out;

    }



    memset(&cfg, 0, sizeof(cfg));

    cfg.buckets[THROTTLE_BPS_TOTAL].avg = bps;

    cfg.buckets[THROTTLE_BPS_READ].avg  = bps_rd;

    cfg.buckets[THROTTLE_BPS_WRITE].avg = bps_wr;



    cfg.buckets[THROTTLE_OPS_TOTAL].avg = iops;

    cfg.buckets[THROTTLE_OPS_READ].avg  = iops_rd;

    cfg.buckets[THROTTLE_OPS_WRITE].avg = iops_wr;



    if (has_bps_max) {

        cfg.buckets[THROTTLE_BPS_TOTAL].max = bps_max;

    }

    if (has_bps_rd_max) {

        cfg.buckets[THROTTLE_BPS_READ].max = bps_rd_max;

    }

    if (has_bps_wr_max) {

        cfg.buckets[THROTTLE_BPS_WRITE].max = bps_wr_max;

    }

    if (has_iops_max) {

        cfg.buckets[THROTTLE_OPS_TOTAL].max = iops_max;

    }

    if (has_iops_rd_max) {

        cfg.buckets[THROTTLE_OPS_READ].max = iops_rd_max;

    }

    if (has_iops_wr_max) {

        cfg.buckets[THROTTLE_OPS_WRITE].max = iops_wr_max;

    }



    if (has_iops_size) {

        cfg.op_size = iops_size;

    }



    if (!check_throttle_config(&cfg, errp)) {

        goto out;

    }



    if (throttle_enabled(&cfg)) {

        /* Enable I/O limits if they're not enabled yet, otherwise

         * just update the throttling group. */

        if (!bs->io_limits_enabled) {

            bdrv_io_limits_enable(bs, has_group ? group : device);

        } else if (has_group) {

            bdrv_io_limits_update_group(bs, group);

        }

        /* Set the new throttling configuration */

        bdrv_set_io_limits(bs, &cfg);

    } else if (bs->io_limits_enabled) {

        /* If all throttling settings are set to 0, disable I/O limits */

        bdrv_io_limits_disable(bs);

    }



out:

    aio_context_release(aio_context);

}

void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,

                               int64_t bps_wr,

                               int64_t iops,

                               int64_t iops_rd,

                               int64_t iops_wr,

                               bool has_bps_max,

                               int64_t bps_max,

                               bool has_bps_rd_max,

                               int64_t bps_rd_max,

                               bool has_bps_wr_max,

                               int64_t bps_wr_max,

                               bool has_iops_max,

                               int64_t iops_max,

                               bool has_iops_rd_max,

                               int64_t iops_rd_max,

                               bool has_iops_wr_max,

                               int64_t iops_wr_max,

                               bool has_iops_size,

                               int64_t iops_size,

                               bool has_group,

                               const char *group, Error **errp)

{

    ThrottleConfig cfg;

    BlockDriverState *bs;

    BlockBackend *blk;

    AioContext *aio_context;



    blk = blk_by_name(device);

    if (!blk) {

        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,

                  "Device '%s' not found", device);

        return;

    }



    aio_context = blk_get_aio_context(blk);

    aio_context_acquire(aio_context);



    bs = blk_bs(blk);

    if (!bs) {

        error_setg(errp, "Device '%s' has no medium", device);

        goto out;

    }



    memset(&cfg, 0, sizeof(cfg));

    cfg.buckets[THROTTLE_BPS_TOTAL].avg = bps;

    cfg.buckets[THROTTLE_BPS_READ].avg  = bps_rd;

    cfg.buckets[THROTTLE_BPS_WRITE].avg = bps_wr;



    cfg.buckets[THROTTLE_OPS_TOTAL].avg = iops;

    cfg.buckets[THROTTLE_OPS_READ].avg  = iops_rd;

    cfg.buckets[THROTTLE_OPS_WRITE].avg = iops_wr;



    if (has_bps_max) {

        cfg.buckets[THROTTLE_BPS_TOTAL].max = bps_max;

    }

    if (has_bps_rd_max) {

        cfg.buckets[THROTTLE_BPS_READ].max = bps_rd_max;

    }

    if (has_bps_wr_max) {

        cfg.buckets[THROTTLE_BPS_WRITE].max = bps_wr_max;

    }

    if (has_iops_max) {

        cfg.buckets[THROTTLE_OPS_TOTAL].max = iops_max;

    }

    if (has_iops_rd_max) {

        cfg.buckets[THROTTLE_OPS_READ].max = iops_rd_max;

    }

    if (has_iops_wr_max) {

        cfg.buckets[THROTTLE_OPS_WRITE].max = iops_wr_max;

    }



    if (has_iops_size) {

        cfg.op_size = iops_size;

    }



    if (!check_throttle_config(&cfg, errp)) {

        goto out;

    }



    if (throttle_enabled(&cfg)) {

        



        if (!bs->io_limits_enabled) {

            bdrv_io_limits_enable(bs, has_group ? group : device);

        } else if (has_group) {

            bdrv_io_limits_update_group(bs, group);

        }

        

        bdrv_set_io_limits(bs, &cfg);

    } else if (bs->io_limits_enabled) {

        

        bdrv_io_limits_disable(bs);

    }



out:

    aio_context_release(aio_context);

}

void FUNC_0(const char *VAR_0, int64_t VAR_1, int64_t VAR_2,

                               int64_t VAR_3,

                               int64_t VAR_4,

                               int64_t VAR_5,

                               int64_t VAR_6,

                               bool VAR_7,

                               int64_t VAR_8,

                               bool VAR_9,

                               int64_t VAR_10,

                               bool VAR_11,

                               int64_t VAR_12,

                               bool VAR_13,

                               int64_t VAR_14,

                               bool VAR_15,

                               int64_t VAR_16,

                               bool VAR_17,

                               int64_t VAR_18,

                               bool VAR_19,

                               int64_t VAR_20,

                               bool VAR_21,

                               const char *VAR_22, Error **VAR_23)

{

    ThrottleConfig cfg;

    BlockDriverState *bs;

    BlockBackend *blk;

    AioContext *aio_context;



    blk = blk_by_name(VAR_0);

    if (!blk) {

        error_set(VAR_23, ERROR_CLASS_DEVICE_NOT_FOUND,

                  "Device '%s' not found", VAR_0);

        return;

    }



    aio_context = blk_get_aio_context(blk);

    aio_context_acquire(aio_context);



    bs = blk_bs(blk);

    if (!bs) {

        error_setg(VAR_23, "Device '%s' has no medium", VAR_0);

        goto out;

    }



    memset(&cfg, 0, sizeof(cfg));

    cfg.buckets[THROTTLE_BPS_TOTAL].avg = VAR_1;

    cfg.buckets[THROTTLE_BPS_READ].avg  = VAR_2;

    cfg.buckets[THROTTLE_BPS_WRITE].avg = VAR_3;



    cfg.buckets[THROTTLE_OPS_TOTAL].avg = VAR_4;

    cfg.buckets[THROTTLE_OPS_READ].avg  = VAR_5;

    cfg.buckets[THROTTLE_OPS_WRITE].avg = VAR_6;



    if (VAR_7) {

        cfg.buckets[THROTTLE_BPS_TOTAL].max = VAR_8;

    }

    if (VAR_9) {

        cfg.buckets[THROTTLE_BPS_READ].max = VAR_10;

    }

    if (VAR_11) {

        cfg.buckets[THROTTLE_BPS_WRITE].max = VAR_12;

    }

    if (VAR_13) {

        cfg.buckets[THROTTLE_OPS_TOTAL].max = VAR_14;

    }

    if (VAR_15) {

        cfg.buckets[THROTTLE_OPS_READ].max = VAR_16;

    }

    if (VAR_17) {

        cfg.buckets[THROTTLE_OPS_WRITE].max = VAR_18;

    }



    if (VAR_19) {

        cfg.op_size = VAR_20;

    }



    if (!check_throttle_config(&cfg, VAR_23)) {

        goto out;

    }



    if (throttle_enabled(&cfg)) {

        



        if (!bs->io_limits_enabled) {

            bdrv_io_limits_enable(bs, VAR_21 ? VAR_22 : VAR_0);

        } else if (VAR_21) {

            bdrv_io_limits_update_group(bs, VAR_22);

        }

        

        bdrv_set_io_limits(bs, &cfg);

    } else if (bs->io_limits_enabled) {

        

        bdrv_io_limits_disable(bs);

    }



out:

    aio_context_release(aio_context);

}

void FUNC_0(const char *VAR_0, int64_t VAR_1, int64_t VAR_2,
int64_t VAR_3,
int64_t VAR_4,
int64_t VAR_5,
int64_t VAR_6,
bool VAR_7,
int64_t VAR_8,
bool VAR_9,
int64_t VAR_10,
bool VAR_11,
int64_t VAR_12,
bool VAR_13,
int64_t VAR_14,
bool VAR_15,
int64_t VAR_16,
bool VAR_17,
int64_t VAR_18,
bool VAR_19,
int64_t VAR_20,
bool VAR_21,
const char *VAR_22, Error **VAR_23)
{ ThrottleConfig cfg; BlockDriverState *bs; BlockBackend *blk; AioContext *aio_context; blk = blk_by_name(VAR_0); if (!blk) { error_set(VAR_23, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", VAR_0); return; } aio_context = blk_get_aio_context(blk); aio_context_acquire(aio_context); bs = blk_bs(blk); if (!bs) { error_setg(VAR_23, "Device '%s' has no medium", VAR_0); goto out; } memset(&cfg, 0, sizeof(cfg)); cfg.buckets[THROTTLE_BPS_TOTAL].avg = VAR_1; cfg.buckets[THROTTLE_BPS_READ].avg  = VAR_2; cfg.buckets[THROTTLE_BPS_WRITE].avg = VAR_3; cfg.buckets[THROTTLE_OPS_TOTAL].avg = VAR_4; cfg.buckets[THROTTLE_OPS_READ].avg  = VAR_5; cfg.buckets[THROTTLE_OPS_WRITE].avg = VAR_6; if (VAR_7) { cfg.buckets[THROTTLE_BPS_TOTAL].max = VAR_8; } if (VAR_9) { cfg.buckets[THROTTLE_BPS_READ].max = VAR_10; } if (VAR_11) { cfg.buckets[THROTTLE_BPS_WRITE].max = VAR_12; } if (VAR_13) { cfg.buckets[THROTTLE_OPS_TOTAL].max = VAR_14; } if (VAR_15) { cfg.buckets[THROTTLE_OPS_READ].max = VAR_16; } if (VAR_17) { cfg.buckets[THROTTLE_OPS_WRITE].max = VAR_18; } if (VAR_19) { cfg.op_size = VAR_20; } if (!check_throttle_config(&cfg, VAR_23)) { goto out; } if (throttle_enabled(&cfg)) { if (!bs->io_limits_enabled) { bdrv_io_limits_enable(bs, VAR_21 ? VAR_22 : VAR_0); } else if (VAR_21) { bdrv_io_limits_update_group(bs, VAR_22); } bdrv_set_io_limits(bs, &cfg); } else if (bs->io_limits_enabled) { bdrv_io_limits_disable(bs); } out:
aio_context_release(aio_context); }