From patchwork Tue Oct 1 01:28:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 279300 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4F3242C00AB for ; Tue, 1 Oct 2013 11:29:02 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755534Ab3JAB3B (ORCPT ); Mon, 30 Sep 2013 21:29:01 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:38003 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755105Ab3JAB3A (ORCPT ); Mon, 30 Sep 2013 21:29:00 -0400 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r911SwTx023520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 1 Oct 2013 01:28:59 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r911SwZH009719 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 1 Oct 2013 01:28:58 GMT Received: from abhmt118.oracle.com (abhmt118.oracle.com [141.146.116.70]) by userz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r911Svi0007913; Tue, 1 Oct 2013 01:28:58 GMT Received: from localhost (/10.137.226.112) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 30 Sep 2013 18:28:57 -0700 Subject: [PATCH 21/31] libext2fs: Be more thorough in searching a range of blocks for a cluster To: tytso@mit.edu, darrick.wong@oracle.com From: "Darrick J. Wong" Cc: linux-ext4@vger.kernel.org Date: Mon, 30 Sep 2013 18:28:56 -0700 Message-ID: <20131001012856.28415.77322.stgit@birch.djwong.org> In-Reply-To: <20131001012642.28415.89353.stgit@birch.djwong.org> References: <20131001012642.28415.89353.stgit@birch.djwong.org> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org implied_cluster_alloc() is written such that if the the user passes in a logical block that is the zeroth block in a logical cluster (lblk % cluster_ratio == 0), then it will assume that there is no physical cluster mapped to any other part of the logical cluster. This is not true if we happen to be allocating logical blocks in reverse order. Therefore, search the whole cluster, except for the lblk that we passed in. Signed-off-by: Darrick J. Wong --- lib/ext2fs/bmap.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index aadd22e..5074587 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -140,7 +140,7 @@ static errcode_t extent_bmap(ext2_filsys fs, ext2_ino_t ino, static errcode_t implied_cluster_alloc(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, ext2_extent_handle_t handle, - blk64_t block, blk64_t *phys_blk) + blk64_t lblk, blk64_t *phys_blk) { blk64_t base_block, pblock = 0; int i; @@ -149,10 +149,19 @@ static errcode_t implied_cluster_alloc(ext2_filsys fs, ext2_ino_t ino, EXT4_FEATURE_RO_COMPAT_BIGALLOC)) return 0; - base_block = block & ~EXT2FS_CLUSTER_MASK(fs); + base_block = lblk & ~EXT2FS_CLUSTER_MASK(fs); + /* + * Except for the logical block (lblk) that was passed in, search all + * blocks in this logical cluster for a mapping to a physical cluster. + * If any such map exists, calculate the physical block that maps to + * the logical block and return that. + * + * The old code wouldn't even look if (block % cluster_ratio) == 0; + * this is incorrect if we're allocating blocks in reverse order. + */ for (i = 0; i < EXT2FS_CLUSTER_RATIO(fs); i++) { - if (block == base_block) - return 0; + if (base_block + i == lblk) + continue; extent_bmap(fs, ino, inode, handle, 0, 0, base_block + i, 0, 0, &pblock); if (pblock) @@ -160,7 +169,7 @@ static errcode_t implied_cluster_alloc(ext2_filsys fs, ext2_ino_t ino, } if (pblock == 0) return 0; - *phys_blk = pblock - i + (block - base_block); + *phys_blk = pblock - i + (lblk - base_block); return 0; }