block: Add blklogwrites
PATCH 1/5 block: Add blklogwrites
From: Aapo Vienamo <[email protected]>
Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
The implementation is based on the blkverify and blkdebug block drivers.
--- block.c | 6 - block/Makefile.objs | 1 + block/blklogwrites.c | 441 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 7 + 4 files changed, 449 insertions(+), 6 deletions(-) create mode 100644 block/blklogwrites.c
block.c +0 -6
@@ -1914,12 +1914,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,return 0 ; } -#define DEFAULT_PERM_PASSTHROUGH (BLK_PERM_CONSISTENT_READ \ - | BLK_PERM_WRITE \ - | BLK_PERM_WRITE_UNCHANGED \ - | BLK_PERM_RESIZE) -#define DEFAULT_PERM_UNCHANGED (BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH) - void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildRole *role, BlockReopenQueue *reopen_queue,
block/Makefile.objs +1 -0
@@ -5,6 +5,7 @@ block-obj-y += qed-check.o block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o block-obj-y += quorum.o block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o +block-obj-y += blklogwrites.o block-obj-y += block-backend.o snapshot.o qapi.o block-obj-$(CONFIG_WIN32) += file-win32.o win32-aio.o block-obj-$(CONFIG_POSIX) += file-posix.o
block/blklogwrites.c new file +441 -0
441 lines not on this page · raw message
include/block/block.h +7 -0
@@ -225,6 +225,13 @@ enum {BLK_PERM_GRAPH_MOD =0x10 ,BLK_PERM_ALL =0x1f , + +DEFAULT_PERM_PASSTHROUGH =BLK_PERM_CONSISTENT_READ + |BLK_PERM_WRITE + |BLK_PERM_WRITE_UNCHANGED + |BLK_PERM_RESIZE , + + DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, };char *bdrv_perm_names (uint64_t perm);
Signature · 1 line
2.7.4
PATCH 2/5 block: Add a mechanism for passing a block driver a block configuration
A block driver may need to know about the block configuration, most critically the sector sizes, of a block backend for alignment purposes or for some other reason. It doesn't seem like qemu has an existing mechanism for a block backend to convey the required information to the relevant block driver when it is being realized.
The need for this mechanism rises from the fact that a drive may not have a backend at the time it is created, as devices are created after drives during qemu startup. Therefore, a driver requiring information about the block configuration can get this information when a backend is created for it at the earliest. The most natural place for this to take place seems to be in the realization functions of the various block device drivers, such as scsi-hd. The interface proposed here allows the block driver to receive information about the block configuration and the associated backend through a new callback.
--- block/io.c | 19 +++++++++++++++++++ hw/block/block.c | 11 ++++++++++- include/block/block.h | 10 ++++++++++ include/block/block_int.h | 9 +++++++++ include/hw/block/block.h | 1 + 5 files changed, 49 insertions(+), 1 deletion(-)
block/io.c +19 -0
@@ -2835,3 +2835,22 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *host)bdrv_unregister_buf (child->bs, host); } } + +void bdrv_apply_blkconf (BlockDriverState *bs,BlockConf *conf) +{ +BlockDriver *drv = bs->drv; + +if (!drv) +return ; + +if (drv->bdrv_apply_blkconf) { + drv->bdrv_apply_blkconf (bs, conf); +return ; + } + +if (bs->file && bs->file->bs) +bdrv_apply_blkconf (bs->file->bs, conf); + +if (bs->drv->supports_backing &&backing_bs (bs)) +bdrv_apply_blkconf (backing_bs (bs), conf); +}
hw/block/block.c +10 -1
@@ -38,7 +38,7 @@ void blkconf_blocksizes(BlockConf *conf)/* fill in detected values if they are not defined via qemu command line */ if (!conf->physical_block_size) {if (!backend_ret) { - conf->physical_block_size = blocksizes.phys; + conf->physical_block_size = blocksizes.phys; }else { conf->physical_block_size =BDRV_SECTOR_SIZE ; }
@@ -52,6 +52,15 @@ void blkconf_blocksizes(BlockConf *conf) } } +void blkconf_apply_to_blkdrv (BlockConf *conf) +{ +BlockBackend *blk = conf->blk; +BlockDriverState *bs =blk_bs (blk); + +if (bs) +bdrv_apply_blkconf (bs, conf); +} +bool blkconf_apply_backend_options (BlockConf *conf,bool readonly,bool resizable,Error **errp) {
include/block/block.h +10 -0
@@ -10,6 +10,7 @@#include "block/dirty-bitmap.h" #include "block/blockjob.h" #include "qemu/hbitmap.h" +#include "hw/block/block.h" /* block.c */ typedef struct BlockDriver BlockDriver ;
@@ -618,4 +619,13 @@ bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name,*/ void bdrv_register_buf (BlockDriverState *bs,void *host,size_t size);void bdrv_unregister_buf (BlockDriverState *bs,void *host); + +/** +* bdrv_apply_blkconf: +* +* Recursively finds the highest-level block drivers among the files and +* backing files that accept a block configuration and applies the given block +* configuration to them. +*/ +void bdrv_apply_blkconf (BlockDriverState *bs,BlockConf *conf);#endif
include/block/block_int.h +9 -0
@@ -433,6 +433,15 @@ struct BlockDriver {void (*bdrv_abort_perm_update)(BlockDriverState *bs);/** +* Called to inform the driver of the block configuration of the virtual +* block device. +* +* This function is called by a block device realization function if the +* device wants to inform the block driver of its block configuration. +*/ +void (*bdrv_apply_blkconf)(BlockDriverState *bs,BlockConf *conf); + +/** * Returns in @nperm and @nshared the permissions that the driver for @bs * needs on its child @c, based on the cumulative permissions requested by * the parents in @parent_perm and @parent_shared.
include/hw/block/block.h +1 -0
@@ -77,6 +77,7 @@ bool blkconf_geometry(BlockConf *conf, int *trans, unsigned cyls_max, unsigned heads_max, unsigned secs_max, Error **errp);void blkconf_blocksizes (BlockConf *conf); +void blkconf_apply_to_blkdrv (BlockConf *conf);bool blkconf_apply_backend_options (BlockConf *conf,bool readonly,bool resizable,Error **errp);
Signature · 1 line
2.7.4
PATCH 3/5 hw/scsi/scsi-disk: Always apply block configuration to block driver
This is an example of what all block devices should ideally do in their realization functions to convey the block configuration to the block driver.
--- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+)
hw/scsi/scsi-disk.c +1 -0
@@ -2413,6 +2413,7 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)blk_set_dev_ops (s->qdev.conf.blk, &scsi_disk_block_ops, s); }blk_set_guest_block_size (s->qdev.conf.blk, s->qdev.blocksize); +blkconf_apply_to_blkdrv (&s->qdev.conf);blk_iostatus_enable (s->qdev.conf.blk); }
Signature · 1 line
2.7.4
PATCH 4/5 block/blklogwrites: Use block limits from the backend block configuration
This is to ensure that writes are aligned properly for logging writes to the virtual block device. This is important because the dm-log-writes log format has a granularity of one sector for both the offset and the size of each write. By using the logical sector size for alignment, the log records the writes more faithfully for those devices that have a non-512 logical sector size.
Note that even with this patch, blklogwrites still uses BDRV_SECTOR_SIZE for logging. This will change in a subsequent patch which will introduce support for non-512 sector sizes.
--- block/blklogwrites.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
block/blklogwrites.c +17 -0
@@ -229,6 +229,22 @@ static void blk_log_writes_refresh_limits(BlockDriverState *bs, Error **errp) } } +static void blk_log_writes_apply_blkconf (BlockDriverState *bs,BlockConf *conf) +{ +assert (bs && conf && conf->blk); + + bs->bl.request_alignment = conf->logical_block_size; +if (conf->discard_granularity != (uint32_t )-1 ) + bs->bl.pdiscard_alignment = conf->discard_granularity; + +if (bs->bl.pdiscard_alignment && + bs->bl.pdiscard_alignment < bs->bl.request_alignment) + bs->bl.pdiscard_alignment = bs->bl.request_alignment; +if (bs->bl.pwrite_zeroes_alignment && + bs->bl.pwrite_zeroes_alignment < bs->bl.request_alignment) + bs->bl.pwrite_zeroes_alignment = bs->bl.request_alignment; +} + static int coroutine_fnblk_log_writes_co_preadv (BlockDriverState *bs,uint64_t offset,uint64_t bytes,QEMUIOVector *qiov,int flags)
@@ -424,6 +440,7 @@ static BlockDriver bdrv_blk_log_writes = { .bdrv_refresh_filename = blk_log_writes_refresh_filename, .bdrv_child_perm = blk_log_writes_child_perm, .bdrv_refresh_limits = blk_log_writes_refresh_limits, + .bdrv_apply_blkconf = blk_log_writes_apply_blkconf, .bdrv_co_preadv = blk_log_writes_co_preadv, .bdrv_co_pwritev = blk_log_writes_co_pwritev,
Signature · 1 line
2.7.4
PATCH 5/5 block/blklogwrites: Use the block device logical sector size when logging writes
The guest OS may perform writes which are aligned to the logical sector size instead of the physical one, so logging at this granularity records the writes performed on the block device most faithfully.
--- block/blklogwrites.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-)
block/blklogwrites.c +30 -13
@@ -47,6 +47,8 @@ struct log_write_entry {typedef struct {BdrvChild *log_file; +uint32_t sectorsize; +uint32_t sectorbits;uint64_t cur_log_sector;uint64_t nr_entries; }BDRVBlkLogWritesState ;
@@ -125,6 +127,8 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } + s->sectorsize =BDRV_SECTOR_SIZE ;/* May be updated later */ + s->sectorbits =BDRV_SECTOR_BITS ; s->cur_log_sector =1 ; s->nr_entries =0 ;qdict_put_str (options,"log.driver" ,"raw" );
@@ -229,11 +233,20 @@ static void blk_log_writes_refresh_limits(BlockDriverState *bs, Error **errp) } } +static inline uint32_t blk_log_writes_log2 (uint32_t value) +{ +assert (value >0 ); +return 31 -clz32 (value); +} +static void blk_log_writes_apply_blkconf (BlockDriverState *bs,BlockConf *conf) { -assert (bs && conf && conf->blk); +BDRVBlkLogWritesState *s = bs->opaque; +assert (bs && conf && conf->blk && s); - bs->bl.request_alignment = conf->logical_block_size; + s->sectorsize = conf->logical_block_size; + s->sectorbits =blk_log_writes_log2 (s->sectorsize); + bs->bl.request_alignment = s->sectorsize;if (conf->discard_granularity != (uint32_t )-1 ) bs->bl.pdiscard_alignment = conf->discard_granularity;
@@ -279,11 +292,11 @@ static void coroutine_fn blk_log_writes_co_do_log(void *opaque) {BlkLogWritesLogReq *lr = opaque;BDRVBlkLogWritesState *s = lr->r->bs->opaque; -uint64_t cur_log_offset = s->cur_log_sector *BDRV_SECTOR_SIZE ; +uint64_t cur_log_offset = s->cur_log_sector << s->sectorbits; s->nr_entries++; s->cur_log_sector += -ROUND_UP (lr->qiov->size,BDRV_SECTOR_SIZE ) >>BDRV_SECTOR_BITS ; +ROUND_UP (lr->qiov->size, s->sectorsize) >> s->sectorbits; lr->log_ret =bdrv_co_pwritev (s->log_file, cur_log_offset, lr->qiov->size, lr->qiov,0 );
@@ -294,20 +307,21 @@ static void coroutine_fn blk_log_writes_co_do_log(void *opaque) .magic = cpu_to_le64(WRITE_LOG_MAGIC), .version = cpu_to_le64(WRITE_LOG_VERSION), .nr_entries = cpu_to_le64(s->nr_entries), - .sectorsize = cpu_to_le32(1 << BDRV_SECTOR_BITS), + .sectorsize = cpu_to_le32(s->sectorsize), }; -static const char zeroes[BDRV_SECTOR_SIZE -sizeof (super)] = {'\0' }; +void *zeroes =g_malloc0 (s->sectorsize -sizeof (super));QEMUIOVector qiov;qemu_iovec_init (&qiov,2 );qemu_iovec_add (&qiov, &super,sizeof (super)); -qemu_iovec_add (&qiov, (void *)zeroes,sizeof (zeroes)); +qemu_iovec_add (&qiov, zeroes, s->sectorsize -sizeof (super)); lr->log_ret = -bdrv_co_pwritev (s->log_file,0 ,BDRV_SECTOR_SIZE , &qiov,0 ); +bdrv_co_pwritev (s->log_file,0 , s->sectorsize, &qiov,0 );if (lr->log_ret ==0 ) lr->log_ret =bdrv_co_flush (s->log_file->bs);qemu_iovec_destroy (&qiov); +g_free (zeroes); } lr->r->done++;
@@ -332,6 +346,7 @@ blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t bytes, {QEMUIOVector log_qiov;size_t niov = qiov ? qiov->niov :0 ; +BDRVBlkLogWritesState *s = bs->opaque;Coroutine *co_log, *co_file;BlkLogWritesReq r = { .co =qemu_coroutine_self (),
@@ -349,21 +364,22 @@ blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t bytes, .r = &r, .qiov = &log_qiov, .entry = { - .sector = cpu_to_le64(offset >> BDRV_SECTOR_BITS), - .nr_sectors = cpu_to_le64(bytes >> BDRV_SECTOR_BITS), + .sector = cpu_to_le64(offset >> s->sectorbits), + .nr_sectors = cpu_to_le64(bytes >> s->sectorbits), .flags = cpu_to_le64(entry_flags), .data_len = 0, }, }; -static const char zeroes[BDRV_SECTOR_SIZE -sizeof (struct log_write_entry )] - = {'\0' }; +void *zeroes =g_malloc0 (s->sectorsize -sizeof (lr.entry)); +assert ((1 << s->sectorbits) == s->sectorsize); +assert (bs->bl.request_alignment == s->sectorsize);assert (QEMU_IS_ALIGNED (offset, bs->bl.request_alignment));assert (QEMU_IS_ALIGNED (bytes, bs->bl.request_alignment));qemu_iovec_init (&log_qiov, niov +2 );qemu_iovec_add (&log_qiov, &lr.entry,sizeof (lr.entry)); -qemu_iovec_add (&log_qiov, (void *)zeroes,sizeof (zeroes)); +qemu_iovec_add (&log_qiov, zeroes, s->sectorsize -sizeof (lr.entry));for (size_t i =0 ; i < niov; ++i) {qemu_iovec_add (&log_qiov, qiov->iov[i].iov_base, qiov->iov[i].iov_len); }
@@ -379,6 +395,7 @@ blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t bytes, }qemu_iovec_destroy (&log_qiov); +g_free (zeroes);if (lr.log_ret <0 ) {return lr.log_ret;
Signature · 1 line
2.7.4
Quoted 3 lines · Ari Sundholm
From: Aapo Vienamo <[email protected]>
Implements a block device write logging system, similar to Linux kernel
[meta-comment]
Your patch threading is awkward - you forgot a cover letter, and then you did deep threading (every message in-reply-to the previous) instead of shallow threading (all messages in-reply-to only the 0/5 cover letter). This makes it harder for automated tooling to recognize your series properly.
More patch submission hints at:
http://wiki.qemu.org/Contribute/SubmitAPatch
Quoted 13 lines
device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
The implementation is based on the blkverify and blkdebug block drivers.
Signed-off-by Aapo Vienamo <[email protected]>Signed-off-by Ari Sundholm <[email protected]>
Quoted 7 lines
--- block.c | 6 - block/Makefile.objs | 1 + block/blklogwrites.c | 441 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 7 + 4 files changed, 449 insertions(+), 6 deletions(-)create mode 100644
block/blklogwrites.c
Without a cover letter, I'll have to read the entire series to see if there is something obviously missing. For example, I don't yet know if a later patch adds to qapi/block-core.json to allow creation of this new block device from QMP.
Quoted 6 lines
block.c +0
-0
block.c int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, · line 1922
Quoted 9 lines
block.c +0
-6@@ -1914,12 +1914,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,return 0 ; } -#define DEFAULT_PERM_PASSTHROUGH (BLK_PERM_CONSISTENT_READ \ - | BLK_PERM_WRITE \ - | BLK_PERM_WRITE_UNCHANGED \ - | BLK_PERM_RESIZE) -#define DEFAULT_PERM_UNCHANGED (BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH) -
Your commit message didn't mention why this code motion was necessary; in fact, if it IS necessary, it might be better to split it off into a separate patch.
Quoted 13 lines
block.c +12
-0+++ b/block/blklogwrites.c@@ -0,0 +1,441 @@ +/* +* Write logging blk driver based on blkverify and blkdebug. +* +* Copyright (c) 2017 Tuomas Tynkkynen <[email protected]> +* Copyright (c) 2018 Aapo Vienamo <[email protected]> +* Copyright (c) 2018 Ari Sundholm <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +
block.c line 21
Quoted 10 lines
block.c +10
-0+#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/sockets.h" /* for EINPROGRESS on Windows */ +#include "block/block_int.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qemu/cutils.h" +#include "qemu/option.h" + +/* Disk format stuff - taken from Linux drivers/md/dm-log-writes.c */
Your copyright claims GPLv2+; but drivers/md/dm-log-writes.c states only "* This file is released under the GPL." - I guess that means you're okay (parts of Linux are GPLv2-only, which we can't copy into a GPLv2+ file).
block.c line 26
Quoted 5 lines
block.c +5
-0+ +/* Valid blk_log_writes filenames look like: +* blk_log_writes:path/to/raw_image:path/to/logfile */ +static void blk_log_writes_parse_filename (const char *filename,QDict *options, +Error **errp)
Do we still want to support yet another legacy syntax addition? I'd rather just require the user to pass in a valid --blockdev specification (which implies that you MUST support a QMP description), and skip the legacy syntax altogether.
Quoted 4 lines
block.c +4
-0+ +static QemuOptsList runtime_opts = { + .name ="blk_log_writes" , + .head =QTAILQ_HEAD_INITIALIZER (runtime_opts.head),
block.c line 40
Quoted 10 lines
block.c +10
-0+ .desc = { + { + .name = "x-raw", + .type = QEMU_OPT_STRING, + .help = "[internal use only, will be removed]", + }, + { + .name = "x-log", + .type = QEMU_OPT_STRING, + .help = "[internal use only, will be removed]",
And the fact that you are adding internal options from the getgo points to the fact that we really want a QMP interface.
block.c line 43
Quoted 3 lines
block.c +3
-0+static void blk_log_writes_refresh_limits (BlockDriverState *bs,Error **errp) +{ +if (bs->bl.request_alignment <BDRV_SECTOR_SIZE ) {
Why do you need sector alignment? And in what cases would bs->bl.request_alignment be larger than sector alignment (does the block layer take into account if your log file and/or child BDS already have a larger alignment?)
block.c line 48
Quoted 5 lines
block.c +5
-0+ bs->bl.request_alignment =BDRV_SECTOR_SIZE ; + +if (bs->bl.pdiscard_alignment && + bs->bl.pdiscard_alignment < bs->bl.request_alignment) + bs->bl.pdiscard_alignment = bs->bl.request_alignment;
Every 'if' MUST use {}. scripts/checkpatch.pl should have flagged this.
Quoted 5 lines
block.c +4
-0+static void coroutine_fn blk_log_writes_co_do_log(void *opaque) +{ + + lr->r->done++;
block.c
Quoted 10 lines
block.c +10
-0+qemu_coroutine_enter_if_inactive (lr->r->co); +} + +static void blk_log_writes_co_do_file (void *opaque) +{ +BlkLogWritesFileReq *fr = opaque; + + fr->file_ret = fr->func (fr); + + fr->r->done++;
Two non-atomic increments...
Quoted 6 lines
block.c +6
-0+qemu_coroutine_enter_if_inactive (fr->r->co); +} + +static int coroutine_fn +blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags,
block.c
Quoted 10 lines
block.c +9
-0+int (*file_func)(BlkLogWritesFileReq *r), + uint64_t entry_flags) +{ +qemu_coroutine_enter (co_file ); +qemu_coroutine_enter (co_log); + +while (r.done <2 ) { +qemu_coroutine_yield (); + }
...used as the condition for waiting. Since the point of coroutines is to allow (restricted) parallel operation, there's a chance that the coroutine implementation can be utilizing parallel threads; if that's the case, then on the rare race when both threads try to increment at near the same time, they can both read 0 and write 1, at which point this wait loop would be an infinite loop. You're probably better off using atomics (even if I'm wrong about coroutines being able to race each other on the increment, as the other point of coroutines is that they provide restricted parallelism where you can also implement them in only a single thread because of well-defined yield points).
Quoted 10 lines
block.c +10
-0+static BlockDriver bdrv_blk_log_writes = { + .format_name ="blk_log_writes" , + .protocol_name ="blk_log_writes" , + .instance_size =sizeof (BDRVBlkLogWritesState), + + .bdrv_parse_filename = blk_log_writes_parse_filename, + .bdrv_file_open = blk_log_writes_open, + .bdrv_close = blk_log_writes_close, + .bdrv_getlength = blk_log_writes_getlength, + .bdrv_refresh_filename = blk_log_writes_refresh_filename,
block.c
Quoted 10 lines
block.c +10
-0+ .bdrv_child_perm = blk_log_writes_child_perm, + .bdrv_refresh_limits = blk_log_writes_refresh_limits, + + .bdrv_co_preadv = blk_log_writes_co_preadv, + .bdrv_co_pwritev = blk_log_writes_co_pwritev, + .bdrv_co_flush_to_disk = blk_log_writes_co_flush_to_disk, + .bdrv_co_pdiscard = blk_log_writes_co_pdiscard, + + .is_filter = true, +};
No .bdrv_co_pwrite_zeroes support? While the block layer will emulate zero support on top of .bdrv_co_pwritev, that is probably a performance killer compared to you implementing it directly.
Also, you probably want .bdrv_co_block_status = bdrv_co_block_status_from_file, so that the block layer sees the underlying device's block status rather than treating the entire device as non-sparse.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 12 lines · Eric Blake
Quoted 3 lines · Ari Sundholm
From: Aapo Vienamo <[email protected]>
Implements a block device write logging system, similar to Linux kernel
[meta-comment]
Your patch threading is awkward - you forgot a cover letter, and then you did deep threading (every message in-reply-to the previous) instead of shallow threading (all messages in-reply-to only the 0/5 cover letter). This makes it harder for automated tooling to recognize your series properly.
More patch submission hints at:
http://wiki.qemu.org/Contribute/SubmitAPatch
Thank you, I will improve this in the next version. I was not aware that the threading choice breaks the tooling. I should definitely have included a cover letter and perhaps moved some of the comment in the first patch there, with more explanation about some of the choices made.
Quoted 34 lines
Quoted 13 lines
device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
The implementation is based on the blkverify and blkdebug block drivers.
Signed-off-by Aapo Vienamo <[email protected]>Signed-off-by Ari Sundholm <[email protected]>Quoted 8 lines
---
block.c | 6 -
block/Makefile.objs | 1 +
block/blklogwrites.c | 441
++++++++++++++++++++++++++++++++++++++++++++++++++
include/block/block.h| 7 +4 files changed, 449 insertions(+), 6 deletions(-)create mode 100644
block/blklogwrites.cWithout a cover letter, I'll have to read the entire series to see if there is something obviously missing. For example, I don't yet know if a later patch adds to
qapi/block-core.jsonto allow creation of this new block device from QMP.Quoted 10 lines
block.c +0
-1@@ -1914,12 +1914,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, return 0; } -#define DEFAULT_PERM_PASSTHROUGH (BLK_PERM_CONSISTENT_READ \
Quoted 9 lines
block.c int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, · line 1922
Quoted 6 lines
block.c +0
-5- | BLK_PERM_WRITE \ - | BLK_PERM_WRITE_UNCHANGED \ - | BLK_PERM_RESIZE) -#define DEFAULT_PERM_UNCHANGED (BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH) -Your commit message didn't mention why this code motion was necessary; in fact, if it IS necessary, it might be better to split it off into a separate patch.
This was just to allow using these constants outside of block.c. Will split this off into a separate patch, as requested.
Quoted 18 lines
Quoted 18 lines
block.c +9
-0+++ b/block/blklogwrites.c@@ -0,0 +1,441 @@ +/* +* Write logging blk driver based on blkverify and blkdebug. +* +* Copyright (c) 2017 Tuomas Tynkkynen <[email protected]> +* Copyright (c) 2018 Aapo Vienamo <[email protected]> +* Copyright (c) 2018 Ari Sundholm <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */block.c +5
-0+ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/sockets.h" /* for EINPROGRESS on Windows */ +#include "block/block_int.h"
Quoted 9 lines
block.c
Quoted 6 lines
block.c +6
-0+#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qemu/cutils.h" +#include "qemu/option.h" + +/* Disk format stuff - taken from Linux drivers/md/dm-log-writes.c */ Your copyright claims GPLv2+; but
drivers/md/dm-log-writes.cstates only "* This file is released under the GPL." - I guess that means you're okay (parts of Linux are GPLv2-only, which we can't copy into a GPLv2+ file).
I consulted legal counsel on this part, and it is our opinion that the constants and structs taken from the Linux kernel are insignificant and required for compatibility, so it should be OK to license the file as GPLv2+ in any case. Just to confirm, do you see this differently?
Quoted 9 lines
Quoted 6 lines
block.c +4
-0+ +/* Valid blk_log_writes filenames look like: +* blk_log_writes:path/to/raw_image:path/to/logfile */ +static void blk_log_writes_parse_filename(const char *filename, QDict*options,
+ Error **errp)Do we still want to support yet another legacy syntax addition? I'd rather just require the user to pass in a valid --blockdev specification (which implies that you MUST support a QMP description), and skip the legacy syntax altogether.
I believe this was inherited from blkverify, which was used as a basis. I will have to do some research into how to do this properly for this kind of a driver which requires multiple filenames. Any pointers would be appreciated.
Quoted 8 lines
Quoted 8 lines
block.c +8
-0+ +static QemuOptsList runtime_opts = { + .name = "blk_log_writes", + .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), + .desc = { + { + .name = "x-raw", + .type = QEMU_OPT_STRING,
Quoted 9 lines
Quoted 6 lines
+ .help = "[internal use only, will be removed]", + },
+ {
+ .name = "x-log",
+ .type =QEMU_OPT_STRING,
+ .help = "[internal use only, will be removed]",And the fact that you are adding internal options from the getgo points to the fact that we really want a QMP interface.
Will try to find out how to do this properly.
Quoted 8 lines
Quoted 5 lines
+static void
blk_log_writes_refresh_limits(BlockDriverState *bs, Error **errp)
+{
+ if (bs->bl.request_alignment<BDRV_SECTOR_SIZE) {Why do you need sector alignment? And in what cases would
bs->bl.request_alignmentbe larger than sector alignment (does the block layer take into account if your log file and/or child BDS already have a larger alignment?)
Sector alignment is needed because the write logging takes place at sector granularity. Each write log entry contains the sector offset and the number of sectors the write spanned. I'll try to make this clearer in the next version.
Quoted 8 lines
Quoted 5 lines
+
bs->bl.request_alignment=BDRV_SECTOR_SIZE;
+
+ if (bs->bl.pdiscard_alignment&&
+bs->bl.pdiscard_alignment<bs->bl.request_alignment) +bs->bl.pdiscard_alignment=bs->bl.request_alignment;Every 'if' MUST use {}.
scripts/checkpatch.plshould have flagged this.
Thanks, will fix this and other instances.
Quoted 29 lines
Quoted 5 lines
block.c +4
-0+static void coroutine_fn blk_log_writes_co_do_log(void *opaque) +{ + + lr->r->done++;block.c
Quoted 10 lines
block.c +10
-0+ qemu_coroutine_enter_if_inactive(lr->r->co); +} + +static void blk_log_writes_co_do_file (void *opaque) +{ + BlkLogWritesFileReq *fr = opaque; + + fr->file_ret = fr->func(fr); + + fr->r->done++;Two non-atomic increments...
Quoted 10 lines
+
qemu_coroutine_enter_if_inactive(fr->r->co);block.c +4
-0+} + +static int coroutine_fn +blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_tbytes,
+ QEMUIOVector *qiov, int flags, + int (*file_func)(BlkLogWritesFileReq *r), +uint64_tentry_flags)
+{
Quoted 9 lines
Quoted 6 lines
+
qemu_coroutine_enter(co_file);
+qemu_coroutine_enter(co_log);
+
+ while (r.done < 2) {
+qemu_coroutine_yield();
+ }...used as the condition for waiting. Since the point of coroutines is to allow (restricted) parallel operation, there's a chance that the coroutine implementation can be utilizing parallel threads; if that's the case, then on the rare race when both threads try to increment at near the same time, they can both read 0 and write 1, at which point this wait loop would be an infinite loop. You're probably better off using atomics (even if I'm wrong about coroutines being able to race each other on the increment, as the other point of coroutines is that they provide restricted parallelism where you can also implement them in only a single thread because of well-defined yield points).
Inherited from blkverify, I believe. Will fix.
Quoted 15 lines
Quoted 15 lines
block.c +14
-0+static BlockDriver bdrv_blk_log_writes = { + .format_name = "blk_log_writes", + .protocol_name = "blk_log_writes", + .instance_size = sizeof(BDRVBlkLogWritesState), + + .bdrv_parse_filename = blk_log_writes_parse_filename, + .bdrv_file_open = blk_log_writes_open, + .bdrv_close = blk_log_writes_close, + .bdrv_getlength = blk_log_writes_getlength, + .bdrv_refresh_filename = blk_log_writes_refresh_filename, + .bdrv_child_perm = blk_log_writes_child_perm, + .bdrv_refresh_limits = blk_log_writes_refresh_limits, + + .bdrv_co_preadv = blk_log_writes_co_preadv,
Quoted 9 lines
block.c
Quoted 6 lines
+ .bdrv_co_pwritev =
blk_log_writes_co_pwritev, + .bdrv_co_flush_to_disk =blk_log_writes_co_flush_to_disk, + .bdrv_co_pdiscard =blk_log_writes_co_pdiscard,block.c +3
-0+ + .is_filter = true, +};No .bdrv_co_pwrite_zeroes support? While the block layer will emulate zero support on top of .bdrv_co_pwritev, that is probably a performance killer compared to you implementing it directly.
I see. I'll have to consider the implications with regard to accurate write logging to see if this is feasible and desirable.
Quoted 2 lines
Also, you probably want .bdrv_co_block_status =
bdrv_co_block_status_from_file, so that the block layer sees the underlying device's block status rather than treating the entire device as non-sparse.
Thank you, will look into this.
Best regards,
Ari Sundholm
[email protected]
Quoted 28 lines · Ari Sundholm
Quoted 18 lines
Quoted 18 lines
+++
b/block/blklogwrites.cblock/blklogwrites.c new file +8
-0@@ -0,0 +1,441 @@ +/* +* Write logging blk driver based on blkverify and blkdebug. +* +* Copyright (c) 2017 Tuomas Tynkkynen <[email protected]> +* Copyright (c) 2018 Aapo Vienamo <[email protected]> +* Copyright (c) 2018 Ari Sundholm <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */block/blklogwrites.c new file +5
-0+ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/sockets.h" /* for EINPROGRESS on Windows */ +#include "block/block_int.h" Quoted 9 lines
block/blklogwrites.c line 21
Quoted 6 lines
block/blklogwrites.c new file +6
-0+#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qemu/cutils.h" +#include "qemu/option.h" + +/* Disk format stuff - taken from Linux drivers/md/dm-log-writes.c */ Your copyright claims GPLv2+; but
drivers/md/dm-log-writes.cstates only "* This file is released under the GPL." - I guess that means you're okay (parts of Linux are GPLv2-only, which we can't copy into a GPLv2+ file).
Quoted 1 line
I consulted legal counsel on this part, and it is our opinion that the constants and structs taken from the Linux kernel are insignificant and required for compatibility, so it should be OK to license the file as GPLv2+ in any case. Just to confirm, do you see this differently?
I'm not a lawyer, but I don't see any problem for the code you copied from that particular file (that is, any source file that says just "GPL" can be interpreted as "GPLv1+", which is therefore okay to copy into a "GPLv2+" file). I was more pointing out that in general, any time you copy code but use a different license, you DO have to perform due diligence to ensure you aren't treading on dangerous ground. And the fact that you consulted legal counsel is a good thing. If it were a more controversial claim (copying from a "GPLv2-only" file on the ground that the copied portion is part of an essential interface and therefore not bound by GPLv2-only and therefore okay for inclusion in GPLv2+, then I'd have mentioned the legal counsel's advice as part of the commit message; but in this case I don't think that's necessary. Also, we DO have files in qemu that are GPLv2-only - we don't like adding more when not necessary, but when copying from a GPLv2-only source, it is certainly a justifiable action (rather than worrying about whether licensing your file as GPLv2+ is violating the intent of the copied portions in your file) - but again, I don't see that as something needed for this patch, given that your source file did not state GPLv2-only.
Quoted 5 lines
Quoted 2 lines
Do we still want to support yet another legacy syntax addition? I'd rather just require the user to pass in a valid --blockdev specification (which implies that you MUST support a QMP description), and skip the legacy syntax altogether.
I believe this was inherited from blkverify, which was used as a basis. I will have to do some research into how to do this properly for this kind of a driver which requires multiple filenames. Any pointers would be appreciated.
Look at qapi/block-core.json BlockdevOptionsBlkverify for how to declare the QMP type. Kevin may also have some hints.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 33 lines · Eric Blake
Quoted 28 lines · Ari Sundholm
Quoted 18 lines
Quoted 18 lines
+++
b/block/blklogwrites.cblock/blklogwrites.c new file +8
-0@@ -0,0 +1,441 @@ +/* +* Write logging blk driver based on blkverify and blkdebug. +* +* Copyright (c) 2017 Tuomas Tynkkynen <[email protected]> +* Copyright (c) 2018 Aapo Vienamo <[email protected]> +* Copyright (c) 2018 Ari Sundholm <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */block/blklogwrites.c new file +5
-0+ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/sockets.h" /* for EINPROGRESS on Windows */ +#include "block/block_int.h" Quoted 9 lines
block/blklogwrites.c line 21
Quoted 6 lines
block/blklogwrites.c new file +6
-0+#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qemu/cutils.h" +#include "qemu/option.h" + +/* Disk format stuff - taken from Linux drivers/md/dm-log-writes.c */ Your copyright claims GPLv2+; but
drivers/md/dm-log-writes.cstates only "* This file is released under the GPL." - I guess that means you're okay (parts of Linux are GPLv2-only, which we can't copy into a GPLv2+ file).Quoted 1 line
I consulted legal counsel on this part, and it is our opinion that the constants and structs taken from the Linux kernel are insignificant and required for compatibility, so it should be OK to license the file as GPLv2+ in any case. Just to confirm, do you see this differently?
I'm not a lawyer, but I don't see any problem for the code you copied from that particular file (that is, any source file that says just "GPL" can be interpreted as "GPLv1+", which is therefore okay to copy into a "GPLv2+" file). I was more pointing out that in general, any time you copy code but use a different license, you DO have to perform due diligence to ensure you aren't treading on dangerous ground. And the fact that you consulted legal counsel is a good thing. If it were a more controversial claim (copying from a "GPLv2-only" file on the ground that the copied portion is part of an essential interface and therefore not bound by GPLv2-only and therefore okay for inclusion in GPLv2+, then I'd have mentioned the legal counsel's advice as part of the commit message; but in this case I don't think that's necessary. Also, we DO have files in qemu that are GPLv2-only - we don't like adding more when not necessary, but when copying from a GPLv2-only source, it is certainly a justifiable action (rather than worrying about whether licensing your file as GPLv2+ is violating the intent of the copied portions in your file) - but again, I don't see that as something needed for this patch, given that your source file did not state GPLv2-only.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we still want to support yet another legacy syntax addition? I'd rather just require the user to pass in a valid --blockdev specification (which implies that you MUST support a QMP description), and skip the legacy syntax altogether.
I believe this was inherited from blkverify, which was used as a basis. I will have to do some research into how to do this properly for this kind of a driver which requires multiple filenames. Any pointers would be appreciated.
Look at
qapi/block-core.jsonBlockdevOptionsBlkverify for how to declare the QMP type. Kevin may also have some hints.
Thank you.
I'll try to get a new, more proper version of the patchset out for review/comments next week. Sorry for the sloppiness in this first version!
Thanks,
Ari Sundholm
[email protected]
Quoted 3 lines · Ari Sundholm
Thank you.
I'll try to get a new, more proper version of the patchset out for review/comments next week. Sorry for the sloppiness in this first version!
Looking forward to it, even if, as Stefan pointed out, we can already do everything by use of the existing quorum driver and a custom NBD server.
And don't worry about the patch not being perfect the first time - that's just a typical part of the review process. Although unintended on my end, I know that my reviews can be perceived as coming across rather negatively, especially when I don't always remember to also express my appreciation for the efforts you've already put into writing a patch. The community is always better when we remember to treat newcomers (and long-time contributors) nicely, regardless of the outcome of the patch review process; and the reason we review things is so that however sloppy a first draft was, the final product is a lot better!
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 28 lines · Eric Blake
block/blklogwrites.c line 307
Quoted 7 lines · Ari Sundholm
block/blklogwrites.c new file +7
-0+static void blk_log_writes_co_do_file (void *opaque) +{ +BlkLogWritesFileReq *fr = opaque; + + fr->file_ret = fr->func (fr); + + fr->r->done++;Two non-atomic increments...
Quoted 6 lines
block/blklogwrites.c new file +6
-0+qemu_coroutine_enter_if_inactive (fr->r->co); +} + +static int coroutine_fn +blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags,block/blklogwrites.c line 363
Quoted 10 lines
block/blklogwrites.c new file +9
-0+int (*file_func)(BlkLogWritesFileReq *r), + uint64_t entry_flags) +{ +qemu_coroutine_enter (co_file ); +qemu_coroutine_enter (co_log); + +while (r.done <2 ) { +qemu_coroutine_yield (); + }
Quoted 10 lines
...used as the condition for waiting. Since the point of coroutines is to allow (restricted) parallel operation, there's a chance that the coroutine implementation can be utilizing parallel threads; if that's the case, then on the rare race when both threads try to increment at near the same time, they can both read 0 and write 1, at which point this wait loop would be an infinite loop. You're probably better off using atomics (even if I'm wrong about coroutines being able to race each other on the increment, as the other point of coroutines is that they provide restricted parallelism where you can also implement them in only a single thread because of well-defined yield points).
In this case the coroutines run from a single event loop (the BlockDriverState's AioContext) so they cannot race.
As QEMU transitions to a multi-queue block layer we will need to think about parallelism more. But the multi-queue block layer isn't implemented yet, so I prefer writing straightforward code now without trying to anticipate what parallelism issues might arise in the future.
Stefan
Quoted 1 line · Ari Sundholm
From: Aapo Vienamo <[email protected]>
Thanks for the patch!
Quoted 9 lines
Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
This patch doesn't implement the same semantics as dm-log-writes, where only completed writes are logged to make fs consistency testing easier. If you intend to use it for this purpose, shouldn't it act the same way as dm-log-writes?
Quoted 1 line
The implementation is based on the blkverify and blkdebug block drivers.
This functionality overlaps with existing block drivers. In the long-term people want to observe I/O requests in various ways beyond what the dm-log-writes offers. Therefore I'd like to suggest a different approach that extends the quorum driver instead:
Add a read-pattern=first parameter to the block/quorum.c driver so it only reads from the first child. QEMU can be launched with quorum and NBD so that writes and flushes are mirrored to the external NBD server.
Any file format or online analysis can be implemented in the NBD server. There are a number of NBD plugins here:
https://github.com/libguestfs/nbdkit
I think sending the writes and flushes over NBD is more flexible.
Quoted 11 lines · Stefan Hajnoczi
Quoted 1 line · Ari Sundholm
From: Aapo Vienamo <[email protected]>
Thanks for the patch!
Quoted 6 lines
Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
Quoted 9 lines
Quoted 3 lines
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
This patch doesn't implement the same semantics as dm-log-writes, where only completed writes are logged to make fs consistency testing easier. If you intend to use it for this purpose, shouldn't it act the same way as dm-log-writes?
I am not quite sure what you mean. I am not the original author of this proposed feature, but to me (admittedly with little experience of qemu internals), it looks like the driver accurately logs the writes and flushes performed on the guest block device. It intentionally does not concern itself with when the write actually hits the physical host block device or file, as we're interested in the direct interactions between a filesystem driver and the guest block device. The write hitting the various levels of the host-side caches and devices is left up to the caching mode. But perhaps there's something obvious I'm not seeing?
Speaking of the caching mode, I now realized that the log superblock is probably never written out when cache=unsafe is set, which will need fixing.
Quoted 11 lines
Quoted 1 line
The implementation is based on the blkverify and blkdebug block drivers.
This functionality overlaps with existing block drivers. In the long-term people want to observe I/O requests in various ways beyond what the dm-log-writes offers. Therefore I'd like to suggest a different approach that extends the quorum driver instead:
Add a read-pattern=first parameter to the
block/quorum.cdriver so it only reads from the first child. QEMU can be launched with quorum and NBD so that writes and flushes are mirrored to the external NBD server.
Quoted 6 lines
Any file format or online analysis can be implemented in the NBD server. There are a number of NBD plugins here:
https://github.com/libguestfs/nbdkitI think sending the writes and flushes over NBD is more flexible.
That sounds interesting! I will look into this possibility.
Thanks,
Ari Sundholm
[email protected]
Quoted 22 lines · Ari Sundholm
Quoted 11 lines · Stefan Hajnoczi
Quoted 1 line · Ari Sundholm
From: Aapo Vienamo <[email protected]>
Thanks for the patch!
Quoted 6 lines
Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
Quoted 9 lines
Quoted 3 lines
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
This patch doesn't implement the same semantics as dm-log-writes, where only completed writes are logged to make fs consistency testing easier. If you intend to use it for this purpose, shouldn't it act the same way as dm-log-writes?
Quoted 9 lines
I am not quite sure what you mean. I am not the original author of this proposed feature, but to me (admittedly with little experience of qemu internals), it looks like the driver accurately logs the writes and flushes performed on the guest block device. It intentionally does not concern itself with when the write actually hits the physical host block device or file, as we're interested in the direct interactions between a filesystem driver and the guest block device. The write hitting the various levels of the host-side caches and devices is left up to the caching mode. But perhaps there's something obvious I'm not seeing?
Linux dm-log-writes is specific about when logging happens:
* We log writes only after they have been flushed, this makes the log describe
* close to the order in which the data hits the actual disk, not its cache. So
* for example the following sequence (W means write, C means complete) *
* Wa,Wb,Wc,Cc,Ca,FLUSH,FUAd,Cb,CFLUSH,CFUAd
*
* Would result in the log looking like this:
*
* c,a,flush,fuad,b,<other writes>,<next flush>
*
* This is meant to help expose problems where file systems do not properly wait
* on data being written before invoking a FLUSH. FUA bypasses cache so once it
* completes it is added to the log as it should be on disk.
This patch implements the same on-disk format but the semantics are different since it doesn't wait for a flush.
If I use dm-log-writes on a linear device-mapper target inside the guest or on the host, then I would have expected the same output as QEMU's dm-log-writes, but I think this is not the case.
It's worth at least documenting this quirk.
Stefan
Quoted 49 lines · Stefan Hajnoczi
Quoted 22 lines · Ari Sundholm
Quoted 11 lines · Stefan Hajnoczi
Quoted 1 line · Ari Sundholm
From: Aapo Vienamo <[email protected]>
Thanks for the patch!
Quoted 6 lines
Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
Quoted 9 lines
Quoted 3 lines
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
This patch doesn't implement the same semantics as dm-log-writes, where only completed writes are logged to make fs consistency testing easier. If you intend to use it for this purpose, shouldn't it act the same way as dm-log-writes?
Quoted 9 lines
I am not quite sure what you mean. I am not the original author of this proposed feature, but to me (admittedly with little experience of qemu internals), it looks like the driver accurately logs the writes and flushes performed on the guest block device. It intentionally does not concern itself with when the write actually hits the physical host block device or file, as we're interested in the direct interactions between a filesystem driver and the guest block device. The write hitting the various levels of the host-side caches and devices is left up to the caching mode. But perhaps there's something obvious I'm not seeing?
Linux dm-log-writes is specific about when logging happens:
* We log writes only after they have been flushed, this makes the log describe
* close to the order in which the data hits the actual disk, not its cache. So
* for example the following sequence (W means write, C means complete) *
* Wa,Wb,Wc,Cc,Ca,FLUSH,FUAd,Cb,CFLUSH,CFUAd
*
* Would result in the log looking like this:
*
* c,a,flush,fuad,b,<other writes>,<next flush>
*
* This is meant to help expose problems where file systems do not properly wait
* on data being written before invoking a FLUSH. FUA bypasses cache so once it
* completes it is added to the log as it should be on disk.
Quoted 8 lines
This patch implements the same on-disk format but the semantics are different since it doesn't wait for a flush.
If I use dm-log-writes on a linear device-mapper target inside the guest or on the host, then I would have expected the same output as QEMU's dm-log-writes, but I think this is not the case.
It's worth at least documenting this quirk.
Oh, now I see what you mean.
I was under the impression that when we do the logging at the level it is done now, we see the actual writes to the guest block device to completion, as far as the guest is concerned (being safely in the host's page cache is enough for this). Is this understanding incorrect?
Regarding the issue of waiting for flushes, as it is now, the driver only updates the superblock of the log on flush, and everything in the log file/device beyond the limits set by the values in the superblock is typically ignored as garbage by tools handling dm-log-writes logs. (I wonder if dm-log-writes actually works similarly by exploiting this fact?) QEMU does a flush on shutdown, though, so, with how the code works, all writes will have hit the disk and been logged, unless QEMU has crashed or cache=unsafe is on (have to figure out what to do about that last bit!).
I guess this at least requires documenting, regardless of whether the behavior is correct or not. Thank you for bringing this up!
Thanks,
Ari Sundholm
[email protected]
Quoted 3 lines
Stefan
Quoted 57 lines · Ari Sundholm
Quoted 56 lines · Stefan Hajnoczi
Quoted 22 lines · Ari Sundholm
Quoted 11 lines · Stefan Hajnoczi
Quoted 1 line · Ari Sundholm
From: Aapo Vienamo <[email protected]>
Thanks for the patch!
Quoted 6 lines
Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
Quoted 9 lines
Quoted 3 lines
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
This patch doesn't implement the same semantics as dm-log-writes, where only completed writes are logged to make fs consistency testing easier. If you intend to use it for this purpose, shouldn't it act the same way as dm-log-writes?
Quoted 9 lines
I am not quite sure what you mean. I am not the original author of this proposed feature, but to me (admittedly with little experience of qemu internals), it looks like the driver accurately logs the writes and flushes performed on the guest block device. It intentionally does not concern itself with when the write actually hits the physical host block device or file, as we're interested in the direct interactions between a filesystem driver and the guest block device. The write hitting the various levels of the host-side caches and devices is left up to the caching mode. But perhaps there's something obvious I'm not seeing?
Linux dm-log-writes is specific about when logging happens:
* We log writes only after they have been flushed, this makes the log describe
* close to the order in which the data hits the actual disk, not its cache. So
* for example the following sequence (W means write, C means complete) *
* Wa,Wb,Wc,Cc,Ca,FLUSH,FUAd,Cb,CFLUSH,CFUAd
*
* Would result in the log looking like this:
*
* c,a,flush,fuad,b,<other writes>,<next flush>
*
* This is meant to help expose problems where file systems do not properly wait
* on data being written before invoking a FLUSH. FUA bypasses cache so once it
* completes it is added to the log as it should be on disk.This patch implements the same on-disk format but the semantics are different since it doesn't wait for a flush.
If I use dm-log-writes on a linear device-mapper target inside the guest or on the host, then I would have expected the same output as QEMU's dm-log-writes, but I think this is not the case.
Quoted 8 lines
Quoted 1 line
It's worth at least documenting this quirk.
Oh, now I see what you mean.
I was under the impression that when we do the logging at the level it is done now, we see the actual writes to the guest block device to completion, as far as the guest is concerned (being safely in the host's page cache is enough for this). Is this understanding incorrect?
.bdrv_co_pwritev is called on request submission. blk_log_writes_co_log() spawns a coroutine for blk_log_writes_co_do_log(), which appends a struct log_write_entry to the log file independently of the other coroutine that is doing the actual write to the underlying file.
This means the entry could be added to the log file before the write request completes.
If you want to log on request completion then you cannot spawn the log coroutine in parallel with the write coroutine. Instead you would have to complete the write and then update the log.
Quoted 5 lines
Regarding the issue of waiting for flushes, as it is now, the driver only updates the superblock of the log on flush, and everything in the log file/device beyond the limits set by the values in the superblock is typically ignored as garbage by tools handling dm-log-writes logs. (I wonder if dm-log-writes actually works similarly by exploiting this fact?)
This does work in the current patch because the log is updated before the write has completed.
Stefan
Quoted 73 lines · Stefan Hajnoczi
Quoted 57 lines · Ari Sundholm
Quoted 56 lines · Stefan Hajnoczi
Quoted 22 lines · Ari Sundholm
Quoted 11 lines · Stefan Hajnoczi
Quoted 1 line · Ari Sundholm
From: Aapo Vienamo <[email protected]>
Thanks for the patch!
Quoted 6 lines
Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported.
Quoted 9 lines
Quoted 3 lines
This functionality can be used for fail-safe and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels.
This patch doesn't implement the same semantics as dm-log-writes, where only completed writes are logged to make fs consistency testing easier. If you intend to use it for this purpose, shouldn't it act the same way as dm-log-writes?
Quoted 9 lines
I am not quite sure what you mean. I am not the original author of this proposed feature, but to me (admittedly with little experience of qemu internals), it looks like the driver accurately logs the writes and flushes performed on the guest block device. It intentionally does not concern itself with when the write actually hits the physical host block device or file, as we're interested in the direct interactions between a filesystem driver and the guest block device. The write hitting the various levels of the host-side caches and devices is left up to the caching mode. But perhaps there's something obvious I'm not seeing?
Linux dm-log-writes is specific about when logging happens:
* We log writes only after they have been flushed, this makes the log describe
* close to the order in which the data hits the actual disk, not its cache. So
* for example the following sequence (W means write, C means complete) *
* Wa,Wb,Wc,Cc,Ca,FLUSH,FUAd,Cb,CFLUSH,CFUAd
*
* Would result in the log looking like this:
*
* c,a,flush,fuad,b,<other writes>,<next flush>
*
* This is meant to help expose problems where file systems do not properly wait
* on data being written before invoking a FLUSH. FUA bypasses cache so once it
* completes it is added to the log as it should be on disk.This patch implements the same on-disk format but the semantics are different since it doesn't wait for a flush.
If I use dm-log-writes on a linear device-mapper target inside the guest or on the host, then I would have expected the same output as QEMU's dm-log-writes, but I think this is not the case.
Quoted 8 lines
Quoted 1 line
It's worth at least documenting this quirk.
Oh, now I see what you mean.
I was under the impression that when we do the logging at the level it is done now, we see the actual writes to the guest block device to completion, as far as the guest is concerned (being safely in the host's page cache is enough for this). Is this understanding incorrect?
.bdrv_co_pwritev is called on request submission.
blk_log_writes_co_log()spawns a coroutine forblk_log_writes_co_do_log(), which appends a structlog_write_entryto the log file independently of the other coroutine that is doing the actual write to the underlying file.
Quoted 7 lines
This means the entry could be added to the log file before the write request completes.
If you want to log on request completion then you cannot spawn the log coroutine in parallel with the write coroutine. Instead you would have to complete the write and then update the log.
Thank you. I can't believe I missed that...
Will be fixed in next version by making things sequential.
Quoted 11 lines
Quoted 5 lines
Regarding the issue of waiting for flushes, as it is now, the driver only updates the superblock of the log on flush, and everything in the log file/device beyond the limits set by the values in the superblock is typically ignored as garbage by tools handling dm-log-writes logs. (I wonder if dm-log-writes actually works similarly by exploiting this fact?)
This does work in the current patch because the log is updated before the write has completed.
Stefan
Best regards,
Ari Sundholm
[email protected]