qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

block: Use QEMU_IS_ALIGNED

Replace instances of:

(n & (BDRV_SECTOR_SIZE - 1)) == 0

And:

(n & ~BDRV_SECTOR_MASK) == 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.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Message-id: 20190827185913.27427-2-nsoffer@redhat.com
Reviewed-by: John Snow <jsnow@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>

authored by

Nir Soffer and committed by
Max Reitz
1bbbf32d dd25f97c

+19 -19
+2 -2
block/bochs.c
··· 248 248 QEMUIOVector local_qiov; 249 249 int ret; 250 250 251 - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); 252 - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); 251 + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); 252 + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); 253 253 254 254 qemu_iovec_init(&local_qiov, qiov->niov); 255 255 qemu_co_mutex_lock(&s->lock);
+2 -2
block/cloop.c
··· 253 253 int nb_sectors = bytes >> BDRV_SECTOR_BITS; 254 254 int ret, i; 255 255 256 - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); 257 - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); 256 + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); 257 + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); 258 258 259 259 qemu_co_mutex_lock(&s->lock); 260 260
+2 -2
block/dmg.c
··· 697 697 int nb_sectors = bytes >> BDRV_SECTOR_BITS; 698 698 int ret, i; 699 699 700 - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); 701 - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); 700 + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); 701 + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); 702 702 703 703 qemu_co_mutex_lock(&s->lock); 704 704
+4 -4
block/io.c
··· 1097 1097 sector_num = offset >> BDRV_SECTOR_BITS; 1098 1098 nb_sectors = bytes >> BDRV_SECTOR_BITS; 1099 1099 1100 - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); 1101 - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); 1100 + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); 1101 + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); 1102 1102 assert(bytes <= BDRV_REQUEST_MAX_BYTES); 1103 1103 assert(drv->bdrv_co_readv); 1104 1104 ··· 1171 1171 sector_num = offset >> BDRV_SECTOR_BITS; 1172 1172 nb_sectors = bytes >> BDRV_SECTOR_BITS; 1173 1173 1174 - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); 1175 - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); 1174 + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); 1175 + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); 1176 1176 assert(bytes <= BDRV_REQUEST_MAX_BYTES); 1177 1177 1178 1178 assert(drv->bdrv_co_writev);
+2 -2
block/qcow2-cluster.c
··· 471 471 { 472 472 if (bytes && bs->encrypted) { 473 473 BDRVQcow2State *s = bs->opaque; 474 - assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0); 475 - assert((bytes & ~BDRV_SECTOR_MASK) == 0); 474 + assert(QEMU_IS_ALIGNED(offset_in_cluster, BDRV_SECTOR_SIZE)); 475 + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); 476 476 assert(s->crypto); 477 477 if (qcow2_co_encrypt(bs, cluster_offset, 478 478 src_cluster_offset + offset_in_cluster,
+2 -2
block/qcow2.c
··· 2067 2067 goto fail; 2068 2068 } 2069 2069 2070 - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); 2071 - assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) == 0); 2070 + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); 2071 + assert(QEMU_IS_ALIGNED(cur_bytes, BDRV_SECTOR_SIZE)); 2072 2072 if (qcow2_co_decrypt(bs, cluster_offset, offset, 2073 2073 cluster_data, cur_bytes) < 0) { 2074 2074 ret = -EIO;
+4 -4
block/vvfat.c
··· 1547 1547 int nb_sectors = bytes >> BDRV_SECTOR_BITS; 1548 1548 void *buf; 1549 1549 1550 - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); 1551 - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); 1550 + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); 1551 + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); 1552 1552 1553 1553 buf = g_try_malloc(bytes); 1554 1554 if (bytes && buf == NULL) { ··· 3082 3082 int nb_sectors = bytes >> BDRV_SECTOR_BITS; 3083 3083 void *buf; 3084 3084 3085 - assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); 3086 - assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); 3085 + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); 3086 + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); 3087 3087 3088 3088 buf = g_try_malloc(bytes); 3089 3089 if (bytes && buf == NULL) {
+1 -1
qemu-img.c
··· 2141 2141 int64_t sval; 2142 2142 2143 2143 sval = cvtnum(optarg); 2144 - if (sval < 0 || sval & (BDRV_SECTOR_SIZE - 1) || 2144 + if (sval < 0 || !QEMU_IS_ALIGNED(sval, BDRV_SECTOR_SIZE) || 2145 2145 sval / BDRV_SECTOR_SIZE > MAX_BUF_SECTORS) { 2146 2146 error_report("Invalid buffer size for sparse output specified. " 2147 2147 "Valid sizes are multiples of %llu up to %llu. Select "