]> git.proxmox.com Git - mirror_qemu.git/blame - block/blkdebug.c
blkdebug: Basic request passthrough
[mirror_qemu.git] / block / blkdebug.c
CommitLineData
6a143727
KW
1/*
2 * Block protocol for I/O error injection
3 *
4 * Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#include "qemu-common.h"
26#include "block_int.h"
27#include "module.h"
28
29typedef struct BDRVBlkdebugState {
30 BlockDriverState *hd;
31} BDRVBlkdebugState;
32
33static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags)
34{
35 BDRVBlkdebugState *s = bs->opaque;
36
37 if (strncmp(filename, "blkdebug:", strlen("blkdebug:"))) {
38 return -EINVAL;
39 }
40 filename += strlen("blkdebug:");
41
42 return bdrv_file_open(&s->hd, filename, flags);
43}
44
45static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
46 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
47 BlockDriverCompletionFunc *cb, void *opaque)
48{
49 BDRVBlkdebugState *s = bs->opaque;
50 BlockDriverAIOCB *acb =
51 bdrv_aio_readv(s->hd, sector_num, qiov, nb_sectors, cb, opaque);
52 return acb;
53}
54
55static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
56 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
57 BlockDriverCompletionFunc *cb, void *opaque)
58{
59 BDRVBlkdebugState *s = bs->opaque;
60 BlockDriverAIOCB *acb =
61 bdrv_aio_writev(s->hd, sector_num, qiov, nb_sectors, cb, opaque);
62 return acb;
63}
64
65static void blkdebug_close(BlockDriverState *bs)
66{
67 BDRVBlkdebugState *s = bs->opaque;
68 bdrv_delete(s->hd);
69}
70
71static void blkdebug_flush(BlockDriverState *bs)
72{
73 BDRVBlkdebugState *s = bs->opaque;
74 bdrv_flush(s->hd);
75}
76
77static BlockDriverAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
78 BlockDriverCompletionFunc *cb, void *opaque)
79{
80 BDRVBlkdebugState *s = bs->opaque;
81 return bdrv_aio_flush(s->hd, cb, opaque);
82}
83
84static BlockDriver bdrv_blkdebug = {
85 .format_name = "blkdebug",
86 .protocol_name = "blkdebug",
87
88 .instance_size = sizeof(BDRVBlkdebugState),
89
90 .bdrv_open = blkdebug_open,
91 .bdrv_close = blkdebug_close,
92 .bdrv_flush = blkdebug_flush,
93
94 .bdrv_aio_readv = blkdebug_aio_readv,
95 .bdrv_aio_writev = blkdebug_aio_writev,
96 .bdrv_aio_flush = blkdebug_aio_flush,
97};
98
99static void bdrv_blkdebug_init(void)
100{
101 bdrv_register(&bdrv_blkdebug);
102}
103
104block_init(bdrv_blkdebug_init);