Skip to content

Commit cf7c49c

Browse files
committed
bitmap: Enforce maximum bitmap name length
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 <[email protected]> Message-Id: <[email protected]> Reviewed-by: Maxim Levitsky <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
1 parent 9d7ab22 commit cf7c49c

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

block/dirty-bitmap.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
104104

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

107-
if (name && bdrv_find_dirty_bitmap(bs, name)) {
108-
error_setg(errp, "Bitmap already exists: %s", name);
109-
return NULL;
107+
if (name) {
108+
if (bdrv_find_dirty_bitmap(bs, name)) {
109+
error_setg(errp, "Bitmap already exists: %s", name);
110+
return NULL;
111+
}
112+
if (strlen(name) > BDRV_BITMAP_MAX_NAME_SIZE) {
113+
error_setg(errp, "Bitmap name too long: %s", name);
114+
return NULL;
115+
}
110116
}
111117
bitmap_size = bdrv_getlength(bs);
112118
if (bitmap_size < 0) {

block/qcow2-bitmap.c

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#define BME_MIN_GRANULARITY_BITS 9
4343
#define BME_MAX_NAME_SIZE 1023
4444

45+
QEMU_BUILD_BUG_ON(BME_MAX_NAME_SIZE != BDRV_BITMAP_MAX_NAME_SIZE);
46+
4547
#if BME_MAX_TABLE_SIZE * 8ULL > INT_MAX
4648
#error In the code bitmap table physical size assumed to fit into int
4749
#endif

include/block/dirty-bitmap.h

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ typedef enum BitmapCheckFlags {
1414
BDRV_BITMAP_INCONSISTENT)
1515
#define BDRV_BITMAP_ALLOW_RO (BDRV_BITMAP_BUSY | BDRV_BITMAP_INCONSISTENT)
1616

17+
#define BDRV_BITMAP_MAX_NAME_SIZE 1023
18+
1719
BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
1820
uint32_t granularity,
1921
const char *name,

qapi/block-core.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,7 @@
20422042
#
20432043
# @node: name of device/node which the bitmap is tracking
20442044
#
2045-
# @name: name of the dirty bitmap
2045+
# @name: name of the dirty bitmap (must be less than 1024 bytes)
20462046
#
20472047
# @granularity: the bitmap granularity, default is 64k for
20482048
# block-dirty-bitmap-add

0 commit comments

Comments
 (0)