block: Use QEMU_IS_ALIGNED instead of reinventing it
PATCH 1/1 block: Use QEMU_IS_ALIGNED instead of reinventing it
Replace instances of:
(n & (BDRV_SECTOR_SIZE - 1)) == 0)
With:
QEMU_IS_ALIGNED(n, BDRV_SECTOR_SIZE)
Which reveals the intent of the code better, and makes it easier to locate the code checking alignment.
QEMU_IS_ALIGNED is implemented using %, which may be less efficient but it is used only in assert() except one instance, so it should not matter.
--- block/bochs.c | 4 ++-- block/cloop.c | 4 ++-- block/dmg.c | 4 ++-- block/io.c | 8 ++++---- block/qcow2.c | 4 ++-- block/vvfat.c | 8 ++++---- qemu-img.c | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-)
block/bochs.c +2 -2
@@ -248,8 +248,8 @@ bochs_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,QEMUIOVector local_qiov;int ret; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_iovec_init (&local_qiov, qiov->niov);qemu_co_mutex_lock (&s->lock);
block/cloop.c +2 -2
@@ -253,8 +253,8 @@ cloop_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,int nb_sectors = bytes >>BDRV_SECTOR_BITS ;int ret, i; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_co_mutex_lock (&s->lock);
block/dmg.c +2 -2
@@ -697,8 +697,8 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,int nb_sectors = bytes >>BDRV_SECTOR_BITS ;int ret, i; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_co_mutex_lock (&s->lock);
block/io.c +4 -4
@@ -1080,8 +1080,8 @@ static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs, sector_num = offset >>BDRV_SECTOR_BITS ; nb_sectors = bytes >>BDRV_SECTOR_BITS ; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));assert (bytes <=BDRV_REQUEST_MAX_BYTES );assert (drv->bdrv_co_readv);
@@ -1133,8 +1133,8 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs, sector_num = offset >>BDRV_SECTOR_BITS ; nb_sectors = bytes >>BDRV_SECTOR_BITS ; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));assert (bytes <=BDRV_REQUEST_MAX_BYTES );assert (drv->bdrv_co_writev);
block/qcow2.c +2 -2
@@ -2072,8 +2072,8 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset, }if (bs->encrypted) {assert (s->crypto); -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((cur_bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (cur_bytes,BDRV_SECTOR_SIZE ));if (qcow2_co_decrypt (bs, cluster_offset, offset, cluster_data, cur_bytes) <0 ) { ret = -EIO ;
block/vvfat.c +4 -4
@@ -1547,8 +1547,8 @@ vvfat_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,int nb_sectors = bytes >>BDRV_SECTOR_BITS ;void *buf; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE )); buf =g_try_malloc (bytes);if (bytes && buf ==NULL ) {
@@ -3082,8 +3082,8 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,int nb_sectors = bytes >>BDRV_SECTOR_BITS ;void *buf; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE )); buf =g_try_malloc (bytes);if (bytes && buf ==NULL ) {
qemu-img.c +1 -1
@@ -2138,7 +2138,7 @@ static int img_convert(int argc, char **argv)int64_t sval; sval =cvtnum (optarg); -if (sval <0 || sval & (BDRV_SECTOR_SIZE -1 ) || +if (sval <0 || !QEMU_IS_ALIGNED (sval,BDRV_SECTOR_SIZE ) || sval /BDRV_SECTOR_SIZE >MAX_BUF_SECTORS ) {error_report ("Invalid buffer size for sparse output specified. " "Valid sizes are multiples of %llu up to %llu. Select "
Signature · 1 line
2.20.1
Quoted 8 lines · Nir Soffer
Replace instances of:
(n & (BDRV_SECTOR_SIZE - 1)) == 0)With:
QEMU_IS_ALIGNED(n, BDRV_SECTOR_SIZE)
Do you have a magical incantation you used to find these?
Quoted 7 lines
Which reveals the intent of the code better, and makes it easier to locate the code checking alignment.
QEMU_IS_ALIGNEDis implemented using %, which may be less efficient but it is used only inassert()except one instance, so it should not matter.
There is virtually no way these aren't optimized by the compiler.
Quoted 1 line
Signed-off-by Nir Soffer <[email protected]>
Therefore:
Quoted 136 lines
--- block/bochs.c | 4 ++-- block/cloop.c | 4 ++-- block/dmg.c | 4 ++-- block/io.c | 8 ++++---- block/qcow2.c | 4 ++-- block/vvfat.c | 8 ++++---- qemu-img.c | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-)block/bochs.c +2
-2@@ -248,8 +248,8 @@ bochs_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,QEMUIOVector local_qiov;int ret; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_iovec_init (&local_qiov, qiov->niov);qemu_co_mutex_lock (&s->lock);block/cloop.c +2
-2@@ -253,8 +253,8 @@ cloop_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,int nb_sectors = bytes >>BDRV_SECTOR_BITS ;int ret, i; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_co_mutex_lock (&s->lock);block/dmg.c +2
-2@@ -697,8 +697,8 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,int nb_sectors = bytes >>BDRV_SECTOR_BITS ;int ret, i; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_co_mutex_lock (&s->lock);block/io.c +4
-4@@ -1080,8 +1080,8 @@ static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs, sector_num = offset >>BDRV_SECTOR_BITS ; nb_sectors = bytes >>BDRV_SECTOR_BITS ; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));assert (bytes <=BDRV_REQUEST_MAX_BYTES );assert (drv->bdrv_co_readv);@@ -1133,8 +1133,8 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs, sector_num = offset >>BDRV_SECTOR_BITS ; nb_sectors = bytes >>BDRV_SECTOR_BITS ; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));assert (bytes <=BDRV_REQUEST_MAX_BYTES );assert (drv->bdrv_co_writev);block/qcow2.c +2
-2@@ -2072,8 +2072,8 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset, }if (bs->encrypted) {assert (s->crypto); -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((cur_bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (cur_bytes,BDRV_SECTOR_SIZE ));if (qcow2_co_decrypt (bs, cluster_offset, offset, cluster_data, cur_bytes) <0 ) { ret = -EIO ;block/vvfat.c +4
-4@@ -1547,8 +1547,8 @@ vvfat_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,int nb_sectors = bytes >>BDRV_SECTOR_BITS ;void *buf; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE )); buf =g_try_malloc (bytes);if (bytes && buf ==NULL ) {@@ -3082,8 +3082,8 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,int nb_sectors = bytes >>BDRV_SECTOR_BITS ;void *buf; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE )); buf =g_try_malloc (bytes);if (bytes && buf ==NULL ) {qemu-img.c +1
-1@@ -2138,7 +2138,7 @@ static int img_convert(int argc, char **argv)int64_t sval; sval =cvtnum (optarg); -if (sval <0 || sval & (BDRV_SECTOR_SIZE -1 ) || +if (sval <0 || !QEMU_IS_ALIGNED (sval,BDRV_SECTOR_SIZE ) || sval /BDRV_SECTOR_SIZE >MAX_BUF_SECTORS ) {error_report ("Invalid buffer size for sparse output specified. " "Valid sizes are multiples of %llu up to %llu. Select "
Quoted 5 lines · John Snow
Quoted 2 lines · Nir Soffer
Replace instances of:
Quoted 9 lines
Quoted 6 lines
(n & (BDRV_SECTOR_SIZE - 1)) == 0)With:
QEMU_IS_ALIGNED(n, BDRV_SECTOR_SIZE)Do you have a magical incantation you used to find these?
I found the first by accident, then I used:
git grep 'BDRV_SECTOR_SIZE - 1'
Quoted 10 lines
Which reveals the intent of the code better, and makes it easier to
Quoted 6 lines
locate the code checking alignment.
QEMU_IS_ALIGNEDis implemented using %, which may be less efficient but it is used only inassert()except one instance, so it should not matter.There is virtually no way these aren't optimized by the compiler.
Makes sense, but I did not check.
Quoted 156 lines
Quoted 2 lines
Signed-off-by Nir Soffer <[email protected]>Therefore:
Reviewed-by John Snow <[email protected]>block/bochs.c bochs_co_preadv(BlockDriverState *bs, uint64_t
Quoted 15 lines
--- block/bochs.c | 4 ++-- block/cloop.c | 4 ++-- block/dmg.c | 4 ++-- block/io.c | 8 ++++---- block/qcow2.c | 4 ++-- block/vvfat.c | 8 ++++---- qemu-img.c | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-)block/bochs.c +0
-0@@ -248,8 +248,8 @@ bochs_co_preadv(BlockDriverState *bs, uint64_toffset,
uint64_tbytes,block/cloop.c cloop_co_preadv(BlockDriverState *bs, uint64_t
Quoted 15 lines
block/bochs.c +2
-2QEMUIOVector local_qiov;int ret; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_iovec_init (&local_qiov, qiov->niov);qemu_co_mutex_lock (&s->lock);block/cloop.c +0
-0@@ -253,8 +253,8 @@ cloop_co_preadv(BlockDriverState *bs, uint64_toffset,
uint64_tbytes,block/dmg.c dmg_co_preadv(BlockDriverState *bs, uint64_t offset,
Quoted 15 lines
block/cloop.c +2
-2int nb_sectors = bytes >>BDRV_SECTOR_BITS ;int ret, i; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_co_mutex_lock (&s->lock);block/dmg.c +0
-0@@ -697,8 +697,8 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset,
uint64_tbytes,block/io.c static int coroutine_fn
Quoted 15 lines
block/dmg.c +2
-2int nb_sectors = bytes >>BDRV_SECTOR_BITS ;int ret, i; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));qemu_co_mutex_lock (&s->lock);block/io.c +0
-0@@ -1080,8 +1080,8 @@ static int coroutine_fnbdrv_driver_preadv(BlockDriverState *bs,
block/io.c static int coroutine_fn
Quoted 11 lines
block/io.c +2
-2sector_num = offset >>BDRV_SECTOR_BITS ; nb_sectors = bytes >>BDRV_SECTOR_BITS ; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));assert (bytes <=BDRV_REQUEST_MAX_BYTES );assert (drv->bdrv_co_readv);@@ -1133,8 +1133,8 @@ static int coroutine_fnbdrv_driver_pwritev(BlockDriverState *bs,
block/qcow2.c static coroutine_fn int
Quoted 15 lines
block/io.c +2
-2sector_num = offset >>BDRV_SECTOR_BITS ; nb_sectors = bytes >>BDRV_SECTOR_BITS ; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE ));assert (bytes <=BDRV_REQUEST_MAX_BYTES );assert (drv->bdrv_co_writev);block/qcow2.c +0
-0@@ -2072,8 +2072,8 @@ static coroutine_fn intqcow2_co_preadv(BlockDriverState *bs,
uint64_toffset,block/vvfat.c vvfat_co_preadv(BlockDriverState *bs, uint64_t
Quoted 15 lines
block/qcow2.c +2
-2}if (bs->encrypted) {assert (s->crypto); -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((cur_bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (cur_bytes,BDRV_SECTOR_SIZE ));if (qcow2_co_decrypt (bs, cluster_offset, offset, cluster_data, cur_bytes) <0 ) { ret = -EIO ;block/vvfat.c +0
-0@@ -1547,8 +1547,8 @@ vvfat_co_preadv(BlockDriverState *bs, uint64_toffset,
uint64_tbytes,block/vvfat.c vvfat_co_pwritev(BlockDriverState *bs, uint64_t
Quoted 11 lines
block/vvfat.c +2
-2int nb_sectors = bytes >>BDRV_SECTOR_BITS ;void *buf; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE )); buf =g_try_malloc (bytes);if (bytes && buf ==NULL ) {@@ -3082,8 +3082,8 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_toffset,
uint64_tbytes,Quoted 15 lines
block/vvfat.c +2
-2int nb_sectors = bytes >>BDRV_SECTOR_BITS ;void *buf; -assert ((offset & (BDRV_SECTOR_SIZE -1 )) ==0 ); -assert ((bytes & (BDRV_SECTOR_SIZE -1 )) ==0 ); +assert (QEMU_IS_ALIGNED (offset,BDRV_SECTOR_SIZE )); +assert (QEMU_IS_ALIGNED (bytes,BDRV_SECTOR_SIZE )); buf =g_try_malloc (bytes);if (bytes && buf ==NULL ) {qemu-img.c +0
-0qemu-img.c static int img_convert(int argc, char **argv) · line 2143
Quoted 7 lines
qemu-img.c +1
-1@@ -2138,7 +2138,7 @@ static int img_convert(int argc, char **argv)int64_t sval; sval =cvtnum (optarg); -if (sval <0 || sval & (BDRV_SECTOR_SIZE -1 ) || +if (sval <0 || !QEMU_IS_ALIGNED (sval,BDRV_SECTOR_SIZE ) || sval /BDRV_SECTOR_SIZE >MAX_BUF_SECTORS ) { error_report("Invalid buffer size for sparse outputspecified. "
qemu-img.c static int img_convert(int argc, char **argv) · line 2144
Quoted 1 line
qemu-img.c +0
-0"Valid sizes are multiples of %llu up to %llu.Select "
Quoted 1 line
Quoted 16 lines · Nir Soffer
Replace instances of:
(n & (BDRV_SECTOR_SIZE - 1)) == 0)With:
QEMU_IS_ALIGNED(n, BDRV_SECTOR_SIZE)Which reveals the intent of the code better, and makes it easier to locate the code checking alignment.
QEMU_IS_ALIGNEDis implemented using %, which may be less efficient but it is used only inassert()except one instance, so it should not matter.Signed-off-by Nir Soffer <[email protected]>
Quoted 9 lines
--- block/bochs.c | 4 ++-- block/cloop.c | 4 ++-- block/dmg.c | 4 ++-- block/io.c | 8 ++++---- block/qcow2.c | 4 ++-- block/vvfat.c | 8 ++++---- qemu-img.c | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-)
Because John was speaking about a magical incantation, I found BDRV_SECTOR_MASK. There are two places in block/qcow2-cluster.c that use that to check alignment, I think those should be amended as well.
Max
Quoted 27 lines · Max Reitz
Quoted 16 lines · Nir Soffer
Replace instances of:
(n & (BDRV_SECTOR_SIZE - 1)) == 0)With:
QEMU_IS_ALIGNED(n, BDRV_SECTOR_SIZE)Which reveals the intent of the code better, and makes it easier to locate the code checking alignment.
QEMU_IS_ALIGNEDis implemented using %, which may be less efficient but it is used only inassert()except one instance, so it should not matter.Signed-off-by Nir Soffer <[email protected]>Quoted 9 lines
--- block/bochs.c | 4 ++-- block/cloop.c | 4 ++-- block/dmg.c | 4 ++-- block/io.c | 8 ++++---- block/qcow2.c | 4 ++-- block/vvfat.c | 8 ++++---- qemu-img.c | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-)
Quoted 4 lines
Because John was speaking about a magical incantation, I found
BDRV_SECTOR_MASK. There are two places inblock/qcow2-cluster.cthat use that to check alignment, I think those should be amended as well.
$ git grep BDRV_SECTOR_MASK block/qcow2-cluster.c: assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0); block/qcow2-cluster.c: assert((bytes & ~BDRV_SECTOR_MASK) == 0);
Right, should use QEMU_IS_ALIGNED
include/block/block.h:#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1)
include/block/block.h:#define BDRV_BLOCK_OFFSET_MASK BDRV_SECTOR_MASKmigration/block.c: flags = addr & ~BDRV_SECTOR_MASK;
This could use (BDRV_SECTOR_SIZE - 1).
In Linux SECTOR_MASK is defined as:
drivers/block/null_blk_main.c:#define SECTOR_MASK
(PAGE_SECTORS - 1)
It seems that qemu use use the same.
I will try to handle these in v2.
Nir