Skip to contentSkip to conversation

mirror: correct buf_size

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

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mirror: correct buf_size

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

---
 block/mirror.c | 4 ++++
 1 file changed, 4 insertions(+)
block/mirror.c +4 -0
index 58f391a..bb6bc27 100644
@@ -686,6 +686,10 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
     s->granularity = granularity;
     s->buf_size = MAX(buf_size, granularity);
 
+    if (s->buf_size % granularity != 0) {
+        s->buf_size = ROUND_UP(s->buf_size, granularity);
+    }
+
     s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
     if (!s->dirty_bitmap) {
         return;
Signature · 1 line
2.1.0
#1 lore raw
Quoted 10 lines · Wen Congyang
---
 block/mirror.c | 4 ++++
 1 file changed, 4 insertions(+)
block/mirror.c +0 -0
index 58f391a..bb6bc27 100644

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

Quoted 7 lines
block/mirror.c +4 -0
@@ -686,6 +686,10 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
     s->granularity = granularity;
     s->buf_size = MAX(buf_size, granularity);
 
+    if (s->buf_size % granularity != 0) {
+        s->buf_size = ROUND_UP(s->buf_size, granularity);
+    }
+

Good catch! But I think the "if" is not needed, and also this removes the need for the s->buf_size assignment before.

The ROUND_UP is really the only thing that is needed.

Paolo