[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v15 25/25] qcow2-bitmap: improve check_constraints_o
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH v15 25/25] qcow2-bitmap: improve check_constraints_on_bitmap |
Date: |
Wed, 15 Feb 2017 13:10:30 +0300 |
Add detailed error messages.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
block/qcow2-bitmap.c | 48 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 9177c56..e25c872 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -160,28 +160,49 @@ static int check_table_entry(uint64_t entry, int
cluster_size)
static int check_constraints_on_bitmap(BlockDriverState *bs,
const char *name,
- uint32_t granularity)
+ uint32_t granularity,
+ Error **errp)
{
BDRVQcow2State *s = bs->opaque;
int granularity_bits = ctz32(granularity);
int64_t len = bdrv_getlength(bs);
- bool fail;
assert(granularity > 0);
assert((granularity & (granularity - 1)) == 0);
if (len < 0) {
+ error_setg_errno(errp, -len, "Failed to get size of '%s'",
+ bdrv_get_device_or_node_name(bs));
return len;
}
- fail = (granularity_bits > BME_MAX_GRANULARITY_BITS) ||
- (granularity_bits < BME_MIN_GRANULARITY_BITS) ||
- (len > (uint64_t)BME_MAX_PHYS_SIZE << granularity_bits) ||
- (len > (uint64_t)BME_MAX_TABLE_SIZE * s->cluster_size <<
- granularity_bits) ||
- (strlen(name) > BME_MAX_NAME_SIZE);
+ if (granularity_bits > BME_MAX_GRANULARITY_BITS) {
+ error_setg(errp, "Granularity exceeds maximum (%u bytes)",
+ 1 << BME_MAX_GRANULARITY_BITS);
+ return -EINVAL;
+ }
+ if (granularity_bits < BME_MIN_GRANULARITY_BITS) {
+ error_setg(errp, "Granularity is under minimum (%u bytes)",
+ 1 << BME_MIN_GRANULARITY_BITS);
+ return -EINVAL;
+ }
- return fail ? -EINVAL : 0;
+ if ((len > (uint64_t)BME_MAX_PHYS_SIZE << granularity_bits) ||
+ (len > (uint64_t)BME_MAX_TABLE_SIZE * s->cluster_size <<
+ granularity_bits))
+ {
+ error_setg(errp, "Too much space will be occupied by the bitmap. "
+ "Use larger granularity");
+ return -EINVAL;
+ }
+
+ if (strlen(name) > BME_MAX_NAME_SIZE) {
+ error_setg(errp, "Name length exceeds maximum (%u characters)",
+ BME_MAX_NAME_SIZE);
+ return -EINVAL;
+ }
+
+ return 0;
}
static void clear_bitmap_table(BlockDriverState *bs, uint64_t *bitmap_table,
@@ -1142,9 +1163,9 @@ void
qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
continue;
}
- if (check_constraints_on_bitmap(bs, name, granularity) < 0) {
- error_setg(errp, "Bitmap '%s' doesn't satisfy the constraints",
- name);
+ if (check_constraints_on_bitmap(bs, name, granularity, errp) < 0) {
+ error_prepend(errp, "Bitmap '%s' doesn't satisfy the constraints:
",
+ name);
goto fail;
}
@@ -1233,8 +1254,7 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverState
*bs,
bool found;
Qcow2BitmapList *bm_list;
- if (check_constraints_on_bitmap(bs, name, granularity) != 0) {
- error_setg(errp, "The constraints are not satisfied");
+ if (check_constraints_on_bitmap(bs, name, granularity, errp) != 0) {
goto fail;
}
--
1.8.3.1
- [Qemu-block] [PATCH v15 00/25] qcow2: persistent dirty bitmaps, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 04/25] tests: add hbitmap iter test, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 01/25] specs/qcow2: fix bitmap granularity qemu-specific note, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 02/25] specs/qcow2: do not use wording 'bitmap header', Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 05/25] block: fix bdrv_dirty_bitmap_granularity signature, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 15/25] qcow2: add .bdrv_can_store_new_dirty_bitmap, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 24/25] qmp: block-dirty-bitmap-remove: remove persistent, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 11/25] block: introduce persistent dirty bitmaps, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 25/25] qcow2-bitmap: improve check_constraints_on_bitmap,
Vladimir Sementsov-Ogievskiy <=
[Qemu-block] [PATCH v15 08/25] block: introduce auto-loading bitmaps, Vladimir Sementsov-Ogievskiy, 2017/02/15