aboutsummaryrefslogtreecommitdiff
path: root/block/qcow2-refcount.c
diff options
context:
space:
mode:
authorAlberto Garcia <berto@igalia.com>2019-05-10 19:22:54 +0300
committerKevin Wolf <kwolf@redhat.com>2019-05-20 17:08:56 +0200
commitb6c246942b14d3e0dec46a6c5868ed84e7dbea19 (patch)
treece424eaf7dd574d6ae54e64dcc380dac9c2de656 /block/qcow2-refcount.c
parent50ba5b2d994853b38fed10e0841b119da0f8b8e5 (diff)
downloadqemu-b6c246942b14d3e0dec46a6c5868ed84e7dbea19.zip
qemu-b6c246942b14d3e0dec46a6c5868ed84e7dbea19.tar.gz
qemu-b6c246942b14d3e0dec46a6c5868ed84e7dbea19.tar.bz2
qcow2: Define and use QCOW2_COMPRESSED_SECTOR_SIZE
When an L2 table entry points to a compressed cluster the space used by the data is specified in 512-byte sectors. This size is independent from BDRV_SECTOR_SIZE and is specific to the qcow2 file format. The QCOW2_COMPRESSED_SECTOR_SIZE constant defined in this patch makes this explicit. Signed-off-by: Alberto Garcia <berto@igalia.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2-refcount.c')
-rw-r--r--block/qcow2-refcount.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 7481903..0b09d68 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -1172,12 +1172,11 @@ void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
switch (ctype) {
case QCOW2_CLUSTER_COMPRESSED:
{
- int nb_csectors;
- nb_csectors = ((l2_entry >> s->csize_shift) &
- s->csize_mask) + 1;
- qcow2_free_clusters(bs,
- (l2_entry & s->cluster_offset_mask) & ~511,
- nb_csectors * 512, type);
+ int64_t offset = (l2_entry & s->cluster_offset_mask)
+ & QCOW2_COMPRESSED_SECTOR_MASK;
+ int size = QCOW2_COMPRESSED_SECTOR_SIZE *
+ (((l2_entry >> s->csize_shift) & s->csize_mask) + 1);
+ qcow2_free_clusters(bs, offset, size, type);
}
break;
case QCOW2_CLUSTER_NORMAL:
@@ -1317,9 +1316,12 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
nb_csectors = ((entry >> s->csize_shift) &
s->csize_mask) + 1;
if (addend != 0) {
+ uint64_t coffset = (entry & s->cluster_offset_mask)
+ & QCOW2_COMPRESSED_SECTOR_MASK;
ret = update_refcount(
- bs, (entry & s->cluster_offset_mask) & ~511,
- nb_csectors * 512, abs(addend), addend < 0,
+ bs, coffset,
+ nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE,
+ abs(addend), addend < 0,
QCOW2_DISCARD_SNAPSHOT);
if (ret < 0) {
goto fail;
@@ -1635,9 +1637,10 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
nb_csectors = ((l2_entry >> s->csize_shift) &
s->csize_mask) + 1;
l2_entry &= s->cluster_offset_mask;
- ret = qcow2_inc_refcounts_imrt(bs, res,
- refcount_table, refcount_table_size,
- l2_entry & ~511, nb_csectors * 512);
+ ret = qcow2_inc_refcounts_imrt(
+ bs, res, refcount_table, refcount_table_size,
+ l2_entry & QCOW2_COMPRESSED_SECTOR_MASK,
+ nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE);
if (ret < 0) {
goto fail;
}