Skip to content

Commit

Permalink
blkdebug: process all set_state rules in the old state
Browse files Browse the repository at this point in the history
Currently it is impossible to write a blkdebug script that ping-pongs
between two states, because the second set-state rule will use the
state that is set in the first.  If you have

    [set-state]
    event = "..."
    state = "1"
    new_state = "2"

    [set-state]
    event = "..."
    state = "2"
    new_state = "1"

for example the state will remain locked at 1.  This can be fixed
by first processing all rules, and then setting the state.

Signed-off-by: Paolo Bonzini <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
bonzini authored and kevmw committed Sep 28, 2012
1 parent 1d80909 commit 8f96b5b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions block/blkdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

typedef struct BDRVBlkdebugState {
int state;
int new_state;
QLIST_HEAD(, BlkdebugRule) rules[BLKDBG_EVENT_MAX];
QSIMPLEQ_HEAD(, BlkdebugRule) active_rules;
} BDRVBlkdebugState;
Expand Down Expand Up @@ -403,12 +404,12 @@ static void blkdebug_close(BlockDriverState *bs)
}

static bool process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
int old_state, bool injected)
bool injected)
{
BDRVBlkdebugState *s = bs->opaque;

/* Only process rules for the current state */
if (rule->state && rule->state != old_state) {
if (rule->state && rule->state != s->state) {
return injected;
}

Expand All @@ -423,7 +424,7 @@ static bool process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
break;

case ACTION_SET_STATE:
s->state = rule->options.set_state.new_state;
s->new_state = rule->options.set_state.new_state;
break;
}
return injected;
Expand All @@ -433,15 +434,16 @@ static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event)
{
BDRVBlkdebugState *s = bs->opaque;
struct BlkdebugRule *rule;
int old_state = s->state;
bool injected;

assert((int)event >= 0 && event < BLKDBG_EVENT_MAX);

injected = false;
s->new_state = s->state;
QLIST_FOREACH(rule, &s->rules[event], next) {
injected = process_rule(bs, rule, old_state, injected);
injected = process_rule(bs, rule, injected);
}
s->state = s->new_state;
}

static int64_t blkdebug_getlength(BlockDriverState *bs)
Expand Down

0 comments on commit 8f96b5b

Please sign in to comment.