static int add_rule(QemuOpts *opts, void *opaque)

{

    struct add_rule_data *d = opaque;

    BDRVBlkdebugState *s = d->s;

    const char* event_name;

    BlkDebugEvent event;

    struct BlkdebugRule *rule;



    /* Find the right event for the rule */

    event_name = qemu_opt_get(opts, "event");

    if (!event_name || get_event_by_name(event_name, &event) < 0) {

        return -1;

    }



    /* Set attributes common for all actions */

    rule = g_malloc0(sizeof(*rule));

    *rule = (struct BlkdebugRule) {

        .event  = event,

        .action = d->action,

        .state  = qemu_opt_get_number(opts, "state", 0),

    };



    /* Parse action-specific options */

    switch (d->action) {

    case ACTION_INJECT_ERROR:

        rule->options.inject.error = qemu_opt_get_number(opts, "errno", EIO);

        rule->options.inject.once  = qemu_opt_get_bool(opts, "once", 0);

        rule->options.inject.immediately =

            qemu_opt_get_bool(opts, "immediately", 0);

        rule->options.inject.sector = qemu_opt_get_number(opts, "sector", -1);

        break;



    case ACTION_SET_STATE:

        rule->options.set_state.new_state =

            qemu_opt_get_number(opts, "new_state", 0);

        break;



    case ACTION_SUSPEND:

        rule->options.suspend.tag =

            g_strdup(qemu_opt_get(opts, "tag"));

        break;

    };



    /* Add the rule */

    QLIST_INSERT_HEAD(&s->rules[event], rule, next);



    return 0;

}

static int add_rule(QemuOpts *opts, void *opaque)

{

    struct add_rule_data *d = opaque;

    BDRVBlkdebugState *s = d->s;

    const char* event_name;

    BlkDebugEvent event;

    struct BlkdebugRule *rule;



    

    event_name = qemu_opt_get(opts, "event");

    if (!event_name || get_event_by_name(event_name, &event) < 0) {

        return -1;

    }



    

    rule = g_malloc0(sizeof(*rule));

    *rule = (struct BlkdebugRule) {

        .event  = event,

        .action = d->action,

        .state  = qemu_opt_get_number(opts, "state", 0),

    };



    

    switch (d->action) {

    case ACTION_INJECT_ERROR:

        rule->options.inject.error = qemu_opt_get_number(opts, "errno", EIO);

        rule->options.inject.once  = qemu_opt_get_bool(opts, "once", 0);

        rule->options.inject.immediately =

            qemu_opt_get_bool(opts, "immediately", 0);

        rule->options.inject.sector = qemu_opt_get_number(opts, "sector", -1);

        break;



    case ACTION_SET_STATE:

        rule->options.set_state.new_state =

            qemu_opt_get_number(opts, "new_state", 0);

        break;



    case ACTION_SUSPEND:

        rule->options.suspend.tag =

            g_strdup(qemu_opt_get(opts, "tag"));

        break;

    };



    

    QLIST_INSERT_HEAD(&s->rules[event], rule, next);



    return 0;

}

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

{

    struct add_rule_data *VAR_2 = VAR_1;

    BDRVBlkdebugState *s = VAR_2->s;

    const char* VAR_3;

    BlkDebugEvent event;

    struct BlkdebugRule *VAR_4;



    

    VAR_3 = qemu_opt_get(VAR_0, "event");

    if (!VAR_3 || get_event_by_name(VAR_3, &event) < 0) {

        return -1;

    }



    

    VAR_4 = g_malloc0(sizeof(*VAR_4));

    *VAR_4 = (struct BlkdebugRule) {

        .event  = event,

        .action = VAR_2->action,

        .state  = qemu_opt_get_number(VAR_0, "state", 0),

    };



    

    switch (VAR_2->action) {

    case ACTION_INJECT_ERROR:

        VAR_4->options.inject.error = qemu_opt_get_number(VAR_0, "errno", EIO);

        VAR_4->options.inject.once  = qemu_opt_get_bool(VAR_0, "once", 0);

        VAR_4->options.inject.immediately =

            qemu_opt_get_bool(VAR_0, "immediately", 0);

        VAR_4->options.inject.sector = qemu_opt_get_number(VAR_0, "sector", -1);

        break;



    case ACTION_SET_STATE:

        VAR_4->options.set_state.new_state =

            qemu_opt_get_number(VAR_0, "new_state", 0);

        break;



    case ACTION_SUSPEND:

        VAR_4->options.suspend.tag =

            g_strdup(qemu_opt_get(VAR_0, "tag"));

        break;

    };



    

    QLIST_INSERT_HEAD(&s->rules[event], VAR_4, next);



    return 0;

}

static int FUNC_0(QemuOpts *VAR_0, void *VAR_1)
{ struct add_rule_data *VAR_2 = VAR_1; BDRVBlkdebugState *s = VAR_2->s; const char* VAR_3; BlkDebugEvent event; struct BlkdebugRule *VAR_4; VAR_3 = qemu_opt_get(VAR_0, "event"); if (!VAR_3 || get_event_by_name(VAR_3, &event) < 0) { return -1; } VAR_4 = g_malloc0(sizeof(*VAR_4)); *VAR_4 = (struct BlkdebugRule) { .event  = event,
.action = VAR_2->action,
.state  = qemu_opt_get_number(VAR_0, "state", 0),
}; switch (VAR_2->action) { case ACTION_INJECT_ERROR:
VAR_4->options.inject.error = qemu_opt_get_number(VAR_0, "errno", EIO); VAR_4->options.inject.once  = qemu_opt_get_bool(VAR_0, "once", 0); VAR_4->options.inject.immediately =
qemu_opt_get_bool(VAR_0, "immediately", 0); VAR_4->options.inject.sector = qemu_opt_get_number(VAR_0, "sector", -1); break; case ACTION_SET_STATE:
VAR_4->options.set_state.new_state =
qemu_opt_get_number(VAR_0, "new_state", 0); break; case ACTION_SUSPEND:
VAR_4->options.suspend.tag =
g_strdup(qemu_opt_get(VAR_0, "tag")); break; }; QLIST_INSERT_HEAD(&s->rules[event], VAR_4, next); return 0; }