backup-top filter driver for backup
v10 cover backup-top filter driver for backup
Hi all!
These series introduce backup-top driver. It's a filter-node, which do copy-before-write operation. Mirror uses filter-node for handling guest writes, let's move to filter-node (from write-notifiers) for backup too.
v10 (mostly by Max's comments):
01: - s/MIN(end - start, job->len - start)/MIN(end, job->len) - start
- Max's r-b
02: s/offset/start/ and drop extra variable from backup_do_copy
03: new
04: - add job->source_bs
- use two progress callbacks instead of one combined
- add comment to skip_unallocated
- drop zeroing blk's in block_copy_state_free
- s/g_new0/g_new/ before compound literal
- add comment and assertion about aio context for block-copy source and target
- in backup_clean handle possibly executing in parallel backup_drain and check only s->bcs pointer in backup_drain
- fix s/job/bcs in trace-events file
05: partly new, now only fix comments style
06: a lot of changes as rebased on above changes, but it's still a clean
code move, keep Max's r-b
07: add Max's r-b
08: deeper refactoring of tests
09-11: add Max's r-b
[also, fix my email in 11]
12: - drop bdrv_refresh_filename(bs->backing->bs) call
- drop assertion of taken permission
- active = false + refresh_perms in _drop() instead of _set_perm()
13: - add comment about WRITE perm sharing
- add backup_top bs to job state
- fix cleanup on failure path in backup_job_create
- keep "fail:" path in block_copy_with_bounce_buffer
- in 56, collide on job-id instead of posix locks
Vladimir Sementsov-Ogievskiy (14):
block/backup: fix backup_cow_with_offload for last cluster block/backup: split shareable copying part from backup_do_cow block/backup: improve comment about image fleecing block/backup: introduce BlockCopyState
block/backup: fix block-comment style
block: move block_copy from block/backup.c to separate file
block: teach bdrv_debug_breakpoint skip filters with backing
iotests: prepare 124 and 257 bitmap querying for backup-top filter
iotests: 257: drop unused Drive.device field
iotests: 257: drop device_add
block/io: refactor wait_serialising_requests
block: add lock/unlock range functions
block: introduce backup-top filter driver
block/backup: use backup-top instead of write notifiers
qapi/block-core.json | 8 +- block/backup-top.h | 37 ++ include/block/block-copy.h | 75 ++++ include/block/block_int.h | 5 + block.c | 34 +- block/backup-top.c | 240 ++++++++++++ block/backup.c | 454 +++++---------------- block/block-copy.c | 337 ++++++++++++++++ block/io.c | 68 +++- block/replication.c | 2 +- blockdev.c | 1 + block/Makefile.objs | 3 + block/trace-events | 14 +- tests/qemu-iotests/056 | 8 +- tests/qemu-iotests/124 | 83 ++-- tests/qemu-iotests/257 | 91 ++--- tests/qemu-iotests/257.out | 714 ++++++++++++++-------------------- tests/qemu-iotests/iotests.py | 27 ++ 18 files changed, 1281 insertions(+), 920 deletions(-) create mode 100644 block/backup-top.h create mode 100644 include/block/block-copy.h create mode 100644 block/backup-top.c create mode 100644 block/block-copy.c
Signature · 1 line
2.18.0
PATCH v10 1/14 block/backup: fix backup_cow_with_offload for last cluster
We shouldn't try to copy bytes beyond EOF. Fix it.
--- block/backup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/backup.c +1 -1
@@ -161,7 +161,7 @@ static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job,assert (QEMU_IS_ALIGNED (job->copy_range_size, job->cluster_size));assert (QEMU_IS_ALIGNED (start, job->cluster_size)); - nbytes =MIN (job->copy_range_size, end - start); + nbytes =MIN (job->copy_range_size,MIN (end, job->len) - start); nr_clusters =DIV_ROUND_UP (nbytes, job->cluster_size);bdrv_reset_dirty_bitmap (job->copy_bitmap, start, job->cluster_size * nr_clusters);
Signature · 1 line
2.18.0
PATCH v10 2/14 block/backup: split shareable copying part from backup_do_cow
In reply to Vladimir Sementsov-OgievskiySplit copying logic which will be shared with backup-top filter.
--- block/backup.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-)
block/backup.c +32 -15
@@ -248,26 +248,18 @@ static int64_t backup_bitmap_reset_unallocated(BackupBlockJob *s,return ret; } -static int coroutine_fn backup_do_cow(BackupBlockJob *job, -int64_t offset,uint64_t bytes, -bool *error_is_read, -bool is_write_notifier) +static int coroutine_fn backup_do_copy(BackupBlockJob *job, +int64_t start,uint64_t bytes, +bool *error_is_read, +bool is_write_notifier) { -CowRequest cow_request;int ret =0 ; -int64_t start, end;/* bytes */ +int64_t end = bytes + start;/* bytes */ void *bounce_buffer =NULL ;int64_t status_bytes; -qemu_co_rwlock_rdlock (&job->flush_rwlock); - - start =QEMU_ALIGN_DOWN (offset, job->cluster_size); - end =QEMU_ALIGN_UP (bytes + offset, job->cluster_size); - -trace_backup_do_cow_enter (job, start, offset, bytes); - -wait_for_overlapping_requests (job, start, end); -cow_request_begin (&cow_request, job, start, end); +assert (QEMU_IS_ALIGNED (start, job->cluster_size)); +assert (QEMU_IS_ALIGNED (end, job->cluster_size));while (start < end) {int64_t dirty_end;
@@ -326,6 +318,31 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job,qemu_vfree (bounce_buffer); } +return ret; +} + +static int coroutine_fn backup_do_cow(BackupBlockJob *job, +int64_t offset,uint64_t bytes, +bool *error_is_read, +bool is_write_notifier) +{ +CowRequest cow_request; +int ret =0 ; +int64_t start, end;/* bytes */ + +qemu_co_rwlock_rdlock (&job->flush_rwlock); + + start =QEMU_ALIGN_DOWN (offset, job->cluster_size); + end =QEMU_ALIGN_UP (bytes + offset, job->cluster_size); + +trace_backup_do_cow_enter (job, start, offset, bytes); + +wait_for_overlapping_requests (job, start, end); +cow_request_begin (&cow_request, job, start, end); + + ret =backup_do_copy (job, start, end - start, error_is_read, + is_write_notifier); +cow_request_end (&cow_request);trace_backup_do_cow_return (job, offset, bytes, ret);
Signature · 1 line
2.18.0
Re: [Qemu-devel] [PATCH v10 02/14] block/backup: split shareable copying part from backup_do_cow
Quoted 6 lines · Vladimir Sementsov-Ogievskiy
Split copying logic which will be shared with backup-top filter.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-)
PATCH v10 3/14 block/backup: improve comment about image fleecing
In reply to Vladimir Sementsov-Ogievskiy--- block/backup.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
block/backup.c +12 -3
@@ -764,9 +764,18 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, job->bitmap_mode = bitmap_mode;/* -* Set write flags: -* 1. Detect image-fleecing (and similar) schemes -* 2. Handle compression +* If source is in backing chain of target assume that target is going to be +* used for "image fleecing", i.e. it should represent a kind of snapshot of +* source at backup-start point in time. And target is going to be read by +* somebody (for example, used as NBD export) during backup job. +* +* In this case, we need to add BDRV_REQ_SERIALISING write flag to avoid +* intersection of backup writes and third party reads from target, +* otherwise reading from target we may occasionally read already updated by +* guest data. +* +* For more information see commit f8d59dfb40bb and test +* tests/qemu-iotests/222 */ job->write_flags = (bdrv_chain_contains(target, bs) ? BDRV_REQ_SERIALISING : 0) |
Signature · 1 line
2.18.0
Re: [Qemu-devel] [PATCH v10 03/14] block/backup: improve comment about image fleecing
Quoted 4 lines · Vladimir Sementsov-Ogievskiy
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
PATCH v10 4/14 block/backup: introduce BlockCopyState
In reply to Vladimir Sementsov-OgievskiySplit copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining job->common.blk users only use it to get bs by blk_bs() call, so clear job->commen.blk permissions set in block_job_create and add job->source_bs to be used instead of blk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.
2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)
block/backup.c +225 -132
@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { +BlockBackend *source; +BlockBackend *target; +BdrvDirtyBitmap *copy_bitmap; +int64_t cluster_size; +bool use_copy_range; +int64_t copy_range_size; +uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ +bool skip_unallocated; + +/* progress_bytes_callback called when some copying progress is done. */ +ProgressBytesCallbackFunc progress_bytes_callback; + +/* +* progress_reset_callback called when some bytes reset from copy_bitmap +* (see @skip_unallocated above) +*/ +ProgressResetCallbackFunc progress_reset_callback; +void *progress_opaque; +}BlockCopyState ; + typedef struct BackupBlockJob { BlockJob common; - BlockBackend *target; + BlockDriverState *source_bs; BdrvDirtyBitmap *sync_bitmap; - BdrvDirtyBitmap *copy_bitmap; MirrorSyncMode sync_mode; BitmapSyncMode bitmap_mode;
@@ -53,11 +84,7 @@ typedef struct BackupBlockJob {NotifierWithReturn before_write; QLIST_HEAD(, CowRequest) inflight_reqs; -bool use_copy_range; -int64_t copy_range_size; - -BdrvRequestFlags write_flags; -bool initializing_bitmap; +BlockCopyState *bcs; } BackupBlockJob;static const BlockJobDriver backup_job_driver;
@@ -99,9 +126,88 @@ static void cow_request_end(CowRequest *req)qemu_co_queue_restart_all (&req->wait_queue); } +static void block_copy_state_free (BlockCopyState *s) +{ +if (!s) { +return ; + } + +bdrv_release_dirty_bitmap (blk_bs (s->source), s->copy_bitmap); +blk_unref (s->source); +blk_unref (s->target); +g_free (s); +} + +static BlockCopyState *block_copy_state_new ( +BlockDriverState *source,BlockDriverState *target, +int64_t cluster_size,BdrvRequestFlags write_flags, +ProgressBytesCallbackFunc progress_bytes_callback, +ProgressResetCallbackFunc progress_reset_callback, +void *progress_opaque,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; + + copy_bitmap =bdrv_create_dirty_bitmap (source, cluster_size,NULL , errp); +if (!copy_bitmap) { +return NULL ; + } +bdrv_disable_dirty_bitmap (copy_bitmap); + + 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), + .copy_bitmap = copy_bitmap, + .cluster_size = cluster_size, + .len =bdrv_dirty_bitmap_size (copy_bitmap), + .write_flags = write_flags, + .use_copy_range = !(write_flags &BDRV_REQ_WRITE_COMPRESSED ), + .progress_bytes_callback = progress_bytes_callback, + .progress_reset_callback = progress_reset_callback, + .progress_opaque = progress_opaque, + }; + + s->copy_range_size =QEMU_ALIGN_UP (MIN (blk_get_max_transfer (s->source), +blk_get_max_transfer (s->target)), + s->cluster_size); + +/* +* 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 ; +} +/* Copy range to target with a bounce buffer and return the bytes copied. If * error occurred, return a negative error number */ -static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job, +static int coroutine_fn block_copy_with_bounce_buffer(BlockCopyState *s, int64_t start, int64_t end, bool is_write_notifier,
@@ -109,30 +215,29 @@ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job, void **bounce_buffer) {int ret; -BlockBackend *blk = job->common.blk;int nbytes;int read_flags = is_write_notifier ?BDRV_REQ_NO_SERIALISING :0 ; -assert (QEMU_IS_ALIGNED (start, job->cluster_size)); -bdrv_reset_dirty_bitmap (job->copy_bitmap, start, job->cluster_size); - nbytes =MIN (job->cluster_size, job->len - start); +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 (blk, job->cluster_size); + *bounce_buffer =blk_blockalign (s->source, s->cluster_size); } - ret =blk_co_pread (blk, start, nbytes, *bounce_buffer, read_flags); + ret =blk_co_pread (s->source, start, nbytes, *bounce_buffer, read_flags);if (ret <0 ) { -trace_backup_do_cow_read_fail (job, start, ret); +trace_block_copy_with_bounce_buffer_read_fail (s, start, ret);if (error_is_read) { *error_is_read = true; } goto fail; } - ret =blk_co_pwrite (job->target, start, nbytes, *bounce_buffer, - job->write_flags); + ret =blk_co_pwrite (s->target, start, nbytes, *bounce_buffer, + s->write_flags);if (ret <0 ) { -trace_backup_do_cow_write_fail (job, start, ret); +trace_block_copy_with_bounce_buffer_write_fail (s, start, ret);if (error_is_read) { *error_is_read = false; }
@@ -141,36 +246,35 @@ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job,return nbytes; fail: -bdrv_set_dirty_bitmap (job->copy_bitmap, start, job->cluster_size); +bdrv_set_dirty_bitmap (s->copy_bitmap, start, s->cluster_size);return ret; }/* Copy range to target and return the bytes copied. If error occurred, return a * negative error number. */ -static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job, +static int coroutine_fn block_copy_with_offload(BlockCopyState *s,int64_t start,int64_t end,bool is_write_notifier) {int ret;int nr_clusters; -BlockBackend *blk = job->common.blk;int nbytes;int read_flags = is_write_notifier ?BDRV_REQ_NO_SERIALISING :0 ; -assert (QEMU_IS_ALIGNED (job->copy_range_size, job->cluster_size)); -assert (QEMU_IS_ALIGNED (start, job->cluster_size)); - nbytes =MIN (job->copy_range_size,MIN (end, job->len) - start); - nr_clusters =DIV_ROUND_UP (nbytes, job->cluster_size); -bdrv_reset_dirty_bitmap (job->copy_bitmap, start, - job->cluster_size * nr_clusters); - ret =blk_co_copy_range (blk, start, job->target, start, nbytes, - read_flags, job->write_flags); +assert (QEMU_IS_ALIGNED (s->copy_range_size, s->cluster_size)); +assert (QEMU_IS_ALIGNED (start, s->cluster_size)); + nbytes =MIN (s->copy_range_size,MIN (end, s->len) - start); + 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);if (ret <0 ) { -trace_backup_do_cow_copy_range_fail (job, start, ret); -bdrv_set_dirty_bitmap (job->copy_bitmap, start, - job->cluster_size * nr_clusters); +trace_block_copy_with_offload_fail (s, start, ret); +bdrv_set_dirty_bitmap (s->copy_bitmap, start, + s->cluster_size * nr_clusters);return ret; }
@@ -181,10 +285,10 @@ static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job,* Check if the cluster starting at offset is allocated or not. * return via pnum the number of contiguous clusters sharing this allocation. */ -static int backup_is_cluster_allocated (BackupBlockJob *s,int64_t offset, -int64_t *pnum) +static int block_copy_is_cluster_allocated (BlockCopyState *s,int64_t offset, +int64_t *pnum) { -BlockDriverState *bs =blk_bs (s->common.blk); +BlockDriverState *bs =blk_bs (s->source);int64_t count, total_count =0 ;int64_t bytes = s->len - offset;int ret;
@@ -225,13 +329,13 @@ static int backup_is_cluster_allocated(BackupBlockJob *s, int64_t offset,* @return 0 when the cluster at @offset was unallocated, * 1 otherwise, and -ret on error. */ -static int64_t backup_bitmap_reset_unallocated (BackupBlockJob *s, -int64_t offset,int64_t *count) +static int64_t block_copy_reset_unallocated (BlockCopyState *s, +int64_t offset,int64_t *count) {int ret; -int64_t clusters, bytes, estimate; +int64_t clusters, bytes; - ret =backup_is_cluster_allocated (s, offset, &clusters); + ret =block_copy_is_cluster_allocated (s, offset, &clusters);if (ret <0 ) {return ret; }
@@ -240,46 +344,51 @@ static int64_t backup_bitmap_reset_unallocated(BackupBlockJob *s,if (!ret) {bdrv_reset_dirty_bitmap (s->copy_bitmap, offset, bytes); - estimate =bdrv_get_dirty_count (s->copy_bitmap); -job_progress_set_remaining (&s->common.job, estimate); + s->progress_reset_callback (s->progress_opaque); } *count = bytes;return ret; } -static int coroutine_fn backup_do_copy(BackupBlockJob *job, -int64_t start,uint64_t bytes, -bool *error_is_read, -bool is_write_notifier) +static int coroutine_fn block_copy(BlockCopyState *s, +int64_t start,uint64_t bytes, +bool *error_is_read, +bool is_write_notifier) {int ret =0 ;int64_t end = bytes + start;/* bytes */ void *bounce_buffer =NULL ;int64_t status_bytes; -assert (QEMU_IS_ALIGNED (start, job->cluster_size)); -assert (QEMU_IS_ALIGNED (end, job->cluster_size)); +/* +* 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 (QEMU_IS_ALIGNED (start, s->cluster_size)); +assert (QEMU_IS_ALIGNED (end, s->cluster_size));while (start < end) {int64_t dirty_end; -if (!bdrv_dirty_bitmap_get (job->copy_bitmap, start)) { -trace_backup_do_cow_skip (job, start); - start += job->cluster_size; +if (!bdrv_dirty_bitmap_get (s->copy_bitmap, start)) { +trace_block_copy_skip (s, start); + start += s->cluster_size;continue ;/* already copied */ } - dirty_end =bdrv_dirty_bitmap_next_zero (job->copy_bitmap, start, + dirty_end =bdrv_dirty_bitmap_next_zero (s->copy_bitmap, start, (end - start));if (dirty_end <0 ) { dirty_end = end; } -if (job->initializing_bitmap) { - ret =backup_bitmap_reset_unallocated (job, start, &status_bytes); +if (s->skip_unallocated) { + ret =block_copy_reset_unallocated (s, start, &status_bytes);if (ret ==0 ) { -trace_backup_do_cow_skip_range (job, start, status_bytes); +trace_block_copy_skip_range (s, start, status_bytes); start += status_bytes;continue ; }
@@ -287,17 +396,17 @@ static int coroutine_fn backup_do_copy(BackupBlockJob *job, dirty_end =MIN (dirty_end, start + status_bytes); } -trace_backup_do_cow_process (job, start); +trace_block_copy_process (s, start); -if (job->use_copy_range) { - ret =backup_cow_with_offload (job, start, dirty_end, +if (s->use_copy_range) { + ret =block_copy_with_offload (s, start, dirty_end, is_write_notifier);if (ret <0 ) { - job->use_copy_range = false; + s->use_copy_range = false; } } -if (!job->use_copy_range) { - ret =backup_cow_with_bounce_buffer (job, start, dirty_end, +if (!s->use_copy_range) { + ret =block_copy_with_bounce_buffer (s, start, dirty_end, is_write_notifier, error_is_read, &bounce_buffer); }
@@ -305,12 +414,8 @@ static int coroutine_fn backup_do_copy(BackupBlockJob *job,break ; } -/* Publish progress, guest I/O counts as progress too. Note that the -* offset field is an opaque progress value, it is not a disk offset. -*/ start += ret; - job->bytes_read += ret; -job_progress_update (&job->common.job, ret); + s->progress_bytes_callback (ret, s->progress_opaque); ret =0 ; }
@@ -321,6 +426,22 @@ static int coroutine_fn backup_do_copy(BackupBlockJob *job,return ret; } +static void backup_progress_bytes_callback (int64_t bytes,void *opaque) +{ +BackupBlockJob *s = opaque; + + s->bytes_read += bytes; +job_progress_update (&s->common.job, bytes); +} + +static void backup_progress_reset_callback (void *opaque) +{ +BackupBlockJob *s = opaque; +uint64_t estimate =bdrv_get_dirty_count (s->bcs->copy_bitmap); + +job_progress_set_remaining (&s->common.job, estimate); +} + static int coroutine_fn backup_do_cow(BackupBlockJob *job, int64_t offset, uint64_t bytes, bool *error_is_read,
@@ -340,8 +461,8 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job,wait_for_overlapping_requests (job, start, end);cow_request_begin (&cow_request, job, start, end); - ret =backup_do_copy (job, start, end - start, error_is_read, - is_write_notifier); + ret =block_copy (job->bcs, start, end - start, error_is_read, + is_write_notifier);cow_request_end (&cow_request);
@@ -359,7 +480,7 @@ static int coroutine_fn backup_before_write_notify(BackupBlockJob *job =container_of (notifier, BackupBlockJob, before_write);BdrvTrackedRequest *req = opaque; -assert (req->bs ==blk_bs (job->common.blk)); +assert (req->bs == job->source_bs);assert (QEMU_IS_ALIGNED (req->offset,BDRV_SECTOR_SIZE ));assert (QEMU_IS_ALIGNED (req->bytes,BDRV_SECTOR_SIZE ));
@@ -369,7 +490,6 @@ static int coroutine_fn backup_before_write_notify(static void backup_cleanup_sync_bitmap (BackupBlockJob *job,int ret) {BdrvDirtyBitmap *bm; -BlockDriverState *bs =blk_bs (job->common.blk);bool sync = (((ret ==0 ) || (job->bitmap_mode ==BITMAP_SYNC_MODE_ALWAYS )) \ && (job->bitmap_mode !=BITMAP_SYNC_MODE_NEVER ));
@@ -378,20 +498,20 @@ static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)* We succeeded, or we always intended to sync the bitmap. * Delete this bitmap and install the child. */ - bm =bdrv_dirty_bitmap_abdicate (bs, job->sync_bitmap,NULL ); + bm =bdrv_dirty_bitmap_abdicate (job->source_bs, job->sync_bitmap,NULL ); }else {/* * We failed, or we never intended to sync the bitmap anyway. * Merge the successor back into the parent, keeping all data. */ - bm =bdrv_reclaim_dirty_bitmap (bs, job->sync_bitmap,NULL ); + bm =bdrv_reclaim_dirty_bitmap (job->source_bs, job->sync_bitmap,NULL ); }assert (bm);if (ret <0 && job->bitmap_mode ==BITMAP_SYNC_MODE_ALWAYS ) {/* If we failed and synced, merge in the bits we didn't copy: */ -bdrv_dirty_bitmap_merge_internal (bm, job->copy_bitmap, +bdrv_dirty_bitmap_merge_internal (bm, job->bcs->copy_bitmap,NULL , true); } }
@@ -415,16 +535,16 @@ static void backup_abort(Job *job)static void backup_clean (Job *job) {BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); -BlockDriverState *bs =blk_bs (s->common.blk); +BlockCopyState *bcs = s->bcs; -if (s->copy_bitmap) { -bdrv_release_dirty_bitmap (bs, s->copy_bitmap); - s->copy_bitmap =NULL ; - } +/* +* Zero pointer first, to not interleave with backup_drain during some +* yield. TODO: just block_copy_state_free(s->bcs) after backup_drain +* dropped. +*/ + s->bcs =NULL ; -assert (s->target); -blk_unref (s->target); - s->target =NULL ; +block_copy_state_free (bcs); }void backup_do_checkpoint (BlockJob *job,Error **errp)
@@ -439,7 +559,7 @@ void backup_do_checkpoint(BlockJob *job, Error **errp)return ; } -bdrv_set_dirty_bitmap (backup_job->copy_bitmap,0 , backup_job->len); +bdrv_set_dirty_bitmap (backup_job->bcs->copy_bitmap,0 , backup_job->len); }static void backup_drain (BlockJob *job)
@@ -449,8 +569,8 @@ static void backup_drain(BlockJob *job)/* Need to keep a reference in case blk_drain triggers execution * of backup_complete... */ -if (s->target) { -BlockBackend *target = s->target; +if (s->bcs) { +BlockBackend *target = s->bcs->target;blk_ref (target);blk_drain (target);blk_unref (target);
@@ -497,7 +617,7 @@ static int coroutine_fn backup_loop(BackupBlockJob *job)BdrvDirtyBitmapIter *bdbi;int ret =0 ; - bdbi =bdrv_dirty_iter_new (job->copy_bitmap); + bdbi =bdrv_dirty_iter_new (job->bcs->copy_bitmap);while ((offset =bdrv_dirty_iter_next (bdbi)) !=-1 ) { do { if (yield_and_check(job)) {
@@ -524,7 +644,7 @@ static void backup_init_copy_bitmap(BackupBlockJob *job)uint64_t estimate;if (job->sync_mode ==MIRROR_SYNC_MODE_BITMAP ) { - ret =bdrv_dirty_bitmap_merge_internal (job->copy_bitmap, + ret =bdrv_dirty_bitmap_merge_internal (job->bcs->copy_bitmap, job->sync_bitmap,NULL , true);assert (ret);
@@ -534,19 +654,18 @@ static void backup_init_copy_bitmap(BackupBlockJob *job)* We can't hog the coroutine to initialize this thoroughly. * Set a flag and resume work when we are able to yield safely. */ - job->initializing_bitmap = true; + job->bcs->skip_unallocated = true; } -bdrv_set_dirty_bitmap (job->copy_bitmap,0 , job->len); +bdrv_set_dirty_bitmap (job->bcs->copy_bitmap,0 , job->len); } - estimate =bdrv_get_dirty_count (job->copy_bitmap); + estimate =bdrv_get_dirty_count (job->bcs->copy_bitmap);job_progress_set_remaining (&job->common.job, estimate); } static int coroutine_fn backup_run(Job *job, Error **errp) {BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); -BlockDriverState *bs =blk_bs (s->common.blk);int ret =0 ;QLIST_INIT (&s->inflight_reqs);
@@ -555,7 +674,7 @@ static int coroutine_fn backup_run(Job *job, Error **errp)backup_init_copy_bitmap (s); s->before_write.notify = backup_before_write_notify; -bdrv_add_before_write_notifier (bs, &s->before_write); +bdrv_add_before_write_notifier (s->source_bs, &s->before_write);if (s->sync_mode ==MIRROR_SYNC_MODE_TOP ) {int64_t offset =0 ;
@@ -567,14 +686,14 @@ static int coroutine_fn backup_run(Job *job, Error **errp) goto out; } - ret =backup_bitmap_reset_unallocated (s, offset, &count); + ret =block_copy_reset_unallocated (s->bcs, offset, &count);if (ret <0 ) { goto out; } offset += count; } - s->initializing_bitmap = false; + s->bcs->skip_unallocated = false; }if (s->sync_mode ==MIRROR_SYNC_MODE_NONE ) {
@@ -663,9 +782,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, {int64_t len;BackupBlockJob *job =NULL ; -int ret;int64_t cluster_size; -BdrvDirtyBitmap *copy_bitmap =NULL ; +BdrvRequestFlags write_flags;assert (bs);assert (target);
@@ -730,33 +848,14 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, goto error; } - copy_bitmap =bdrv_create_dirty_bitmap (bs, cluster_size,NULL , errp); -if (!copy_bitmap) { - goto error; - } -bdrv_disable_dirty_bitmap (copy_bitmap); -/* job->len is fixed, so we can't allow resize */ - job =block_job_create (job_id, &backup_job_driver, txn, bs, -BLK_PERM_CONSISTENT_READ , -BLK_PERM_CONSISTENT_READ |BLK_PERM_WRITE | -BLK_PERM_WRITE_UNCHANGED |BLK_PERM_GRAPH_MOD , + job =block_job_create (job_id, &backup_job_driver, txn, bs,0 ,BLK_PERM_ALL , speed, creation_flags, cb, opaque, errp);if (!job) { goto error; } -/* The target must match the source in size, so no resize here either */ - job->target =blk_new (job->common.job.aio_context, -BLK_PERM_WRITE , -BLK_PERM_CONSISTENT_READ |BLK_PERM_WRITE | -BLK_PERM_WRITE_UNCHANGED |BLK_PERM_GRAPH_MOD ); - ret =blk_insert_bs (job->target, target, errp); -if (ret <0 ) { - goto error; - } -blk_set_disable_request_queuing (job->target, true); - + job->source_bs = bs; job->on_source_error = on_source_error; job->on_target_error = on_target_error; job->sync_mode = sync_mode;
@@ -777,21 +876,19 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,* For more information see commit f8d59dfb40bb and test * tests/qemu-iotests/222 */ - job->write_flags = - (bdrv_chain_contains (target, bs) ?BDRV_REQ_SERIALISING :0 ) | - (compress ?BDRV_REQ_WRITE_COMPRESSED :0 ); + write_flags = (bdrv_chain_contains (target, bs) ?BDRV_REQ_SERIALISING :0 ) | + (compress ?BDRV_REQ_WRITE_COMPRESSED :0 ), + + job->bcs =block_copy_state_new (bs, target, cluster_size, write_flags, + backup_progress_bytes_callback, + backup_progress_reset_callback, job, errp); +if (!job->bcs) { + goto error; + } job->cluster_size = cluster_size; - job->copy_bitmap = copy_bitmap; - copy_bitmap =NULL ; - job->use_copy_range = !compress;/* compression isn't supported for it */ - job->copy_range_size =MIN_NON_ZERO (blk_get_max_transfer (job->common.blk), -blk_get_max_transfer (job->target)); - job->copy_range_size =MAX (job->cluster_size, -QEMU_ALIGN_UP (job->copy_range_size, - job->cluster_size)); - -/* Required permissions are already taken with target's blk_new() */ + +/* Required permissions are already taken by block-copy-state target */ block_job_add_bdrv (&job->common,"target" , target,0 ,BLK_PERM_ALL , &error_abort); job->len = len;
@@ -799,10 +896,6 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,return &job->common; error: -if (copy_bitmap) { -assert (!job || !job->copy_bitmap); -bdrv_release_dirty_bitmap (bs, copy_bitmap); - }if (sync_bitmap) {bdrv_reclaim_dirty_bitmap (bs, sync_bitmap,NULL ); }
block/trace-events +6 -6
@@ -40,12 +40,12 @@ mirror_yield_in_flight(void *s, int64_t offset, int in_flight) "s %p offset %" P # backup.c backup_do_cow_enter(void *job, int64_t start, int64_t offset, uint64_t bytes) "job %p start %" PRId64 " offset %" PRId64 " bytes %" PRIu64 backup_do_cow_return(void *job, int64_t offset, uint64_t bytes, int ret) "job %p offset %" PRId64 " bytes %" PRIu64 " ret %d" -backup_do_cow_skip(void *job, int64_t start) "job %p start %"PRId64 -backup_do_cow_skip_range(void *job, int64_t start, uint64_t bytes) "job %p start %"PRId64" bytes %"PRId64 -backup_do_cow_process(void *job, int64_t start) "job %p start %"PRId64 -backup_do_cow_read_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" -backup_do_cow_write_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" -backup_do_cow_copy_range_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" +block_copy_skip(void *bcs, int64_t start) "job %p start %"PRId64 +block_copy_skip_range(void *bcs, int64_t start, uint64_t bytes) "job %p start %"PRId64" bytes %"PRId64 +block_copy_process(void *bcs, int64_t start) "job %p start %"PRId64 +block_copy_with_bounce_buffer_read_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d" +block_copy_with_bounce_buffer_write_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d" +block_copy_with_offload_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d" # ../blockdev.c qmp_block_job_cancel(void *job) "job %p"
Signature · 1 line
2.18.0
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Split copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining
job->common.blkusers only use it to get bs byblk_bs()call, so clearjob->commen.blkpermissions set inblock_job_createand addjob->source_bsto be used instead ofblk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)block/backup.c +9
-0@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { + BlockBackend *source; + BlockBackend *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_range_size;
block/backup.c typedef struct CowRequest { · line 56
Quoted 10 lines
block/backup.c +10
-0+uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/
It isn’t quite clear that this refers to the copy_bitmap. Maybe something like
“If true, the copy operation prepares a sync=top job: It scans the source's top layer to find all unallocated areas and resets them in the copy_bitmap (so they will not be copied). Whenever any such area is cleared, progress_reset_callback will be invoked.
Once the whole top layer has been scanned, skip_unallocated is cleared and the actual copying begins.”
instead?
block/backup.c typedef struct CowRequest { · line 59
Quoted 3 lines
block/backup.c +3
-0+bool skip_unallocated; + +/* progress_bytes_callback called when some copying progress is done. */
Maybe add a colon after the attribute name? (Or drop the name altogether)
block/backup.c typedef struct CowRequest { · line 64
Quoted 5 lines
block/backup.c +5
-0+ProgressBytesCallbackFunc progress_bytes_callback; + +/* +* progress_reset_callback called when some bytes reset from copy_bitmap +* (see @skip_unallocated above)
Maybe you should keep the note you before on what to do then, i.e. that the callee should probably recalculate how many bytes remain based on the copy_bitmap’s dirty bit count.
Quoted 4 lines
block/backup.c +4
-0+*/ +ProgressResetCallbackFunc progress_reset_callback; +void *progress_opaque; +} BlockCopyState;
[...]
Quoted 6 lines
block/backup.c +1
-1@@ -415,16 +535,16 @@ static void backup_abort(Job *job)static void backup_clean (Job *job) {BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); -BlockDriverState *bs =blk_bs (s->common.blk); +BlockCopyState *bcs = s->bcs;
block/backup.c static void backup_abort(Job *job) · line 544
Quoted 10 lines
block/backup.c +5
-4-if (s->copy_bitmap) { -bdrv_release_dirty_bitmap (bs, s->copy_bitmap); - s->copy_bitmap =NULL ; - } +/* +* Zero pointer first, to not interleave with backup_drain during some +* yield. TODO: just block_copy_state_free(s->bcs) after backup_drain +* dropped. +*/
I suppose that‘s now. :-)
Quoted 7 lines
block/backup.c +2
-3+ s->bcs =NULL ; -assert (s->target); -blk_unref (s->target); - s->target =NULL ; +block_copy_state_free (bcs); }
[...]
block/backup.c static void backup_drain(BlockJob *job) · line 576
Quoted 11 lines
block/backup.c +2
-2@@ -449,8 +569,8 @@ static void backup_drain(BlockJob *job)/* Need to keep a reference in case blk_drain triggers execution * of backup_complete... */ -if (s->target) { -BlockBackend *target = s->target; +if (s->bcs) { +BlockBackend *target = s->bcs->target;blk_ref (target);blk_drain (target);blk_unref (target);
(And this hunk can go away now.)
[...]
Quoted 10 lines
block/trace-events +0
-2@@ -40,12 +40,12 @@ mirror_yield_in_flight(void *s, int64_t offset, int in_flight) "s %p offset %" P # backup.c backup_do_cow_enter(void *job, int64_t start, int64_t offset, uint64_t bytes) "job %p start %" PRId64 " offset %" PRId64 " bytes %" PRIu64 backup_do_cow_return(void *job, int64_t offset, uint64_t bytes, int ret) "job %p offset %" PRId64 " bytes %" PRIu64 " ret %d" -backup_do_cow_skip(void *job, int64_t start) "job %p start %"PRId64 -backup_do_cow_skip_range(void *job, int64_t start, uint64_t bytes) "job %p start %"PRId64" bytes %"PRId64
block/trace-events mirror_yield_in_flight(void *s, int64_t offset, int in_flight) "s %p offset %" P · line 48
Quoted 10 lines
block/trace-events +6
-4-backup_do_cow_process(void *job, int64_t start) "job %p start %"PRId64 -backup_do_cow_read_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" -backup_do_cow_write_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" -backup_do_cow_copy_range_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" +block_copy_skip(void *bcs, int64_t start) "job %p start %"PRId64 +block_copy_skip_range(void *bcs, int64_t start, uint64_t bytes) "job %p start %"PRId64" bytes %"PRId64 +block_copy_process(void *bcs, int64_t start) "job %p start %"PRId64 +block_copy_with_bounce_buffer_read_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d" +block_copy_with_bounce_buffer_write_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d" +block_copy_with_offload_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d"
The messages probably should stop calling it a “job”, too.
Max
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 58 lines · Max Reitz
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Split copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining
job->common.blkusers only use it to get bs byblk_bs()call, so clearjob->commen.blkpermissions set inblock_job_createand addjob->source_bsto be used instead ofblk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)block/backup.c +9
-0@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { + BlockBackend *source; + BlockBackend *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_range_size;block/backup.c typedef struct CowRequest { · line 56
Quoted 10 lines
block/backup.c +10
-0+uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ It isn’t quite clear that this refers to the
copy_bitmap. Maybe something like
Quoted 1 line
“If true, the copy operation prepares a sync=top job: It scans the
hmm, now it's not refactored to scan it before copying loop, so it's not precise wording..
Quoted 1 line
source's top layer to find all unallocated areas and resets them in the
Not all, but mostly inside block-copy requested area (but may be more)
Quoted 4 lines
copy_bitmap(so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked.
Once the whole top layer has been scanned,skip_unallocatedis cleared and the actual copying begins.”
Last sentence sounds like it's a block-copy who will clear skip_unallocated, but it's not so. It's not very good design and may be refactored in future, but for now, I'd better drop last sentence.
Quoted 2 lines
instead?
Or, what about the following mix:
Used for job sync=top mode. If true, block_copy() will reset in copy_bitmap areas unallocated in top image (so they will not be copied). Whenever any such area is cleared, progress_reset_callback will be invoked. User is assumed to call in background block_copy_reset_unallocated() several times to cover the whole copied disk and then clear skip_unallocated, to prevent extra effort.
Quoted 6 lines
block/backup.c typedef struct CowRequest { · line 59
Quoted 4 lines
block/backup.c +3
-0+bool skip_unallocated; + +/* progress_bytes_callback called when some copying progress is done. */ Maybe add a colon after the attribute name? (Or drop the name altogether)
OK
Quoted 10 lines
block/backup.c typedef struct CowRequest { · line 64
Quoted 6 lines
block/backup.c +5
-0+ProgressBytesCallbackFunc progress_bytes_callback; + +/* +* progress_reset_callback called when some bytes reset from copy_bitmap +* (see @skip_unallocated above) Maybe you should keep the note you before on what to do then, i.e. that the callee should probably recalculate how many bytes remain based on the copy_bitmap’s dirty bit count.
OK
Quoted 15 lines
Quoted 5 lines
block/backup.c +4
-0+*/ +ProgressResetCallbackFunc progress_reset_callback; +void *progress_opaque; +} BlockCopyState;[...]
Quoted 7 lines
block/backup.c +1
-1@@ -415,16 +535,16 @@ static void backup_abort(Job *job)static void backup_clean (Job *job) {BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); -BlockDriverState *bs =blk_bs (s->common.blk); +BlockCopyState *bcs = s->bcs;
Quoted 11 lines
block/backup.c static void backup_abort(Job *job) · line 544
Quoted 9 lines
block/backup.c +5
-4-if (s->copy_bitmap) { -bdrv_release_dirty_bitmap (bs, s->copy_bitmap); - s->copy_bitmap =NULL ; - } +/* +* Zero pointer first, to not interleave with backup_drain during some +* yield. TODO: just block_copy_state_free(s->bcs) after backup_drain +* dropped. +*/ I suppose that‘s now. :-)
Hmm, it's in Kevin's branch. Should I rebase on it?
Quoted 41 lines
Quoted 8 lines
block/backup.c +2
-3+ s->bcs =NULL ; -assert (s->target); -blk_unref (s->target); - s->target =NULL ; +block_copy_state_free (bcs); }[...]
block/backup.c static void backup_drain(BlockJob *job) · line 576
Quoted 11 lines
block/backup.c +2
-2@@ -449,8 +569,8 @@ static void backup_drain(BlockJob *job)/* Need to keep a reference in case blk_drain triggers execution * of backup_complete... */ -if (s->target) { -BlockBackend *target = s->target; +if (s->bcs) { +BlockBackend *target = s->bcs->target;blk_ref (target);blk_drain (target);blk_unref (target);(And this hunk can go away now.)
[...]
Quoted 14 lines
block/trace-events +0
-6@@ -40,12 +40,12 @@ mirror_yield_in_flight(void *s, int64_t offset, int in_flight) "s %p offset %" P # backup.c backup_do_cow_enter(void *job, int64_t start, int64_t offset, uint64_t bytes) "job %p start %" PRId64 " offset %" PRId64 " bytes %" PRIu64 backup_do_cow_return(void *job, int64_t offset, uint64_t bytes, int ret) "job %p offset %" PRId64 " bytes %" PRIu64 " ret %d" -backup_do_cow_skip(void *job, int64_t start) "job %p start %"PRId64 -backup_do_cow_skip_range(void *job, int64_t start, uint64_t bytes) "job %p start %"PRId64" bytes %"PRId64 -backup_do_cow_process(void *job, int64_t start) "job %p start %"PRId64 -backup_do_cow_read_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" -backup_do_cow_write_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" -backup_do_cow_copy_range_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d"
Quoted 9 lines
block/trace-events mirror_yield_in_flight(void *s, int64_t offset, int in_flight) "s %p offset %" P · line 48
Quoted 6 lines
block/trace-events +6
-0+block_copy_skip(void *bcs, int64_t start) "job %p start %"PRId64 +block_copy_skip_range(void *bcs, int64_t start, uint64_t bytes) "job %p start %"PRId64" bytes %"PRId64 +block_copy_process(void *bcs, int64_t start) "job %p start %"PRId64 +block_copy_with_bounce_buffer_read_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d" +block_copy_with_bounce_buffer_write_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d" +block_copy_with_offload_fail(void *bcs, int64_t start, int ret) "job %p start %"PRId64" ret %d"The messages probably should stop calling it a “job”, too.
Oops sorry, I'd better do s/job/bcs/g instead of fixing first job argument by hand.
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 59 lines · Vladimir Sementsov-Ogievskiy
Quoted 58 lines · Max Reitz
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Split copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining
job->common.blkusers only use it to get bs byblk_bs()call, so clearjob->commen.blkpermissions set inblock_job_createand addjob->source_bsto be used instead ofblk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)block/backup.c +9
-0@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { + BlockBackend *source; + BlockBackend *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_range_size;block/backup.c typedef struct CowRequest { · line 56
Quoted 10 lines
block/backup.c +10
-0+uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ It isn’t quite clear that this refers to the
copy_bitmap. Maybe something like
Quoted 8 lines
Quoted 1 line
“If true, the copy operation prepares a sync=top job: It scans the
hmm, now it's not refactored to scan it before copying loop, so it's not precise wording..
Quoted 1 line
source's top layer to find all unallocated areas and resets them in the
Not all, but mostly inside block-copy requested area (but may be more)
Sorry, I meant backup operation.
Quoted 8 lines
Quoted 4 lines
copy_bitmap(so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked.
Once the whole top layer has been scanned,skip_unallocatedis cleared and the actual copying begins.”Last sentence sounds like it's a block-copy who will clear
skip_unallocated, but it's not so. It's not very good design and may be refactored in future, but for now, I'd better drop last sentence.
But wasn’t that the point of this variable? That it goes back to false once the bitmap is fully initialized?
Quoted 10 lines
Quoted 2 lines
instead?
Or, what about the following mix:
Used for job sync=top mode. If true,
block_copy()will reset incopy_bitmapareas unallocated in top image (so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked. User is assumed to call in backgroundblock_copy_reset_unallocated()several times to cover the whole copied disk and then clearskip_unallocated, to prevent extra effort.
I don’t know. The point of this variable is the initialization of the bitmap. block-copy only uses this as a hint that it needs to participate in that initialization process, too, and cannot assume the bitmap to be fully allocated.
Furthermore, it sounds a bit strange to imply that there’d be a strict separation between block-copy and its user. They work tightly together on this. I don’t think it would hurt to be more concrete on what the backup job does here instead of just alluding to it as being “the user”.
[...]
Quoted 19 lines
Quoted 7 lines
Quoted 7 lines
block/backup.c +1
-1@@ -415,16 +535,16 @@ static void backup_abort(Job *job)static void backup_clean (Job *job) {BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); -BlockDriverState *bs =blk_bs (s->common.blk); +BlockCopyState *bcs = s->bcs;Quoted 11 lines
block/backup.c static void backup_abort(Job *job) · line 544
Quoted 9 lines
block/backup.c +5
-4-if (s->copy_bitmap) { -bdrv_release_dirty_bitmap (bs, s->copy_bitmap); - s->copy_bitmap =NULL ; - } +/* +* Zero pointer first, to not interleave with backup_drain during some +* yield. TODO: just block_copy_state_free(s->bcs) after backup_drain +* dropped. +*/ I suppose that‘s now. :-)
Quoted 1 line
Hmm, it's in Kevin's branch. Should I rebase on it?
Yep, that’s what I meant.
Max
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 76 lines · Max Reitz
Quoted 59 lines · Vladimir Sementsov-Ogievskiy
Quoted 58 lines · Max Reitz
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Split copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining
job->common.blkusers only use it to get bs byblk_bs()call, so clearjob->commen.blkpermissions set inblock_job_createand addjob->source_bsto be used instead ofblk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)block/backup.c +9
-0@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { + BlockBackend *source; + BlockBackend *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_range_size;block/backup.c typedef struct CowRequest { · line 56
Quoted 10 lines
block/backup.c +10
-0+uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ It isn’t quite clear that this refers to the
copy_bitmap. Maybe something likeQuoted 8 lines
Quoted 1 line
“If true, the copy operation prepares a sync=top job: It scans the
hmm, now it's not refactored to scan it before copying loop, so it's not precise wording..
Quoted 1 line
source's top layer to find all unallocated areas and resets them in the
Not all, but mostly inside block-copy requested area (but may be more)
Sorry, I meant backup operation.
Quoted 5 lines
Quoted 4 lines
copy_bitmap(so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked.
Once the whole top layer has been scanned,skip_unallocatedis cleared and the actual copying begins.”
Quoted 6 lines
Quoted 3 lines
Last sentence sounds like it's a block-copy who will clear
skip_unallocated, but it's not so. It's not very good design and may be refactored in future, but for now, I'd better drop last sentence.But wasn’t that the point of this variable? That it goes back to false once the bitmap is fully initialized?
I just want to stress, that block-copy itself (which will be in a separate file, so it would be clean enough, what is block-copy and what is its user) do not clear this variable. It of course may track calls to block_copy_reset_unallocated() and clear this variable automatically, but it don't do it now. And your wording looks for me like block-copy code may automatically clear this variable
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
instead?
Or, what about the following mix:
Used for job sync=top mode. If true,
block_copy()will reset incopy_bitmapareas unallocated in top image (so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked. User is assumed to call in backgroundblock_copy_reset_unallocated()several times to cover the whole copied disk and then clearskip_unallocated, to prevent extra effort.
Quoted 4 lines
I don’t know. The point of this variable is the initialization of the bitmap. block-copy only uses this as a hint that it needs to participate in that initialization process, too, and cannot assume the bitmap to be fully allocated.
Hmm, but where is a conflict of this and my wording? IMHO, I just documented exactly what's written in the code.
Quoted 5 lines
Furthermore, it sounds a bit strange to imply that there’d be a strict separation between block-copy and its user. They work tightly together on this. I don’t think it would hurt to be more concrete on what the backup job does here instead of just alluding to it as being “the user”.
However, I'd prefer block-copy to be separate enough and have clear interface, still these series don't bring it to this final point.
Quoted 28 lines
[...]
Quoted 19 lines
Quoted 7 lines
Quoted 7 lines
block/backup.c +1
-1@@ -415,16 +535,16 @@ static void backup_abort(Job *job)static void backup_clean (Job *job) {BackupBlockJob *s =container_of (job, BackupBlockJob, common.job); -BlockDriverState *bs =blk_bs (s->common.blk); +BlockCopyState *bcs = s->bcs;Quoted 11 lines
block/backup.c static void backup_abort(Job *job) · line 544
Quoted 9 lines
block/backup.c +5
-4-if (s->copy_bitmap) { -bdrv_release_dirty_bitmap (bs, s->copy_bitmap); - s->copy_bitmap =NULL ; - } +/* +* Zero pointer first, to not interleave with backup_drain during some +* yield. TODO: just block_copy_state_free(s->bcs) after backup_drain +* dropped. +*/ I suppose that‘s now. :-)
Quoted 1 line
Hmm, it's in Kevin's branch. Should I rebase on it?
Yep, that’s what I meant.
Max
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 81 lines · Vladimir Sementsov-Ogievskiy
Quoted 80 lines · Max Reitz
Quoted 59 lines · Vladimir Sementsov-Ogievskiy
Quoted 58 lines · Max Reitz
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Split copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining
job->common.blkusers only use it to get bs byblk_bs()call, so clearjob->commen.blkpermissions set inblock_job_createand addjob->source_bsto be used instead ofblk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)block/backup.c +9
-0@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { + BlockBackend *source; + BlockBackend *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_range_size;block/backup.c typedef struct CowRequest { · line 56
Quoted 10 lines
block/backup.c +10
-0+uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ It isn’t quite clear that this refers to the
copy_bitmap. Maybe something likeQuoted 8 lines
Quoted 1 line
“If true, the copy operation prepares a sync=top job: It scans the
hmm, now it's not refactored to scan it before copying loop, so it's not precise wording..
Quoted 1 line
source's top layer to find all unallocated areas and resets them in the
Not all, but mostly inside block-copy requested area (but may be more)
Sorry, I meant backup operation.
Quoted 8 lines
Quoted 4 lines
copy_bitmap(so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked.
Once the whole top layer has been scanned,skip_unallocatedis cleared and the actual copying begins.”Last sentence sounds like it's a block-copy who will clear
skip_unallocated, but it's not so. It's not very good design and may be refactored in future, but for now, I'd better drop last sentence.
Quoted 8 lines
Quoted 2 lines
But wasn’t that the point of this variable? That it goes back to false once the bitmap is fully initialized?
I just want to stress, that block-copy itself (which will be in a separate file, so it would be clean enough, what is block-copy and what is its user) do not clear this variable. It of course may track calls to
block_copy_reset_unallocated()and clear this variable automatically, but it don't do it now. And your wording looks for me like block-copy code may automatically clear this variable
Hm, OK.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
instead?
Or, what about the following mix:
Used for job sync=top mode. If true,
block_copy()will reset incopy_bitmapareas unallocated in top image (so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked. User is assumed to call in backgroundblock_copy_reset_unallocated()several times to cover the whole copied disk and then clearskip_unallocated, to prevent extra effort.
Quoted 7 lines
Quoted 4 lines
I don’t know. The point of this variable is the initialization of the bitmap. block-copy only uses this as a hint that it needs to participate in that initialization process, too, and cannot assume the bitmap to be fully allocated.
Hmm, but where is a conflict of this and my wording? IMHO, I just documented exactly what's written in the code.
There’s no conflict because it isn’t mentioned; which is the problem I have with it.
What I was really confused about is who consumes the variable. It all becomes much clearer when I take it as a given that all of your description just is an imperative to block-copy. That simply wasn’t clear to me. (Which is why you don’t like my description, precisely because it tells the story from another POV, namely that of backup.)
Furthermore, I just miss the big picture about it. Why does the variable even exist? I don’t quite like leaving puzzling together the bits to the reader, if we can avoid it.
Max
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 116 lines · Max Reitz
Quoted 81 lines · Vladimir Sementsov-Ogievskiy
Quoted 80 lines · Max Reitz
Quoted 59 lines · Vladimir Sementsov-Ogievskiy
Quoted 58 lines · Max Reitz
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Split copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining
job->common.blkusers only use it to get bs byblk_bs()call, so clearjob->commen.blkpermissions set inblock_job_createand addjob->source_bsto be used instead ofblk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)block/backup.c +9
-0@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { + BlockBackend *source; + BlockBackend *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_range_size;block/backup.c typedef struct CowRequest { · line 56
Quoted 10 lines
block/backup.c +10
-0+uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ It isn’t quite clear that this refers to the
copy_bitmap. Maybe something likeQuoted 8 lines
Quoted 1 line
“If true, the copy operation prepares a sync=top job: It scans the
hmm, now it's not refactored to scan it before copying loop, so it's not precise wording..
Quoted 1 line
source's top layer to find all unallocated areas and resets them in the
Not all, but mostly inside block-copy requested area (but may be more)
Sorry, I meant backup operation.
Quoted 8 lines
Quoted 4 lines
copy_bitmap(so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked.
Once the whole top layer has been scanned,skip_unallocatedis cleared and the actual copying begins.”Last sentence sounds like it's a block-copy who will clear
skip_unallocated, but it's not so. It's not very good design and may be refactored in future, but for now, I'd better drop last sentence.Quoted 8 lines
Quoted 2 lines
But wasn’t that the point of this variable? That it goes back to false once the bitmap is fully initialized?
I just want to stress, that block-copy itself (which will be in a separate file, so it would be clean enough, what is block-copy and what is its user) do not clear this variable. It of course may track calls to
block_copy_reset_unallocated()and clear this variable automatically, but it don't do it now. And your wording looks for me like block-copy code may automatically clear this variableHm, OK.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
instead?
Or, what about the following mix:
Used for job sync=top mode. If true,
block_copy()will reset incopy_bitmapareas unallocated in top image (so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked. User is assumed to call in backgroundblock_copy_reset_unallocated()several times to cover the whole copied disk and then clearskip_unallocated, to prevent extra effort.Quoted 7 lines
Quoted 4 lines
I don’t know. The point of this variable is the initialization of the bitmap. block-copy only uses this as a hint that it needs to participate in that initialization process, too, and cannot assume the bitmap to be fully allocated.
Hmm, but where is a conflict of this and my wording? IMHO, I just documented exactly what's written in the code.
There’s no conflict because it isn’t mentioned; which is the problem I have with it.
Quoted 8 lines
What I was really confused about is who consumes the variable. It all becomes much clearer when I take it as a given that all of your description just is an imperative to block-copy. That simply wasn’t clear to me. (Which is why you don’t like my description, precisely because it tells the story from another POV, namely that of backup.)
Furthermore, I just miss the big picture about it. Why does the variable even exist?
Too keep it simpler for now, we can improve it as a follow-up. I see several solutions:
1. track sequential calls to block_copy_reset_unallocated() and when it comes to the disk end - clear the variable
2. don't publish block_copy_reset_unallocated() at all, assuming sequential calls to block_copy() and do like in (1.)
3. keep additional bitmap to track, what was already explored about being allocated/unallocated (seems too much)
I think, I'll resend with [2.] soon, if no other ideas. Or I can leave it for a follow-up.
I don’t quite like leaving puzzling together the
Quoted 4 lines
bits to the reader, if we can avoid it.
Max
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 129 lines · Vladimir Sementsov-Ogievskiy
Quoted 116 lines · Max Reitz
Quoted 81 lines · Vladimir Sementsov-Ogievskiy
Quoted 80 lines · Max Reitz
Quoted 59 lines · Vladimir Sementsov-Ogievskiy
Quoted 58 lines · Max Reitz
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Split copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining
job->common.blkusers only use it to get bs byblk_bs()call, so clearjob->commen.blkpermissions set inblock_job_createand addjob->source_bsto be used instead ofblk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)block/backup.c +9
-0@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { + BlockBackend *source; + BlockBackend *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_range_size;block/backup.c typedef struct CowRequest { · line 56
Quoted 10 lines
block/backup.c +10
-0+uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ It isn’t quite clear that this refers to the
copy_bitmap. Maybe something likeQuoted 8 lines
Quoted 1 line
“If true, the copy operation prepares a sync=top job: It scans the
hmm, now it's not refactored to scan it before copying loop, so it's not precise wording..
Quoted 1 line
source's top layer to find all unallocated areas and resets them in the
Not all, but mostly inside block-copy requested area (but may be more)
Sorry, I meant backup operation.
Quoted 8 lines
Quoted 4 lines
copy_bitmap(so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked.
Once the whole top layer has been scanned,skip_unallocatedis cleared and the actual copying begins.”Last sentence sounds like it's a block-copy who will clear
skip_unallocated, but it's not so. It's not very good design and may be refactored in future, but for now, I'd better drop last sentence.Quoted 8 lines
Quoted 2 lines
But wasn’t that the point of this variable? That it goes back to false once the bitmap is fully initialized?
I just want to stress, that block-copy itself (which will be in a separate file, so it would be clean enough, what is block-copy and what is its user) do not clear this variable. It of course may track calls to
block_copy_reset_unallocated()and clear this variable automatically, but it don't do it now. And your wording looks for me like block-copy code may automatically clear this variableHm, OK.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
instead?
Or, what about the following mix:
Used for job sync=top mode. If true,
block_copy()will reset incopy_bitmapareas unallocated in top image (so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked. User is assumed to call in backgroundblock_copy_reset_unallocated()several times to cover the whole copied disk and then clearskip_unallocated, to prevent extra effort.Quoted 7 lines
Quoted 4 lines
I don’t know. The point of this variable is the initialization of the bitmap. block-copy only uses this as a hint that it needs to participate in that initialization process, too, and cannot assume the bitmap to be fully allocated.
Hmm, but where is a conflict of this and my wording? IMHO, I just documented exactly what's written in the code.
There’s no conflict because it isn’t mentioned; which is the problem I have with it.
Quoted 8 lines
What I was really confused about is who consumes the variable. It all becomes much clearer when I take it as a given that all of your description just is an imperative to block-copy. That simply wasn’t clear to me. (Which is why you don’t like my description, precisely because it tells the story from another POV, namely that of backup.)
Furthermore, I just miss the big picture about it. Why does the variable even exist?
Too keep it simpler for now, we can improve it as a follow-up. I see several solutions:
Quoted 8 lines
1. track sequential calls to
block_copy_reset_unallocated()and when it comes to the disk end - clear the variable2. don't publish
block_copy_reset_unallocated()at all, assuming sequential calls toblock_copy()and do like in (1.)3. keep additional bitmap to track, what was already explored about being allocated/unallocated (seems too much)
Sorry, over some editing I accidentally removed the meaning from what I wrote there. I didn’t mean literally “Why does the variable exist” or “I don’t understand the big picture”. I meant “The comment does not explain the big picture, for example, it does not explain why the variable even exists.”
Max
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 136 lines · Max Reitz
Quoted 135 lines · Vladimir Sementsov-Ogievskiy
Quoted 116 lines · Max Reitz
Quoted 81 lines · Vladimir Sementsov-Ogievskiy
Quoted 80 lines · Max Reitz
Quoted 59 lines · Vladimir Sementsov-Ogievskiy
Quoted 58 lines · Max Reitz
Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Split copying code part from backup to "block-copy", including separate state structure and function renaming. This is needed to share it with backup-top filter driver in further commits.
Notes:
1. As BlockCopyState keeps own BlockBackend objects, remaining
job->common.blkusers only use it to get bs byblk_bs()call, so clearjob->commen.blkpermissions set inblock_job_createand addjob->source_bsto be used instead ofblk_bs(job->common.blk), to keep it more clear which bs we use when introduce backup-top filter in further commit.2. Rename s/initializing_bitmap/skip_unallocated/ to sound a bit better as interface to BlockCopyState
3. Split is not very clean: there left some duplicated fields, backup code uses some BlockCopyState fields directly, let's postpone it for further improvements and keep this comment simpler for review.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 357 ++++++++++++++++++++++++++++----------------- block/trace-events | 12 +- 2 files changed, 231 insertions(+), 138 deletions(-)block/backup.c +9
-0@@ -35,12 +35,43 @@ typedef struct CowRequest {CoQueue wait_queue;/* coroutines blocked on this request */ } CowRequest; +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { + BlockBackend *source; + BlockBackend *target; + BdrvDirtyBitmap *copy_bitmap; + int64_t cluster_size; + bool use_copy_range; + int64_t copy_range_size;block/backup.c typedef struct CowRequest { · line 56
Quoted 10 lines
block/backup.c +10
-0+uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ It isn’t quite clear that this refers to the
copy_bitmap. Maybe something likeQuoted 8 lines
Quoted 1 line
“If true, the copy operation prepares a sync=top job: It scans the
hmm, now it's not refactored to scan it before copying loop, so it's not precise wording..
Quoted 1 line
source's top layer to find all unallocated areas and resets them in the
Not all, but mostly inside block-copy requested area (but may be more)
Sorry, I meant backup operation.
Quoted 8 lines
Quoted 4 lines
copy_bitmap(so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked.
Once the whole top layer has been scanned,skip_unallocatedis cleared and the actual copying begins.”Last sentence sounds like it's a block-copy who will clear
skip_unallocated, but it's not so. It's not very good design and may be refactored in future, but for now, I'd better drop last sentence.Quoted 8 lines
Quoted 2 lines
But wasn’t that the point of this variable? That it goes back to false once the bitmap is fully initialized?
I just want to stress, that block-copy itself (which will be in a separate file, so it would be clean enough, what is block-copy and what is its user) do not clear this variable. It of course may track calls to
block_copy_reset_unallocated()and clear this variable automatically, but it don't do it now. And your wording looks for me like block-copy code may automatically clear this variableHm, OK.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
instead?
Or, what about the following mix:
Used for job sync=top mode. If true,
block_copy()will reset incopy_bitmapareas unallocated in top image (so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked. User is assumed to call in backgroundblock_copy_reset_unallocated()several times to cover the whole copied disk and then clearskip_unallocated, to prevent extra effort.Quoted 7 lines
Quoted 4 lines
I don’t know. The point of this variable is the initialization of the bitmap. block-copy only uses this as a hint that it needs to participate in that initialization process, too, and cannot assume the bitmap to be fully allocated.
Hmm, but where is a conflict of this and my wording? IMHO, I just documented exactly what's written in the code.
There’s no conflict because it isn’t mentioned; which is the problem I have with it.
Quoted 8 lines
What I was really confused about is who consumes the variable. It all becomes much clearer when I take it as a given that all of your description just is an imperative to block-copy. That simply wasn’t clear to me. (Which is why you don’t like my description, precisely because it tells the story from another POV, namely that of backup.)
Furthermore, I just miss the big picture about it. Why does the variable even exist?
Too keep it simpler for now, we can improve it as a follow-up. I see several solutions:
1. track sequential calls to
block_copy_reset_unallocated()and when it comes to the disk end - clear the variable2. don't publish
block_copy_reset_unallocated()at all, assuming sequential calls toblock_copy()and do like in (1.)
Quoted 9 lines
Quoted 2 lines
3. keep additional bitmap to track, what was already explored about being allocated/unallocated (seems too much)
Sorry, over some editing I accidentally removed the meaning from what I wrote there. I didn’t mean literally “Why does the variable exist” or “I don’t understand the big picture”. I meant “The comment does not explain the big picture, for example, it does not explain why the variable even exists.”
Ok, than
4. Postpone improvements for a follow-up (anyway, finally, block-copy should use block_status to copy by larger chunks, like mirror does), and improve the comment like this:
"""
Used for job sync=top mode, which currently works as follows (the size of the comment definitely shows unclean design, but this is a TODO to improve it):
If job started in sync=top mode, which means that we want to copy only parts allocated in top layer, job should behave like this:
1. Create block-copy state with skip_unallocated = true.
2. Then, block_copy() will automatically check for allocation in top layer, and do not copy areas which are not allocated in top layer. So, for example, copy-before-write operations in backup works correctly even before [3.]
3. Sequentially call block_copy_reset_unallocated() to cover the whole source node, copy_bitmap will be updated correspondingly.
4. Unset skip_unallocated variable in block-copy state, to avoid extra (as everything is covered by [3.]) block-status queries in block_copy() calls
5. Do sequential copying by loop of block_copy() calls, all needed allocation information is already in copy_bitmap.
From block_copy() side, it behaves like this:
If skip_unallocated is set, block_copy() will reset in copy_bitmap areas unallocated in top image (so they will not be copied). Whenever any such area is cleared, progress_reset_callback will be invoked. Note, that progress_reset_callback is called from block_copy_reset_unallocated() too. """
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
On 10.09.19 11:22, Vladimir Sementsov-Ogievskiy wrote:
[...]
Quoted 23 lines
Ok, than
4. Postpone improvements for a follow-up (anyway, finally, block-copy should use
block_statusto copy by larger chunks, like mirror does), and improve the comment like this:"""
Used for job sync=top mode, which currently works as follows (the size of the comment definitely shows unclean design, but this is a TODO to improve it):
If job started in sync=top mode, which means that we want to copy only parts allocated in top layer, job should behave like this:1. Create block-copy state with
skip_unallocated= true.
2. Then,block_copy()will automatically check for allocation in top layer, and do not copy areas which are not allocated in top layer. So, for example, copy-before-write operations in backup works correctly even before [3.]
3. Sequentially callblock_copy_reset_unallocated()to cover the whole source node,copy_bitmapwill be updated correspondingly.
4. Unsetskip_unallocatedvariable in block-copy state, to avoid extra (as everything is covered by [3.]) block-status queries inblock_copy()calls
5. Do sequential copying by loop ofblock_copy()calls, all needed allocation information is already incopy_bitmap.
Quoted 6 lines
From
block_copy()side, it behaves like this:
Ifskip_unallocatedis set,block_copy()will reset incopy_bitmapareas unallocated in top image (so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked. Note, thatprogress_reset_callbackis called fromblock_copy_reset_unallocated()too. """
Can this not be simplified?
"""
Used by sync=top jobs, which first scan the source node for unallocated areas and clear them in the copy_bitmap. During this process, the bitmap is thus not fully initialized: It may still have bits set for areas that are unallocated and should actually not be copied.
This is indicated by skip_unallocated.
In this case, block_copy() will query the source’s allocation status, skip unallocated regions, clear them in the copy_bitmap, and invoke block_copy_reset_unallocated() every time it does.
Otherwise, block_copy() copies everything that’s dirty in the copy_bitmap. """
Max
Re: [Qemu-devel] [PATCH v10 04/14] block/backup: introduce BlockCopyState
Quoted 42 lines · Max Reitz
On 10.09.19 11:22, Vladimir Sementsov-Ogievskiy wrote:
[...]
Quoted 23 lines
Ok, than
4. Postpone improvements for a follow-up (anyway, finally, block-copy should use
block_statusto copy by larger chunks, like mirror does), and improve the comment like this:"""
Used for job sync=top mode, which currently works as follows (the size of the comment definitely shows unclean design, but this is a TODO to improve it):
If job started in sync=top mode, which means that we want to copy only parts allocated in top layer, job should behave like this:1. Create block-copy state with
skip_unallocated= true.
2. Then,block_copy()will automatically check for allocation in top layer, and do not copy areas which are not allocated in top layer. So, for example, copy-before-write operations in backup works correctly even before [3.]
3. Sequentially callblock_copy_reset_unallocated()to cover the whole source node,copy_bitmapwill be updated correspondingly.
4. Unsetskip_unallocatedvariable in block-copy state, to avoid extra (as everything is covered by [3.]) block-status queries inblock_copy()calls
5. Do sequential copying by loop ofblock_copy()calls, all needed allocation information is already incopy_bitmap.Quoted 6 lines
From
block_copy()side, it behaves like this:
Ifskip_unallocatedis set,block_copy()will reset incopy_bitmapareas unallocated in top image (so they will not be copied). Whenever any such area is cleared,progress_reset_callbackwill be invoked. Note, thatprogress_reset_callbackis called fromblock_copy_reset_unallocated()too. """Can this not be simplified?
"""
Used by sync=top jobs, which first scan the source node for unallocated areas and clear them in thecopy_bitmap. During this process, the bitmap is thus not fully initialized: It may still have bits set for areas that are unallocated and should actually not be copied.
Quoted 9 lines
This is indicated by
skip_unallocated.In this case,
block_copy()will query the source’s allocation status, skip unallocated regions, clear them in thecopy_bitmap, and invokeblock_copy_reset_unallocated()every time it does.Otherwise,
block_copy()copies everything that’s dirty in thecopy_bitmap. """
OK, thanks)
Signature · 2 lines
Best regards, Vladimir
PATCH v10 5/14 block/backup: fix block-comment style
In reply to Vladimir Sementsov-OgievskiyWe need to fix comment style around block-copy functions before further moving them to separate file to satisfy checkpatch. But do more: fix all comments style. Also, seems like doubled first asterisk is not forbidden, but drop it too for consistency.
--- block/backup.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
block/backup.c +23 -12
@@ -205,8 +205,10 @@ fail:return NULL ; } -/* Copy range to target with a bounce buffer and return the bytes copied. If -* error occurred, return a negative error number */ +/* +* Copy range to target with a bounce buffer and return the bytes copied. If +* error occurred, return a negative error number +*/ static int coroutine_fn block_copy_with_bounce_buffer(BlockCopyState *s, int64_t start, int64_t end,
@@ -251,8 +253,10 @@ fail: } -/* Copy range to target and return the bytes copied. If error occurred, return a -* negative error number. */ +/* +* Copy range to target and return the bytes copied. If error occurred, return a +* negative error number. +*/ static int coroutine_fn block_copy_with_offload(BlockCopyState *s, int64_t start, int64_t end,
@@ -323,7 +327,7 @@ static int block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, } } -/** +/* * Reset bits in copy_bitmap starting at offset if they represent unallocated * data in the image. May reset subsequent contiguous bits. * @return 0 when the cluster at @offset was unallocated,
@@ -566,7 +570,8 @@ static void backup_drain(BlockJob *job) {BackupBlockJob *s =container_of (job, BackupBlockJob, common); -/* Need to keep a reference in case blk_drain triggers execution +/* +* Need to keep a reference in case blk_drain triggers execution * of backup_complete... */ if (s->bcs) {
@@ -597,8 +602,10 @@ static bool coroutine_fn yield_and_check(BackupBlockJob *job)return true; } -/* We need to yield even for delay_ns = 0 so that bdrv_drain_all() can -* return. Without a yield, the VM would not reboot. */ +/* +* We need to yield even for delay_ns = 0 so that bdrv_drain_all() can +* return. Without a yield, the VM would not reboot. +*/ delay_ns =block_job_ratelimit_get_delay (&job->common, job->bytes_read); job->bytes_read =0 ;job_sleep_ns (&job->common.job, delay_ns);
@@ -697,11 +704,15 @@ static int coroutine_fn backup_run(Job *job, Error **errp) }if (s->sync_mode ==MIRROR_SYNC_MODE_NONE ) { -/* All bits are set in copy_bitmap to allow any cluster to be copied. -* This does not actually require them to be copied. */ +/* +* All bits are set in copy_bitmap to allow any cluster to be copied. +* This does not actually require them to be copied. +*/ while (!job_is_cancelled (job)) { -/* Yield until the job is cancelled. We just let our before_write -* notify callback service CoW requests. */ +/* +* Yield until the job is cancelled. We just let our before_write +* notify callback service CoW requests. +*/ job_yield (job); } }else {
Signature · 1 line
2.18.0
Re: [Qemu-devel] [PATCH v10 05/14] block/backup: fix block-comment style
Quoted 4 lines · Vladimir Sementsov-Ogievskiy
We need to fix comment style around block-copy functions before further moving them to separate file to satisfy checkpatch. But do more: fix all comments style. Also, seems like doubled first asterisk is not forbidden, but drop it too for consistency.
Oh, no, it definitely isn’t forbidden. I very much like to use it specifically when documenting some function’s interface.
Quoted 5 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
Anyway:
PATCH v10 6/14 block: move block_copy from block/backup.c to separate file
In reply to Vladimir Sementsov-OgievskiySplit block_copy to separate file, to be cleanly shared with backup-top filter driver in further commits.
It's a clean movement, the only change is drop "static" from interface functions.
--- include/block/block-copy.h | 67 ++++++++ block/backup.c | 337 +------------------------------------ block/block-copy.c | 324 +++++++++++++++++++++++++++++++++++ block/Makefile.objs | 1 + block/trace-events | 2 + 5 files changed, 395 insertions(+), 336 deletions(-) create mode 100644 include/block/block-copy.h create mode 100644 block/block-copy.c
include/block/block-copy.h new file +67 -0
@@ -0,0 +1,67 @@ +/* +* block_copy API +* +* Copyright (C) 2013 Proxmox Server Solutions +* Copyright (c) 2019 Virtuozzo International GmbH. +* +* Authors: +* Dietmar Maurer ([email protected]) +* Vladimir Sementsov-Ogievskiy <[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. +*/ + +#ifndef BLOCK_COPY_H +#define BLOCK_COPY_H + +#include "block/block.h" + +typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque); +typedef void (*ProgressResetCallbackFunc )(void *opaque); +typedef struct BlockCopyState { +BlockBackend *source; +BlockBackend *target; +BdrvDirtyBitmap *copy_bitmap; +int64_t cluster_size; +bool use_copy_range; +int64_t copy_range_size; +uint64_t len; + +BdrvRequestFlags write_flags; + +/* +* skip_unallocated: if true, on copy operation firstly reset areas +* unallocated in top layer of source (and then of course don't copy +* corresponding clusters). If some bytes reset, call +* progress_reset_callback. +*/ +bool skip_unallocated; + +/* progress_bytes_callback called when some copying progress is done. */ +ProgressBytesCallbackFunc progress_bytes_callback; + +/* +* progress_reset_callback called when some bytes reset from copy_bitmap +* (see @skip_unallocated above) +*/ +ProgressResetCallbackFunc progress_reset_callback; +void *progress_opaque; +}BlockCopyState ; + +BlockCopyState *block_copy_state_new ( +BlockDriverState *source,BlockDriverState *target, +int64_t cluster_size,BdrvRequestFlags write_flags, +ProgressBytesCallbackFunc progress_bytes_callback, +ProgressResetCallbackFunc progress_reset_callback, +void *progress_opaque,Error **errp); + +void block_copy_state_free (BlockCopyState *s); + +int64_t block_copy_reset_unallocated (BlockCopyState *s, +int64_t offset,int64_t *count); + +int coroutine_fn block_copy(BlockCopyState *s, int64_t start, uint64_t bytes, +bool *error_is_read,bool is_write_notifier); + +#endif /* BLOCK_COPY_H */
block/backup.c +1 -336
355 lines not on this page · raw message
block/block-copy.c new file +324 -0
324 lines not on this page · raw message
block/Makefile.objs +1 -0
@@ -37,6 +37,7 @@ block-obj-y += write-threshold.o block-obj-y += backup.o block-obj-$(CONFIG_REPLICATION) += replication.o block-obj-y += throttle.o copy-on-read.o +block-obj-y += block-copy.o block-obj-y += crypto.o
block/trace-events +2 -0
@@ -40,6 +40,8 @@ mirror_yield_in_flight(void *s, int64_t offset, int in_flight) "s %p offset %" P # backup.c backup_do_cow_enter(void *job, int64_t start, int64_t offset, uint64_t bytes) "job %p start %" PRId64 " offset %" PRId64 " bytes %" PRIu64 backup_do_cow_return(void *job, int64_t offset, uint64_t bytes, int ret) "job %p offset %" PRId64 " bytes %" PRIu64 " ret %d" + +# block-copy.c block_copy_skip(void *bcs, int64_t start) "job %p start %"PRId64 block_copy_skip_range(void *bcs, int64_t start, uint64_t bytes) "job %p start %"PRId64" bytes %"PRId64 block_copy_process(void *bcs, int64_t start) "job %p start %"PRId64
Signature · 1 line
2.18.0
PATCH v10 7/14 block: teach bdrv_debug_breakpoint skip filters with backing
In reply to Vladimir Sementsov-OgievskiyTeach bdrv_debug_breakpoint and bdrv_debug_remove_breakpoint skip filters with backing. This is needed to implement and use in backup job it's own backup_top filter driver (like mirror already has one), and without this improvement, breakpoint removal will fail at least in 55 iotest.
--- block.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
block.c +26 -8
@@ -5164,14 +5164,35 @@ void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event) bs->drv->bdrv_debug_event (bs, event); } -int bdrv_debug_breakpoint (BlockDriverState *bs,const char *event, -const char *tag) +static BlockDriverState *bdrv_find_debug_node (BlockDriverState *bs) {while (bs && bs->drv && !bs->drv->bdrv_debug_breakpoint) { - bs = bs->file ? bs->file->bs :NULL ; +if (bs->file) { + bs = bs->file->bs; +continue ; + } + +if (bs->drv->is_filter && bs->backing) { + bs = bs->backing->bs; +continue ; + } + +break ; }if (bs && bs->drv && bs->drv->bdrv_debug_breakpoint) { +assert (bs->drv->bdrv_debug_remove_breakpoint); +return bs; + } + +return NULL ; +} + +int bdrv_debug_breakpoint (BlockDriverState *bs,const char *event, +const char *tag) +{ + bs =bdrv_find_debug_node (bs); +if (bs) {return bs->drv->bdrv_debug_breakpoint (bs, event, tag); }
@@ -5180,11 +5201,8 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const char *event,int bdrv_debug_remove_breakpoint (BlockDriverState *bs,const char *tag) { -while (bs && bs->drv && !bs->drv->bdrv_debug_remove_breakpoint) { - bs = bs->file ? bs->file->bs :NULL ; - } - -if (bs && bs->drv && bs->drv->bdrv_debug_remove_breakpoint) { + bs =bdrv_find_debug_node (bs); +if (bs) {return bs->drv->bdrv_debug_remove_breakpoint (bs, tag); }
Signature · 1 line
2.18.0
PATCH v10 8/14 iotests: prepare 124 and 257 bitmap querying for backup-top filter
In reply to Vladimir Sementsov-OgievskiyAfter backup-top filter appearing it's not possible to see dirty bitmaps in top node, so use node-name instead.
--- tests/qemu-iotests/124 | 83 ++++---- tests/qemu-iotests/257 | 49 ++--- tests/qemu-iotests/257.out | 364 +++++++++++++--------------------- tests/qemu-iotests/iotests.py | 27 +++ 4 files changed, 219 insertions(+), 304 deletions(-)
tests/qemu-iotests/124 +36 -47
@@ -105,7 +105,7 @@ class TestIncrementalBackupBase(iotests.QMPTestCase): # Create a base image with a distinctive patterning drive0 = self.add_node('drive0') self.img_create(drive0['file'], drive0['fmt']) - self.vm.add_drive(drive0['file']) + self.vm.add_drive(drive0['file'], opts='node-name=node0') self.write_default_pattern(drive0['file']) self.vm.launch()
@@ -348,12 +348,14 @@ class TestIncrementalBackup(TestIncrementalBackupBase): ('0xfe', '16M', '256k'), ('0x64', '32736k', '64k'))) # Check the dirty bitmap stats - result = self.vm.qmp('query-block') - self.assert_qmp(result, 'return[0]/dirty-bitmaps[0]/name', 'bitmap0') - self.assert_qmp(result, 'return[0]/dirty-bitmaps[0]/count', 458752) - self.assert_qmp(result, 'return[0]/dirty-bitmaps[0]/granularity', 65536) - self.assert_qmp(result, 'return[0]/dirty-bitmaps[0]/status', 'active') - self.assert_qmp(result, 'return[0]/dirty-bitmaps[0]/persistent', False) + self.assertTrue(self.vm.check_bitmap_status( + 'node0', bitmap0.name, { + 'name': 'bitmap0', + 'count': 458752, + 'granularity': 65536, + 'status': 'active', + 'persistent': False + })) # Prepare a cluster_size=128k backup target without a backing file. (target, _) = bitmap0.new_target()
@@ -670,9 +672,8 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBackupBase): """ drive0 = self.drives[0] - # NB: The blkdebug script here looks for a "flush, read, read" pattern. - # The flush occurs in hmp_io_writes, the first read in device_add, and - # the last read during the block job. + # NB: The blkdebug script here looks for a "flush, read" pattern. + # The flush occurs in hmp_io_writes, and the read during the block job. result = self.vm.qmp('blockdev-add', node_name=drive0['id'], driver=drive0['fmt'],
@@ -686,15 +687,11 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBackupBase): 'event': 'flush_to_disk', 'state': 1, 'new_state': 2 - },{ - 'event': 'read_aio', - 'state': 2, - 'new_state': 3 }], 'inject-error': [{ 'event': 'read_aio', 'errno': 5, - 'state': 3, + 'state': 2, 'immediately': False, 'once': True }],
@@ -708,23 +705,15 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBackupBase): ('0xfe', '16M', '256k'), ('0x64', '32736k', '64k'))) - # For the purposes of query-block visibility of bitmaps, add a drive - # frontend after we've written data; otherwise we can't use hmp-io - result = self.vm.qmp("device_add", - id="device0", - drive=drive0['id'], - driver="virtio-blk") - self.assert_qmp(result, 'return', {}) - # Bitmap Status Check - query = self.vm.qmp('query-block') - ret = [bmap for bmap in query['return'][0]['dirty-bitmaps'] - if bmap.get('name') == bitmap.name][0] - self.assert_qmp(ret, 'count', 458752) - self.assert_qmp(ret, 'granularity', 65536) - self.assert_qmp(ret, 'status', 'active') - self.assert_qmp(ret, 'busy', False) - self.assert_qmp(ret, 'recording', True) + self.assertTrue(self.vm.check_bitmap_status( + drive0['id'], bitmap.name, { + 'count': 458752, + 'granularity': 65536, + 'status': 'active', + 'busy': False, + 'recording': True + })) # Start backup parent, _ = bitmap.last_target()
@@ -748,14 +737,14 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBackupBase): 'operation': 'read'}) # Bitmap Status Check - query = self.vm.qmp('query-block') - ret = [bmap for bmap in query['return'][0]['dirty-bitmaps'] - if bmap.get('name') == bitmap.name][0] - self.assert_qmp(ret, 'count', 458752) - self.assert_qmp(ret, 'granularity', 65536) - self.assert_qmp(ret, 'status', 'frozen') - self.assert_qmp(ret, 'busy', True) - self.assert_qmp(ret, 'recording', True) + self.assertTrue(self.vm.check_bitmap_status( + drive0['id'], bitmap.name, { + 'count': 458752, + 'granularity': 65536, + 'status': 'frozen', + 'busy': True, + 'recording': True + })) # Resume and check incremental backup for consistency res = self.vm.qmp('block-job-resume', device=bitmap.drive['id'])
@@ -763,14 +752,14 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBackupBase): self.wait_qmp_backup(bitmap.drive['id']) # Bitmap Status Check - query = self.vm.qmp('query-block') - ret = [bmap for bmap in query['return'][0]['dirty-bitmaps'] - if bmap.get('name') == bitmap.name][0] - self.assert_qmp(ret, 'count', 0) - self.assert_qmp(ret, 'granularity', 65536) - self.assert_qmp(ret, 'status', 'active') - self.assert_qmp(ret, 'busy', False) - self.assert_qmp(ret, 'recording', True) + self.assertTrue(self.vm.check_bitmap_status( + drive0['id'], bitmap.name, { + 'count': 0, + 'granularity': 65536, + 'status': 'active', + 'busy': False, + 'recording': True + })) # Finalize / Cleanup self.make_reference_backup(bitmap)
tests/qemu-iotests/257 +16 -33
105 lines not on this page · raw message
tests/qemu-iotests/257.out +140 -224
1,204 lines not on this page · raw message
tests/qemu-iotests/iotests.py +27 -0
@@ -643,6 +643,33 @@ class VM(qtest.QEMUQtestMachine): return x return None + def query_bitmaps(self): + res = self.qmp("query-named-block-nodes") + return {device['node-name']: device['dirty-bitmaps'] + for device in res['return'] if 'dirty-bitmaps' in device} + + def get_bitmap(self, node_name, bitmap_name, recording=None, bitmaps=None): + """ + get a specific bitmap from the object returned by query_bitmaps. + :param recording: If specified, filter results by the specified value. + :param bitmaps: If specified, use it instead of call query_bitmaps() + """ + if bitmaps is None: + bitmaps = self.query_bitmaps() + + for bitmap in bitmaps[node_name]: + if bitmap.get('name', '') == bitmap_name: + if recording is None: + return bitmap + elif bitmap.get('recording') == recording: + return bitmap + return None + + def check_bitmap_status(self, node_name, bitmap_name, fields): + ret = self.get_bitmap(node_name, bitmap_name) + + return fields.items() <= ret.items() + index_re = re.compile(r'([^\[]+)\[([^\]]+)\]')
Signature · 1 line
2.18.0
Re: [Qemu-devel] [PATCH v10 08/14] iotests: prepare 124 and 257 bitmap querying for backup-top filter
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
After backup-top filter appearing it's not possible to see dirty bitmaps in top node, so use node-name instead.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- tests/qemu-iotests/124 | 83 ++++---- tests/qemu-iotests/257 | 49 ++--- tests/qemu-iotests/257.out | 364 +++++++++++++--------------------- tests/qemu-iotests/iotests.py | 27 +++ 4 files changed, 219 insertions(+), 304 deletions(-)
[...]
Quoted 5 lines
tests/qemu-iotests/iotests.py +0
-0@@ -643,6 +643,33 @@ class VM(qtest.QEMUQtestMachine):
[...]
tests/qemu-iotests/iotests.py class VM(qtest.QEMUQtestMachine): · line 671
Quoted 4 lines
tests/qemu-iotests/iotests.py +4
-0+ def check_bitmap_status(self, node_name, bitmap_name, fields): + ret = self.get_bitmap(node_name, bitmap_name) + + return fields.items() <= ret.items()
Why the <=? AFAIU, it will compare each of the arrays’ elements one by one and return true if all of the ones in @fields are less than or equal to the ones in @ret.
But that would mean that the values given in @fields no longer need to be equal to the ones in @ret. On top of that, I suppose if @fields.items() at some index contains a key that is not equal to the key in @ret.items() at the same index, luck will determine whether the comparison passes or not.
Why not just loop through all keys of @fields and check that @fields and @ret contain the same value for all of them?
Max
Re: [Qemu-devel] [PATCH v10 08/14] iotests: prepare 124 and 257 bitmap querying for backup-top filter
Quoted 22 lines · Max Reitz
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
After backup-top filter appearing it's not possible to see dirty bitmaps in top node, so use node-name instead.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- tests/qemu-iotests/124 | 83 ++++---- tests/qemu-iotests/257 | 49 ++--- tests/qemu-iotests/257.out | 364 +++++++++++++--------------------- tests/qemu-iotests/iotests.py | 27 +++ 4 files changed, 219 insertions(+), 304 deletions(-)[...]
Quoted 5 lines
tests/qemu-iotests/iotests.py +0
-0@@ -643,6 +643,33 @@ class VM(qtest.QEMUQtestMachine):[...]
Quoted 8 lines
tests/qemu-iotests/iotests.py class VM(qtest.QEMUQtestMachine): · line 671
Quoted 4 lines
tests/qemu-iotests/iotests.py +4
-0+ def check_bitmap_status(self, node_name, bitmap_name, fields): + ret = self.get_bitmap(node_name, bitmap_name) + + return fields.items() <= ret.items()Why the <=? AFAIU, it will compare each of the arrays’ elements one by one and return true if all of the ones in @fields are less than or equal to the ones in @ret.
No, it's a valid way to check that one dict is subdict of another, as dict_view works like Set class:
$ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information.
Quoted 1 line
Quoted 1 line
Quoted 1 line
{1,2,3} <= {4,5,6}
False
Quoted 1 line
Quoted 1 line
Quoted 1 line
{1,2,3} <= {0,3,2,1}
True
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'a':4, 'b':2, 'c':1}.items()
True
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'a':4, 'b':2, 'c':2}.items()
False
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'a':4, 'b':2, 'c':0}.items()
False
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'d':4, 'b':2}.items()
False
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'c':1, 'b':3}.items()
False
Bad thing is that it's not so for python2, in which we need to use .viewitems() instead..
$ python2 Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information.
Quoted 1 line
Quoted 1 line
Quoted 1 line
{1,2,3} <= {0,3,2,1}
True
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'a':4, 'b':2, 'c':1}.items()
False
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'d':4, 'b':2}.items()
False
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
{'c':1, 'b':2}.items() <= {'c':1, 'b':2}.items()
True
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'c':1, 'b':3}.items()
True
Quoted 1 line
Quoted 1 line
Quoted 1 line
{'c':1, 'b':2}.items() <= {'c':1, 'b':3}.items()
True
Should I care about python2 now, or we already dropped its support in iotests?
[and, honestly, I learned it all mostly from here https://stackoverflow.com/questions/30818694/test-if-dict-contained-in-dict]
Quoted 12 lines
But that would mean that the values given in @fields no longer need to be equal to the ones in @ret. On top of that, I suppose if @fields.items() at some index contains a key that is not equal to the key in @ret.items() at the same index, luck will determine whether the comparison passes or not.
Why not just loop through all keys of @fields and check that @fields and @ret contain the same value for all of them?
Max
Signature · 2 lines
Best regards, Vladimir
Max Reitz
Reviewed-byRe: [Qemu-devel] [PATCH v10 08/14] iotests: prepare 124 and 257 bitmap querying for backup-top filter
Quoted 28 lines · Vladimir Sementsov-Ogievskiy
Quoted 27 lines · Max Reitz
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
After backup-top filter appearing it's not possible to see dirty bitmaps in top node, so use node-name instead.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- tests/qemu-iotests/124 | 83 ++++---- tests/qemu-iotests/257 | 49 ++--- tests/qemu-iotests/257.out | 364 +++++++++++++--------------------- tests/qemu-iotests/iotests.py | 27 +++ 4 files changed, 219 insertions(+), 304 deletions(-)[...]
Quoted 5 lines
tests/qemu-iotests/iotests.py +0
-0@@ -643,6 +643,33 @@ class VM(qtest.QEMUQtestMachine):[...]
Quoted 4 lines
tests/qemu-iotests/iotests.py +4
-0+ def check_bitmap_status(self, node_name, bitmap_name, fields): + ret = self.get_bitmap(node_name, bitmap_name) + + return fields.items() <= ret.items()
Quoted 6 lines
Quoted 3 lines
Why the <=? AFAIU, it will compare each of the arrays’ elements one by one and return true if all of the ones in @fields are less than or equal to the ones in @ret.
No, it's a valid way to check that one dict is subdict of another, as
dict_viewworks like Set class:
OK. It looked to me like .items() just returned an array. (When I googled for how <= behaves here.)
[...]
Quoted 1 line
Should I care about python2 now, or we already dropped its support in iotests?
We haven’t officially. OTOH, 4.2 is set to release on December 3, which is less than one month before Python 2’s EOL. So it would be close to wrong to care at this point, I guess?
PATCH v10 9/14 iotests: 257: drop unused Drive.device field
In reply to Vladimir Sementsov-OgievskiyAfter previous commit Drive.device is actually unused. Drop it together with .name property. While being here reuse .node in qmp commands instead of writing 'drive0' twice.
--- tests/qemu-iotests/257 | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-)
tests/qemu-iotests/257 +15 -22
@@ -148,11 +148,6 @@ class Drive: self.fmt = None self.size = None self.node = None - self.device = None - - @property - def name(self): - return self.node or self.device def img_create(self, fmt, size): self.fmt = fmt
@@ -201,7 +196,7 @@ def blockdev_backup(vm, device, target, sync, **kwargs): def blockdev_backup_mktarget(drive, target_id, filepath, sync, **kwargs): target_drive = Drive(filepath, vm=drive.vm) target_drive.create_target(target_id, drive.fmt, drive.size) - blockdev_backup(drive.vm, drive.name, target_id, sync, **kwargs) + blockdev_backup(drive.vm, drive.node, target_id, sync, **kwargs) def reference_backup(drive, n, filepath): log("--- Reference Backup #{:d} ---\n".format(n))
@@ -229,7 +224,7 @@ def perform_writes(drive, n): pattern.offset, pattern.size) log(cmd) - log(drive.vm.hmp_qemu_io(drive.name, cmd)) + log(drive.vm.hmp_qemu_io(drive.node, cmd)) bitmaps = drive.vm.query_bitmaps() log({'bitmaps': bitmaps}, indent=2) log('')
@@ -324,18 +319,17 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None): }] } + drive0.node = 'drive0' vm.qmp_log('blockdev-add', filters=[iotests.filter_qmp_testfiles], - node_name="drive0", + node_name=drive0.node, driver=drive0.fmt, file=file_config) - drive0.node = 'drive0' - drive0.device = 'device0' # Use share-rw to allow writes directly to the node; # The anonymous block-backend for this configuration prevents us # from using HMP's qemu-io commands to address the device. - vm.qmp_log("device_add", id=drive0.device, - drive=drive0.name, driver="scsi-hd", + vm.qmp_log("device_add", id='device0', + drive=drive0.node, driver="scsi-hd", share_rw=True) log('')
@@ -343,7 +337,7 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None): perform_writes(drive0, 0) reference_backup(drive0, 0, fbackup0) log('--- Add Bitmap ---\n') - vm.qmp_log("block-dirty-bitmap-add", node=drive0.name, + vm.qmp_log("block-dirty-bitmap-add", node=drive0.node, name="bitmap0", granularity=GRANULARITY) log('') ebitmap = EmulatedBitmap()
@@ -358,7 +352,7 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None): # 1 - Test Backup (w/ Optional induced failure) if failure == 'intermediate': # Activate blkdebug induced failure for second-to-next read - log(vm.hmp_qemu_io(drive0.name, 'flush')) + log(vm.hmp_qemu_io(drive0.node, 'flush')) log('') job = backup(drive0, 1, bsync1, msync_mode, bitmap="bitmap0", bitmap_mode=bsync_mode)
@@ -426,7 +420,7 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None): log('--- Cleanup ---\n') vm.qmp_log("block-dirty-bitmap-remove", - node=drive0.name, name="bitmap0") + node=drive0.node, name="bitmap0") bitmaps = vm.query_bitmaps() log({'bitmaps': bitmaps}, indent=2) vm.shutdown()
@@ -467,22 +461,21 @@ def test_backup_api(): 'filename': drive0.path } + drive0.node = 'drive0' vm.qmp_log('blockdev-add', filters=[iotests.filter_qmp_testfiles], - node_name="drive0", + node_name=drive0.node, driver=drive0.fmt, file=file_config) - drive0.node = 'drive0' - drive0.device = 'device0' - vm.qmp_log("device_add", id=drive0.device, - drive=drive0.name, driver="scsi-hd") + vm.qmp_log("device_add", id='device0', + drive=drive0.node, driver="scsi-hd") log('') target0 = Drive(backup_path, vm=vm) target0.create_target("backup_target", drive0.fmt, drive0.size) log('') - vm.qmp_log("block-dirty-bitmap-add", node=drive0.name, + vm.qmp_log("block-dirty-bitmap-add", node=drive0.node, name="bitmap0", granularity=GRANULARITY) log('')
@@ -521,7 +514,7 @@ def test_backup_api(): log("-- Sync mode {:s} tests --\n".format(sync_mode)) for bitmap in (None, 'bitmap404', 'bitmap0'): for policy in error_cases[sync_mode][bitmap]: - blockdev_backup(drive0.vm, drive0.name, "backup_target", + blockdev_backup(drive0.vm, drive0.node, "backup_target", sync_mode, job_id='api_job', bitmap=bitmap, bitmap_mode=policy) log('')
Signature · 1 line
2.18.0
PATCH v10 10/14 iotests: 257: drop device_add
In reply to Vladimir Sementsov-OgievskiySCSI devices are unused in test, drop them.
--- tests/qemu-iotests/257 | 8 ------- tests/qemu-iotests/257.out | 44 -------------------------------------- 2 files changed, 52 deletions(-)
tests/qemu-iotests/257 +0 -8
@@ -325,12 +325,6 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None): node_name=drive0.node, driver=drive0.fmt, file=file_config) - # Use share-rw to allow writes directly to the node; - # The anonymous block-backend for this configuration prevents us - # from using HMP's qemu-io commands to address the device. - vm.qmp_log("device_add", id='device0', - drive=drive0.node, driver="scsi-hd", - share_rw=True) log('') # 0 - Writes and Reference Backup
@@ -467,8 +461,6 @@ def test_backup_api(): node_name=drive0.node, driver=drive0.fmt, file=file_config) - vm.qmp_log("device_add", id='device0', - drive=drive0.node, driver="scsi-hd") log('') target0 = Drive(backup_path, vm=vm)
tests/qemu-iotests/257.out +0 -44
176 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v10 11/14 block/io: refactor wait_serialising_requests
In reply to Vladimir Sementsov-OgievskiySplit out do_wait_serialising_requests with additional possibility to not actually wait but just check, that there is something to wait for.
--- block/io.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
block/io.c +16 -8
@@ -785,12 +785,13 @@ void bdrv_dec_in_flight(BlockDriverState *bs)bdrv_wakeup (bs); } -static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self) +static bool coroutine_fn do_wait_serialising_requests(BdrvTrackedRequest *self, +bool wait) {BlockDriverState *bs = self->bs;BdrvTrackedRequest *req;bool retry; -bool waited = false; +bool found = false;if (!atomic_read (&bs->serialising_in_flight)) {return false;
@@ -816,11 +817,13 @@ static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)* will wait for us as soon as it wakes up, then just go on * (instead of producing a deadlock in the former case). */ if (!req->waiting_for) { - self->waiting_for = req; -qemu_co_queue_wait (&req->wait_queue, &bs->reqs_lock); - self->waiting_for =NULL ; - retry = true; - waited = true; + found = true; +if (wait) { + self->waiting_for = req; +qemu_co_queue_wait (&req->wait_queue, &bs->reqs_lock); + self->waiting_for =NULL ; + retry = true; + }break ; } }
@@ -828,7 +831,12 @@ static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)qemu_co_mutex_unlock (&bs->reqs_lock); }while (retry); -return waited; +return found; +} + +static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self) +{ +return do_wait_serialising_requests (self, true); } static int bdrv_check_byte_request(BlockDriverState *bs, int64_t offset,
Signature · 1 line
2.18.0
PATCH v10 12/14 block: add lock/unlock range functions
In reply to Vladimir Sementsov-OgievskiyIntroduce lock/unlock range functionality, based on serialized requests. This is needed to refactor backup, dropping local tracked-request-like synchronization.
--- include/block/block_int.h | 4 ++++ block/io.c | 44 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-)
include/block/block_int.h +4 -0
@@ -65,6 +65,7 @@ enum BdrvTrackedRequestType {BDRV_TRACKED_WRITE ,BDRV_TRACKED_DISCARD ,BDRV_TRACKED_TRUNCATE , + BDRV_TRACKED_LOCK, }; typedef struct BdrvTrackedRequest {
@@ -947,6 +948,9 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, int coroutine_fn bdrv_co_pwritev(BdrvChild *child,int64_t offset,unsigned int bytes,QEMUIOVector *qiov,BdrvRequestFlags flags); +void *coroutine_fn bdrv_co_try_lock(BlockDriverState *bs, +int64_t offset,unsigned int bytes); +void coroutine_fn bdrv_co_unlock(void *opaque); static inline int coroutine_fn bdrv_co_pread(BdrvChild *child,int64_t offset,unsigned int bytes,void *buf,BdrvRequestFlags flags)
block/io.c +43 -1
65 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v10 13/14 block: introduce backup-top filter driver
In reply to Vladimir Sementsov-OgievskiyBackup-top filter caches write operations and does copy-before-write operations.
The driver will be used in backup instead of write-notifiers.
--- block/backup-top.h | 37 +++++++ block/backup-top.c | 244 ++++++++++++++++++++++++++++++++++++++++++++ block/Makefile.objs | 2 + 3 files changed, 283 insertions(+) create mode 100644 block/backup-top.h create mode 100644 block/backup-top.c
block/backup-top.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* backup-top filter driver +* +* The driver performs Copy-Before-Write (CBW) operation: it is injected above +* some node, and before each write it copies _old_ data to the target node. +* +* Copyright (c) 2018-2019 Virtuozzo International GmbH. +* +* Author: +* Sementsov-Ogievskiy Vladimir <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef BACKUP_TOP_H +#define BACKUP_TOP_H + +#include "block/block_int.h" + +BlockDriverState *bdrv_backup_top_append (BlockDriverState *source, +const char *filter_node_name, +Error **errp); +void bdrv_backup_top_set_bcs (BlockDriverState *bs,BlockCopyState *copy_state); +void bdrv_backup_top_drop (BlockDriverState *bs); + +#endif /* BACKUP_TOP_H */
block/backup-top.c new file +244 -0
244 lines not on this page · raw message
block/Makefile.objs +2 -0
@@ -41,6 +41,8 @@ block-obj-y += block-copy.o block-obj-y += crypto.o +block-obj-y += backup-top.o + common-obj-y += stream.o nfs.o-libs := $(LIBNFS_LIBS)
Signature · 1 line
2.18.0
Re: [Qemu-devel] [PATCH v10 13/14] block: introduce backup-top filter driver
Quoted 5 lines · Vladimir Sementsov-Ogievskiy
Backup-top filter caches write operations and does copy-before-write operations.
The driver will be used in backup instead of write-notifiers.
Quoted 8 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/backup-top.h | 37 +++++++ block/backup-top.c | 244 ++++++++++++++++++++++++++++++++++++++++++++ block/Makefile.objs | 2 + 3 files changed, 283 insertions(+) create mode 100644 block/backup-top.h create mode 100644 block/backup-top.c
PATCH v10 14/14 block/backup: use backup-top instead of write notifiers
In reply to Vladimir Sementsov-OgievskiyDrop 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. Intersecting requests handling changed, now synchronization between backup-top, backup and guest writes are all done in block/block-copy.c and works as follows:
On copy operation, we work only with dirty areas. If bits are dirty it means that there are no requests intersecting with this area. We clear dirty bits and take bdrv range lock (bdrv_co_try_lock) on this area to prevent further operations from interaction with guest (only with guest, as neither backup nor backup-top will touch non-dirty area). If copy-operation failed we set dirty bits back together with releasing the lock.
The actual difference with old scheme is that on guest writes we don't lock the whole region but only dirty-parts, and to be more
precise: only dirty-part we are currently operate on. In old scheme guest write to non-dirty area (which may be safely ignored by backup) may wait for intersecting request, touching some other area which is dirty.
4. To sync with in-flight requests at job finish we now have drained removing of the filter, we don't need rw-lock.
= Notes =
Note the consequence of three objects appearing: backup-top, backup job and block-copy-state:
1. We want to insert backup-top before job creation, to behave similar with mirror and commit, where job is started upon filter.
2. We also have to create block-copy-state after filter injection, as we don't want its source child be replaced by filter. Instead we want to keep BCS.source to be real source node, as we want to use bdrv_co_try_lock in CBW operations and it can't be used on filter, as on filter we already have in-flight (write) request from upper layer.
So, we firstly create inject backup-top, then create job and BCS. BCS is the latest just to not create extra variable for it. Finally we set bcs for backup-top filter.
= 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.
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.
--- qapi/block-core.json | 8 +- include/block/block-copy.h | 10 +- include/block/block_int.h | 1 + block/backup-top.c | 14 +- block/backup.c | 113 +++----------- block/block-copy.c | 45 ++++-- block/replication.c | 2 +- blockdev.c | 1 + tests/qemu-iotests/056 | 8 +- tests/qemu-iotests/257 | 7 +- tests/qemu-iotests/257.out | 306 ++++++++++++++++++------------------- 11 files changed, 238 insertions(+), 277 deletions(-)
qapi/block-core.json +7 -1
@@ -1391,6 +1391,11 @@ # list without user intervention. # Defaults to true. (Since 2.12) # +# @filter-node-name: the node name that should be assigned to the +# filter driver that the backup job inserts into the graph +# above node specified by @drive. If this option is not given, +# a node name is autogenerated. (Since: 4.2) +# # Note: @on-source-error and @on-target-error only affect background # I/O. If an error occurs during a guest write request, the device's # rerror/werror actions will be used.
@@ -1404,7 +1409,8 @@ '*compress': 'bool', '*on-source-error': 'BlockdevOnError', '*on-target-error': 'BlockdevOnError', - '*auto-finalize': 'bool', '*auto-dismiss': 'bool' } } + '*auto-finalize': 'bool', '*auto-dismiss': 'bool', + '*filter-node-name': 'str' } } ## # @DriveBackup:
include/block/block-copy.h +9 -1
@@ -20,6 +20,14 @@typedef void (*ProgressBytesCallbackFunc )(int64_t bytes,void *opaque);typedef void (*ProgressResetCallbackFunc )(void *opaque); typedef struct BlockCopyState { + /* + * block-copy shares WRITE permission on source, but it relies on user to + * guarantee that nobody is touching dirty areas. + * + * For backup job this is guaranteed by backup-top filter, which don't share + * WRITE permission and calls block_copy on any write, so it will handle + * dirty areas by itself. + */ BlockBackend *source; BlockBackend *target; BdrvDirtyBitmap *copy_bitmap;
@@ -62,6 +70,6 @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count); 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);#endif /* BLOCK_COPY_H */
include/block/block_int.h +1 -0
@@ -1179,6 +1179,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,BdrvDirtyBitmap *sync_bitmap, BitmapSyncMode bitmap_mode, bool compress, + const char *filter_node_name, BlockdevOnError on_source_error, BlockdevOnError on_target_error, int creation_flags,
block/backup-top.c +5 -9
@@ -49,15 +49,11 @@ static coroutine_fn int backup_top_co_preadv( static coroutine_fn int backup_top_cbw(BlockDriverState *bs, uint64_t offset,uint64_t bytes) { -/* -* Here we'd like to use block_copy(), but it needs some additional -* synchronization mechanism to prevent intersecting guest writes during -* copy operation. The will appear in further commit (it should be done -* together with moving backup to using of backup-top and to the same -* synchronization mechanism), and for now it is a TODO. -*/ - -abort (); +BDRVBackupTopState *s = bs->opaque; +uint64_t end =QEMU_ALIGN_UP (offset + bytes, s->bcs->cluster_size); +uint64_t off =QEMU_ALIGN_DOWN (offset, s->bcs->cluster_size); + +return block_copy (s->bcs, off, end - off,NULL ); } static int coroutine_fn backup_top_co_pdiscard(BlockDriverState *bs,
block/backup.c +23 -90
227 lines not on this page · raw message
block/block-copy.c +29 -16
113 lines not on this page · raw message
block/replication.c +1 -1
@@ -543,7 +543,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, s->backup_job =backup_job_create (NULL , s->secondary_disk->bs, s->hidden_disk->bs, -0 ,MIRROR_SYNC_MODE_NONE ,NULL ,0 , false, +0 ,MIRROR_SYNC_MODE_NONE ,NULL ,0 , false,NULL ,BLOCKDEV_ON_ERROR_REPORT ,BLOCKDEV_ON_ERROR_REPORT ,JOB_INTERNAL , backup_job_completed, bs,NULL , &local_err);
blockdev.c +1 -0
@@ -3601,6 +3601,7 @@ static BlockJob *do_backup_common(BackupCommon *backup, job =backup_job_create (backup->job_id, bs, target_bs, backup->speed, backup->sync, bmap, backup->bitmap_mode, backup->compress, + backup->filter_node_name, backup->on_source_error, backup->on_target_error, job_flags,NULL ,NULL , txn, errp);
tests/qemu-iotests/056 +5 -3
@@ -133,6 +133,7 @@ class BackupTest(iotests.QMPTestCase): self.vm = iotests.VM() self.test_img = img_create('test') self.dest_img = img_create('dest') + self.dest_img2 = img_create('dest2') self.ref_img = img_create('ref') self.vm.add_drive(self.test_img) self.vm.launch()
@@ -141,6 +142,7 @@ class BackupTest(iotests.QMPTestCase): self.vm.shutdown() try_remove(self.test_img) try_remove(self.dest_img) + try_remove(self.dest_img2) try_remove(self.ref_img) def hmp_io_writes(self, drive, patterns):
@@ -253,9 +255,9 @@ class BackupTest(iotests.QMPTestCase): res = self.vm.qmp('query-block-jobs') self.assert_qmp(res, 'return[0]/status', 'concluded') # Leave zombie job un-dismissed, observe a failure: - res = self.qmp_backup_and_wait(serror="Node 'drive0' is busy: block device is in use by block job: backup", + res = self.qmp_backup_and_wait(serror="Job ID 'drive0' already in use", device='drive0', format=iotests.imgfmt, - sync='full', target=self.dest_img, + sync='full', target=self.dest_img2, auto_dismiss=False) self.assertEqual(res, False) # OK, dismiss the zombie.
@@ -265,7 +267,7 @@ class BackupTest(iotests.QMPTestCase): self.assert_qmp(res, 'return', []) # Ensure it's really gone. self.qmp_backup_and_wait(device='drive0', format=iotests.imgfmt, - sync='full', target=self.dest_img, + sync='full', target=self.dest_img2, auto_dismiss=False) def dismissal_failure(self, dismissal_opt):
tests/qemu-iotests/257 +4 -3
@@ -190,6 +190,7 @@ def blockdev_backup(vm, device, target, sync, **kwargs): device=device, target=target, sync=sync, + filter_node_name='backup-top', **kwargs) return result
@@ -216,7 +217,7 @@ def backup(drive, n, filepath, sync, **kwargs): job_id=job_id, **kwargs) return job_id -def perform_writes(drive, n): +def perform_writes(drive, n, filter_node_name=None): log("--- Write #{:d} ---\n".format(n)) for pattern in GROUPS[n].patterns: cmd = "write -P{:s} 0x{:07x} 0x{:x}".format(
@@ -224,7 +225,7 @@ def perform_writes(drive, n): pattern.offset, pattern.size) log(cmd) - log(drive.vm.hmp_qemu_io(drive.node, cmd)) + log(drive.vm.hmp_qemu_io(filter_node_name or drive.node, cmd)) bitmaps = drive.vm.query_bitmaps() log({'bitmaps': bitmaps}, indent=2) log('')
@@ -355,7 +356,7 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None): """Issue writes while the job is open to test bitmap divergence.""" # Note: when `failure` is 'intermediate', this isn't called. log('') - bitmaps = perform_writes(drive0, 2) + bitmaps = perform_writes(drive0, 2, filter_node_name='backup-top') # Named bitmap (static, should be unchanged) ebitmap.compare(vm.get_bitmap(drive0.node, 'bitmap0', bitmaps=bitmaps))
tests/qemu-iotests/257.out +153 -153
1,043 lines not on this page · raw message
Signature · 1 line
2.18.0
Re: [Qemu-devel] [PATCH v10 14/14] block/backup: use backup-top instead of write notifiers
Quoted 68 lines · Vladimir Sementsov-Ogievskiy
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_notifierparameter is dropped from block-copy paths.3. Intersecting requests handling changed, now synchronization between backup-top, backup and guest writes are all done in
block/block-copy.cand works as follows:On copy operation, we work only with dirty areas. If bits are dirty it means that there are no requests intersecting with this area. We clear dirty bits and take bdrv range lock (
bdrv_co_try_lock) on this area to prevent further operations from interaction with guest (only with guest, as neither backup nor backup-top will touch non-dirty area). If copy-operation failed we set dirty bits back together with releasing the lock.The actual difference with old scheme is that on guest writes we don't lock the whole region but only dirty-parts, and to be more
precise: only dirty-part we are currently operate on. In old scheme guest write to non-dirty area (which may be safely ignored by backup) may wait for intersecting request, touching some other area which is dirty.4. To sync with in-flight requests at job finish we now have drained removing of the filter, we don't need rw-lock.
= Notes =
Note the consequence of three objects appearing: backup-top, backup job and block-copy-state:
1. We want to insert backup-top before job creation, to behave similar with mirror and commit, where job is started upon filter.
2. We also have to create block-copy-state after filter injection, as we don't want its source child be replaced by filter. Instead we want to keep BCS.source to be real source node, as we want to use
bdrv_co_try_lockin CBW operations and it can't be used on filter, as on filter we already have in-flight (write) request from upper layer.So, we firstly create inject backup-top, then create job and BCS. BCS is the latest just to not create extra variable for it. Finally we set bcs for backup-top filter.
= 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.
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 <[email protected]>
Quoted 13 lines
--- qapi/block-core.json | 8 +- include/block/block-copy.h | 10 +- include/block/block_int.h | 1 + block/backup-top.c | 14 +- block/backup.c | 113 +++----------- block/block-copy.c | 45 ++++-- block/replication.c | 2 +- blockdev.c | 1 + tests/qemu-iotests/056 | 8 +- tests/qemu-iotests/257 | 7 +- tests/qemu-iotests/257.out | 306 ++++++++++++++++++------------------- 11 files changed, 238 insertions(+), 277 deletions(-)