[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 07/18] hbitmap: Fix merge when b is empty, and re
From: |
John Snow |
Subject: |
[Qemu-devel] [PATCH v3 07/18] hbitmap: Fix merge when b is empty, and result is not an alias of a |
Date: |
Fri, 5 Jul 2019 16:16:20 -0400 |
Nobody calls the function like this currently, but we neither prohibit
or cope with this behavior. I decided to make the function cope with it.
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: John Snow <address@hidden>
---
util/hbitmap.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 7905212a8b..3b6acae42b 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -781,8 +781,9 @@ bool hbitmap_can_merge(const HBitmap *a, const HBitmap *b)
}
/**
- * Given HBitmaps A and B, let A := A (BITOR) B.
- * Bitmap B will not be modified.
+ * Given HBitmaps A and B, let R := A (BITOR) B.
+ * Bitmaps A and B will not be modified,
+ * except when bitmap R is an alias of A or B.
*
* @return true if the merge was successful,
* false if it was not attempted.
@@ -797,7 +798,13 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b,
HBitmap *result)
}
assert(hbitmap_can_merge(b, result));
- if (hbitmap_count(b) == 0) {
+ if ((!hbitmap_count(a) && result == b) ||
+ (!hbitmap_count(b) && result == a)) {
+ return true;
+ }
+
+ if (!hbitmap_count(a) && !hbitmap_count(b)) {
+ hbitmap_reset_all(result);
return true;
}
--
2.21.0
- [Qemu-devel] [PATCH v3 02/18] drive-backup: create do_backup_common, (continued)
- [Qemu-devel] [PATCH v3 02/18] drive-backup: create do_backup_common, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 04/18] qapi: add BitmapSyncMode enum, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 05/18] block/backup: Add mirror sync mode 'bitmap', John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 06/18] block/backup: add 'never' policy to bitmap sync mode, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 08/18] hbitmap: enable merging across granularities, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 09/18] block/dirty-bitmap: add bdrv_dirty_bitmap_merge_internal, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 07/18] hbitmap: Fix merge when b is empty, and result is not an alias of a,
John Snow <=
- [Qemu-devel] [PATCH v3 10/18] block/dirty-bitmap: add bdrv_dirty_bitmap_get, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 12/18] block/backup: add 'always' bitmap sync policy, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 11/18] block/backup: upgrade copy_bitmap to BdrvDirtyBitmap, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 13/18] iotests: add testing shim for script-style python tests, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 14/18] iotests: teach run_job to cancel pending jobs, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 15/18] iotests: teach FilePath to produce multiple paths, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 16/18] iotests: Add virtio-scsi device helper, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 18/18] block/backup: loosen restriction on readonly bitmaps, John Snow, 2019/07/05
- [Qemu-devel] [PATCH v3 17/18] iotests: add test 257 for bitmap-mode backups, John Snow, 2019/07/05