Would this also solve https://gitlab.com/qemu-project/qemu/-/issues/2909 perhaps?

On 20/01/2026 18:20, Polina Vishneva wrote:
Marking the bitmaps that are found in_use in the image as inconsistent
works in the most cases. However, in some cases, like migration,
it's critical for bdrv_dirty_bitmap_check() to always pass.

Instead of asking the user to manually request the deletion of
inconsistent bitmaps, delete them automatically if we can,
while respecting the possible edge cases like repairing an image with
overlaps.

Originally-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Signed-off-by: Polina Vishneva <[email protected]>
---
  block/qcow2-bitmap.c                          | 111 ++++++++++++++++--
  block/qcow2.c                                 |   9 ++
  block/qcow2.h                                 |   2 +
  tests/qemu-iotests/tests/migrate-bitmaps-test |   2 +
  tests/qemu-iotests/tests/qemu-img-bitmaps     |   2 +-
  tests/qemu-iotests/tests/qemu-img-bitmaps.out |  36 +++---
  .../qemu-iotests/tests/qemu-img-close-errors  |   3 +-
  7 files changed, 132 insertions(+), 33 deletions(-)

diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 256ec99878..6ab857ad1a 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -1008,6 +1052,32 @@ qcow2_load_dirty_bitmaps(BlockDriverState *bs,
              continue;
          }
+ if ((bm->flags & BME_FLAG_IN_USE) && can_write(bs) &&
+            !(s->flags & BDRV_O_CHECK))
+        {
+            /*
+             * Remove inconsistent bitmaps.
+             * This is to avoid errors on migrations, when
+             * whenbdrv_dirty_bitmap_check() could be called on a bitmap
Small typo here btw :)
+             * marked as inconsistent, causing an error and requiring the user
+             * to manually request inconsistent bitmap deletion.
+             *
+             * In case we have a corrupted image, there's no guarantee that
+             * update_ext_header_and_dir() will succeed.
+             * This would render some images impossible to repair.
+             * Therefore, skip it on the image open if we're in the check mode
+             * (and do it later when the image is successfully repaired).
+             */
+            qemu_log("Removing inconsistent bitmap '%s' at image '%s'\n",
+                     bm->name, bs->filename);
+
+            QSIMPLEQ_REMOVE(bm_list, bm, Qcow2Bitmap, entry);
+            free_bitmap_clusters(bs, &bm->table);
+            bitmap_free(bm);
+            removed_persistent_bitmaps = true;
+            continue;
+        }
+
          bitmap = load_bitmap(bs, bm, errp);
          if (bitmap == NULL) {
              goto fail;


Thanks
Jean-Louis


Reply via email to