From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TimJw-0007H7-NR for qemu-devel@nongnu.org; Wed, 12 Dec 2012 08:26:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TimJq-0006MF-Ai for qemu-devel@nongnu.org; Wed, 12 Dec 2012 08:25:56 -0500 Received: from mail.univention.de ([82.198.197.8]:1258) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TimJq-0006M3-0E for qemu-devel@nongnu.org; Wed, 12 Dec 2012 08:25:50 -0500 From: Philipp Hahn Date: Wed, 12 Dec 2012 14:25:36 +0100 References: <1339767219-24297-1-git-send-email-kwolf@redhat.com> <1339767219-24297-29-git-send-email-kwolf@redhat.com> In-Reply-To: <1339767219-24297-29-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1756602.d8HaZGxXZL"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201212121425.41850.hahn@univention.de> Subject: [Qemu-devel] [BUG] qemu-1.1.2 [FIXED-BY] qcow2: Fix avail_sectors in cluster allocation code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Michael Tokarev Cc: Kevin Wolf --nextPart1756602.d8HaZGxXZL Content-Type: multipart/mixed; boundary="Boundary-01=_QXIyQjvuDhqSKcH" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_QXIyQjvuDhqSKcH Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello Kevin, hello Michael, hello *, we noticed a data corruption bug in qemu-1.1.2, which will be shipped by=20 Debian and our own Debian based distibution. The corruption mostly manifests while installing large Debian package files= =20 and seems to be reladed to memory preasure: As long as the file is still in= =20 the page cache, everything looks fine, but when the file is re-read from th= e=20 virtual hard disk using a qcow2 file backed by another qcow2 file, the file= =20 is corrupted: dpkg complains that the .tar.gz file inside the Debian archiv= e=20 file is corrupted and the md5sum no longer matches. I tracked this down using "git bisect" to your patch attached below, which= =20 fixed this bug, so everything is fine with qemu-kvm-1.2.0. =46rom my reading this seems to explain our problems, since during my own=20 testing during development I never used backing chains and the problem only= =20 showed up when my collegues started using qemu-kvm-1.1.2 with their VMs usi= ng=20 backing chains. @Kevin: Do you thinks that's a valid explanation and your patch should fix= =20 that problem? I'd like to get your expertise before filing a bug with Debian and asking=20 Michael to include that patch with his next stable update for 1.1. Thanks in advance. Sincerely Philipp =2D-=20 Philipp Hahn Open Source Software Engineer hahn@univention.de Univention GmbH be open. fon: +49 421 22 232- 0 Mary-Somerville-Str.1 D-28359 Bremen fax: +49 421 22 232-99 http://www.univention.de/ --Boundary-01=_QXIyQjvuDhqSKcH Content-Type: message/rfc822; name="forwarded message" Content-Transfer-Encoding: 7bit Content-Description: Kevin Wolf : [Qemu-devel] [PATCH 28/39] qcow2: Fix avail_sectors in cluster allocation code Content-Disposition: inline Return-Path: Received: from localhost (localhost [127.0.0.1]) by slugis (Cyrus v2.2.13-Debian-2.2.13-14.117.201112201012) with LMTPA; Fri, 15 Jun 2012 16:57:58 +0200 X-Sieve: CMU Sieve 2.2 Received: from localhost (localhost [127.0.0.1]) by slugis.knut.univention.de (Postfix) with ESMTP id 79633164B10E for ; Fri, 15 Jun 2012 16:57:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by slugis.knut.univention.de (Postfix) with ESMTP id 6E4D1164B10F for ; Fri, 15 Jun 2012 16:57:58 +0200 (CEST) X-Virus-Scanned: by amavisd-new-2.6.1 (20080629) (Debian) at knut.univention.de X-Spam-Flag: NO X-Spam-Score: -9.298 X-Spam-Level: X-Spam-Status: No, score=-9.298 tagged_above=-1000 required=3 tests=[AWL=1.302, BAYES_00=-2.599, RCVD_IN_DNSWL_HI=-8, SPF_PASS=-0.001] Received: from mail.univention.de ([127.0.0.1]) by localhost (slugis.knut.univention.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lfQb2Jrj7Ar0 for ; Fri, 15 Jun 2012 16:57:58 +0200 (CEST) Received: from slugis.knut.univention.de (localhost [127.0.0.1]) by slugis.knut.univention.de (Postfix) with ESMTP id 11B98164B10E for ; Fri, 15 Jun 2012 16:57:58 +0200 (CEST) Delivery-Date: Fri, 15 Jun 2012 16:57:56 +0200 Received-SPF: pass (mxbap3: domain of nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+hahn=univention.de@nongnu.org; helo=lists.gnu.org; Received: from pop.kundenserver.de by slugis.knut.univention.de with POP3 (fetchmail-6.3.9-rc2) for (single-drop); Fri, 15 Jun 2012 16:57:58 +0200 (CEST) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.kundenserver.de (node=mxbap3) with ESMTP (Nemesis) id 0LopDP-1Rz4Xv1oaZ-00gHFq for hahn@univention.de; Fri, 15 Jun 2012 16:57:56 +0200 Received: from localhost ([::1]:38238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfXyF-0001hC-2n for hahn@univention.de; Fri, 15 Jun 2012 10:57:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfWfX-00027d-Mx for qemu-devel@nongnu.org; Fri, 15 Jun 2012 09:34:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SfWfO-0004qe-Ha for qemu-devel@nongnu.org; Fri, 15 Jun 2012 09:34:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53657) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfWfO-0004qF-9o for qemu-devel@nongnu.org; Fri, 15 Jun 2012 09:34:22 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5FDYKjm003863 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Jun 2012 09:34:20 -0400 Received: from dhcp-5-188.str.redhat.com (vpn1-6-30.ams2.redhat.com [10.36.6.30]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5FDXepM016743; Fri, 15 Jun 2012 09:34:19 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 15 Jun 2012 15:33:28 +0200 Message-Id: <1339767219-24297-29-git-send-email-kwolf@redhat.com> In-Reply-To: <1339767219-24297-1-git-send-email-kwolf@redhat.com> References: <1339767219-24297-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 28/39] qcow2: Fix avail_sectors in cluster allocation code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+hahn=univention.de@nongnu.org Sender: qemu-devel-bounces+hahn=univention.de@nongnu.org X-UI-Loop: V01:YXn2UVngatg=:4PyaKqH4+kkhlJIF+sfv8TF5mEm19YWfNbQxH/NY2YY= Envelope-To: hahn@univention.de X-Kolab-Scheduling-Message: FALSE X-Length: 6588 avail_sectors should really be the number of sectors from the start of the allocation, not from the start of the write request. We're lucky enough that this mistake didn't cause any real bug. avail_sectors is only used in the intialiser of QCowL2Meta: .nb_available = MIN(requested_sectors, avail_sectors), m->nb_available in turn is only used for COW at the end of the allocation. A COW occurs only if the request wasn't cluster aligned, which in turn would imply that requested_sectors was less than avail_sectors (both in the original and in the fixed version). In this case avail_sectors is ignored and therefore the mistake doesn't cause any misbehaviour. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 98fba71..d7e0e19 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -947,8 +947,16 @@ again: /* save info needed for meta data update */ if (nb_clusters > 0) { + /* + * requested_sectors: Number of sectors from the start of the first + * newly allocated cluster to the end of the (possibly shortened + * before) write request. + * + * avail_sectors: Number of sectors from the start of the first + * newly allocated to the end of the last newly allocated cluster. + */ int requested_sectors = n_end - keep_clusters * s->cluster_sectors; - int avail_sectors = (keep_clusters + nb_clusters) + int avail_sectors = nb_clusters << (s->cluster_bits - BDRV_SECTOR_BITS); *m = (QCowL2Meta) { -- 1.7.6.5 --Boundary-01=_QXIyQjvuDhqSKcH-- --nextPart1756602.d8HaZGxXZL Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAlDIhdAACgkQYPlgoZpUDjkfwwCeL6q8GSjIH3AiDTlRQGR/c9bb ZEcAnjj3maLL5UoPuc5ZxjtQx6+QJuhw =Bvpc -----END PGP SIGNATURE----- --nextPart1756602.d8HaZGxXZL--