From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGu07-0002iV-7R for qemu-devel@nongnu.org; Wed, 26 Sep 2012 11:58:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGu00-00051g-Gh for qemu-devel@nongnu.org; Wed, 26 Sep 2012 11:58:14 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:36644) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGu00-0004Z6-8i for qemu-devel@nongnu.org; Wed, 26 Sep 2012 11:58:08 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so2106416pbb.4 for ; Wed, 26 Sep 2012 08:58:07 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 26 Sep 2012 17:56:22 +0200 Message-Id: <1348675011-8794-17-git-send-email-pbonzini@redhat.com> In-Reply-To: <1348675011-8794-1-git-send-email-pbonzini@redhat.com> References: <1348675011-8794-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 16/45] blkdebug: process all set_state rules in the old state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, jcody@redhat.com 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 --- v1->v2: dropped stray debug printfs block/blkdebug.c | 12 +++++++----- 1 file modificato, 7 inserzioni(+), 5 rimozioni(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 59dcea0..1206d52 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -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; @@ -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; } @@ -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; @@ -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) -- 1.7.12