From patchwork Mon Feb 4 10:40:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 217961 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 55E9C2C02AD for ; Tue, 5 Feb 2013 02:03:55 +1100 (EST) Received: from localhost ([::1]:56507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2Jgd-0001ud-Ka for incoming@patchwork.ozlabs.org; Mon, 04 Feb 2013 05:54:07 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2JgK-0001Pz-4I for qemu-devel@nongnu.org; Mon, 04 Feb 2013 05:53:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U2JgH-0004Te-M9 for qemu-devel@nongnu.org; Mon, 04 Feb 2013 05:53:48 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:57147) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2JgH-0004TN-5k; Mon, 04 Feb 2013 05:53:45 -0500 Received: from gandalf.tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by isrv.corpit.ru (Postfix) with ESMTP id 787D5A03E9; Mon, 4 Feb 2013 14:53:44 +0400 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id 0C4C153F; Mon, 4 Feb 2013 14:41:29 +0400 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2013 14:40:53 +0400 Message-Id: <1359974470-17044-44-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359974470-17044-1-git-send-email-mjt@msgid.tls.msk.ru> References: <1359974470-17044-1-git-send-email-mjt@msgid.tls.msk.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 86.62.121.231 Cc: Kevin Wolf , Michael Tokarev , qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 43/60] 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 From: Kevin Wolf 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 (cherry picked from commit b7ab0fea37c15ca9e249c42c46f5c48fd1a0943c) Signed-off-by: Michael Tokarev --- block/qcow2-cluster.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index c173fcd..58e7e24 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -949,8 +949,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) {