[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 26/78] qcow2-bitmaps: fix qcow2_can_store_new_dirty_bitmap
From: |
Michael Roth |
Subject: |
[PATCH 26/78] qcow2-bitmaps: fix qcow2_can_store_new_dirty_bitmap |
Date: |
Tue, 16 Jun 2020 09:14:55 -0500 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
qcow2_can_store_new_dirty_bitmap works wrong, as it considers only
bitmaps already stored in the qcow2 image and ignores persistent
BdrvDirtyBitmap objects.
So, let's instead count persistent BdrvDirtyBitmaps. We load all qcow2
bitmaps on open, so there should not be any bitmap in the image for
which we don't have BdrvDirtyBitmaps version. If it is - it's a kind of
corruption, and no reason to check for corruptions here (open() and
close() are better places for it).
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191014115126.15360-2-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Max Reitz <mreitz@redhat.com>
(cherry picked from commit a1db8733d28d615bc0daeada6c406a6dd5c5d5ef)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
block/qcow2-bitmap.c | 41 ++++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index c6c8ebbe89..d41f5d049b 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -1703,8 +1703,14 @@ bool coroutine_fn
qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs,
Error **errp)
{
BDRVQcow2State *s = bs->opaque;
- bool found;
- Qcow2BitmapList *bm_list;
+ BdrvDirtyBitmap *bitmap;
+ uint64_t bitmap_directory_size = 0;
+ uint32_t nb_bitmaps = 0;
+
+ if (bdrv_find_dirty_bitmap(bs, name)) {
+ error_setg(errp, "Bitmap already exists: %s", name);
+ return false;
+ }
if (s->qcow_version < 3) {
/* Without autoclear_features, we would always have to assume
@@ -1720,38 +1726,27 @@ bool coroutine_fn
qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs,
goto fail;
}
- if (s->nb_bitmaps == 0) {
- return true;
+ FOR_EACH_DIRTY_BITMAP(bs, bitmap) {
+ if (bdrv_dirty_bitmap_get_persistence(bitmap)) {
+ nb_bitmaps++;
+ bitmap_directory_size +=
+ calc_dir_entry_size(strlen(bdrv_dirty_bitmap_name(bitmap)), 0);
+ }
}
+ nb_bitmaps++;
+ bitmap_directory_size += calc_dir_entry_size(strlen(name), 0);
- if (s->nb_bitmaps >= QCOW2_MAX_BITMAPS) {
+ if (nb_bitmaps > QCOW2_MAX_BITMAPS) {
error_setg(errp,
"Maximum number of persistent bitmaps is already reached");
goto fail;
}
- if (s->bitmap_directory_size + calc_dir_entry_size(strlen(name), 0) >
- QCOW2_MAX_BITMAP_DIRECTORY_SIZE)
- {
+ if (bitmap_directory_size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) {
error_setg(errp, "Not enough space in the bitmap directory");
goto fail;
}
- qemu_co_mutex_lock(&s->lock);
- bm_list = bitmap_list_load(bs, s->bitmap_directory_offset,
- s->bitmap_directory_size, errp);
- qemu_co_mutex_unlock(&s->lock);
- if (bm_list == NULL) {
- goto fail;
- }
-
- found = find_bitmap_by_name(bm_list, name);
- bitmap_list_free(bm_list);
- if (found) {
- error_setg(errp, "Bitmap with the same name is already stored");
- goto fail;
- }
-
return true;
fail:
--
2.17.1
- [PATCH 16/78] target/arm: Set ISSIs16Bit in make_issinfo, (continued)
- [PATCH 16/78] target/arm: Set ISSIs16Bit in make_issinfo, Michael Roth, 2020/06/16
- [PATCH 17/78] virtio: update queue size on guest write, Michael Roth, 2020/06/16
- [PATCH 18/78] virtio-mmio: update queue size on guest write, Michael Roth, 2020/06/16
- [PATCH 19/78] virtio: add ability to delete vq through a pointer, Michael Roth, 2020/06/16
- [PATCH 20/78] virtio: make virtio_delete_queue idempotent, Michael Roth, 2020/06/16
- [PATCH 01/78] block/nbd: extract the common cleanup code, Michael Roth, 2020/06/16
- [PATCH 21/78] virtio: reset region cache when on queue deletion, Michael Roth, 2020/06/16
- [PATCH 27/78] dp8393x: Mask EOL bit from descriptor addresses, Michael Roth, 2020/06/16
- [PATCH 22/78] virtio-net: delete also control queue when TX/RX deleted, Michael Roth, 2020/06/16
- [PATCH 23/78] intel_iommu: a fix to vtd_find_as_from_bus_num(), Michael Roth, 2020/06/16
- [PATCH 26/78] qcow2-bitmaps: fix qcow2_can_store_new_dirty_bitmap,
Michael Roth <=
- [PATCH 30/78] dp8393x: Have dp8393x_receive() return the packet size, Michael Roth, 2020/06/16
- [PATCH 02/78] block/nbd: fix memory leak in nbd_open(), Michael Roth, 2020/06/16
- [PATCH 29/78] dp8393x: Clean up endianness hacks, Michael Roth, 2020/06/16
- [PATCH 24/78] intel_iommu: add present bit check for pasid table entries, Michael Roth, 2020/06/16
- [PATCH 25/78] vfio/pci: Don't remove irqchip notifier if not registered, Michael Roth, 2020/06/16
- [PATCH 32/78] dp8393x: Clear RRRA command register bit only when appropriate, Michael Roth, 2020/06/16
- [PATCH 31/78] dp8393x: Update LLFA and CRDA registers from rx descriptor, Michael Roth, 2020/06/16
- [PATCH 34/78] dp8393x: Don't clobber packet checksum, Michael Roth, 2020/06/16
- [PATCH 28/78] dp8393x: Always use 32-bit accesses, Michael Roth, 2020/06/16
- [PATCH 33/78] dp8393x: Implement packet size limit and RBAE interrupt, Michael Roth, 2020/06/16