Skip to contentSkip to conversation

mirror: correct buf_size

PATCH Superseded Wen Congyang 3 participants 4 messages May 14, 2015 Block layer

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mirror: correct buf_size

If buf_size % granularity is not 0, mirror_free_init() will do dangerous things.

---
 block/mirror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/mirror.c +1 -1
index 58f391a..9521212 100644
@@ -684,7 +684,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
     s->is_none_mode = is_none_mode;
     s->base = base;
     s->granularity = granularity;
-    s->buf_size = MAX(buf_size, granularity);
+    s->buf_size = ROUND_UP(buf_size, granularity);
 
     s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
     if (!s->dirty_bitmap) {
Signature · 1 line
2.1.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines · Wen Congyang

If buf_size % granularity is not 0, mirror_free_init() will do dangerous things.

---
 block/mirror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/mirror.c +0 -0
index 58f391a..9521212 100644

block/mirror.c static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, · line 690

Quoted 8 lines
block/mirror.c +1 -1
@@ -684,7 +684,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
     s->is_none_mode = is_none_mode;
     s->base = base;
     s->granularity = granularity;
-    s->buf_size = MAX(buf_size, granularity);
+    s->buf_size = ROUND_UP(buf_size, granularity);
 
     s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
     if (!s->dirty_bitmap) {
#2 lore raw
Quoted 23 lines · Paolo Bonzini
Quoted 20 lines · Wen Congyang

If buf_size % granularity is not 0, mirror_free_init() will do dangerous things.

---
 block/mirror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/mirror.c +1 -1
index 58f391a..9521212 100644
@@ -684,7 +684,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
     s->is_none_mode = is_none_mode;
     s->base = base;
     s->granularity = granularity;
-    s->buf_size = MAX(buf_size, granularity);
+    s->buf_size = ROUND_UP(buf_size, granularity);
 
Quoted 5 lines

block/mirror.c static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, · line 690

Quoted 3 lines
block/mirror.c +0 -0
     s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
     if (!s->dirty_bitmap) {

What if buf_size is negative?

Fam

#3 lore raw
Quoted 24 lines · Fam Zheng
Quoted 23 lines · Paolo Bonzini
Quoted 20 lines · Wen Congyang

If buf_size % granularity is not 0, mirror_free_init() will do dangerous things.

---
 block/mirror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/mirror.c +1 -1
index 58f391a..9521212 100644
@@ -684,7 +684,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
     s->is_none_mode = is_none_mode;
     s->base = base;
     s->granularity = granularity;
-    s->buf_size = MAX(buf_size, granularity);
+    s->buf_size = ROUND_UP(buf_size, granularity);
 
Quoted 7 lines
Quoted 5 lines

block/mirror.c static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, · line 690

Quoted 3 lines
block/mirror.c +0 -0
     s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
     if (!s->dirty_bitmap) {

What if buf_size is negative?

This will fail:

    s->buf = qemu_try_blockalign(bs, s->buf_size);

O:-)

but really that should be checked in mirror_start_job, so that the command fails.

Paolo