Skip to content

Commit 6e9f21a

Browse files
pipoebblake
authored andcommitted
migration: dirty-bitmap: Allow control of bitmap persistence
Bitmap's source persistence is transported over the migration stream and the destination mirrors it. In some cases the destination might want to persist bitmaps which are not persistent on the source (e.g. the result of merging bitmaps from a number of layers on the source when migrating into a squashed image) but currently it would need to create another set of persistent bitmaps and merge them. This patch adds a 'transform' property to the alias map which allows overriding the persistence of migrated bitmaps both on the source and destination sides. Signed-off-by: Peter Krempa <[email protected]> Message-Id: <b20afb675917b86f6359ac3591166ac6d4233573.1613150869.git.pkrempa@redhat.com> Reviewed-by: Eric Blake <[email protected]> [eblake: grammar tweaks, drop dead conditional] Signed-off-by: Eric Blake <[email protected]>
1 parent 0d1e450 commit 6e9f21a

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

migration/block-dirty-bitmap.c

+26-3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ typedef struct DBMLoadState {
150150
BdrvDirtyBitmap *bitmap;
151151

152152
bool before_vm_start_handled; /* set in dirty_bitmap_mig_before_vm_start */
153+
BitmapMigrationBitmapAlias *bmap_inner;
153154

154155
/*
155156
* cancelled
@@ -529,6 +530,7 @@ static int add_bitmaps_to_list(DBMSaveState *s, BlockDriverState *bs,
529530
}
530531

531532
FOR_EACH_DIRTY_BITMAP(bs, bitmap) {
533+
BitmapMigrationBitmapAliasTransform *bitmap_transform = NULL;
532534
bitmap_name = bdrv_dirty_bitmap_name(bitmap);
533535
if (!bitmap_name) {
534536
continue;
@@ -549,6 +551,9 @@ static int add_bitmaps_to_list(DBMSaveState *s, BlockDriverState *bs,
549551
}
550552

551553
bitmap_alias = bmap_inner->alias;
554+
if (bmap_inner->has_transform) {
555+
bitmap_transform = bmap_inner->transform;
556+
}
552557
} else {
553558
if (strlen(bitmap_name) > UINT8_MAX) {
554559
error_report("Cannot migrate bitmap '%s' on node '%s': "
@@ -574,8 +579,15 @@ static int add_bitmaps_to_list(DBMSaveState *s, BlockDriverState *bs,
574579
if (bdrv_dirty_bitmap_enabled(bitmap)) {
575580
dbms->flags |= DIRTY_BITMAP_MIG_START_FLAG_ENABLED;
576581
}
577-
if (bdrv_dirty_bitmap_get_persistence(bitmap)) {
578-
dbms->flags |= DIRTY_BITMAP_MIG_START_FLAG_PERSISTENT;
582+
if (bitmap_transform &&
583+
bitmap_transform->has_persistent) {
584+
if (bitmap_transform->persistent) {
585+
dbms->flags |= DIRTY_BITMAP_MIG_START_FLAG_PERSISTENT;
586+
}
587+
} else {
588+
if (bdrv_dirty_bitmap_get_persistence(bitmap)) {
589+
dbms->flags |= DIRTY_BITMAP_MIG_START_FLAG_PERSISTENT;
590+
}
579591
}
580592

581593
QSIMPLEQ_INSERT_TAIL(&s->dbms_list, dbms, entry);
@@ -783,6 +795,7 @@ static int dirty_bitmap_load_start(QEMUFile *f, DBMLoadState *s)
783795
uint32_t granularity = qemu_get_be32(f);
784796
uint8_t flags = qemu_get_byte(f);
785797
LoadBitmapState *b;
798+
bool persistent;
786799

787800
if (s->cancelled) {
788801
return 0;
@@ -807,7 +820,15 @@ static int dirty_bitmap_load_start(QEMUFile *f, DBMLoadState *s)
807820
return -EINVAL;
808821
}
809822

810-
if (flags & DIRTY_BITMAP_MIG_START_FLAG_PERSISTENT) {
823+
if (s->bmap_inner &&
824+
s->bmap_inner->has_transform &&
825+
s->bmap_inner->transform->has_persistent) {
826+
persistent = s->bmap_inner->transform->persistent;
827+
} else {
828+
persistent = flags & DIRTY_BITMAP_MIG_START_FLAG_PERSISTENT;
829+
}
830+
831+
if (persistent) {
811832
bdrv_dirty_bitmap_set_persistence(s->bitmap, true);
812833
}
813834

@@ -1091,6 +1112,8 @@ static int dirty_bitmap_load_header(QEMUFile *f, DBMLoadState *s,
10911112
} else {
10921113
bitmap_name = bmap_inner->name;
10931114
}
1115+
1116+
s->bmap_inner = bmap_inner;
10941117
}
10951118

10961119
if (!s->cancelled) {

qapi/migration.json

+18-1
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,19 @@
536536
'data': [ 'none', 'zlib',
537537
{ 'name': 'zstd', 'if': 'defined(CONFIG_ZSTD)' } ] }
538538

539+
##
540+
# @BitmapMigrationBitmapAliasTransform:
541+
#
542+
# @persistent: If present, the bitmap will be made persistent
543+
# or transient depending on this parameter.
544+
#
545+
# Since: 6.0
546+
##
547+
{ 'struct': 'BitmapMigrationBitmapAliasTransform',
548+
'data': {
549+
'*persistent': 'bool'
550+
} }
551+
539552
##
540553
# @BitmapMigrationBitmapAlias:
541554
#
@@ -544,12 +557,16 @@
544557
# @alias: An alias name for migration (for example the bitmap name on
545558
# the opposite site).
546559
#
560+
# @transform: Allows the modification of the migrated bitmap.
561+
# (since 6.0)
562+
#
547563
# Since: 5.2
548564
##
549565
{ 'struct': 'BitmapMigrationBitmapAlias',
550566
'data': {
551567
'name': 'str',
552-
'alias': 'str'
568+
'alias': 'str',
569+
'*transform': 'BitmapMigrationBitmapAliasTransform'
553570
} }
554571

555572
##

0 commit comments

Comments
 (0)