From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRPVu-0005TQ-Oh for qemu-devel@nongnu.org; Fri, 27 Feb 2015 13:19:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YRPVo-0001Gd-7R for qemu-devel@nongnu.org; Fri, 27 Feb 2015 13:19:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YRPVn-0001GQ-VD for qemu-devel@nongnu.org; Fri, 27 Feb 2015 13:19:44 -0500 From: Stefan Hajnoczi Date: Fri, 27 Feb 2015 18:18:13 +0000 Message-Id: <1425061147-1411-16-git-send-email-stefanha@redhat.com> In-Reply-To: <1425061147-1411-1-git-send-email-stefanha@redhat.com> References: <1425061147-1411-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 15/69] qcow2: Add two new fields to BDRVQcowState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Maydell , Max Reitz From: Max Reitz 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 Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/qcow2-refcount.c | 4 ++-- block/qcow2.c | 3 +++ block/qcow2.h | 2 ++ 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 2ed8d95..2c01e25 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]; -- 2.1.0