From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwA7z-0001Sl-53 for qemu-devel@nongnu.org; Wed, 03 Dec 2014 08:38:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XwA7t-0004AU-0s for qemu-devel@nongnu.org; Wed, 03 Dec 2014 08:37:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwA7s-0004AN-P8 for qemu-devel@nongnu.org; Wed, 03 Dec 2014 08:37:52 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sB3DbpMd021702 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 3 Dec 2014 08:37:51 -0500 From: Max Reitz Date: Wed, 3 Dec 2014 14:37:21 +0100 Message-Id: <1417613866-25890-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1417613866-25890-1-git-send-email-mreitz@redhat.com> References: <1417613866-25890-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v4 01/26] 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 , Stefan Hajnoczi , 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 --- block/qcow2-refcount.c | 2 +- block/qcow2.c | 3 +++ block/qcow2.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 9afdb40..6016211 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; } diff --git a/block/qcow2.c b/block/qcow2.c index 8b9ffc4..5ed982b 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 6e39a1b..4d8c902 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]; -- 1.9.3