Skip to content

Commit 9a3978a

Browse files
Vladimir Sementsov-OgievskiyXanClic
authored andcommitted
qcow2: compressed read: simplify cluster descriptor passing
Let's pass the whole L2 entry and not bother with L2E_COMPRESSED_OFFSET_SIZE_MASK. It also helps further refactoring that adds generic qcow2_parse_compressed_l2_entry() helper. Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Reviewed-by: Eric Blake <[email protected]> Reviewed-by: Alberto Garcia <[email protected]> Reviewed-by: Hanna Reitz <[email protected]> Message-Id: <[email protected]> Signed-off-by: Hanna Reitz <[email protected]>
1 parent 786c22d commit 9a3978a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

block/qcow2-cluster.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ static int coroutine_fn do_perform_cow_write(BlockDriverState *bs,
556556
* offset needs to be aligned to a cluster boundary.
557557
*
558558
* If the cluster is unallocated then *host_offset will be 0.
559-
* If the cluster is compressed then *host_offset will contain the
560-
* complete compressed cluster descriptor.
559+
* If the cluster is compressed then *host_offset will contain the l2 entry.
561560
*
562561
* On entry, *bytes is the maximum number of contiguous bytes starting at
563562
* offset that we are interested in.
@@ -660,7 +659,7 @@ int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset,
660659
ret = -EIO;
661660
goto fail;
662661
}
663-
*host_offset = l2_entry & L2E_COMPRESSED_OFFSET_SIZE_MASK;
662+
*host_offset = l2_entry;
664663
break;
665664
case QCOW2_SUBCLUSTER_ZERO_PLAIN:
666665
case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN:

block/qcow2.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef struct {
7474

7575
static int coroutine_fn
7676
qcow2_co_preadv_compressed(BlockDriverState *bs,
77-
uint64_t cluster_descriptor,
77+
uint64_t l2_entry,
7878
uint64_t offset,
7979
uint64_t bytes,
8080
QEMUIOVector *qiov,
@@ -2205,7 +2205,7 @@ typedef struct Qcow2AioTask {
22052205

22062206
BlockDriverState *bs;
22072207
QCow2SubclusterType subcluster_type; /* only for read */
2208-
uint64_t host_offset; /* or full descriptor in compressed clusters */
2208+
uint64_t host_offset; /* or l2_entry for compressed read */
22092209
uint64_t offset;
22102210
uint64_t bytes;
22112211
QEMUIOVector *qiov;
@@ -4693,7 +4693,7 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,
46934693

46944694
static int coroutine_fn
46954695
qcow2_co_preadv_compressed(BlockDriverState *bs,
4696-
uint64_t cluster_descriptor,
4696+
uint64_t l2_entry,
46974697
uint64_t offset,
46984698
uint64_t bytes,
46994699
QEMUIOVector *qiov,
@@ -4705,8 +4705,10 @@ qcow2_co_preadv_compressed(BlockDriverState *bs,
47054705
uint8_t *buf, *out_buf;
47064706
int offset_in_cluster = offset_into_cluster(s, offset);
47074707

4708-
coffset = cluster_descriptor & s->cluster_offset_mask;
4709-
nb_csectors = ((cluster_descriptor >> s->csize_shift) & s->csize_mask) + 1;
4708+
assert(qcow2_get_cluster_type(bs, l2_entry) == QCOW2_CLUSTER_COMPRESSED);
4709+
4710+
coffset = l2_entry & s->cluster_offset_mask;
4711+
nb_csectors = ((l2_entry >> s->csize_shift) & s->csize_mask) + 1;
47104712
csize = nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE -
47114713
(coffset & ~QCOW2_COMPRESSED_SECTOR_MASK);
47124714

block/qcow2.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,6 @@ typedef enum QCow2MetadataOverlap {
588588

589589
#define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
590590
#define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
591-
#define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL
592591

593592
#define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
594593

0 commit comments

Comments
 (0)