2 * Block protocol for I/O error injection
4 * Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 #include "qemu-common.h"
26 #include "block_int.h"
29 typedef struct BDRVBlkdebugState
{
33 static int blkdebug_open(BlockDriverState
*bs
, const char *filename
, int flags
)
35 BDRVBlkdebugState
*s
= bs
->opaque
;
37 if (strncmp(filename
, "blkdebug:", strlen("blkdebug:"))) {
40 filename
+= strlen("blkdebug:");
42 return bdrv_file_open(&s
->hd
, filename
, flags
);
45 static BlockDriverAIOCB
*blkdebug_aio_readv(BlockDriverState
*bs
,
46 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
47 BlockDriverCompletionFunc
*cb
, void *opaque
)
49 BDRVBlkdebugState
*s
= bs
->opaque
;
50 BlockDriverAIOCB
*acb
=
51 bdrv_aio_readv(s
->hd
, sector_num
, qiov
, nb_sectors
, cb
, opaque
);
55 static BlockDriverAIOCB
*blkdebug_aio_writev(BlockDriverState
*bs
,
56 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
57 BlockDriverCompletionFunc
*cb
, void *opaque
)
59 BDRVBlkdebugState
*s
= bs
->opaque
;
60 BlockDriverAIOCB
*acb
=
61 bdrv_aio_writev(s
->hd
, sector_num
, qiov
, nb_sectors
, cb
, opaque
);
65 static void blkdebug_close(BlockDriverState
*bs
)
67 BDRVBlkdebugState
*s
= bs
->opaque
;
71 static void blkdebug_flush(BlockDriverState
*bs
)
73 BDRVBlkdebugState
*s
= bs
->opaque
;
77 static BlockDriverAIOCB
*blkdebug_aio_flush(BlockDriverState
*bs
,
78 BlockDriverCompletionFunc
*cb
, void *opaque
)
80 BDRVBlkdebugState
*s
= bs
->opaque
;
81 return bdrv_aio_flush(s
->hd
, cb
, opaque
);
84 static BlockDriver bdrv_blkdebug
= {
85 .format_name
= "blkdebug",
86 .protocol_name
= "blkdebug",
88 .instance_size
= sizeof(BDRVBlkdebugState
),
90 .bdrv_open
= blkdebug_open
,
91 .bdrv_close
= blkdebug_close
,
92 .bdrv_flush
= blkdebug_flush
,
94 .bdrv_aio_readv
= blkdebug_aio_readv
,
95 .bdrv_aio_writev
= blkdebug_aio_writev
,
96 .bdrv_aio_flush
= blkdebug_aio_flush
,
99 static void bdrv_blkdebug_init(void)
101 bdrv_register(&bdrv_blkdebug
);
104 block_init(bdrv_blkdebug_init
);