static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,

    const char **throttling_group, ThrottleConfig *throttle_cfg,

    BlockdevDetectZeroesOptions *detect_zeroes, Error **errp)

{

    const char *discard;

    Error *local_error = NULL;

    const char *aio;



    if (bdrv_flags) {

        if (!qemu_opt_get_bool(opts, "read-only", false)) {

            *bdrv_flags |= BDRV_O_RDWR;

        }

        if (qemu_opt_get_bool(opts, "copy-on-read", false)) {

            *bdrv_flags |= BDRV_O_COPY_ON_READ;

        }



        if ((discard = qemu_opt_get(opts, "discard")) != NULL) {

            if (bdrv_parse_discard_flags(discard, bdrv_flags) != 0) {

                error_setg(errp, "Invalid discard option");

                return;

            }

        }



        if ((aio = qemu_opt_get(opts, "aio")) != NULL) {

            if (!strcmp(aio, "native")) {

                *bdrv_flags |= BDRV_O_NATIVE_AIO;

            } else if (!strcmp(aio, "threads")) {

                /* this is the default */

            } else {

               error_setg(errp, "invalid aio option");

               return;

            }

        }

    }



    /* disk I/O throttling */

    if (throttling_group) {

        *throttling_group = qemu_opt_get(opts, "throttling.group");

    }



    if (throttle_cfg) {

        memset(throttle_cfg, 0, sizeof(*throttle_cfg));

        throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg =

            qemu_opt_get_number(opts, "throttling.bps-total", 0);

        throttle_cfg->buckets[THROTTLE_BPS_READ].avg  =

            qemu_opt_get_number(opts, "throttling.bps-read", 0);

        throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg =

            qemu_opt_get_number(opts, "throttling.bps-write", 0);

        throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg =

            qemu_opt_get_number(opts, "throttling.iops-total", 0);

        throttle_cfg->buckets[THROTTLE_OPS_READ].avg =

            qemu_opt_get_number(opts, "throttling.iops-read", 0);

        throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg =

            qemu_opt_get_number(opts, "throttling.iops-write", 0);



        throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max =

            qemu_opt_get_number(opts, "throttling.bps-total-max", 0);

        throttle_cfg->buckets[THROTTLE_BPS_READ].max  =

            qemu_opt_get_number(opts, "throttling.bps-read-max", 0);

        throttle_cfg->buckets[THROTTLE_BPS_WRITE].max =

            qemu_opt_get_number(opts, "throttling.bps-write-max", 0);

        throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max =

            qemu_opt_get_number(opts, "throttling.iops-total-max", 0);

        throttle_cfg->buckets[THROTTLE_OPS_READ].max =

            qemu_opt_get_number(opts, "throttling.iops-read-max", 0);

        throttle_cfg->buckets[THROTTLE_OPS_WRITE].max =

            qemu_opt_get_number(opts, "throttling.iops-write-max", 0);



        throttle_cfg->op_size =

            qemu_opt_get_number(opts, "throttling.iops-size", 0);



        if (!check_throttle_config(throttle_cfg, errp)) {

            return;

        }

    }



    if (detect_zeroes) {

        *detect_zeroes =

            qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,

                            qemu_opt_get(opts, "detect-zeroes"),

                            BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,

                            BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,

                            &local_error);

        if (local_error) {

            error_propagate(errp, local_error);

            return;

        }



        if (bdrv_flags &&

            *detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&

            !(*bdrv_flags & BDRV_O_UNMAP))

        {

            error_setg(errp, "setting detect-zeroes to unmap is not allowed "

                             "without setting discard operation to unmap");

            return;

        }

    }

}

static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,

    const char **throttling_group, ThrottleConfig *throttle_cfg,

    BlockdevDetectZeroesOptions *detect_zeroes, Error **errp)

