migration: add incremental mode on drive-mirror
PATCH 1/1 migration: add incremental mode on drive-mirror
From: mahaocong <[email protected]>
Hi all,
This patch adds possibility to start mirroring with specific dirty-bitmap. The use-case is, for live migration with ceph rbd image.
1.create rbd image in ceph cluster, and map nbd device with rbd image. 2.create a new bitmap attached to drive.
3.create a full backup on nbd device and sync it to the rbd image. 4.create new image in destination host and set it's backingfile as rbd image. 5.start incremental mirroring to destination with dirty-bitmap from step 2. 6.live migrate VM to destination, bitmap should be migrated too. 7.unmap nbd in source host and map in destination.
Then I can use incremental backup to sync data and renew bitmap. If live migrate VM again, repeat step 4 to step 7.
mahaocong (1):
migration: add incremental mode on drive-mirror
block/dirty-bitmap.c | 14 ++++++++++ block/mirror.c | 63 +++++++++++++++++++++++++++++++++++--------- blockdev.c | 36 +++++++++++++++++++++++-- include/block/block_int.h | 3 ++- include/block/dirty-bitmap.h | 3 +++ include/qemu/hbitmap.h | 2 ++ qapi/block-core.json | 4 ++- util/hbitmap.c | 28 ++++++++++++++++++++ 8 files changed, 136 insertions(+), 17 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/1 migration: add incremental mode on drive-mirror
From: mahaocong <[email protected]>
--- block/dirty-bitmap.c | 14 ++++++++++ block/mirror.c | 63 +++++++++++++++++++++++++++++++++++--------- blockdev.c | 36 +++++++++++++++++++++++-- include/block/block_int.h | 3 ++- include/block/dirty-bitmap.h | 3 +++ include/qemu/hbitmap.h | 2 ++ qapi/block-core.json | 4 ++- util/hbitmap.c | 28 ++++++++++++++++++++ 8 files changed, 136 insertions(+), 17 deletions(-)
block/dirty-bitmap.c +14 -0
@@ -348,6 +348,20 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,return ret; } +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap_locked (BdrvDirtyBitmap *src, +BdrvDirtyBitmap *dest, +Error **errp) +{ +qemu_mutex_lock (src->mutex); +if (!hbitmap_copy (dest->bitmap, src->bitmap)) { +error_setg (errp,"Error: copy src bitmap failed" ); +return NULL ; + } +qemu_mutex_unlock (src->mutex); + +return dest; +} +/** * Truncates _all_ bitmaps attached to a BDS. * Called with BQL taken.
block/mirror.c +50 -13
123 lines not on this page · raw message
blockdev.c +34 -2
@@ -3663,6 +3663,8 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,BlockDriverState *target, bool has_replaces, const char *replaces, enum MirrorSyncMode sync, + bool has_bitmap_name, + const char *bitmap_name, BlockMirrorBackingMode backing_mode, bool has_speed, int64_t speed, bool has_granularity, uint32_t granularity,
@@ -3680,6 +3682,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs, Error **errp) {int job_flags =JOB_DEFAULT ; +BdrvDirtyBitmap *src_bitmap;if (!has_speed) { speed =0 ;
@@ -3702,6 +3705,23 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,if (!has_filter_node_name) { filter_node_name =NULL ; } +if (!has_bitmap_name) { + bitmap_name =NULL ; + } +/* +* In incremental mode, we should create null name bitmap by +* using user bitmap's granularity. +*/ +if (sync ==MIRROR_SYNC_MODE_INCREMENTAL && bitmap_name !=NULL ) { + src_bitmap =bdrv_find_dirty_bitmap (bs, bitmap_name); +if (!src_bitmap) { +error_setg (errp,"Error: can't find dirty bitmap " +"before start incremental drive-mirror" ); +return ; + } + granularity =bdrv_dirty_bitmap_granularity (src_bitmap); + } +if (!has_copy_mode) { copy_mode =MIRROR_COPY_MODE_BACKGROUND ; }
@@ -3739,7 +3759,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,*/ mirror_start (job_id, bs, target, has_replaces ? replaces :NULL , job_flags, - speed, granularity, buf_size, sync, backing_mode, + speed, granularity, buf_size, sync, bitmap_name, backing_mode, on_source_error, on_target_error, unmap, filter_node_name, copy_mode, errp); }
@@ -3786,6 +3806,16 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)if (arg->sync ==MIRROR_SYNC_MODE_NONE ) { source = bs; } +if ((arg->sync ==MIRROR_SYNC_MODE_INCREMENTAL ) && + (!arg->has_bitmap_name)) { +error_setg (errp,"incremental mode must specify the bitmap name" ); + goto out; + } +if ((arg->sync ==MIRROR_SYNC_MODE_INCREMENTAL ) && + (arg->has_granularity)) { +error_setg (errp,"incremental mode can not set bitmap granularity" ); + goto out; + } size =bdrv_getlength (bs);if (size <0 ) {
@@ -3880,6 +3910,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs, arg->has_replaces, arg->replaces, arg->sync, + arg->has_bitmap_name, arg->bitmap_name, backing_mode, arg->has_speed, arg->speed, arg->has_granularity, arg->granularity, arg->has_buf_size, arg->buf_size,
@@ -3937,7 +3968,8 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,bdrv_set_aio_context (target_bs, aio_context); blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs, - has_replaces, replaces, sync, backing_mode, + has_replaces, replaces, sync, false, NULL, + backing_mode, has_speed, speed, has_granularity, granularity, has_buf_size, buf_size,
include/block/block_int.h +2 -1
@@ -1054,7 +1054,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, const char *bitmap_name, + BlockMirrorBackingMode backing_mode, BlockdevOnError on_source_error, BlockdevOnError on_target_error, bool unmap, const char *filter_node_name,
include/block/dirty-bitmap.h +3 -0
@@ -21,6 +21,9 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap (BlockDriverState *bs,BdrvDirtyBitmap *bitmap,Error **errp); +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap_locked (BdrvDirtyBitmap *src, +BdrvDirtyBitmap *dest, +Error **errp);void bdrv_dirty_bitmap_enable_successor (BdrvDirtyBitmap *bitmap);BdrvDirtyBitmap *bdrv_find_dirty_bitmap (BlockDriverState *bs,const char *name);
include/qemu/hbitmap.h +2 -0
@@ -91,6 +91,8 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result);*/ bool hbitmap_can_merge (const HBitmap *a,const HBitmap *b); +bool hbitmap_copy (HBitmap *dst,const HBitmap *src); +/** * hbitmap_empty: * @hb: HBitmap to operate on.
qapi/block-core.json +3 -1
@@ -1727,6 +1727,8 @@ # (all the disk, only the sectors allocated in the topmost image, or # only new I/O). # +# @bitmap-name: the bitmap to be used in incremental mode. +# # @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
@@ -1768,7 +1770,7 @@ { 'struct': 'DriveMirror', 'data': { '*job-id': 'str', 'device': 'str', 'target': 'str', '*format': 'str', '*node-name': 'str', '*replaces': 'str', - 'sync': 'MirrorSyncMode', '*mode': 'NewImageMode', + 'sync': 'MirrorSyncMode', '*bitmap-name': 'str', '*mode': 'NewImageMode', '*speed': 'int', '*granularity': 'uint32', '*buf-size': 'int', '*on-source-error': 'BlockdevOnError', '*on-target-error': 'BlockdevOnError',
util/hbitmap.c +28 -0
@@ -765,6 +765,34 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result)return true; } +/* +* Copy HBitmaps form src to dst. +* +* @return true if the copy was successful, +* false if it was not attempted. +*/ +bool hbitmap_copy (HBitmap *dst,const HBitmap *src) +{ +int i; + +if ((dst->size != src->size) || (dst->granularity != src->granularity)) { +return false; + } + +if (hbitmap_count (src) ==0 ) { +return true; + } + +for (i =HBITMAP_LEVELS -1 ; i >=0 ; i--) { +memcpy (dst->levels[i], src->levels[i], + src->sizes[i] *sizeof (unsigned long )); + } + + dst->count = src->count; +return true; +} + +HBitmap *hbitmap_create_meta (HBitmap *hb,int chunk_size) {assert (!(chunk_size & (chunk_size -1 )));
Signature · 1 line
1.8.3.1
Quoted 3 lines · mahaocong
From: mahaocong <[email protected]>
Signed-off-by mahaocong <[email protected]>
The subject line tells "what", but you are missing a commit message body that gives the "why". Details about the new feature, and how it is useful, go a long way to making the code easier to review. How much of your cover letter should be here as well?
At a first glance, I'm just going to focus on the interface:
Quoted 14 lines
--- block/dirty-bitmap.c | 14 ++++++++++ block/mirror.c | 63 +++++++++++++++++++++++++++++++++++--------- blockdev.c | 36 +++++++++++++++++++++++-- include/block/block_int.h | 3 ++- include/block/dirty-bitmap.h | 3 +++ include/qemu/hbitmap.h | 2 ++ qapi/block-core.json | 4 ++- util/hbitmap.c | 28 ++++++++++++++++++++ 8 files changed, 136 insertions(+), 17 deletions(-)+++
b/qapi/block-core.json
qapi/block-core.json line 1730
Quoted 4 lines
qapi/block-core.json +1
-0@@ -1727,6 +1727,8 @@ # (all the disk, only the sectors allocated in the topmost image, or # only new I/O). # +# @bitmap-name: the bitmap to be used in incremental mode.
Missing a '(since 4.0)' tag. And doesn't really explain what incremental mode in a mirroring operation actually means.
qapi/block-core.json line 1773
Quoted 10 lines
qapi/block-core.json +2
-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@@ -1768,7 +1770,7 @@ { 'struct': 'DriveMirror', 'data': { '*job-id': 'str', 'device': 'str', 'target': 'str', '*format': 'str', '*node-name': 'str', '*replaces': 'str', - 'sync': 'MirrorSyncMode', '*mode': 'NewImageMode', + 'sync': 'MirrorSyncMode', '*bitmap-name': 'str', '*mode': 'NewImageMode',
Can this be named just 'bitmap', instead of the longer 'bitmap-name'?
Quoted 6 lines
qapi/block-core.json +0
-0'*speed': 'int', '*granularity': 'uint32', '*buf-size': 'int', '*on-source-error': 'BlockdevOnError', '*on-target-error': 'BlockdevOnError',util/hbitmap.c +0
-1--- a/util/hbitmap.c
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
I redescribe details on cover letter and send a new mail in December 20, 2018. Please help me review again, thank you.
在 2018/12/19 下午10:48,“Eric Blake”<[email protected]> 写入:
On 12/19/18 12:50 AM, mahaocong wrote:
> From: mahaocong <[email protected]> >
> Signed-off-by: mahaocong <[email protected]>
The subject line tells "what", but you are missing a commit message body that gives the "why". Details about the new feature, and how it is useful, go a long way to making the code easier to review. How much of your cover letter should be here as well?
At a first glance, I'm just going to focus on the interface:
> ---
> block/dirty-bitmap.c | 14 ++++++++++
> block/mirror.c | 63 +++++++++++++++++++++++++++++++++++---------
> blockdev.c | 36 +++++++++++++++++++++++--
> include/block/block_int.h | 3 ++-
> include/block/dirty-bitmap.h | 3 +++
> include/qemu/hbitmap.h | 2 ++
> qapi/block-core.json | 4 ++-
> util/hbitmap.c | 28 ++++++++++++++++++++
> 8 files changed, 136 insertions(+), 17 deletions(-)
>
> +++ b/qapi/block-core.json
> @@ -1727,6 +1727,8 @@
> # (all the disk, only the sectors allocated in the topmost image, or
> # only new I/O).
> #
> +# @bitmap-name: the bitmap to be used in incremental mode.
Missing a '(since 4.0)' tag. And doesn't really explain what incremental mode in a mirroring operation actually means.
> +#
> # @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
> @@ -1768,7 +1770,7 @@
> { 'struct': 'DriveMirror',
> 'data': { '*job-id': 'str', 'device': 'str', 'target': 'str',
> '*format': 'str', '*node-name': 'str', '*replaces': 'str',
> - 'sync': 'MirrorSyncMode', '*mode': 'NewImageMode',
> + 'sync': 'MirrorSyncMode', '*bitmap-name': 'str', '*mode': 'NewImageMode',
Can this be named just 'bitmap', instead of the longer 'bitmap-name'?
> '*speed': 'int', '*granularity': 'uint32',
> '*buf-size': 'int', '*on-source-error': 'BlockdevOnError',
> '*on-target-error': 'BlockdevOnError',
> diff --git a/util/hbitmap.c b/util/hbitmap.c > index 8d402c5..7ae2fc2 100644
> --- a/util/hbitmap.c
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org