blkverify: Add block driver for verifying I/O
Subsystems (2)
PATCH v3 1/1 blkverify: Add block driver for verifying I/O
The blkverify block driver makes investigating image format data corruption much easier. A raw image initialized with the same contents as the test image (e.g. qcow2 file) must be provided. The raw image mirrors read/write operations and is used to verify that data read from the test image is correct.
---
v3:
* Fix compile error in blkverify_aio_cancel()
v2:
* Implement aio_cancel() by waiting for pending requests
* Fix conflict in Makefile.objs
Makefile.objs | 2 +- block/blkverify.c | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++++ docs/blkverify.txt | 69 +++++++++++ 3 files changed, 394 insertions(+), 1 deletions(-) create mode 100644 block/blkverify.c create mode 100644 docs/blkverify.txt
Makefile.objs +1 -1
@@ -14,7 +14,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o 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 blkdebug.o sheepdog.o +block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o block-nested-$(CONFIG_CURL) += curl.o
block/blkverify.c new file +324 -0
324 lines not on this page · raw message
docs/blkverify.txt new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v3 1/1 blkverify: Add block driver for verifying I/O
The blkverify block driver makes investigating image format data corruption much easier. A raw image initialized with the same contents as the test image (e.g. qcow2 file) must be provided. The raw image mirrors read/write operations and is used to verify that data read from the test image is correct.
---
This is embarassing, I sent out the v2 patch instead of the v3 patch the first time!
v3:
* Fix compile error in blkverify_aio_cancel()
v2:
* Implement aio_cancel() by waiting for pending requests
* Fix conflict in Makefile.objs
Makefile.objs | 2 +- block/blkverify.c | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++++ docs/blkverify.txt | 69 +++++++++++ 3 files changed, 394 insertions(+), 1 deletions(-) create mode 100644 block/blkverify.c create mode 100644 docs/blkverify.txt
Makefile.objs +1 -1
@@ -14,7 +14,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o 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 blkdebug.o sheepdog.o +block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o block-nested-$(CONFIG_CURL) += curl.o
block/blkverify.c new file +324 -0
324 lines not on this page · raw message
docs/blkverify.txt new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
1.7.1
Am 04.09.2010 17:34, schrieb Stefan Hajnoczi:
Quoted 83 lines
The blkverify block driver makes investigating image format data corruption much easier. A raw image initialized with the same contents as the test image (e.g. qcow2 file) must be provided. The raw image mirrors read/write operations and is used to verify that data read from the test image is correct.
Signed-off-by Stefan Hajnoczi <[email protected]>---
This is embarassing, I sent out the v2 patch instead of the v3 patch the first time!v3:
* Fix compile error inblkverify_aio_cancel()v2:
* Implementaio_cancel()by waiting for pending requests
* Fix conflict in Makefile.objsMakefile.objs | 2 +- block/blkverify.c | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++++ docs/blkverify.txt | 69 +++++++++++ 3 files changed, 394 insertions(+), 1 deletions(-) create mode 100644 block/blkverify.c create mode 100644 docs/blkverify.txtMakefile.objs +1
-1@@ -14,7 +14,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o 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 blkdebug.o sheepdog.o +block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o block-nested-$(CONFIG_CURL) += curl.oblock/blkverify.c new file +39
-0@@ -0,0 +1,324 @@ +/* +* Block protocol for block driver correctness testing +* +* Copyright (C) 2010 IBM, Corp. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include <stdarg.h> +#include "block_int.h" + +typedef struct { +BlockDriverState *test_file; +}BDRVBlkverifyState ; + +typedef struct BlkverifyAIOCB BlkverifyAIOCB ; +struct BlkverifyAIOCB { +BlockDriverAIOCB common; +QEMUBH *bh; + +/* Request metadata */ +bool is_write; +int64_t sector_num; +int nb_sectors; + +int ret;/* first completed request's result */ +unsigned int done;/* completion counter */ + +QEMUIOVector *qiov;/* user I/O vector */ +QEMUIOVector raw_qiov;/* cloned I/O vector for raw file */ +void *buf;/* buffer for raw file I/O */ + +void (*verify)(BlkverifyAIOCB *acb); +}; + +static void blkverify_aio_cancel_cb (void *opaque,int ret) +{ + *(bool *)opaque = true;
block/blkverify.c line 49
Quoted 10 lines
block/blkverify.c new file +10
-0+} + +static void blkverify_aio_cancel (BlockDriverAIOCB *acb) +{ +bool done = false; + +/* Allow the request to complete so the raw file and test file stay in +* sync. Hijack the callback (since the request is cancelled anyway) to +* wait for completion. +*/
The approach of completing the request sounds okay, but I think you need to call the original callback if you let it complete.
block/blkverify.c line 54
Quoted 5 lines
block/blkverify.c new file +5
-0+ acb->cb = blkverify_aio_cancel_cb; + acb->opaque = &done; +while (!done) { +qemu_aio_wait (); + }
qemu_aio_release(acb)?
Quoted 44 lines
block/blkverify.c new file +44
-0+} + +static AIOPool blkverify_aio_pool = { + .aiocb_size =sizeof (BlkverifyAIOCB), + .cancel = blkverify_aio_cancel, +}; + +static void blkverify_err (BlkverifyAIOCB *acb,const char *fmt, ...) +{ +va_list ap; + +va_start (ap, fmt); +fprintf (stderr,"blkverify: %s sector_num=%ld nb_sectors=%d " , + acb->is_write ?"write" :"read" , acb->sector_num, + acb->nb_sectors); +vfprintf (stderr, fmt, ap); +fprintf (stderr,"\n" ); +va_end (ap); +exit (1 ); +} + +/* Valid blkverify filenames look like blkverify:path/to/raw_image:path/to/image */ +static int blkverify_open (BlockDriverState *bs,const char *filename,int flags) +{ +BDRVBlkverifyState *s = bs->opaque; +int ret; +char *raw, *c; + +/* Parse the blkverify: prefix */ +if (strncmp (filename,"blkverify:" ,strlen ("blkverify:" ))) { +return -EINVAL ; + } + filename +=strlen ("blkverify:" ); + +/* Parse the raw image filename */ + c =strchr (filename,':' ); +if (c ==NULL ) { +return -EINVAL ; + } + + raw =strdup (filename); + raw[c - filename] ='\0' ; + ret =bdrv_file_open (&bs->file, raw, flags); +free (raw);
block/blkverify.c line 108
Quoted 10 lines
block/blkverify.c new file +10
-0+if (ret <0 ) { +return ret; + } + filename = c +1 ; + +/* Open the test file */ + s->test_file =bdrv_new ("" ); + ret =bdrv_open (s->test_file, filename, flags,NULL ); +if (ret <0 ) { +return ret;
This leaks bs->file.
Kevin
Thanks for your comments Kevin!
I'd like to merge the overlapping I/O patch I sent today since blkverify is not in mainline yet. Are you okay with that or should I keep them separate?
Quoted 12 lines · Kevin Wolf
Am 04.09.2010 17:34, schrieb Stefan Hajnoczi:
block/blkverify.c line 49
Quoted 8 lines
block/blkverify.c new file +8
-0+static void blkverify_aio_cancel (BlockDriverAIOCB *acb) +{ + bool done = false; + + /* Allow the request to complete so the raw file and test file stay in +* sync. Hijack the callback (since the request is cancelled anyway) to +* wait for completion. +*/ The approach of completing the request sounds okay, but I think you need to call the original callback if you let it complete.
Neither posix-aio-compat.c nor block/qcow2.c invoke the callback. Am I missing something?
Quoted 7 lines
Quoted 5 lines
+ acb->cb =
blkverify_aio_cancel_cb;
+ acb->opaque = &done;
+ while (!done) {
+ qemu_aio_wait();
+ }
qemu_aio_release(acb)?
Will fix.
Quoted 7 lines
Quoted 5 lines
+ /* Open the test file */
+ s->test_file =bdrv_new("");
+ ret =bdrv_open(s->test_file, filename, flags, NULL);
+ if (ret < 0) {
+ return ret;This leaks
bs->file.
s->test_file needs bdrv_delete(). block.c:bdrv_open_common() calls bdrv_delete(bs->file) on failure to close and delete bs->file, but we don't need to rely on that. I will fix both.
Stefan
Am 20.09.2010 17:22, schrieb Stefan Hajnoczi:
Quoted 5 lines
Thanks for your comments Kevin!
I'd like to merge the overlapping I/O patch I sent today since blkverify is not in mainline yet. Are you okay with that or should I keep them separate?
If that works better for you, I don't mind merging them.
Quoted 14 lines · Kevin Wolf
Quoted 12 lines
Am 04.09.2010 17:34, schrieb Stefan Hajnoczi:
block/blkverify.c line 49
Quoted 8 lines
block/blkverify.c new file +8
-0+static void blkverify_aio_cancel (BlockDriverAIOCB *acb) +{ +bool done = false; + +/* Allow the request to complete so the raw file and test file stay in +* sync. Hijack the callback (since the request is cancelled anyway) to +* wait for completion. +*/ The approach of completing the request sounds okay, but I think you need to call the original callback if you let it complete.
Quoted 2 lines
Neither
posix-aio-compat.cnorblock/qcow2.cinvoke the callback. Am I missing something?
qcow2 calls raw, so it doesn't need to do it itself.
posix-aio-compat invokes the callback indirectly by waiting for the request to complete using the normal path.
Quoted 16 lines
Quoted 7 lines
block/blkverify.c line 54
Quoted 5 lines
block/blkverify.c new file +5
-0+ acb->cb = blkverify_aio_cancel_cb; + acb->opaque = &done; +while (!done) { +qemu_aio_wait (); + }
qemu_aio_release(acb)?Will fix.
Quoted 6 lines
Quoted 5 lines
block/blkverify.c new file +5
-0+/* Open the test file */ + s->test_file =bdrv_new ("" ); + ret =bdrv_open (s->test_file, filename, flags,NULL ); +if (ret <0 ) { +return ret;
Quoted 5 lines
Quoted 1 line
This leaks
bs->file.
s->test_fileneedsbdrv_delete(). block.c:bdrv_open_common() callsbdrv_delete(bs->file)on failure to close and deletebs->file, but we don't need to rely on that. I will fix both.
Right, I missed that we're in the same path as with an automatically allocated bs->file. Not exactly intuitive that the common implementation cleans up when it didn't create the file. ;-)
Kevin