Skip to content

Commit

Permalink
bitmap: Enforce maximum bitmap name length
Browse files Browse the repository at this point in the history
We document that for qcow2 persistent bitmaps, the name cannot exceed
1023 bytes.  It is inconsistent if transient bitmaps do not have to
abide by the same limit, and it is unlikely that any existing client
even cares about using bitmap names this long.  It's time to codify
that ALL bitmaps managed by qemu (whether persistent in qcow2 or not)
have a documented maximum length.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20191114024635.11363-3-eblake@redhat.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  • Loading branch information
ebblake committed Nov 18, 2019
1 parent 9d7ab22 commit cf7c49c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions block/dirty-bitmap.c
Expand Up @@ -104,9 +104,15 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,

assert(is_power_of_2(granularity) && granularity >= BDRV_SECTOR_SIZE);

if (name && bdrv_find_dirty_bitmap(bs, name)) {
error_setg(errp, "Bitmap already exists: %s", name);
return NULL;
if (name) {
if (bdrv_find_dirty_bitmap(bs, name)) {
error_setg(errp, "Bitmap already exists: %s", name);
return NULL;
}
if (strlen(name) > BDRV_BITMAP_MAX_NAME_SIZE) {
error_setg(errp, "Bitmap name too long: %s", name);
return NULL;
}
}
bitmap_size = bdrv_getlength(bs);
if (bitmap_size < 0) {
Expand Down
2 changes: 2 additions & 0 deletions block/qcow2-bitmap.c
Expand Up @@ -42,6 +42,8 @@
#define BME_MIN_GRANULARITY_BITS 9
#define BME_MAX_NAME_SIZE 1023

QEMU_BUILD_BUG_ON(BME_MAX_NAME_SIZE != BDRV_BITMAP_MAX_NAME_SIZE);

#if BME_MAX_TABLE_SIZE * 8ULL > INT_MAX
#error In the code bitmap table physical size assumed to fit into int
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/block/dirty-bitmap.h
Expand Up @@ -14,6 +14,8 @@ typedef enum BitmapCheckFlags {
BDRV_BITMAP_INCONSISTENT)
#define BDRV_BITMAP_ALLOW_RO (BDRV_BITMAP_BUSY | BDRV_BITMAP_INCONSISTENT)

#define BDRV_BITMAP_MAX_NAME_SIZE 1023

BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
uint32_t granularity,
const char *name,
Expand Down
2 changes: 1 addition & 1 deletion qapi/block-core.json
Expand Up @@ -2042,7 +2042,7 @@
#
# @node: name of device/node which the bitmap is tracking
#
# @name: name of the dirty bitmap
# @name: name of the dirty bitmap (must be less than 1024 bytes)
#
# @granularity: the bitmap granularity, default is 64k for
# block-dirty-bitmap-add
Expand Down

0 comments on commit cf7c49c

Please sign in to comment.