Skip to contentSkip to conversation

mirror: fix improperly filled copy_bitmap for mirror block job

PATCH Superseded Denis V. Lunev 2 participants 3 messages Sep 6, 2016 – Sep 7, 2016 Block layer

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mirror: fix improperly filled copy_bitmap for mirror block job

bdrv_is_allocated_above() returns true in the case if qcow2 even for completely zeroed areas as BDRV_BLOCK_ALLOCATED flag is set in both cases. Though we have completely zeroed out the image just above or it was already zeroed.

The patch stops using bdrv_is_allocated_above() wrapper and switches to bdrv_get_block_status_above() to distinguish zeroed areas and areas with data to avoid extra IO operations, which could be VERY slow.

CC Jeff Cody <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
---
 block/mirror.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
block/mirror.c +8 -5
index e0b3f41..87edbd8 100644
@@ -552,7 +552,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
     BlockDriverState *base = s->base;
     BlockDriverState *bs = blk_bs(s->common.blk);
     BlockDriverState *target_bs = blk_bs(s->target);
-    int ret, n;
+    int n;
 
     end = s->bdev_length / BDRV_SECTOR_SIZE;
 
@@ -590,6 +590,8 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
         /* Just to make sure we are not exceeding int limit. */
         int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS,
                              end - sector_num);
+        int64_t status;
+        BlockDriverState *file;
 
         mirror_throttle(s);
 
@@ -597,13 +599,14 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
             return 0;
         }
 
-        ret = bdrv_is_allocated_above(bs, base, sector_num, nb_sectors, &n);
-        if (ret < 0) {
-            return ret;
+        status = bdrv_get_block_status_above(bs, base, sector_num,
+                                             nb_sectors, &n, &file);
+        if (status < 0) {
+            return status;
         }
 
         assert(n > 0);
-        if (ret == 1) {
+        if (status & BDRV_BLOCK_DATA) {
             bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n);
         }
         sector_num += n;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines · Denis V. Lunev

bdrv_is_allocated_above() returns true in the case if qcow2 even for completely zeroed areas as BDRV_BLOCK_ALLOCATED flag is set in both cases.

Hi Denis,

Not just qcow2. BDRV_BLOCK_ALLOCATED for a layer means the content of the block is defined by that layer (even if that is a zero block, that doesn't mean it is unallocated). This applies to all image formats.

Quoted 2 lines

Though we have completely zeroed out the image just above or it was already zeroed.

This is only true if we are in 'sync = full' mode.

Quoted 3 lines

The patch stops using bdrv_is_allocated_above() wrapper and switches to bdrv_get_block_status_above() to distinguish zeroed areas and areas with data to avoid extra IO operations, which could be VERY slow.

For 'sync = top', we need to make sure to appropriately allocate the sector, even if it is BDRV_BLOCK_ZERO.

Quoted 36 lines
CC Jeff Cody <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
---
 block/mirror.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
block/mirror.c +3 -3
index e0b3f41..87edbd8 100644
@@ -552,7 +552,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
     BlockDriverState *base = s->base;
     BlockDriverState *bs = blk_bs(s->common.blk);
     BlockDriverState *target_bs = blk_bs(s->target);
-    int ret, n;
+    int n;
 
     end = s->bdev_length / BDRV_SECTOR_SIZE;
 
@@ -590,6 +590,8 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
         /* Just to make sure we are not exceeding int limit. */
         int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS,
                              end - sector_num);
+        int64_t status;
+        BlockDriverState *file;
 
         mirror_throttle(s);
 
@@ -597,13 +599,14 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
             return 0;
         }
 
-        ret = bdrv_is_allocated_above(bs, base, sector_num, nb_sectors, &n);
-        if (ret < 0) {

block/mirror.c static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) · line 609

Quoted 10 lines
block/mirror.c +5 -2
-            return ret;
+        status = bdrv_get_block_status_above(bs, base, sector_num,
+                                             nb_sectors, &n, &file);
+        if (status < 0) {
+            return status;
         }
 
         assert(n > 0);
-        if (ret == 1) {
+        if (status & BDRV_BLOCK_DATA) {

I think this patch would work if this was changed to something like this:

         mark_dirty = base == NULL ? status & BDRV_BLOCK_DATA :     /* 'full' */
                                     status & BDRV_BLOCK_ALLOCATED;

         if (mark_dirty) {

Thanks,
Jeff

Quoted 9 lines
block/mirror.c +0 -0
             bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n);
         }
 

         sector_num += n;
Signature · 1 line
2.7.4
#2 lore raw
Quoted 68 lines · Jeff Cody
Quoted 3 lines · Denis V. Lunev

bdrv_is_allocated_above() returns true in the case if qcow2 even for completely zeroed areas as BDRV_BLOCK_ALLOCATED flag is set in both cases.

Hi Denis,

Not just qcow2. BDRV_BLOCK_ALLOCATED for a layer means the content of the block is defined by that layer (even if that is a zero block, that doesn't mean it is unallocated). This applies to all image formats.

Quoted 2 lines

Though we have completely zeroed out the image just above or it was already zeroed.

This is only true if we are in 'sync = full' mode.

Quoted 3 lines

The patch stops using bdrv_is_allocated_above() wrapper and switches to bdrv_get_block_status_above() to distinguish zeroed areas and areas with data to avoid extra IO operations, which could be VERY slow.

For 'sync = top', we need to make sure to appropriately allocate the sector, even if it is BDRV_BLOCK_ZERO.

Quoted 36 lines
CC Jeff Cody <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
---
 block/mirror.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
block/mirror.c +3 -3
index e0b3f41..87edbd8 100644
@@ -552,7 +552,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
     BlockDriverState *base = s->base;
     BlockDriverState *bs = blk_bs(s->common.blk);
     BlockDriverState *target_bs = blk_bs(s->target);
-    int ret, n;
+    int n;
 
     end = s->bdev_length / BDRV_SECTOR_SIZE;
 
@@ -590,6 +590,8 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
         /* Just to make sure we are not exceeding int limit. */
         int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS,
                              end - sector_num);
+        int64_t status;
+        BlockDriverState *file;
 
         mirror_throttle(s);
 
@@ -597,13 +599,14 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
             return 0;
         }
 
-        ret = bdrv_is_allocated_above(bs, base, sector_num, nb_sectors, &n);
-        if (ret < 0) {

block/mirror.c static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) · line 609

Quoted 10 lines
block/mirror.c +5 -2
-            return ret;
+        status = bdrv_get_block_status_above(bs, base, sector_num,
+                                             nb_sectors, &n, &file);
+        if (status < 0) {
+            return status;
         }
 
         assert(n > 0);
-        if (ret == 1) {
+        if (status & BDRV_BLOCK_DATA) {

I think this patch would work if this was changed to something like this:

Quoted 4 lines
         mark_dirty = base == NULL ? status & BDRV_BLOCK_DATA :     /* 'full' */
                                     status & BDRV_BLOCK_ALLOCATED;

         if (mark_dirty) {

reasonable. I have doubts with the code but was unable to formulate. Thank you for clarifications. Will respin.

Den