Received: from eggs.gnu.org ([2001:4830:134:3::10]:57833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu0tX-00023k-1C for qemu-devel@nongnu.org; Thu, 27 Nov 2014 10:22:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xu0tO-0008UI-0Z for qemu-devel@nongnu.org; Thu, 27 Nov 2014 10:22:10 -0500 Received: from mail-wg0-x233.google.com ([2a00:1450:400c:c00::233]:61711) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu0tN-0008U8-QR for qemu-devel@nongnu.org; Thu, 27 Nov 2014 10:22:01 -0500 Received: by mail-wg0-f51.google.com with SMTP id k14so6649307wgh.38 for ; Thu, 27 Nov 2014 07:22:01 -0800 (PST) Date: Thu, 27 Nov 2014 15:21:58 +0000 From: Stefan Hajnoczi Message-ID: <20141127152158.GG15586@stefanha-thinkpad.lan> References: <1416503198-17031-1-git-send-email-mreitz@redhat.com> <1416503198-17031-8-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qxfKREH7IwbezJ+T" Content-Disposition: inline In-Reply-To: <1416503198-17031-8-git-send-email-mreitz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 07/22] qcow2: Helper function for refcount modification List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi --qxfKREH7IwbezJ+T Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 20, 2014 at 06:06:23PM +0100, Max Reitz wrote: > @@ -116,20 +137,24 @@ int64_t qcow2_get_refcount(BlockDriverState *bs, in= t64_t cluster_index) > } > =20 > ret =3D qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_= offset, > - (void**) &refcount_block); > + &refcount_block); > if (ret < 0) { > return ret; > } > =20 > block_index =3D cluster_index & (s->refcount_block_size - 1); > - refcount =3D be16_to_cpu(refcount_block[block_index]); > + refcount =3D s->get_refcount(refcount_block, block_index); > =20 > - ret =3D qcow2_cache_put(bs, s->refcount_block_cache, > - (void**) &refcount_block); > + ret =3D qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block= ); > if (ret < 0) { > return ret; > } > =20 > + if (refcount < 0) { > + /* overflow */ > + return -ERANGE; > + } I guess this is because QEMU uses int64_t but the maximum refcount size is 64 bits. If we refuse to open files with 64-bit refcounts, can we drop this check? > @@ -583,7 +608,12 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(B= lockDriverState *bs, > /* we can update the count and save it */ > block_index =3D cluster_index & (s->refcount_block_size - 1); > =20 > - refcount =3D be16_to_cpu(refcount_block[block_index]); > + refcount =3D s->get_refcount(refcount_block, block_index); > + if (refcount < 0) { > + ret =3D -ERANGE; > + goto fail; > + } Here again. > @@ -1206,11 +1236,14 @@ static int inc_refcounts(BlockDriverState *bs, > } > } > =20 > - if (++(*refcount_table)[k] =3D=3D 0) { > + refcount =3D s->get_refcount(*refcount_table, k); Here the refcount < 0 check is missing. That's why it would be simpler to eliminate the refcount < 0 case entirely. > @@ -1726,7 +1761,7 @@ static void compare_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, > continue; > } > =20 > - refcount2 =3D refcount_table[i]; > + refcount2 =3D s->get_refcount(refcount_table, i); Missing here too and in other places. > +typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array, > + uint64_t index); Should the return type be int64_t? > +typedef void Qcow2SetRefcountFunc(void *refcount_array, > + uint64_t index, uint64_t value); Should value's type be int64_t? Just because the type is unsigned doesn't make (uint64_t)-1ULL a valid value. --qxfKREH7IwbezJ+T Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUd0GWAAoJEJykq7OBq3PILw8H/jF1ehBaXoDh1hrMrt8UdONw jjmInfQxZz/44TPxFqivyqDubv6R/Y/DASkanZ0UbsXK8Z6EOqrc4JqMAt2jTSce JEzU94lPErv+dESH9KSEkVeOMlyzV15ZjbgUfmgy1kOdmBSuIUBH/skw5ADJp7Rn ECS6xhCKi9wTTUirvv+SLbGG4zYpWLhE6xOhAtk5WbTvnZA99lUYcbYCso5e4Bi8 h9mJCbsTWu5Uhox4nVSsfwcDwUYkY1YxRC6V7PEj90sT+mUvRGOSeG+6GHNp2tUw oLjcWozZwwYT675Jbhj6uI4ZQ1kI6hn/U4VEkFXcNlPmaBSwfAJ9vrJf7xhreeI= =yRNv -----END PGP SIGNATURE----- --qxfKREH7IwbezJ+T--