From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sc9ST-0006OJ-U7 for qemu-devel@nongnu.org; Wed, 06 Jun 2012 02:11:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sc9SS-0004kJ-6A for qemu-devel@nongnu.org; Wed, 06 Jun 2012 02:11:05 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:50120) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sc9SR-0004fk-Te for qemu-devel@nongnu.org; Wed, 06 Jun 2012 02:11:04 -0400 Received: by mail-pz0-f45.google.com with SMTP id v2so9020002dad.4 for ; Tue, 05 Jun 2012 23:11:03 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 6 Jun 2012 08:10:43 +0200 Message-Id: <1338963044-21445-6-git-send-email-pbonzini@redhat.com> In-Reply-To: <1338963044-21445-1-git-send-email-pbonzini@redhat.com> References: <1338963044-21445-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 5/6] blkdebug: optionally tie errors to a specific sector List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com This makes blkdebug scripts more powerful, and independent of the exact sequence of operations performed by streaming. Signed-off-by: Paolo Bonzini --- block/blkdebug.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index d12ebbf..59dcea0 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -59,6 +59,7 @@ typedef struct BlkdebugRule { int error; int immediately; int once; + int64_t sector; } inject; struct { int new_state; @@ -85,6 +86,10 @@ static QemuOptsList inject_error_opts = { .type = QEMU_OPT_NUMBER, }, { + .name = "sector", + .type = QEMU_OPT_NUMBER, + }, + { .name = "once", .type = QEMU_OPT_BOOL, }, @@ -213,6 +218,7 @@ static int add_rule(QemuOpts *opts, void *opaque) 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: @@ -343,7 +349,15 @@ static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque) { BDRVBlkdebugState *s = bs->opaque; - BlkdebugRule *rule = QSIMPLEQ_FIRST(&s->active_rules); + BlkdebugRule *rule = NULL; + + QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) { + if (rule->options.inject.sector == -1 || + (rule->options.inject.sector >= sector_num && + rule->options.inject.sector < sector_num + nb_sectors)) { + break; + } + } if (rule && rule->options.inject.error) { return inject_error(bs, cb, opaque, rule); @@ -357,7 +371,15 @@ static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque) { BDRVBlkdebugState *s = bs->opaque; - BlkdebugRule *rule = QSIMPLEQ_FIRST(&s->active_rules); + BlkdebugRule *rule = NULL; + + QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) { + if (rule->options.inject.sector == -1 || + (rule->options.inject.sector >= sector_num && + rule->options.inject.sector < sector_num + nb_sectors)) { + break; + } + } if (rule && rule->options.inject.error) { return inject_error(bs, cb, opaque, rule); -- 1.7.10.1