From patchwork Wed Dec 12 13:25:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Hahn X-Patchwork-Id: 205511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8E66A2C00A5 for ; Thu, 13 Dec 2012 00:26:13 +1100 (EST) Received: from localhost ([::1]:45712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TimKB-0007HS-N8 for incoming@patchwork.ozlabs.org; Wed, 12 Dec 2012 08:26:11 -0500 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 Received: from localhost (localhost [127.0.0.1]) by slugis.knut.univention.de (Postfix) with ESMTP id 278D6144B25F; Wed, 12 Dec 2012 14:25:47 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by slugis.knut.univention.de (Postfix) with ESMTP id 1A20F144B348; Wed, 12 Dec 2012 14:25:47 +0100 (CET) X-Virus-Scanned: by amavisd-new-2.6.1 (20080629) (Debian) at knut.univention.de 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 smAsCmiayeam; Wed, 12 Dec 2012 14:25:46 +0100 (CET) Received: from stave.knut.univention.de (mail.univention.de [82.198.197.8]) by slugis.knut.univention.de (Postfix) with ESMTPSA id 86C74144B25F; Wed, 12 Dec 2012 14:25:46 +0100 (CET) From: Philipp Hahn Organization: Univention.de To: qemu-devel@nongnu.org, Michael Tokarev Date: Wed, 12 Dec 2012 14:25:36 +0100 User-Agent: KMail/1.9.10 (enterprise35 20100903.1171286) 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> X-KMail-QuotePrefix: > MIME-Version: 1.0 Message-Id: <201212121425.41850.hahn@univention.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 82.198.197.8 Cc: Kevin Wolf Subject: [Qemu-devel] [BUG] qemu-1.1.2 [FIXED-BY] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hello Kevin, hello Michael, hello *, we noticed a data corruption bug in qemu-1.1.2, which will be shipped by Debian and our own Debian based distibution. The corruption mostly manifests while installing large Debian package files and seems to be reladed to memory preasure: As long as the file is still in the page cache, everything looks fine, but when the file is re-read from the virtual hard disk using a qcow2 file backed by another qcow2 file, the file is corrupted: dpkg complains that the .tar.gz file inside the Debian archive file is corrupted and the md5sum no longer matches. I tracked this down using "git bisect" to your patch attached below, which fixed this bug, so everything is fine with qemu-kvm-1.2.0. From my reading this seems to explain our problems, since during my own testing during development I never used backing chains and the problem only showed up when my collegues started using qemu-kvm-1.1.2 with their VMs using backing chains. @Kevin: Do you thinks that's a valid explanation and your patch should fix that problem? I'd like to get your expertise before filing a bug with Debian and asking Michael to include that patch with his next stable update for 1.1. Thanks in advance. Sincerely Philipp 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) {