Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrDnD-0004OW-1h for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:27 -0400 Received: from [199.232.76.173] (port=60316 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrDnB-0004Nw-UI for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:25 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrDnA-0005rM-7L for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12350) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NrDn9-0005rC-Jf for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:23 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2FH9MEE006243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 15 Mar 2010 13:09:22 -0400 From: Kevin Wolf Date: Mon, 15 Mar 2010 18:08:32 +0100 Message-Id: <1268672915-12233-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1268672915-12233-1-git-send-email-kwolf@redhat.com> References: <1268672915-12233-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [RFC][PATCH 4/7] blkdebug: Inject errors List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com Add a mechanism to inject errors instead of passing requests on. With no further patches applied, you can use it by setting inject_errno in gdb. Signed-off-by: Kevin Wolf --- block/blkdebug.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 2c7e0dd..f8ccd3c 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -26,10 +26,26 @@ #include "block_int.h" #include "module.h" +#include + typedef struct BDRVBlkdebugState { BlockDriverState *hd; + + int inject_errno; + bool inject_once; + + /* Decides if aio_readv/writev fails right away (true) or returns an error + * return value only in the callback (false) */ + bool inject_immediately; } BDRVBlkdebugState; +struct callback_data { + QEMUBH *bh; + BlockDriverCompletionFunc *cb; + int ret; + void *opaque; +}; + static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags) { BDRVBlkdebugState *s = bs->opaque; @@ -42,11 +58,53 @@ static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags) return bdrv_file_open(&s->hd, filename, flags); } +static void error_callback_bh(void *opaque) +{ + struct callback_data *d = opaque; + qemu_bh_delete(d->bh); + d->cb(d->opaque, d->ret); + qemu_free(d); +} + +static BlockDriverAIOCB *inject_error(BlockDriverState *bs, + BlockDriverCompletionFunc *cb, void *opaque) +{ + BDRVBlkdebugState *s = bs->opaque; + int error = s->inject_errno; + struct callback_data *d; + QEMUBH *bh; + + if (s->inject_once) { + s->inject_errno = 0; + } + + if (s->inject_immediately) { + return NULL; + } + + d = qemu_mallocz(sizeof(*d)); + d->ret = error; + d->opaque = opaque; + d->cb = cb; + + bh = qemu_bh_new(error_callback_bh, d); + d->bh = bh; + qemu_bh_schedule(bh); + + // TODO Use a real AIOCB + return (BlockDriverAIOCB*) 42; +} + static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque) { BDRVBlkdebugState *s = bs->opaque; + + if (s->inject_errno) { + return inject_error(bs, cb, opaque); + } + BlockDriverAIOCB *acb = bdrv_aio_readv(s->hd, sector_num, qiov, nb_sectors, cb, opaque); return acb; @@ -57,6 +115,11 @@ static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque) { BDRVBlkdebugState *s = bs->opaque; + + if (s->inject_errno) { + return inject_error(bs, cb, opaque); + } + BlockDriverAIOCB *acb = bdrv_aio_writev(s->hd, sector_num, qiov, nb_sectors, cb, opaque); return acb; -- 1.6.6.1