[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 2/4] block/qcow2-bitmap: Don't check size for IN_
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH v2 2/4] block/qcow2-bitmap: Don't check size for IN_USE bitmap |
Date: |
Mon, 11 Mar 2019 21:51:45 +0300 |
We are going to allow image resize when there are persistent bitmaps.
It may lead to appearing of inconsistent bitmaps (IN_USE=1) with
inconsistent size. But we still want to load them as inconsistent.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
block/qcow2-bitmap.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 6adbe06b4d..141bc1e52c 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -462,10 +462,25 @@ static int check_dir_entry(BlockDriverState *bs,
Qcow2BitmapDirEntry *entry)
return len;
}
- fail = (phys_bitmap_bytes > BME_MAX_PHYS_SIZE) ||
- (len > ((phys_bitmap_bytes * 8) << entry->granularity_bits));
+ if (phys_bitmap_bytes > BME_MAX_PHYS_SIZE) {
+ return -EINVAL;
+ }
- return fail ? -EINVAL : 0;
+ if (!(entry->flags & BME_FLAG_IN_USE) &&
+ (len > ((phys_bitmap_bytes * 8) << entry->granularity_bits)))
+ {
+ /*
+ * We've loaded valid bitmap (IN_USE not set) or we are going to store
+ * valid bitmap. But allocated bitmap table size is not enough to store
+ * such bitmap.
+ *
+ * Note, that it's OK to have invalid bitmap with invalid size during
to
+ * bitmap was not correctly saved after image resize.
+ */
+ return -EINVAL;
+ }
+
+ return 0;
}
static inline void bitmap_directory_to_be(uint8_t *dir, size_t size)
--
2.18.0