On Wed, Jan 8, 2020 at 7:50 PM Alberto Garcia <be...@igalia.com> wrote: > > This replaces all remaining instances in the qcow2 code. > > Signed-off-by: Alberto Garcia <be...@igalia.com> > --- > block/qcow2-cluster.c | 2 +- > block/qcow2.c | 16 +++++++++------- > 2 files changed, 10 insertions(+), 8 deletions(-) > > diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c > index 932fc48919..777ca2d409 100644 > --- a/block/qcow2-cluster.c > +++ b/block/qcow2-cluster.c > @@ -219,7 +219,7 @@ static int l2_load(BlockDriverState *bs, uint64_t offset, > * Writes one sector of the L1 table to the disk (can't update single entries > * and we really don't want bdrv_pread to perform a read-modify-write) > */ > -#define L1_ENTRIES_PER_SECTOR (512 / 8) > +#define L1_ENTRIES_PER_SECTOR (BDRV_SECTOR_SIZE / 8) > int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index) > { > BDRVQcow2State *s = bs->opaque; > diff --git a/block/qcow2.c b/block/qcow2.c > index e8ce966f7f..6427c75409 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -2175,7 +2175,7 @@ static coroutine_fn int > qcow2_co_preadv_task(BlockDriverState *bs, > offset, bytes, qiov, qiov_offset); > > case QCOW2_CLUSTER_NORMAL: > - if ((file_cluster_offset & 511) != 0) { > + if ((file_cluster_offset % BDRV_SECTOR_SIZE) != 0) {
All the alignment checks should use QEMU_IS_ALIGNED. > return -EIO; > } > > @@ -2514,7 +2514,7 @@ static coroutine_fn int qcow2_co_pwritev_part( > goto out_locked; > } > > - assert((cluster_offset & 511) == 0); > + assert((cluster_offset % BDRV_SECTOR_SIZE) == 0); > > ret = qcow2_pre_write_overlap_check(bs, 0, > cluster_offset + > offset_in_cluster, > @@ -3283,7 +3283,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options, > Error **errp) > > /* Validate options and set default values */ > if (!QEMU_IS_ALIGNED(qcow2_opts->size, BDRV_SECTOR_SIZE)) { > - error_setg(errp, "Image size must be a multiple of 512 bytes"); > + error_setg(errp, "Image size must be a multiple of %u bytes", > + (unsigned) BDRV_SECTOR_SIZE); > ret = -EINVAL; > goto out; > } > @@ -3839,7 +3840,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, > case QCOW2_CLUSTER_NORMAL: > child = s->data_file; > copy_offset += offset_into_cluster(s, src_offset); > - if ((copy_offset & 511) != 0) { > + if ((copy_offset % BDRV_SECTOR_SIZE) != 0) { > ret = -EIO; > goto out; > } > @@ -3904,7 +3905,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs, > goto fail; > } > > - assert((cluster_offset & 511) == 0); > + assert((cluster_offset % BDRV_SECTOR_SIZE) == 0); > > ret = qcow2_pre_write_overlap_check(bs, 0, > cluster_offset + offset_in_cluster, cur_bytes, true); > @@ -3961,8 +3962,9 @@ static int coroutine_fn > qcow2_co_truncate(BlockDriverState *bs, int64_t offset, > return -ENOTSUP; > } > > - if (offset & 511) { > - error_setg(errp, "The new size must be a multiple of 512"); > + if (offset % BDRV_SECTOR_SIZE) { > + error_setg(errp, "The new size must be a multiple of %u", > + (unsigned) BDRV_SECTOR_SIZE); > return -EINVAL; > } > > -- > 2.20.1 Otherwise looks good. Nir