From patchwork Mon Mar 15 17:08:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 47770 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 90A53B7D14 for ; Tue, 16 Mar 2010 04:23:56 +1100 (EST) Received: from localhost ([127.0.0.1]:57794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrDti-0006Cs-Fa for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2010 13:16:10 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrDnA-0004NY-Ug for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:25 -0400 Received: from [199.232.76.173] (port=60313 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrDn9-0004Mv-UR for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:24 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrDn7-0005r4-Rk for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16426) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NrDn7-0005qy-Cj for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:21 -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 o2FH9K9t012127 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 15 Mar 2010 13:09:20 -0400 Received: from localhost.localdomain (vpn1-6-64.ams2.redhat.com [10.36.6.64]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2FH9CWh018739; Mon, 15 Mar 2010 13:09:18 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 15 Mar 2010 18:08:31 +0100 Message-Id: <1268672915-12233-4-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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [RFC][PATCH 3/7] blkdebug: Basic request passthrough X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This isn't doing anything interesting. It creates the blkdebug block driver as a protocol which just passes everything through to raw. Signed-off-by: Kevin Wolf Reviewed-by: Christoph Hellwig --- Makefile.objs | 2 +- block/blkdebug.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletions(-) create mode 100644 block/blkdebug.c diff --git a/Makefile.objs b/Makefile.objs index e791dd5..ece02d5 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -14,7 +14,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o -block-nested-y += parallels.o nbd.o +block-nested-y += parallels.o nbd.o blkdebug.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o block-nested-$(CONFIG_CURL) += curl.o diff --git a/block/blkdebug.c b/block/blkdebug.c new file mode 100644 index 0000000..2c7e0dd --- /dev/null +++ b/block/blkdebug.c @@ -0,0 +1,104 @@ +/* + * Block protocol for I/O error injection + * + * Copyright (c) 2010 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu-common.h" +#include "block_int.h" +#include "module.h" + +typedef struct BDRVBlkdebugState { + BlockDriverState *hd; +} BDRVBlkdebugState; + +static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags) +{ + BDRVBlkdebugState *s = bs->opaque; + + if (strncmp(filename, "blkdebug:", strlen("blkdebug:"))) { + return -EINVAL; + } + filename += strlen("blkdebug:"); + + return bdrv_file_open(&s->hd, filename, flags); +} + +static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs, + int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, + BlockDriverCompletionFunc *cb, void *opaque) +{ + BDRVBlkdebugState *s = bs->opaque; + BlockDriverAIOCB *acb = + bdrv_aio_readv(s->hd, sector_num, qiov, nb_sectors, cb, opaque); + return acb; +} + +static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs, + int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, + BlockDriverCompletionFunc *cb, void *opaque) +{ + BDRVBlkdebugState *s = bs->opaque; + BlockDriverAIOCB *acb = + bdrv_aio_writev(s->hd, sector_num, qiov, nb_sectors, cb, opaque); + return acb; +} + +static void blkdebug_close(BlockDriverState *bs) +{ + BDRVBlkdebugState *s = bs->opaque; + bdrv_delete(s->hd); +} + +static void blkdebug_flush(BlockDriverState *bs) +{ + BDRVBlkdebugState *s = bs->opaque; + bdrv_flush(s->hd); +} + +static BlockDriverAIOCB *blkdebug_aio_flush(BlockDriverState *bs, + BlockDriverCompletionFunc *cb, void *opaque) +{ + BDRVBlkdebugState *s = bs->opaque; + return bdrv_aio_flush(s->hd, cb, opaque); +} + +static BlockDriver bdrv_blkdebug = { + .format_name = "blkdebug", + .protocol_name = "blkdebug", + + .instance_size = sizeof(BDRVBlkdebugState), + + .bdrv_open = blkdebug_open, + .bdrv_close = blkdebug_close, + .bdrv_flush = blkdebug_flush, + + .bdrv_aio_readv = blkdebug_aio_readv, + .bdrv_aio_writev = blkdebug_aio_writev, + .bdrv_aio_flush = blkdebug_aio_flush, +}; + +static void bdrv_blkdebug_init(void) +{ + bdrv_register(&bdrv_blkdebug); +} + +block_init(bdrv_blkdebug_init);