Skip to contentSkip to conversation

hbitmap: fix hbitmap_status() return value for first dirty bit case

PATCH Applied Andrey Zhadchenko via 5 participants 6 messages Feb 2, 2023 – Feb 16, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hbitmap: fix hbitmap_status() return value for first dirty bit case

The last return statement should return true, as we already evaluated that start == next_dirty

Also, fix hbitmap_status() description in header

Fixes a6426475a75 ("block/dirty-bitmap: introduce bdrv_dirty_bitmap_status()")
---
 include/qemu/hbitmap.h | 2 +-
 util/hbitmap.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/qemu/hbitmap.h +1 -1
index af4e4ab746..8136e33674 100644
@@ -330,7 +330,7 @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end,
                              int64_t *dirty_start, int64_t *dirty_count);
 
 /*
- * bdrv_dirty_bitmap_status:
+ * hbitmap_status:
  * @hb: The HBitmap to operate on
  * @start: The bit to start from
  * @count: Number of bits to proceed
util/hbitmap.c +1 -1
index 297db35fb1..6d6e1b595d 100644
@@ -331,7 +331,7 @@ bool hbitmap_status(const HBitmap *hb, int64_t start, int64_t count,
 
     assert(next_zero > start);
     *pnum = next_zero - start;
-    return false;
+    return true;
 }
 
 bool hbitmap_empty(const HBitmap *hb)
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andrey Zhadchenko via

The last return statement should return true, as we already evaluated that start == next_dirty

Also, fix hbitmap_status() description in header

Quoted 7 lines
Fixes a6426475a75 ("block/dirty-bitmap: introduce bdrv_dirty_bitmap_status()")
---
 include/qemu/hbitmap.h | 2 +-
 util/hbitmap.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Eww, nasty bug; looks like copy-before-write is the only curernt client of this interface.

Is there any way to enhance an iotest to add coverage for this code?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#2 lore raw
Quoted 14 lines · Eric Blake
Quoted 5 lines · Andrey Zhadchenko via

The last return statement should return true, as we already evaluated that start == next_dirty

Also, fix hbitmap_status() description in header

Quoted 7 lines
Fixes a6426475a75 ("block/dirty-bitmap: introduce bdrv_dirty_bitmap_status()")
---
  include/qemu/hbitmap.h | 2 +-
  util/hbitmap.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 2 lines

Eww, nasty bug; looks like copy-before-write is the only curernt client of this interface.

Also this only happens when copy-before-write is used in conjunction with snapshot-access (7.0+), so probably not many people is affected.

Quoted 5 lines

Is there any way to enhance an iotest to add coverage for this code?

Looks like yes. copy-before-write uses bcs bitmaps, which is 64k. So changing existing test

tests/qemu-iotests/tests/image-fleecing +14 -14
index f6e449d071..7eda9a2c6b 100755
@@ -34,23 +34,23 @@ iotests.script_initialize(
     unsupported_imgopts=['compat']
 )
 
-patterns = [('0x5d', '0',         '64k'),
-            ('0xd5', '1M',        '64k'),
-            ('0xdc', '32M',       '64k'),
-            ('0xcd', '0x3ff0000', '64k')]  # 64M - 64K
+patterns = [('0x5d', '0',         '128k'),
+            ('0xd5', '1M',        '128k'),
+            ('0xdc', '32M',       '128k'),
+            ('0xcd', '0x3fe0000', '128k')]  # 64M - 128K
 
-overwrite = [('0xab', '0',         '64k'), # Full overwrite
-             ('0xad', '0x00f8000', '64k'), # Partial-left (1M-32K)
-             ('0x1d', '0x2008000', '64k'), # Partial-right (32M+32K)
-             ('0xea', '0x3fe0000', '64k')] # Adjacent-left (64M - 128K)
+overwrite = [('0xab', '0',         '128k'), # Full overwrite
+             ('0xad', '0x00f0000', '128k'), # Partial-left (1M-64K)
+             ('0x1d', '0x2010000', '128k'), # Partial-right (32M+64K)
+             ('0xea', '0x3fc0000', '128k')] # Adjacent-left (64M - 256K)
 
-zeroes = [('0', '0x00f8000', '32k'), # Left-end of partial-left (1M-32K)
-          ('0', '0x2010000', '32k'), # Right-end of partial-right (32M+64K)
-          ('0', '0x3fe0000', '64k')] # overwrite[3]
+zeroes = [('0', '0x00f0000', '64k'), # Left-end of partial-left (1M-64K)
+          ('0', '0x2020000', '64k'), # Right-end of partial-right (32M+128K)
+          ('0', '0x3fc0000', '128k')] # overwrite[3]
 
-remainder = [('0xd5', '0x108000',  '32k'), # Right-end of partial-left [1]
-             ('0xdc', '32M',       '32k'), # Left-end of partial-right [2]
-             ('0xcd', '0x3ff0000', '64k')] # patterns[3]
+remainder = [('0xd5', '0x110000',  '64k'), # Right-end of partial-left [1]
+             ('0xdc', '32M',       '64k'), # Left-end of partial-right [2]
+             ('0xcd', '0x3fe0000', '128k')] # patterns[3]
 
 def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path,
             fleece_img_path, nbd_sock_path=None,

From 64k chunks to 128k chunks (so at the read moment we have N bit dirty and N+1 clean) produces the following for one of NBD test cases:

--- Setting up NBD Export ---

{"return": {}}
{"return": {}}

--- Sanity Check ---

read -P0x5d 0 128k
read -P0xd5 1M 128k
read -P0xdc 32M 128k
read -P0xcd 0x3fe0000 128k
read -P0 0x00f0000 64k
read failed: Invalid argument

read -P0 0x2020000 64k
read failed: Invalid argument

read -P0 0x3fc0000 128k
read failed: Invalid argument

I am not good at qemi-io tool, I guess that EINVAL in that case means qemu-io found out that image data does not follow requested pattern?

Also this does not trigger for non-nbd tests since backup job is probably copying one cluster at a time.

#3 lore raw
Quoted 95 lines · Andrey Zhadchenko
Quoted 14 lines · Eric Blake
Quoted 5 lines · Andrey Zhadchenko via

The last return statement should return true, as we already evaluated that start == next_dirty

Also, fix hbitmap_status() description in header

Quoted 7 lines
Fixes a6426475a75 ("block/dirty-bitmap: introduce bdrv_dirty_bitmap_status()")

---
  include/qemu/hbitmap.h | 2 +-
  util/hbitmap.c         | 2 +-

  2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 2 lines

Eww, nasty bug; looks like copy-before-write is the only curernt client of this interface.

Also this only happens when copy-before-write is used in conjunction with snapshot-access (7.0+), so probably not many people is affected.

Quoted 5 lines

Is there any way to enhance an iotest to add coverage for this code?

Looks like yes. copy-before-write uses bcs bitmaps, which is 64k. So changing existing test

tests/qemu-iotests/tests/image-fleecing +14 -14
index f6e449d071..7eda9a2c6b 100755
@@ -34,23 +34,23 @@ iotests.script_initialize(
      unsupported_imgopts=['compat']
  )
 
-patterns = [('0x5d', '0',         '64k'),
-            ('0xd5', '1M',        '64k'),
-            ('0xdc', '32M',       '64k'),
-            ('0xcd', '0x3ff0000', '64k')]  # 64M - 64K
+patterns = [('0x5d', '0',         '128k'),
+            ('0xd5', '1M',        '128k'),
+            ('0xdc', '32M',       '128k'),
+            ('0xcd', '0x3fe0000', '128k')]  # 64M - 128K
 
-overwrite = [('0xab', '0',         '64k'), # Full overwrite
-             ('0xad', '0x00f8000', '64k'), # Partial-left (1M-32K)
-             ('0x1d', '0x2008000', '64k'), # Partial-right (32M+32K)
-             ('0xea', '0x3fe0000', '64k')] # Adjacent-left (64M - 128K)
+overwrite = [('0xab', '0',         '128k'), # Full overwrite
+             ('0xad', '0x00f0000', '128k'), # Partial-left (1M-64K)
+             ('0x1d', '0x2010000', '128k'), # Partial-right (32M+64K)
+             ('0xea', '0x3fc0000', '128k')] # Adjacent-left (64M - 256K)
 
-zeroes = [('0', '0x00f8000', '32k'), # Left-end of partial-left (1M-32K)
-          ('0', '0x2010000', '32k'), # Right-end of partial-right 
 (32M+64K)
-          ('0', '0x3fe0000', '64k')] # overwrite[3]
+zeroes = [('0', '0x00f0000', '64k'), # Left-end of partial-left (1M-64K)
+          ('0', '0x2020000', '64k'), # Right-end of partial-right 
 (32M+128K)
+          ('0', '0x3fc0000', '128k')] # overwrite[3]
 
-remainder = [('0xd5', '0x108000',  '32k'), # Right-end of partial-left [1]
-             ('0xdc', '32M',       '32k'), # Left-end of partial-right [2]
-             ('0xcd', '0x3ff0000', '64k')] # patterns[3]
+remainder = [('0xd5', '0x110000',  '64k'), # Right-end of partial-left [1]
+             ('0xdc', '32M',       '64k'), # Left-end of partial-right [2]
+             ('0xcd', '0x3fe0000', '128k')] # patterns[3]
 

 def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path, fleece_img_path, nbd_sock_path=None,

From 64k chunks to 128k chunks (so at the read moment we have N bit
dirty and N+1 clean) produces the following for one of NBD test cases:

--- Setting up NBD Export ---

{"return": {}}
{"return": {}}

--- Sanity Check ---

read -P0x5d 0 128k
read -P0xd5 1M 128k
read -P0xdc 32M 128k
read -P0xcd 0x3fe0000 128k
read -P0 0x00f0000 64k
read failed: Invalid argument

read -P0 0x2020000 64k
read failed: Invalid argument

Quoted 7 lines

read -P0 0x3fc0000 128k
read failed: Invalid argument

I am not good at qemi-io tool, I guess that EINVAL in that case means qemu-io found out that image data does not follow requested pattern?

Also this does not trigger for non-nbd tests since backup job is probably copying one cluster at a time.

Please disregard this.

This EINVALs are somewhat anticipated as they are also present in expected example image-fleecing.out (and applying my patch doesn't get rid of them)

I should think more about possible test cases

Reviewed-by on v1 1/1
#4 lore raw
In reply to Andrey Zhadchenko via
Quoted 7 lines · Andrey Zhadchenko via

The last return statement should return true, as we already evaluated that start == next_dirty

Also, fix hbitmap_status() description in header

Fixes a6426475a75 ("block/dirty-bitmap: introduce bdrv_dirty_bitmap_status()")

Ohh :/

Quoted 1 line
Quoted 31 lines
---
  include/qemu/hbitmap.h | 2 +-
  util/hbitmap.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
include/qemu/hbitmap.h +1 -1
index af4e4ab746..8136e33674 100644
@@ -330,7 +330,7 @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end,
                               int64_t *dirty_start, int64_t *dirty_count);
 
  /*
- * bdrv_dirty_bitmap_status:
+ * hbitmap_status:
   * @hb: The HBitmap to operate on
   * @start: The bit to start from
   * @count: Number of bits to proceed
util/hbitmap.c +1 -1
index 297db35fb1..6d6e1b595d 100644
@@ -331,7 +331,7 @@ bool hbitmap_status(const HBitmap *hb, int64_t start, int64_t count,
 
      assert(next_zero > start);
      *pnum = next_zero - start;
-    return false;
+    return true;
  }
 
  bool hbitmap_empty(const HBitmap *hb)
Signature · 2 lines
Best regards,
Vladimir