diff options
author | Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 2019-10-01 16:14:09 +0300 |
---|---|---|
committer | Max Reitz <mreitz@redhat.com> | 2019-10-10 10:56:18 +0200 |
commit | 00e30f05de1d19586345ec373970ef4c192c6270 (patch) | |
tree | 5ac9d5f5464b9f6c8ff64a47495ce3e03a66afc4 /block/block-copy.c | |
parent | 7df7868b9640402c465eec93c8e0fa9fc2cf5744 (diff) | |
download | qemu-00e30f05de1d19586345ec373970ef4c192c6270.zip qemu-00e30f05de1d19586345ec373970ef4c192c6270.tar.gz qemu-00e30f05de1d19586345ec373970ef4c192c6270.tar.bz2 |
block/backup: use backup-top instead of write notifiers
Drop write notifiers and use filter node instead.
= Changes =
1. Add filter-node-name argument for backup qmp api. We have to do it
in this commit, as 257 needs to be fixed.
2. There are no more write notifiers here, so is_write_notifier
parameter is dropped from block-copy paths.
3. To sync with in-flight requests at job finish we now have drained
removing of the filter, we don't need rw-lock.
4. Block-copy is now using BdrvChildren instead of BlockBackends
5. As backup-top owns these children, we also move block-copy state
into backup-top's ownership.
= Iotest changes =
56: op-blocker doesn't shoot now, as we set it on source, but then
check on filter, when trying to start second backup.
To keep the test we instead can catch another collision: both jobs will
get 'drive0' job-id, as job-id parameter is unspecified. To prevent
interleaving with file-posix locks (as they are dependent on config)
let's use another target for second backup.
Also, it's obvious now that we'd like to drop this op-blocker at all
and add a test-case for two backups from one node (to different
destinations) actually works. But not in these series.
141: Output changed: prepatch, "Node is in use" comes from bdrv_has_blk
check inside qmp_blockdev_del. But we've dropped block-copy blk
objects, so no more blk objects on source bs (job blk is on backup-top
filter bs). New message is from op-blocker, which is the next check in
qmp_blockdev_add.
257: The test wants to emulate guest write during backup. They should
go to filter node, not to original source node, of course. Therefore we
need to specify filter node name and use it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191001131409.14202-6-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block/block-copy.c')
-rw-r--r-- | block/block-copy.c | 81 |
1 files changed, 22 insertions, 59 deletions
diff --git a/block/block-copy.c b/block/block-copy.c index fcb112d..0f76ea1 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -60,24 +60,22 @@ void block_copy_state_free(BlockCopyState *s) return; } - bdrv_release_dirty_bitmap(blk_bs(s->source), s->copy_bitmap); - blk_unref(s->source); - blk_unref(s->target); + bdrv_release_dirty_bitmap(s->source->bs, s->copy_bitmap); g_free(s); } -BlockCopyState *block_copy_state_new(BlockDriverState *source, - BlockDriverState *target, +BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, int64_t cluster_size, BdrvRequestFlags write_flags, Error **errp) { BlockCopyState *s; - int ret; - uint64_t no_resize = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | - BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD; BdrvDirtyBitmap *copy_bitmap; + uint32_t max_transfer = + MIN_NON_ZERO(INT_MAX, MIN_NON_ZERO(source->bs->bl.max_transfer, + target->bs->bl.max_transfer)); - copy_bitmap = bdrv_create_dirty_bitmap(source, cluster_size, NULL, errp); + copy_bitmap = bdrv_create_dirty_bitmap(source->bs, cluster_size, NULL, + errp); if (!copy_bitmap) { return NULL; } @@ -85,19 +83,15 @@ BlockCopyState *block_copy_state_new(BlockDriverState *source, s = g_new(BlockCopyState, 1); *s = (BlockCopyState) { - .source = blk_new(bdrv_get_aio_context(source), - BLK_PERM_CONSISTENT_READ, no_resize), - .target = blk_new(bdrv_get_aio_context(target), - BLK_PERM_WRITE, no_resize), + .source = source, + .target = target, .copy_bitmap = copy_bitmap, .cluster_size = cluster_size, .len = bdrv_dirty_bitmap_size(copy_bitmap), .write_flags = write_flags, }; - s->copy_range_size = QEMU_ALIGN_DOWN(MIN(blk_get_max_transfer(s->source), - blk_get_max_transfer(s->target)), - s->cluster_size); + s->copy_range_size = QEMU_ALIGN_DOWN(max_transfer, cluster_size), /* * Set use_copy_range, consider the following: * 1. Compression is not supported for copy_range. @@ -111,32 +105,7 @@ BlockCopyState *block_copy_state_new(BlockDriverState *source, QLIST_INIT(&s->inflight_reqs); - /* - * We just allow aio context change on our block backends. block_copy() user - * (now it's only backup) is responsible for source and target being in same - * aio context. - */ - blk_set_disable_request_queuing(s->source, true); - blk_set_allow_aio_context_change(s->source, true); - blk_set_disable_request_queuing(s->target, true); - blk_set_allow_aio_context_change(s->target, true); - - ret = blk_insert_bs(s->source, source, errp); - if (ret < 0) { - goto fail; - } - - ret = blk_insert_bs(s->target, target, errp); - if (ret < 0) { - goto fail; - } - return s; - -fail: - block_copy_state_free(s); - - return NULL; } void block_copy_set_callbacks( @@ -157,22 +126,20 @@ void block_copy_set_callbacks( static int coroutine_fn block_copy_with_bounce_buffer(BlockCopyState *s, int64_t start, int64_t end, - bool is_write_notifier, bool *error_is_read, void **bounce_buffer) { int ret; int nbytes; - int read_flags = is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; assert(QEMU_IS_ALIGNED(start, s->cluster_size)); bdrv_reset_dirty_bitmap(s->copy_bitmap, start, s->cluster_size); nbytes = MIN(s->cluster_size, s->len - start); if (!*bounce_buffer) { - *bounce_buffer = blk_blockalign(s->source, s->cluster_size); + *bounce_buffer = qemu_blockalign(s->source->bs, s->cluster_size); } - ret = blk_co_pread(s->source, start, nbytes, *bounce_buffer, read_flags); + ret = bdrv_co_pread(s->source, start, nbytes, *bounce_buffer, 0); if (ret < 0) { trace_block_copy_with_bounce_buffer_read_fail(s, start, ret); if (error_is_read) { @@ -181,8 +148,8 @@ static int coroutine_fn block_copy_with_bounce_buffer(BlockCopyState *s, goto fail; } - ret = blk_co_pwrite(s->target, start, nbytes, *bounce_buffer, - s->write_flags); + ret = bdrv_co_pwrite(s->target, start, nbytes, *bounce_buffer, + s->write_flags); if (ret < 0) { trace_block_copy_with_bounce_buffer_write_fail(s, start, ret); if (error_is_read) { @@ -204,13 +171,11 @@ fail: */ static int coroutine_fn block_copy_with_offload(BlockCopyState *s, int64_t start, - int64_t end, - bool is_write_notifier) + int64_t end) { int ret; int nr_clusters; int nbytes; - int read_flags = is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0; assert(QEMU_IS_ALIGNED(s->copy_range_size, s->cluster_size)); assert(QEMU_IS_ALIGNED(start, s->cluster_size)); @@ -218,8 +183,8 @@ static int coroutine_fn block_copy_with_offload(BlockCopyState *s, nr_clusters = DIV_ROUND_UP(nbytes, s->cluster_size); bdrv_reset_dirty_bitmap(s->copy_bitmap, start, s->cluster_size * nr_clusters); - ret = blk_co_copy_range(s->source, start, s->target, start, nbytes, - read_flags, s->write_flags); + ret = bdrv_co_copy_range(s->source, start, s->target, start, nbytes, + 0, s->write_flags); if (ret < 0) { trace_block_copy_with_offload_fail(s, start, ret); bdrv_set_dirty_bitmap(s->copy_bitmap, start, @@ -237,7 +202,7 @@ static int coroutine_fn block_copy_with_offload(BlockCopyState *s, static int block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, int64_t *pnum) { - BlockDriverState *bs = blk_bs(s->source); + BlockDriverState *bs = s->source->bs; int64_t count, total_count = 0; int64_t bytes = s->len - offset; int ret; @@ -302,8 +267,7 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, int coroutine_fn block_copy(BlockCopyState *s, int64_t start, uint64_t bytes, - bool *error_is_read, - bool is_write_notifier) + bool *error_is_read) { int ret = 0; int64_t end = bytes + start; /* bytes */ @@ -315,7 +279,8 @@ int coroutine_fn block_copy(BlockCopyState *s, * block_copy() user is responsible for keeping source and target in same * aio context */ - assert(blk_get_aio_context(s->source) == blk_get_aio_context(s->target)); + assert(bdrv_get_aio_context(s->source->bs) == + bdrv_get_aio_context(s->target->bs)); assert(QEMU_IS_ALIGNED(start, s->cluster_size)); assert(QEMU_IS_ALIGNED(end, s->cluster_size)); @@ -352,15 +317,13 @@ int coroutine_fn block_copy(BlockCopyState *s, trace_block_copy_process(s, start); if (s->use_copy_range) { - ret = block_copy_with_offload(s, start, dirty_end, - is_write_notifier); + ret = block_copy_with_offload(s, start, dirty_end); if (ret < 0) { s->use_copy_range = false; } } if (!s->use_copy_range) { ret = block_copy_with_bounce_buffer(s, start, dirty_end, - is_write_notifier, error_is_read, &bounce_buffer); } if (ret < 0) { |