Fiona Ebner <f.eb...@proxmox.com> writes: > From: John Snow <js...@redhat.com> > > for the mirror job. The bitmap's granularity is used as the job's > granularity. > > The new @bitmap parameter is marked unstable in the QAPI and can > currently only be used for @sync=full mode. > > Clusters initially dirty in the bitmap as well as new writes are > copied to the target. > > Using block-dirty-bitmap-clear and block-dirty-bitmap-merge API, > callers can simulate the three kinds of @BitmapSyncMode (which is used > by backup): > 1. always: default, just pass bitmap as working bitmap. > 2. never: copy bitmap and pass copy to the mirror job. > 3. on-success: copy bitmap and pass copy to the mirror job and if > successful, merge bitmap into original afterwards. > > When the target image is a non-COW "diff image", i.e. one that was not > used as the target of a previous mirror and the target image's cluster > size is larger than the bitmap's granularity, or when > @copy-mode=write-blocking is used, there is a pitfall, because the > cluster in the target image will be allocated, but not contain all the > data corresponding to the same region in the source image. > > An idea to avoid the limitation would be to mark clusters which are > affected by unaligned writes and are not allocated in the target image > dirty, so they would be copied fully later. However, for migration, > the invariant that an actively synced mirror stays actively synced > (unless an error happens) is useful, because without that invariant, > migration might inactivate block devices when mirror still got work > to do and run into an assertion failure [0]. > > Another approach would be to read the missing data from the source > upon unaligned writes to be able to write the full target cluster > instead. > > But certain targets like NBD do not allow querying the cluster size. > To avoid limiting/breaking the use case of syncing to an existing > target, which is arguably more common than the diff image use case, > document the limitation in QAPI. > > This patch was originally based on one by Ma Haocong, but it has since > been modified pretty heavily, first by John and then again by Fiona. > > [0]: > https://lore.kernel.org/qemu-devel/1db7f571-cb7f-c293-04cc-cd856e060...@proxmox.com/ > > Suggested-by: Ma Haocong <mahaoc...@didichuxing.com> > Signed-off-by: Ma Haocong <mahaoc...@didichuxing.com> > Signed-off-by: John Snow <js...@redhat.com> > [FG: switch to bdrv_dirty_bitmap_merge_internal] > Signed-off-by: Fabian Grünbichler <f.gruenbich...@proxmox.com> > Signed-off-by: Thomas Lamprecht <t.lampre...@proxmox.com> > [FE: rebase for 9.1 > get rid of bitmap mode parameter > use caller-provided bitmap as working bitmap > turn bitmap parameter experimental] > Signed-off-by: Fiona Ebner <f.eb...@proxmox.com>
[...] > diff --git a/include/block/block_int-global-state.h > b/include/block/block_int-global-state.h > index 54f8c8cbcb..8b93db017e 100644 > --- a/include/block/block_int-global-state.h > +++ b/include/block/block_int-global-state.h > @@ -138,6 +138,8 @@ BlockJob *commit_active_start(const char *job_id, > BlockDriverState *bs, > * @granularity: The chosen granularity for the dirty bitmap. > * @buf_size: The amount of data that can be in flight at one time. > * @mode: Whether to collapse all images in the chain to the target. > + * @bitmap: Use this bitmap as a working bitmap, i.e. non-dirty clusters are > + only mirrored if written to later. > * @backing_mode: How to establish the target's backing chain after > completion. > * @zero_target: Whether the target should be explicitly zero-initialized > * @on_source_error: The action to take upon error reading from the source. > @@ -158,7 +160,8 @@ void mirror_start(const char *job_id, BlockDriverState > *bs, > BlockDriverState *target, const char *replaces, > int creation_flags, int64_t speed, > uint32_t granularity, int64_t buf_size, > - MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, > + MirrorSyncMode mode, BdrvDirtyBitmap *bitmap, > + BlockMirrorBackingMode backing_mode, > bool zero_target, > BlockdevOnError on_source_error, > BlockdevOnError on_target_error, > diff --git a/qapi/block-core.json b/qapi/block-core.json > index 9d94129ea2..5ddebe71ee 100644 > --- a/qapi/block-core.json > +++ b/qapi/block-core.json > @@ -2191,6 +2191,18 @@ > # destination (all the disk, only the sectors allocated in the > # topmost image, or only new I/O). > # > +# @bitmap: The name of a bitmap to use as a working bitmap for > +# sync=full mode. This argument must be not be present for other > +# sync modes and not at the same time as @granularity. The > +# bitmap's granularity is used as the job's granularity. When > +# the target does not support COW and is a diff image, i.e. one > +# that should only contain the delta and was not synced to > +# previously, the target's cluster size must not be larger than > +# the bitmap's granularity and copy-mode=write-blocking should not Comma before "and", please. > +# be used. That is, because unaligned writes will lead to Two spaces between sentences for consistency, please. Suggest "Otherwise, unaligned writes ..." > +# allocated clusters with partial data in the target image! > +# (Since 9.1) > +# > # @granularity: granularity of the dirty bitmap, default is 64K if the > # image format doesn't have clusters, 4K if the clusters are > # smaller than that, else the cluster size. Must be a power of 2 > @@ -2228,12 +2240,18 @@ > # disappear from the query list without user intervention. > # Defaults to true. (Since 3.1) > # > +# Features: > +# > +# @unstable: Member @bitmap is experimental. > +# > # Since: 1.3 > ## > { 'struct': 'DriveMirror', > 'data': { '*job-id': 'str', 'device': 'str', 'target': 'str', > '*format': 'str', '*node-name': 'str', '*replaces': 'str', > - 'sync': 'MirrorSyncMode', '*mode': 'NewImageMode', > + 'sync': 'MirrorSyncMode', > + '*bitmap': { 'type': 'str', 'features': [ 'unstable' ] }, > + '*mode': 'NewImageMode', > '*speed': 'int', '*granularity': 'uint32', > '*buf-size': 'int', '*on-source-error': 'BlockdevOnError', > '*on-target-error': 'BlockdevOnError', > @@ -2513,6 +2531,18 @@ > # destination (all the disk, only the sectors allocated in the > # topmost image, or only new I/O). > # > +# @bitmap: The name of a bitmap to use as a working bitmap for > +# sync=full mode. This argument must be not be present for other > +# sync modes and not at the same time as @granularity. The > +# bitmap's granularity is used as the job's granularity. When > +# the target does not support COW and is a diff image, i.e. one > +# that should only contain the delta and was not synced to > +# previously, the target's cluster size must not be larger than > +# the bitmap's granularity and copy-mode=write-blocking should not > +# be used. That is, because unaligned writes will lead to > +# allocated clusters with partial data in the target image! > +# (Since 9.1) Comments above apply. > +# > # @granularity: granularity of the dirty bitmap, default is 64K if the > # image format doesn't have clusters, 4K if the clusters are > # smaller than that, else the cluster size. Must be a power of 2 > @@ -2548,6 +2578,10 @@ > # disappear from the query list without user intervention. > # Defaults to true. (Since 3.1) > # > +# Features: > +# > +# @unstable: Member @bitmap is experimental. > +# > # Since: 2.6 > # > # Example: > @@ -2562,6 +2596,7 @@ > 'data': { '*job-id': 'str', 'device': 'str', 'target': 'str', > '*replaces': 'str', > 'sync': 'MirrorSyncMode', > + '*bitmap': { 'type': 'str', 'features': [ 'unstable' ] }, > '*speed': 'int', '*granularity': 'uint32', > '*buf-size': 'int', '*on-source-error': 'BlockdevOnError', > '*on-target-error': 'BlockdevOnError', [...] With my comments addressed, Acked-by: Markus Armbruster <arm...@redhat.com>