blkdebug
Subsystems (2)
cover blkdebug
This patch series introduces a new block driver which acts as a protocol and whose purpose it is to fail requests. To be more precise, I want it to fail in configurable places, so that qemu-iotests can be extended with tests for the error paths (for example for the case when something with metadata writes goes wrong deep in qcow2).
It works like this (I think this is self-explanatory):
$ cat /tmp/blkdebug.cfg [inject-error] event = "l1_update" errno = "5" immediately = "on" $ qemu-io blkdebug:/tmp/blkdebug.cfg:/tmp/empty.qcow2 qemu-io> read 0 4k read 4096/4096 bytes at offset 0 4 KiB, 1 ops; 0.0000 sec (195.312 MiB/sec and 50000.0000 ops/sec) qemu-io> write 0 4k bdrv_debug_event: 4 blkdebug_debug_event: 4 write failed: Input/output error
Basically what I think is left to do is:
- Resolve TODOs and FIXMEs left in the code
- Require blkdebug to be explicitly enabled before compiling in event generation (not sure if it really matters)
- Add more events, they are only added for qcow2-clusters so far
- Address your comments (if any)
Kevin Wolf (7):
qemu-config: qemu_read_config_file() reads the normal config file
qemu-config: Make qemu_config_parse more generic
blkdebug: Basic request passthrough
blkdebug: Inject errors
Make qemu-config available for tools
blkdebug: Add events and rules
qcow2: Trigger blkdebug events
Makefile.objs | 6 +- block.c | 13 ++ block.h | 28 ++++ block/blkdebug.c | 423 +++++++++++++++++++++++++++++++++++++++++++++++++ block/qcow2-cluster.c | 15 ++ block_int.h | 2 + hw/qdev-properties.c | 19 ++- hw/qdev.h | 1 - qemu-config.c | 45 +++--- qemu-config.h | 4 +- vl.c | 34 ++--- 11 files changed, 540 insertions(+), 50 deletions(-) create mode 100644 block/blkdebug.c
RFC PATCH 1/7 qemu-config: qemu_read_config_file() reads the normal config file
Introduce a new function qemu_read_config_file which reads the VM configuration from a config file. Unlike qemu_config_parse it doesn't take a open file but a filename and reduces code duplication as a side effect.
--- qemu-config.c | 15 +++++++++++++++ qemu-config.h | 2 ++ vl.c | 34 +++++++++++++--------------------- 3 files changed, 30 insertions(+), 21 deletions(-)
qemu-config.c +15 -0
@@ -473,3 +473,18 @@ int qemu_config_parse(FILE *fp) }return 0 ; } + +int qemu_read_config_file (const char *filename) +{ +FILE *f =fopen (filename,"r" ); +if (f ==NULL ) { +return -errno; + } + +if (qemu_config_parse (f) !=0 ) { +return -EINVAL ; + } +fclose (f); + +return 0 ; +}
qemu-config.h +2 -0
@@ -18,4 +18,6 @@ void qemu_add_globals(void);void qemu_config_write (FILE *fp);int qemu_config_parse (FILE *fp); +int qemu_read_config_file (const char *filename); +#endif /* QEMU_CONFIG_H */
vl.c +13 -21
@@ -4940,21 +4940,17 @@ int main(int argc, char **argv, char **envp) }if (defconfig) { -FILE *fp; - fp =fopen (CONFIG_QEMU_CONFDIR "/qemu.conf" ,"r" ); -if (fp) { -if (qemu_config_parse (fp) !=0 ) { -exit (1 ); - } -fclose (fp); +int ret; + + ret =qemu_read_config_file (CONFIG_QEMU_CONFDIR "/qemu.conf" ); +if (ret == -EINVAL ) { +exit (1 ); } - fp =fopen (CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf" ,"r" ); -if (fp) { -if (qemu_config_parse (fp) !=0 ) { -exit (1 ); - } -fclose (fp); + ret =qemu_read_config_file (CONFIG_QEMU_CONFDIR +"/target-" TARGET_ARCH ".conf" ); +if (ret == -EINVAL ) { +exit (1 ); } }#if defined(cpudef_setup)
@@ -5635,16 +5631,12 @@ int main(int argc, char **argv, char **envp)#endif case QEMU_OPTION_readconfig: { -FILE *fp; - fp =fopen (optarg,"r" ); -if (fp ==NULL ) { -fprintf (stderr,"open %s: %s\n" , optarg,strerror (errno)); +int ret =qemu_read_config_file (optarg); +if (ret <0 ) { +fprintf (stderr,"read config %s: %s\n" , optarg, +strerror (-ret));exit (1 ); } -if (qemu_config_parse (fp) !=0 ) { -exit (1 ); - } -fclose (fp);break ; }case QEMU_OPTION_writeconfig:
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC][PATCH 1/7] qemu-config: qemu_read_config_file() reads the normal config file
Quoted 5 lines · Kevin Wolf
Introduce a new function
qemu_read_config_filewhich reads the VM configuration from a config file. Unlikeqemu_config_parseit doesn't take a open file but a filename and reduces code duplication as a side effect.Signed-off-by Kevin Wolf <[email protected]>
Looks good,
RFC PATCH 2/7 qemu-config: Make qemu_config_parse more generic
In reply to Kevin Wolfqemu_config_parse gets the option groups as a parameter now instead of hardcoding the VM configuration groups. This way it can be used for other configurations, too.
--- qemu-config.c | 15 ++++++++------- qemu-config.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-)
qemu-config.c +8 -7
@@ -290,7 +290,7 @@ QemuOptsList qemu_cpudef_opts = { }, }; -static QemuOptsList *lists[] = { +static QemuOptsList *vm_config_groups[] = { &qemu_drive_opts, &qemu_chardev_opts, &qemu_device_opts,
@@ -303,7 +303,7 @@ static QemuOptsList *lists[] = { NULL, }; -static QemuOptsList *find_list (const char *group) +static QemuOptsList *find_list (QemuOptsList **lists,const char *group) {int i;
@@ -330,7 +330,7 @@ int qemu_set_option(const char *str)return -1 ; } - list =find_list (group); + list =find_list (vm_config_groups, group);if (list ==NULL ) {return -1 ; }
@@ -415,6 +415,7 @@ static int config_write_opts(QemuOpts *opts, void *opaque)void qemu_config_write (FILE *fp) {struct ConfigWriteData data = { .fp = fp }; +QemuOptsList **lists = vm_config_groups;int i;fprintf (fp,"# qemu config file\n\n" );
@@ -424,7 +425,7 @@ void qemu_config_write(FILE *fp) } } -int qemu_config_parse (FILE *fp) +int qemu_config_parse (FILE *fp,QemuOptsList **lists) {char line[1024 ], group[64 ], id[64 ], arg[64 ], value[1024 ];QemuOptsList *list =NULL ;
@@ -441,7 +442,7 @@ int qemu_config_parse(FILE *fp) }if (sscanf (line,"[%63s \"%63[^\"]\"]" , group, id) ==2 ) {/* group with id */ - list =find_list (group); + list =find_list (lists, group);if (list ==NULL )return -1 ; opts =qemu_opts_create (list, id,1 );
@@ -449,7 +450,7 @@ int qemu_config_parse(FILE *fp) }if (sscanf (line,"[%63[^]]]" , group) ==1 ) {/* group without id */ - list =find_list (group); + list =find_list (lists, group);if (list ==NULL )return -1 ; opts =qemu_opts_create (list,NULL ,0 );
@@ -481,7 +482,7 @@ int qemu_read_config_file(const char *filename)return -errno; } -if (qemu_config_parse (f) !=0 ) { +if (qemu_config_parse (f, vm_config_groups) !=0 ) {return -EINVAL ; }fclose (f);
qemu-config.h +1 -1
@@ -16,7 +16,7 @@ int qemu_global_option(const char *str);void qemu_add_globals (void );void qemu_config_write (FILE *fp); -int qemu_config_parse (FILE *fp); +int qemu_config_parse (FILE *fp,QemuOptsList **lists);int qemu_read_config_file (const char *filename);
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC][PATCH 2/7] qemu-config: Make qemu_config_parse more generic
Quoted 5 lines · Kevin Wolf
qemu_config_parsegets the option groups as a parameter now instead of hardcoding the VM configuration groups. This way it can be used for other configurations, too.Signed-off-by Kevin Wolf <[email protected]>
Looks good,
RFC PATCH 3/7 blkdebug: Basic request passthrough
In reply to Kevin WolfThis isn't doing anything interesting. It creates the blkdebug block driver as a protocol which just passes everything through to raw.
--- Makefile.objs | 2 +- block/blkdebug.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletions(-) create mode 100644 block/blkdebug.c
Makefile.objs +1 -1
@@ -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
block/blkdebug.c new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC][PATCH 3/7] blkdebug: Basic request passthrough
Quoted 7 lines · Kevin Wolf
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 <[email protected]>--- Makefile.objs | 2 +- block/blkdebug.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
Not a big fan of the blkdebug: prefix, but that's how qemu works elsewhere, too. Also it's not passing through any of the ioctl magic, but that's probably not needed for now.
RFC PATCH 4/7 blkdebug: Inject errors
In reply to Kevin WolfAdd 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.
--- block/blkdebug.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-)
block/blkdebug.c +63 -0
@@ -26,10 +26,26 @@#include "block_int.h" #include "module.h" +#include <stdbool.h> +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;
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC][PATCH 4/7] blkdebug: Inject errors
Quoted 4 lines · Kevin Wolf
Add a mechanism to inject errors instead of passing requests on. With no further patches applied, you can use it by setting
inject_errnoin gdb.Signed-off-by Kevin Wolf <[email protected]>
The magic iocb is quite a hack, but it should work good enough for now.
RFC PATCH 5/7 Make qemu-config available for tools
In reply to Kevin WolfTo be able to use config files for blkdebug, we need to make these functions available in the tools. This involves moving two functions that can only be built in the context of the emulator.
--- Makefile.objs | 4 ++-- hw/qdev-properties.c | 19 ++++++++++++++++++- hw/qdev.h | 1 - qemu-config.c | 17 ----------------- 4 files changed, 20 insertions(+), 21 deletions(-)
Makefile.objs +2 -2
@@ -8,7 +8,7 @@ qobject-obj-y += qerror.o # block-obj-y is code used by both qemu system emulation and qemu-img block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o -block-obj-y += nbd.o block.o aio.o aes.o osdep.o +block-obj-y += nbd.o block.o aio.o aes.o osdep.o qemu-config.o block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
@@ -76,7 +76,7 @@ common-obj-y += buffered_file.o migration.o migration-tcp.o qemu-sockets.o common-obj-y += qemu-char.o savevm.o #aio.o common-obj-y += msmouse.o ps2.o common-obj-y += qdev.o qdev-properties.o -common-obj-y += qemu-config.o block-migration.o +common-obj-y += block-migration.o common-obj-$(CONFIG_BRLAPI) += baum.o common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
hw/qdev-properties.c +18 -1
@@ -666,7 +666,7 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props) static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props); -void qdev_prop_register_global (GlobalProperty *prop) +static void qdev_prop_register_global (GlobalProperty *prop) {QTAILQ_INSERT_TAIL (&global_props, prop, next); }
@@ -694,3 +694,20 @@ void qdev_prop_set_globals(DeviceState *dev) } } } + +static int qdev_add_one_global (QemuOpts *opts,void *opaque) +{ +GlobalProperty *g; + + g =qemu_mallocz (sizeof (*g)); + g->driver =qemu_opt_get (opts,"driver" ); + g->property =qemu_opt_get (opts,"property" ); + g->value =qemu_opt_get (opts,"value" ); +qdev_prop_register_global (g); +return 0 ; +} + +void qemu_add_globals (void ) +{ +qemu_opts_foreach (&qemu_global_opts, qdev_add_one_global,NULL ,0 ); +}
hw/qdev.h +0 -1
@@ -273,7 +273,6 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);void qdev_prop_set_ptr (DeviceState *dev,const char *name,void *value);void qdev_prop_set_defaults (DeviceState *dev,Property *props); -void qdev_prop_register_global (GlobalProperty *prop);void qdev_prop_register_global_list (GlobalProperty *props);void qdev_prop_set_globals (DeviceState *dev);
qemu-config.c +0 -17
@@ -367,23 +367,6 @@ int qemu_global_option(const char *str)return 0 ; } -static int qemu_add_one_global (QemuOpts *opts,void *opaque) -{ -GlobalProperty *g; - - g =qemu_mallocz (sizeof (*g)); - g->driver =qemu_opt_get (opts,"driver" ); - g->property =qemu_opt_get (opts,"property" ); - g->value =qemu_opt_get (opts,"value" ); -qdev_prop_register_global (g); -return 0 ; -} - -void qemu_add_globals (void ) -{ -qemu_opts_foreach (&qemu_global_opts, qemu_add_one_global,NULL ,0 ); -} -struct ConfigWriteData {QemuOptsList *list;FILE *fp;
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC][PATCH 5/7] Make qemu-config available for tools
Quoted 4 lines · Kevin Wolf
available in the tools. This involves moving two functions that can only be built in the context of the emulator.
Signed-off-by Kevin Wolf <[email protected]>
Looks good,
RFC PATCH 6/7 blkdebug: Add events and rules
In reply to Kevin WolfBlock drivers can trigger a blkdebug event whenever they reach a place where it could be useful to inject an error for testing/debugging purposes.
Rules are read from a blkdebug config file and describe which action is taken when an event is triggered. For now this is only injecting an error (with a few options) or changing the state (which is an integer). Rules can be declared to be active only in a specific state; this way later rules can distiguish on which path we came to trigger their event.
--- block.c | 13 +++ block.h | 9 ++ block/blkdebug.c | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++++- block_int.h | 2 + 4 files changed, 264 insertions(+), 1 deletions(-)
block.c +13 -0
@@ -1532,6 +1532,19 @@ int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,return drv->bdrv_load_vmstate (bs, buf, pos, size); } +void bdrv_debug_event (BlockDriverState *bs,BlkDebugEvent event) +{ +BlockDriver *drv = bs->drv; + +fprintf (stderr,"bdrv_debug_event: %d\n" , event); +if (!drv || !drv->bdrv_debug_event) { +return ; + } + +return drv->bdrv_debug_event (bs, event); + +} +/**************************************************************/ /* handling of snapshots */
block.h +9 -0
@@ -207,4 +207,13 @@ int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);void bdrv_reset_dirty (BlockDriverState *bs,int64_t cur_sector,int nr_sectors);int64_t bdrv_get_dirty_count (BlockDriverState *bs); + + +typedef enum { +BLKDBG_EVENT_MAX , +}BlkDebugEvent ; + +#define BLKDBG_EVENT (bs, evt) bdrv_debug_event(bs, evt) +void bdrv_debug_event (BlockDriverState *bs,BlkDebugEvent event); +#endif
block/blkdebug.c +240 -1
286 lines not on this page · raw message
block_int.h +2 -0
@@ -120,6 +120,8 @@ struct BlockDriver {/* Returns number of errors in image, -errno for internal errors */ int (*bdrv_check)(BlockDriverState * bs); +void (*bdrv_debug_event)(BlockDriverState *bs,BlkDebugEvent event); +/* Set if newly created images are not guaranteed to contain only zeros */ int no_zero_init;
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC][PATCH 6/7] blkdebug: Add events and rules
Quoted 1 line · Kevin Wolf
+
fprintf(stderr, "bdrv_debug_event: %d\n", event);
Is this supposed to be in the final version or a leftover debugging aid?
Quoted 1 line
+#define
BLKDBG_EVENT(bs, evt)bdrv_debug_event(bs, evt)
Why not call bdrv_debug_event directly?
Quoted 5 lines
block/blkdebug.c +5
-0+ config =strdup (filename); + config[c - filename] ='\0' ; + ret =read_config (s, config); +if (ret <0 ) { +return ret;
block/blkdebug.c struct callback_data { · line 255
Quoted 10 lines
block/blkdebug.c +10
-0+ } + filename = c +1 ; + +/* Open the backing file */ + ret =bdrv_file_open (&s->hd, filename, flags); +if (ret <0 ) { +return ret; + } + +return 0 ;
Don't we need to free config somewhere?
Re: [Qemu-devel] [RFC][PATCH 6/7] blkdebug: Add events and rules
Am 28.03.2010 15:12, schrieb Christoph Hellwig:
Quoted 4 lines · Kevin Wolf
Quoted 1 line
+
fprintf(stderr, "bdrv_debug_event: %d\n", event);Is this supposed to be in the final version or a leftover debugging aid?
It's not there in the final version (which I have already sent out, btw, so you have reviewed an old version)
Quoted 3 lines
Quoted 1 line
+#define
BLKDBG_EVENT(bs, evt)bdrv_debug_event(bs, evt)Why not call
bdrv_debug_eventdirectly?
Originally I had intended to add a flag to ./configure to enable blkdebug and #ifdef this out if it's not compiled in. Maybe we still want to add that, but then it's not really much that you save.
Quoted 9 lines
Quoted 9 lines
block/blkdebug.c +9
-0+ config =strdup (filename); + config[c - filename] ='\0' ; + ret =read_config (s, config); +if (ret <0 ) { +return ret; + } + filename = c +1 ; + +/* Open the backing file */
Quoted 8 lines
block/blkdebug.c struct callback_data { · line 255
Quoted 6 lines
block/blkdebug.c +6
-0+ ret =bdrv_file_open (&s->hd, filename, flags); +if (ret <0 ) { +return ret; + } + +return 0 ;Don't we need to free config somewhere?
Oops, this one is still there in the final version. I'll send another version of the series.
Kevin
RFC PATCH 7/7 qcow2: Trigger blkdebug events
In reply to Kevin WolfThis adds blkdebug events to qcow2 to allow injecting I/O errors in specific places.
--- block.h | 19 +++++++++++++++++++ block/blkdebug.c | 17 +++++++++++++++++ block/qcow2-cluster.c | 15 +++++++++++++++ 3 files changed, 51 insertions(+), 0 deletions(-)
block.h +19 -0
@@ -210,6 +210,25 @@ int64_t bdrv_get_dirty_count(BlockDriverState *bs);typedef enum { +BLKDBG_L1_UPDATE , + +BLKDBG_L1_GROW_ALLOC_TABLE , +BLKDBG_L1_GROW_WRITE_TABLE , +BLKDBG_L1_GROW_ACTIVATE_TABLE , + +BLKDBG_L2_LOAD , +BLKDBG_L2_UPDATE , +BLKDBG_L2_UPDATE_COMPRESSED , +BLKDBG_L2_ALLOC_COW_READ , +BLKDBG_L2_ALLOC_WRITE , + +BLKDBG_READ , +BLKDBG_READ_BACKING , +BLKDBG_READ_COMPRESSED , + +BLKDBG_COW_READ , +BLKDBG_COW_WRITE , +BLKDBG_EVENT_MAX , }BlkDebugEvent ;
block/blkdebug.c +17 -0
@@ -126,6 +126,23 @@ static QemuOptsList *config_groups[] = { };static const char *event_names[BLKDBG_EVENT_MAX ] = { + [BLKDBG_L1_UPDATE ] ="l1_update" , + [BLKDBG_L1_GROW_ALLOC_TABLE ] ="l1_grow.alloc_table" , + [BLKDBG_L1_GROW_WRITE_TABLE ] ="l1_grow.write_table" , + [BLKDBG_L1_GROW_ACTIVATE_TABLE ] ="l1_grow.activate_table" , + + [BLKDBG_L2_LOAD ] ="l2_load" , + [BLKDBG_L2_UPDATE ] ="l2_update" , + [BLKDBG_L2_UPDATE_COMPRESSED ] ="l2_update_compressed" , + [BLKDBG_L2_ALLOC_COW_READ ] ="l2_alloc.cow_read" , + [BLKDBG_L2_ALLOC_WRITE ] ="l2_alloc.write" , + + [BLKDBG_READ ] ="read" , + [BLKDBG_READ_BACKING ] ="read_backing" , + [BLKDBG_READ_COMPRESSED ] ="read_compressed" , + + [BLKDBG_COW_READ ] ="cow_read" , + [BLKDBG_COW_WRITE ] ="cow_write" , };static int get_event_by_name (const char *name,BlkDebugEvent *event)
block/qcow2-cluster.c +15 -0
@@ -54,12 +54,14 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size)memcpy (new_l1_table, s->l1_table, s->l1_size *sizeof (uint64_t ));/* write new table (align to cluster) */ +BLKDBG_EVENT (s->hd,BLKDBG_L1_GROW_ALLOC_TABLE ); new_l1_table_offset =qcow2_alloc_clusters (bs, new_l1_size2);if (new_l1_table_offset <0 ) {qemu_free (new_l1_table);return new_l1_table_offset; } +BLKDBG_EVENT (s->hd,BLKDBG_L1_GROW_WRITE_TABLE );for (i =0 ; i < s->l1_size; i++) new_l1_table[i] =cpu_to_be64 (new_l1_table[i]); ret =bdrv_pwrite (s->hd, new_l1_table_offset, new_l1_table, new_l1_size2);
@@ -69,6 +71,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) new_l1_table[i] =be64_to_cpu (new_l1_table[i]);/* set new table */ +BLKDBG_EVENT (s->hd,BLKDBG_L1_GROW_ACTIVATE_TABLE );cpu_to_be32w ((uint32_t *)data, new_l1_size);cpu_to_be64w ((uint64_t *)(data +4 ), new_l1_table_offset); ret =bdrv_pwrite (s->hd, offsetof(QCowHeader , l1_size), data,sizeof (data));
@@ -170,6 +173,8 @@ static uint64_t *l2_load(BlockDriverState *bs, uint64_t l2_offset) min_index =l2_cache_new_entry (bs); l2_table = s->l2_cache + (min_index << s->l2_bits); + +BLKDBG_EVENT (s->hd,BLKDBG_L2_LOAD );if (bdrv_pread (s->hd, l2_offset, l2_table, s->l2_size *sizeof (uint64_t )) != s->l2_size *sizeof (uint64_t ))return NULL ;
@@ -195,6 +200,7 @@ static int write_l1_entry(BDRVQcowState *s, int l1_index) buf[i] =cpu_to_be64 (s->l1_table[l1_start_index + i]); } +BLKDBG_EVENT (s->hd,BLKDBG_L1_UPDATE );if (bdrv_pwrite (s->hd, s->l1_table_offset +8 * l1_start_index, buf,sizeof (buf)) !=sizeof (buf)) {
@@ -248,12 +254,14 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index)memset (l2_table,0 , s->l2_size *sizeof (uint64_t )); }else {/* if there was an old l2 table, read it from the disk */ +BLKDBG_EVENT (s->hd,BLKDBG_L2_ALLOC_COW_READ );if (bdrv_pread (s->hd, old_l2_offset, l2_table, s->l2_size *sizeof (uint64_t )) != s->l2_size *sizeof (uint64_t ))return NULL ; }/* write the l2 table to the file */ +BLKDBG_EVENT (s->hd,BLKDBG_L2_ALLOC_WRITE );if (bdrv_pwrite (s->hd, l2_offset, l2_table, s->l2_size *sizeof (uint64_t )) != s->l2_size *sizeof (uint64_t ))
@@ -335,6 +343,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,/* read from the base image */ n1 =qcow2_backing_read1 (bs->backing_hd, sector_num, buf, n);if (n1 >0 ) { +BLKDBG_EVENT (s->hd,BLKDBG_READ_BACKING ); ret =bdrv_read (bs->backing_hd, sector_num, buf, n1);if (ret <0 )return -1 ;
@@ -347,6 +356,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,return -1 ;memcpy (buf, s->cluster_cache + index_in_cluster *512 ,512 * n); }else { +BLKDBG_EVENT (s->hd,BLKDBG_READ ); ret =bdrv_pread (s->hd, cluster_offset + index_in_cluster *512 , buf, n *512 );if (ret != n *512 )return -1 ;
@@ -371,6 +381,7 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect, n = n_end - n_start;if (n <=0 )return 0 ; +BLKDBG_EVENT (s->hd,BLKDBG_COW_READ ); ret =qcow_read (bs, start_sect + n_start, s->cluster_data, n);if (ret <0 )return ret;
@@ -380,6 +391,7 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect, s->cluster_data, n,1 , &s->aes_encrypt_key); } +BLKDBG_EVENT (s->hd,BLKDBG_COW_WRITE ); ret =bdrv_write (s->hd, (cluster_offset >>9 ) + n_start, s->cluster_data, n);if (ret <0 )
@@ -592,6 +604,7 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,/* compressed clusters never have the copied flag */ +BLKDBG_EVENT (s->hd,BLKDBG_L2_UPDATE_COMPRESSED ); l2_table[l2_index] =cpu_to_be64 (cluster_offset); if (bdrv_pwrite(s->hd, l2_offset + l2_index * sizeof(uint64_t),
@@ -615,6 +628,7 @@ static int write_l2_entries(BDRVQcowState *s, uint64_t *l2_table,int end_offset = (8 * (l2_index + num) +511 ) & ~511 ;size_t len = end_offset - start_offset; +BLKDBG_EVENT (s->hd,BLKDBG_L2_UPDATE );if (bdrv_pwrite (s->hd, l2_offset + start_offset, &l2_table[l2_start_index], len) != len) {
@@ -865,6 +879,7 @@ int qcow2_decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset) nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) +1 ; sector_offset = coffset &511 ; csize = nb_csectors *512 - sector_offset; +BLKDBG_EVENT (s->hd,BLKDBG_READ_COMPRESSED ); ret =bdrv_read (s->hd, coffset >>9 , s->cluster_data, nb_csectors);if (ret <0 ) {return -1 ;
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [RFC][PATCH 7/7] qcow2: Trigger blkdebug events
Quoted 2 lines · Kevin Wolf
This adds blkdebug events to qcow2 to allow injecting I/O errors in specific places.
Looks good,
Quoted 5 lines · Kevin Wolf
This patch series introduces a new block driver which acts as a protocol and
whose purpose it is to fail requests. To be more precise, I want it to fail in configurable places, so that qemu-iotests can be extended with tests for the error paths (for example for the case when something with metadata writes goes wrong deep in qcow2).
Nice. Do you think this could be extended (later) to inject errors also to guest from QEMU? Then it would be nice to be able to inject errors when reading/writing to a specific guest block range and for other formats (raw etc.) too.
Am 15.03.2010 18:40, schrieb Blue Swirl:
Quoted 9 lines · Kevin Wolf
Quoted 5 lines
This patch series introduces a new block driver which acts as a protocol and
whose purpose it is to fail requests. To be more precise, I want it to fail in configurable places, so that qemu-iotests can be extended with tests for the error paths (for example for the case when something with metadata writes goes wrong deep in qcow2).Nice. Do you think this could be extended (later) to inject errors also to guest from QEMU?
Not sure what you mean by "from QEMU"? To allow injecting errors from the monitor instead of based on rules? Sounds certainly doable.
Or do you just mean to make it work in qemu as opposed to qemu-io? This really doesn't make a difference to the block layer. If it works in one, it works in the other one, too.
Quoted 3 lines
Then it would be nice to be able to inject
errors when reading/writing to a specific guest block range and for other formats (raw etc.) too.
Should work with all formats, it's implemented as a protocol (but it's untested with everything but qcow2). So you basically stick it between the format driver and the image file. The only thing that could be needed for other formats is some additional events.
For the block range thing, this would need to implement some more conditions instead of just checking the state, but in general this is exactly the kind of things that I'd like to see supported eventually.
So I completely agree that this is the right direction for future improvements, however I can't tell yet if (or when) I'll get to implement it myself. My focus is really the qcow2 error paths for now.
Kevin
Quoted 9 lines · Kevin Wolf
Am 15.03.2010 18:40, schrieb Blue Swirl:
Quoted 7 lines · Kevin Wolf
Quoted 5 lines
This patch series introduces a new block driver which acts as a protocol and
whose purpose it is to fail requests. To be more precise, I want it to fail in configurable places, so that qemu-iotests can be extended with tests for the error paths (for example for the case when something with metadata writes goes wrong deep in qcow2).
Quoted 6 lines
Quoted 2 lines
Nice. Do you think this could be extended (later) to inject errors also to guest from QEMU?
Not sure what you mean by "from QEMU"? To allow injecting errors from
the monitor instead of based on rules? Sounds certainly doable.
I was thinking rule file, but monitor would be more flexible. Even
better: allow switching rule files from monitor :-).
Quoted 15 lines
Or do you just mean to make it work in qemu as opposed to qemu-io? This really doesn't make a difference to the block layer. If it works in one, it works in the other one, too.
Quoted 3 lines
Then it would be nice to be able to inject
errors when reading/writing to a specific guest block range and for other formats (raw etc.) too.Should work with all formats, it's implemented as a protocol (but it's
untested with everything but qcow2). So you basically stick it between the format driver and the image file. The only thing that could be needed for other formats is some additional events.
Quoted 7 lines
For the block range thing, this would need to implement some more conditions instead of just checking the state, but in general this is exactly the kind of things that I'd like to see supported eventually.
So I completely agree that this is the right direction for future improvements, however I can't tell yet if (or when) I'll get to implement it myself. My focus is really the qcow2 error paths for now.
Ok, it's enough to know at this stage that the architecture is flexible for this.