{

    const char *discard;

    Error *local_error = NULL;

    const char *aio;



    if (bdrv_flags) {

        if (!qemu_opt_get_bool(opts, "read-only", false)) {

            *bdrv_flags |= BDRV_O_RDWR;

        }

        if (qemu_opt_get_bool(opts, "copy-on-read", false)) {

            *bdrv_flags |= BDRV_O_COPY_ON_READ;

        }



        if ((discard = qemu_opt_get(opts, "discard")) != NULL) {

            if (bdrv_parse_discard_flags(discard, bdrv_flags) != 0) {

                error_setg(errp, "Invalid discard option");

                return;

            }

        }



        if ((aio = qemu_opt_get(opts, "aio")) != NULL) {

            if (!strcmp(aio, "native")) {

                *bdrv_flags |= BDRV_O_NATIVE_AIO;

            } else if (!strcmp(aio, "threads")) {

                

            } else {

               error_setg(errp, "invalid aio option");

               return;

            }

        }

    }



    

    if (throttling_group) {

        *throttling_group = qemu_opt_get(opts, "throttling.group");

    }



    if (throttle_cfg) {

        memset(throttle_cfg, 0, sizeof(*throttle_cfg));

        throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg =

            qemu_opt_get_number(opts, "throttling.bps-total", 0);

        throttle_cfg->buckets[THROTTLE_BPS_READ].avg  =

            qemu_opt_get_number(opts, "throttling.bps-read", 0);

        throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg =

            qemu_opt_get_number(opts, "throttling.bps-write", 0);

        throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg =

            qemu_opt_get_number(opts, "throttling.iops-total", 0);

        throttle_cfg->buckets[THROTTLE_OPS_READ].avg =

            qemu_opt_get_number(opts, "throttling.iops-read", 0);

        throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg =

            qemu_opt_get_number(opts, "throttling.iops-write", 0);



        throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max =

            qemu_opt_get_number(opts, "throttling.bps-total-max", 0);

        throttle_cfg->buckets[THROTTLE_BPS_READ].max  =

            qemu_opt_get_number(opts, "throttling.bps-read-max", 0);

        throttle_cfg->buckets[THROTTLE_BPS_WRITE].max =

            qemu_opt_get_number(opts, "throttling.bps-write-max", 0);

        throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max =

            qemu_opt_get_number(opts, "throttling.iops-total-max", 0);

        throttle_cfg->buckets[THROTTLE_OPS_READ].max =

            qemu_opt_get_number(opts, "throttling.iops-read-max", 0);

        throttle_cfg->buckets[THROTTLE_OPS_WRITE].max =

            qemu_opt_get_number(opts, "throttling.iops-write-max", 0);



        throttle_cfg->op_size =

            qemu_opt_get_number(opts, "throttling.iops-size", 0);



        if (!check_throttle_config(throttle_cfg, errp)) {

            return;

        }

    }



    if (detect_zeroes) {

        *detect_zeroes =

            qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,

                            qemu_opt_get(opts, "detect-zeroes"),

                            BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,

                            BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,

                            &local_error);

        if (local_error) {

            error_propagate(errp, local_error);

            return;

        }



        if (bdrv_flags &&

            *detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&

            !(*bdrv_flags & BDRV_O_UNMAP))

        {

            error_setg(errp, "setting detect-zeroes to unmap is not allowed "

                             "without setting discard operation to unmap");

            return;

        }

    }

}

static void FUNC_0(QemuOpts *VAR_0, int *VAR_1,

    const char **VAR_2, ThrottleConfig *VAR_3,

    BlockdevDetectZeroesOptions *VAR_4, Error **VAR_5)

{

    const char *VAR_6;

    Error *local_error = NULL;

    const char *VAR_7;



    if (VAR_1) {

        if (!qemu_opt_get_bool(VAR_0, "read-only", false)) {

            *VAR_1 |= BDRV_O_RDWR;

        }

        if (qemu_opt_get_bool(VAR_0, "copy-on-read", false)) {

            *VAR_1 |= BDRV_O_COPY_ON_READ;

        }



        if ((VAR_6 = qemu_opt_get(VAR_0, "VAR_6")) != NULL) {

            if (bdrv_parse_discard_flags(VAR_6, VAR_1) != 0) {

                error_setg(VAR_5, "Invalid VAR_6 option");

                return;

            }

        }



        if ((VAR_7 = qemu_opt_get(VAR_0, "VAR_7")) != NULL) {

            if (!strcmp(VAR_7, "native")) {

                *VAR_1 |= BDRV_O_NATIVE_AIO;

            } else if (!strcmp(VAR_7, "threads")) {

                

            } else {

               error_setg(VAR_5, "invalid VAR_7 option");

               return;

            }

        }

    }



    

    if (VAR_2) {

        *VAR_2 = qemu_opt_get(VAR_0, "throttling.group");

    }



    if (VAR_3) {

        memset(VAR_3, 0, sizeof(*VAR_3));

        VAR_3->buckets[THROTTLE_BPS_TOTAL].avg =

            qemu_opt_get_number(VAR_0, "throttling.bps-total", 0);

        VAR_3->buckets[THROTTLE_BPS_READ].avg  =

            qemu_opt_get_number(VAR_0, "throttling.bps-read", 0);

        VAR_3->buckets[THROTTLE_BPS_WRITE].avg =

            qemu_opt_get_number(VAR_0, "throttling.bps-write", 0);

        VAR_3->buckets[THROTTLE_OPS_TOTAL].avg =

            qemu_opt_get_number(VAR_0, "throttling.iops-total", 0);

        VAR_3->buckets[THROTTLE_OPS_READ].avg =

            qemu_opt_get_number(VAR_0, "throttling.iops-read", 0);

        VAR_3->buckets[THROTTLE_OPS_WRITE].avg =

            qemu_opt_get_number(VAR_0, "throttling.iops-write", 0);



        VAR_3->buckets[THROTTLE_BPS_TOTAL].max =

            qemu_opt_get_number(VAR_0, "throttling.bps-total-max", 0);

        VAR_3->buckets[THROTTLE_BPS_READ].max  =

            qemu_opt_get_number(VAR_0, "throttling.bps-read-max", 0);

        VAR_3->buckets[THROTTLE_BPS_WRITE].max =

            qemu_opt_get_number(VAR_0, "throttling.bps-write-max", 0);

        VAR_3->buckets[THROTTLE_OPS_TOTAL].max =

            qemu_opt_get_number(VAR_0, "throttling.iops-total-max", 0);

        VAR_3->buckets[THROTTLE_OPS_READ].max =

            qemu_opt_get_number(VAR_0, "throttling.iops-read-max", 0);

        VAR_3->buckets[THROTTLE_OPS_WRITE].max =

            qemu_opt_get_number(VAR_0, "throttling.iops-write-max", 0);



        VAR_3->op_size =

            qemu_opt_get_number(VAR_0, "throttling.iops-size", 0);



        if (!check_throttle_config(VAR_3, VAR_5)) {

            return;

        }

    }



    if (VAR_4) {

        *VAR_4 =

            qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,

                            qemu_opt_get(VAR_0, "detect-zeroes"),

                            BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,

                            BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,

                            &local_error);

        if (local_error) {

            error_propagate(VAR_5, local_error);

            return;

        }



        if (VAR_1 &&

            *VAR_4 == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&

            !(*VAR_1 & BDRV_O_UNMAP))

        {

            error_setg(VAR_5, "setting detect-zeroes to unmap is not allowed "

                             "without setting VAR_6 operation to unmap");

            return;

        }

    }

}

