From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH v2 4/7] blkdebug: Inject errors
Date: Mon, 29 Mar 2010 16:52:45 +0200 [thread overview]
Message-ID: <1269874368-31011-5-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1269874368-31011-1-git-send-email-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 <kwolf@redhat.com>
---
block/blkdebug.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 2c7e0dd..dad3ac6 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -26,10 +26,41 @@
#include "block_int.h"
#include "module.h"
+#include <stdbool.h>
+
+typedef struct BlkdebugVars {
+ int state;
+
+ /* If inject_errno != 0, an error is injected for requests */
+ int inject_errno;
+
+ /* Decides if all future requests fail (false) or only the next one and
+ * after the next request inject_errno is reset to 0 (true) */
+ 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;
+} BlkdebugVars;
+
typedef struct BDRVBlkdebugState {
BlockDriverState *hd;
+ BlkdebugVars vars;
} BDRVBlkdebugState;
+typedef struct BlkdebugAIOCB {
+ BlockDriverAIOCB common;
+ QEMUBH *bh;
+ int ret;
+} BlkdebugAIOCB;
+
+static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb);
+
+static AIOPool blkdebug_aio_pool = {
+ .aiocb_size = sizeof(BlkdebugAIOCB),
+ .cancel = blkdebug_aio_cancel,
+};
+
static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVBlkdebugState *s = bs->opaque;
@@ -42,11 +73,56 @@ 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 BlkdebugAIOCB *acb = opaque;
+ qemu_bh_delete(acb->bh);
+ acb->common.cb(acb->common.opaque, acb->ret);
+ qemu_aio_release(acb);
+}
+
+static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb)
+{
+ BlkdebugAIOCB *acb = (BlkdebugAIOCB*) blockacb;
+ qemu_aio_release(acb);
+}
+
+static BlockDriverAIOCB *inject_error(BlockDriverState *bs,
+ BlockDriverCompletionFunc *cb, void *opaque)
+{
+ BDRVBlkdebugState *s = bs->opaque;
+ int error = s->vars.inject_errno;
+ struct BlkdebugAIOCB *acb;
+ QEMUBH *bh;
+
+ if (s->vars.inject_once) {
+ s->vars.inject_errno = 0;
+ }
+
+ if (s->vars.inject_immediately) {
+ return NULL;
+ }
+
+ acb = qemu_aio_get(&blkdebug_aio_pool, bs, cb, opaque);
+ acb->ret = -error;
+
+ bh = qemu_bh_new(error_callback_bh, acb);
+ acb->bh = bh;
+ qemu_bh_schedule(bh);
+
+ return (BlockDriverAIOCB*) acb;
+}
+
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->vars.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 +133,11 @@ static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
BlockDriverCompletionFunc *cb, void *opaque)
{
BDRVBlkdebugState *s = bs->opaque;
+
+ if (s->vars.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
next prev parent reply other threads:[~2010-03-29 14:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-29 14:52 [Qemu-devel] [PATCH v2 0/7] blkdebug Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 1/7] qemu-config: qemu_read_config_file() reads the normal config file Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 2/7] qemu-config: Make qemu_config_parse more generic Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 3/7] blkdebug: Basic request passthrough Kevin Wolf
2010-03-29 14:52 ` Kevin Wolf [this message]
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 5/7] Make qemu-config available for tools Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 6/7] blkdebug: Add events and rules Kevin Wolf
2010-03-29 14:52 ` [Qemu-devel] [PATCH v2 7/7] qcow2: Trigger blkdebug events Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269874368-31011-5-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).