提交 346a53df 编写于 作者: M Max Reitz 提交者: Kevin Wolf

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: NMax Reitz <mreitz@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 0a6ed700
...@@ -584,7 +584,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, ...@@ -584,7 +584,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
refcount = be16_to_cpu(refcount_block[block_index]); refcount = be16_to_cpu(refcount_block[block_index]);
refcount += addend; refcount += addend;
if (refcount < 0 || refcount > 0xffff) { if (refcount < 0 || refcount > s->refcount_max) {
ret = -EINVAL; ret = -EINVAL;
goto fail; goto fail;
} }
...@@ -775,7 +775,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size) ...@@ -775,7 +775,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
return refcount; return refcount;
} }
if (refcount == 0xffff) { if (refcount == s->refcount_max) {
offset = 0; offset = 0;
} }
} }
......
...@@ -684,6 +684,9 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, ...@@ -684,6 +684,9 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
goto fail; goto fail;
} }
s->refcount_order = header.refcount_order; 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) { if (header.crypt_method > QCOW_CRYPT_AES) {
error_setg(errp, "Unsupported encryption method: %" PRIu32, error_setg(errp, "Unsupported encryption method: %" PRIu32,
......
...@@ -258,6 +258,8 @@ typedef struct BDRVQcowState { ...@@ -258,6 +258,8 @@ typedef struct BDRVQcowState {
int qcow_version; int qcow_version;
bool use_lazy_refcounts; bool use_lazy_refcounts;
int refcount_order; int refcount_order;
int refcount_bits;
uint64_t refcount_max;
bool discard_passthrough[QCOW2_DISCARD_MAX]; bool discard_passthrough[QCOW2_DISCARD_MAX];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册