static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,

                         Error **errp)

{

    BDRVBlkdebugState *s = bs->opaque;

    QemuOpts *opts;

    Error *local_err = NULL;

    int ret;



    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, options, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        ret = -EINVAL;

        goto out;

    }



    /* Read rules from config file or command line options */

    s->config_file = g_strdup(qemu_opt_get(opts, "config"));

    ret = read_config(s, s->config_file, options, errp);

    if (ret) {

        goto out;

    }



    /* Set initial state */

    s->state = 1;



    /* Open the image file */

    bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image",

                               bs, &child_file, false, &local_err);

    if (local_err) {

        ret = -EINVAL;

        error_propagate(errp, local_err);

        goto out;

    }



    bs->supported_write_flags = BDRV_REQ_FUA &

        bs->file->bs->supported_write_flags;

    bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &

        bs->file->bs->supported_zero_flags;

    ret = -EINVAL;



    /* Set request alignment */

    s->align = qemu_opt_get_size(opts, "align", 0);

    if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {

        error_setg(errp, "Cannot meet constraints with align %" PRIu64,

                   s->align);

        goto out;

    }



    ret = 0;

out:

    if (ret < 0) {

        g_free(s->config_file);

    }

    qemu_opts_del(opts);

    return ret;

}

static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,

                         Error **errp)

{

    BDRVBlkdebugState *s = bs->opaque;

    QemuOpts *opts;

    Error *local_err = NULL;

    int ret;



    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, options, &local_err);

    if (local_err) {

        error_propagate(errp, local_err);

        ret = -EINVAL;

        goto out;

    }



    

    s->config_file = g_strdup(qemu_opt_get(opts, "config"));

    ret = read_config(s, s->config_file, options, errp);

    if (ret) {

        goto out;

    }



    

    s->state = 1;



    

    bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image",

                               bs, &child_file, false, &local_err);

    if (local_err) {

        ret = -EINVAL;

        error_propagate(errp, local_err);

        goto out;

    }



    bs->supported_write_flags = BDRV_REQ_FUA &

        bs->file->bs->supported_write_flags;

    bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &

        bs->file->bs->supported_zero_flags;

    ret = -EINVAL;



    

    s->align = qemu_opt_get_size(opts, "align", 0);

    if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {

        error_setg(errp, "Cannot meet constraints with align %" PRIu64,

                   s->align);

        goto out;

    }



    ret = 0;

out:

    if (ret < 0) {

        g_free(s->config_file);

    }

    qemu_opts_del(opts);

    return ret;

}

static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,

                         Error **VAR_3)

{

    BDRVBlkdebugState *s = VAR_0->opaque;

    QemuOpts *opts;

    Error *local_err = NULL;

    int VAR_4;



    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);

    qemu_opts_absorb_qdict(opts, VAR_1, &local_err);

    if (local_err) {

        error_propagate(VAR_3, local_err);

        VAR_4 = -EINVAL;

        goto out;

    }



    

    s->config_file = g_strdup(qemu_opt_get(opts, "config"));

    VAR_4 = read_config(s, s->config_file, VAR_1, VAR_3);

    if (VAR_4) {

        goto out;

    }



    

    s->state = 1;



    

    VAR_0->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), VAR_1, "image",

                               VAR_0, &child_file, false, &local_err);

    if (local_err) {

        VAR_4 = -EINVAL;

        error_propagate(VAR_3, local_err);

        goto out;

    }



    VAR_0->supported_write_flags = BDRV_REQ_FUA &

        VAR_0->file->VAR_0->supported_write_flags;

    VAR_0->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &

        VAR_0->file->VAR_0->supported_zero_flags;

    VAR_4 = -EINVAL;



    

    s->align = qemu_opt_get_size(opts, "align", 0);

    if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {

        error_setg(VAR_3, "Cannot meet constraints with align %" PRIu64,

                   s->align);

        goto out;

    }



    VAR_4 = 0;

out:

    if (VAR_4 < 0) {

        g_free(s->config_file);

    }

    qemu_opts_del(opts);

    return VAR_4;

}

static int FUNC_0(BlockDriverState *VAR_0, QDict *VAR_1, int VAR_2,
Error **VAR_3)
{ BDRVBlkdebugState *s = VAR_0->opaque; QemuOpts *opts; Error *local_err = NULL; int VAR_4; opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, VAR_1, &local_err); if (local_err) { error_propagate(VAR_3, local_err); VAR_4 = -EINVAL; goto out; } s->config_file = g_strdup(qemu_opt_get(opts, "config")); VAR_4 = read_config(s, s->config_file, VAR_1, VAR_3); if (VAR_4) { goto out; } s->state = 1; VAR_0->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), VAR_1, "image",
VAR_0, &child_file, false, &local_err); if (local_err) { VAR_4 = -EINVAL; error_propagate(VAR_3, local_err); goto out; } VAR_0->supported_write_flags = BDRV_REQ_FUA &
VAR_0->file->VAR_0->supported_write_flags; VAR_0->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
VAR_0->file->VAR_0->supported_zero_flags; VAR_4 = -EINVAL; s->align = qemu_opt_get_size(opts, "align", 0); if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) { error_setg(VAR_3, "Cannot meet constraints with align %" PRIu64,
s->align); goto out; } VAR_4 = 0; out:
if (VAR_4 < 0) { g_free(s->config_file); } qemu_opts_del(opts); return VAR_4; }