aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2015-02-10 15:28:43 -0500
committerKevin Wolf <kwolf@redhat.com>2015-03-10 14:02:20 +0100
commit346a53df38e29021e4a9e8c2a759b05744902857 (patch)
tree4fb40e0b5184a98ccd17fb7d67708a7ef9c88c5b /block
parent0a6ed700061fdd86b3c4b71366be42503ac2ce23 (diff)
downloadqemu-346a53df38e29021e4a9e8c2a759b05744902857.zip
qemu-346a53df38e29021e4a9e8c2a759b05744902857.tar.gz
qemu-346a53df38e29021e4a9e8c2a759b05744902857.tar.bz2
qcow2: Add two new fields to BDRVQcowState
Add two new fields regarding refcount information (the bit width of every entry and the maximum refcount value) to the BDRVQcowState. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/qcow2-refcount.c4
-rw-r--r--block/qcow2.c3
-rw-r--r--block/qcow2.h2
3 files changed, 7 insertions, 2 deletions
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 9b80ca7..e124a54 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -584,7 +584,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
refcount = be16_to_cpu(refcount_block[block_index]);
refcount += addend;
- if (refcount < 0 || refcount > 0xffff) {
+ if (refcount < 0 || refcount > s->refcount_max) {
ret = -EINVAL;
goto fail;
}
@@ -775,7 +775,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
return refcount;
}
- if (refcount == 0xffff) {
+ if (refcount == s->refcount_max) {
offset = 0;
}
}
diff --git a/block/qcow2.c b/block/qcow2.c
index 50e0a94..e04ba6d 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -684,6 +684,9 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
goto fail;
}
s->refcount_order = header.refcount_order;
+ s->refcount_bits = 1 << s->refcount_order;
+ s->refcount_max = UINT64_C(1) << (s->refcount_bits - 1);
+ s->refcount_max += s->refcount_max - 1;
if (header.crypt_method > QCOW_CRYPT_AES) {
error_setg(errp, "Unsupported encryption method: %" PRIu32,
diff --git a/block/qcow2.h b/block/qcow2.h
index 0fee29b..55138c9 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -258,6 +258,8 @@ typedef struct BDRVQcowState {
int qcow_version;
bool use_lazy_refcounts;
int refcount_order;
+ int refcount_bits;
+ uint64_t refcount_max;
bool discard_passthrough[QCOW2_DISCARD_MAX];