static void FUNC_0(QemuOpts *VAR_0, int *VAR_1,
const char **VAR_2, ThrottleConfig *VAR_3,
BlockdevDetectZeroesOptions *VAR_4, Error **VAR_5)
{ const char *VAR_6; Error *local_error = NULL; const char *VAR_7; if (VAR_1) { if (!qemu_opt_get_bool(VAR_0, "read-only", false)) { *VAR_1 |= BDRV_O_RDWR; } if (qemu_opt_get_bool(VAR_0, "copy-on-read", false)) { *VAR_1 |= BDRV_O_COPY_ON_READ; } if ((VAR_6 = qemu_opt_get(VAR_0, "VAR_6")) != NULL) { if (bdrv_parse_discard_flags(VAR_6, VAR_1) != 0) { error_setg(VAR_5, "Invalid VAR_6 option"); return; } } if ((VAR_7 = qemu_opt_get(VAR_0, "VAR_7")) != NULL) { if (!strcmp(VAR_7, "native")) { *VAR_1 |= BDRV_O_NATIVE_AIO; } else if (!strcmp(VAR_7, "threads")) { } else { error_setg(VAR_5, "invalid VAR_7 option"); return; } } } if (VAR_2) { *VAR_2 = qemu_opt_get(VAR_0, "throttling.group"); } if (VAR_3) { memset(VAR_3, 0, sizeof(*VAR_3)); VAR_3->buckets[THROTTLE_BPS_TOTAL].avg =
qemu_opt_get_number(VAR_0, "throttling.bps-total", 0); VAR_3->buckets[THROTTLE_BPS_READ].avg  =
qemu_opt_get_number(VAR_0, "throttling.bps-read", 0); VAR_3->buckets[THROTTLE_BPS_WRITE].avg =
qemu_opt_get_number(VAR_0, "throttling.bps-write", 0); VAR_3->buckets[THROTTLE_OPS_TOTAL].avg =
qemu_opt_get_number(VAR_0, "throttling.iops-total", 0); VAR_3->buckets[THROTTLE_OPS_READ].avg =
qemu_opt_get_number(VAR_0, "throttling.iops-read", 0); VAR_3->buckets[THROTTLE_OPS_WRITE].avg =
qemu_opt_get_number(VAR_0, "throttling.iops-write", 0); VAR_3->buckets[THROTTLE_BPS_TOTAL].max =
qemu_opt_get_number(VAR_0, "throttling.bps-total-max", 0); VAR_3->buckets[THROTTLE_BPS_READ].max  =
qemu_opt_get_number(VAR_0, "throttling.bps-read-max", 0); VAR_3->buckets[THROTTLE_BPS_WRITE].max =
qemu_opt_get_number(VAR_0, "throttling.bps-write-max", 0); VAR_3->buckets[THROTTLE_OPS_TOTAL].max =
qemu_opt_get_number(VAR_0, "throttling.iops-total-max", 0); VAR_3->buckets[THROTTLE_OPS_READ].max =
qemu_opt_get_number(VAR_0, "throttling.iops-read-max", 0); VAR_3->buckets[THROTTLE_OPS_WRITE].max =
qemu_opt_get_number(VAR_0, "throttling.iops-write-max", 0); VAR_3->op_size =
qemu_opt_get_number(VAR_0, "throttling.iops-size", 0); if (!check_throttle_config(VAR_3, VAR_5)) { return; } } if (VAR_4) { *VAR_4 =
qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
qemu_opt_get(VAR_0, "detect-zeroes"),
BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
&local_error); if (local_error) { error_propagate(VAR_5, local_error); return; } if (VAR_1 &&
*VAR_4 == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&
!(*VAR_1 & BDRV_O_UNMAP))
{ error_setg(VAR_5, "setting detect-zeroes to unmap is not allowed "
"without setting VAR_6 operation to unmap"); return; } } }