aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2018-11-01 21:27:36 +0300
committerKevin Wolf <kwolf@redhat.com>2018-12-14 11:52:40 +0100
commitc068a1cd5203cc406a648a641e773ba906cf4aaa (patch)
tree72b6f60f0b1c6ec34bda0c9ce2509d1422624cb5 /block
parent341926ab83e2b4d5af1f8c7633e8b6d72d318458 (diff)
qcow2: use byte-based read in qcow2_decompress_cluster
We are gradually moving away from sector-based interfaces, towards byte-based. Get rid of it here too. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/qcow2.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index b60c01582c..014aca6492 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3957,17 +3957,19 @@ fail:
return ret;
}
-int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
+int coroutine_fn
+qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
{
BDRVQcow2State *s = bs->opaque;
- int ret, csize, nb_csectors, sector_offset;
+ int ret, csize, nb_csectors;
uint64_t coffset;
+ struct iovec iov;
+ QEMUIOVector local_qiov;
coffset = cluster_offset & s->cluster_offset_mask;
if (s->cluster_cache_offset != coffset) {
nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1;
- sector_offset = coffset & 511;
- csize = nb_csectors * 512 - sector_offset;
+ csize = nb_csectors * 512 - (coffset & 511);
/* Allocate buffers on first decompress operation, most images are
* uncompressed and the memory overhead can be avoided. The buffers
@@ -3985,14 +3987,17 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
s->cluster_cache = g_malloc(s->cluster_size);
}
+ iov.iov_base = s->cluster_data;
+ iov.iov_len = csize;
+ qemu_iovec_init_external(&local_qiov, &iov, 1);
+
BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
- ret = bdrv_read(bs->file, coffset >> 9, s->cluster_data,
- nb_csectors);
+ ret = bdrv_co_preadv(bs->file, coffset, csize, &local_qiov, 0);
if (ret < 0) {
return ret;
}
if (qcow2_decompress(s->cluster_cache, s->cluster_size,
- s->cluster_data + sector_offset, csize) < 0) {
+ s->cluster_data, csize) < 0) {
return -EIO;
}
s->cluster_cache_offset = coffset;