On 06/06/2016 08:59 AM, Kevin Wolf wrote: > Reading from qcow2 images is now byte granularity. > > Most of the affected code in qcow2 actually gets simpler with this > change. The only exception is encryption, which is fixed on 512 bytes > blocks; in order to keep this working, bs->request_alignment is set for > encrypted images. > > Signed-off-by: Kevin Wolf <kw...@redhat.com> > --- > block/qcow2-cluster.c | 27 ++++++------- > block/qcow2.c | 108 > +++++++++++++++++++++++++++----------------------- > block/qcow2.h | 2 +- > 3 files changed, 72 insertions(+), 65 deletions(-) >
> - * on exit, *num is the number of contiguous sectors we can read. > + * On exit, *bytes is the number of bytes staring at offset that have the > same s/staring/starting/ (although "staring" does make for a rather interesting thought :) > @@ -1389,26 +1402,24 @@ static coroutine_fn int > qcow2_co_readv(BlockDriverState *bs, int64_t sector_num, > > qemu_co_mutex_lock(&s->lock); > > - while (remaining_sectors != 0) { > + while (bytes != 0) { > > /* prepare next request */ > - cur_nr_sectors = remaining_sectors; > + cur_bytes = MIN(bytes, INT_MAX); > if (s->cipher) { > - cur_nr_sectors = MIN(cur_nr_sectors, > - QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors); > + cur_bytes = MIN(cur_bytes, > + QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); > } Can this ever result in cur_bytes that is not aligned, even though encryption requires aligned reads? Do you need to round anything to a sector boundary in this case? > qemu_co_mutex_unlock(&s->lock); > - ret = bdrv_co_readv(bs->file->bs, > - (cluster_offset >> 9) + index_in_cluster, > - cur_nr_sectors, &hd_qiov); > + ret = bdrv_co_preadv(bs->file->bs, > + cluster_offset + offset_in_cluster, > + cur_bytes, &hd_qiov, 0); > qemu_co_mutex_lock(&s->lock); > if (ret < 0) { > goto fail; > } > if (bs->encrypted) { > assert(s->cipher); > + assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); > + assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) == 0); Hmm, you do check that later on. So, other than the typo (easy to fix on commit), Reviewed-by: Eric Blake <ebl...@redhat.com> -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature