From patchwork Thu May 1 23:15:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 344855 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 C5ACE140105 for ; Fri, 2 May 2014 09:15:20 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752611AbaEAXPU (ORCPT ); Thu, 1 May 2014 19:15:20 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:28958 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752273AbaEAXPT (ORCPT ); Thu, 1 May 2014 19:15:19 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s41NFHnb024443 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 1 May 2014 23:15:18 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s41NFGnU004909 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 May 2014 23:15:16 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s41NFFYK008709; Thu, 1 May 2014 23:15:16 GMT Received: from localhost (/10.145.179.157) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 01 May 2014 16:15:15 -0700 Subject: [PATCH 26/37] libext2fs: find inode goal when allocating blocks From: "Darrick J. Wong" To: tytso@mit.edu, darrick.wong@oracle.com Cc: linux-ext4@vger.kernel.org Date: Thu, 01 May 2014 16:15:12 -0700 Message-ID: <20140501231512.31890.86618.stgit@birch.djwong.org> In-Reply-To: <20140501231222.31890.82860.stgit@birch.djwong.org> References: <20140501231222.31890.82860.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Try to be a little smarter about where we go to allocate blocks for a inode. Signed-off-by: Darrick J. Wong --- e2fsck/pass2.c | 3 ++- lib/ext2fs/alloc.c | 10 ++++++++++ lib/ext2fs/bmap.c | 5 +++-- lib/ext2fs/expanddir.c | 2 +- lib/ext2fs/ext2fs.h | 1 + lib/ext2fs/ext_attr.c | 3 +-- lib/ext2fs/extent.c | 10 ++-------- lib/ext2fs/mkdir.c | 3 ++- lib/ext2fs/symlink.c | 3 ++- 9 files changed, 24 insertions(+), 16 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/e2fsck/pass2.c b/e2fsck/pass2.c index 1667292..4b19cb8 100644 --- a/e2fsck/pass2.c +++ b/e2fsck/pass2.c @@ -1729,7 +1729,8 @@ static int allocate_dir_block(e2fsck_t ctx, /* * First, find a free block */ - pctx->errcode = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk); + blk = ext2fs_find_inode_goal(fs, db->ino); + pctx->errcode = ext2fs_new_block2(fs, blk, ctx->block_found_map, &blk); if (pctx->errcode) { pctx->str = "ext2fs_new_block"; fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx); diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c index 1be4ecc..aa084ac 100644 --- a/lib/ext2fs/alloc.c +++ b/lib/ext2fs/alloc.c @@ -293,3 +293,13 @@ void ext2fs_set_alloc_block_callback(ext2_filsys fs, fs->get_alloc_block = func; } + +blk64_t ext2fs_find_inode_goal(ext2_filsys fs, ext2_ino_t ino) +{ + dgrp_t group = ext2fs_group_of_ino(fs, ino); + __u8 log_flex = fs->super->s_log_groups_per_flex; + + if (log_flex) + group = group & ~((1 << (log_flex)) - 1); + return ext2fs_group_first_block2(fs, group); +} diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index a4dc8ef..7623052 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -252,7 +252,7 @@ got_block: retval = extent_bmap(fs, ino, inode, handle, block_buf, 0, block-1, 0, blocks_alloc, &blk64); if (retval) - blk64 = 0; + blk64 = ext2fs_find_inode_goal(fs, ino); retval = ext2fs_alloc_block2(fs, blk64, block_buf, &blk64); if (retval) @@ -368,7 +368,8 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, } *phys_blk = inode_bmap(inode, block); - b = block ? inode_bmap(inode, block-1) : 0; + b = block ? inode_bmap(inode, block-1) : + ext2fs_find_inode_goal(fs, ino); if ((*phys_blk == 0) && (bmap_flags & BMAP_ALLOC)) { retval = ext2fs_alloc_block(fs, b, block_buf, &b); diff --git a/lib/ext2fs/expanddir.c b/lib/ext2fs/expanddir.c index d0f7287..2df49ce 100644 --- a/lib/ext2fs/expanddir.c +++ b/lib/ext2fs/expanddir.c @@ -111,7 +111,7 @@ errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir) es.done = 0; es.err = 0; - es.goal = 0; + es.goal = ext2fs_find_inode_goal(fs, dir); es.newblocks = 0; es.dir = dir; diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 819a14a..09423ac 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -690,6 +690,7 @@ extern void ext2fs_set_alloc_block_callback(ext2_filsys fs, errcode_t (**old)(ext2_filsys fs, blk64_t goal, blk64_t *ret)); +blk64_t ext2fs_find_inode_goal(ext2_filsys fs, ext2_ino_t ino); /* alloc_sb.c */ extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs, diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index 308d21d..a756b7b 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -404,8 +404,7 @@ static errcode_t prep_ea_block_for_write(ext2_filsys fs, ext2_ino_t ino, } /* Allocate a block */ - grp = ext2fs_group_of_ino(fs, ino); - goal = ext2fs_inode_table_loc(fs, grp); + goal = ext2fs_find_inode_goal(fs, ino); err = ext2fs_alloc_block2(fs, goal, NULL, &blk); if (err) goto out2; diff --git a/lib/ext2fs/extent.c b/lib/ext2fs/extent.c index c0b34a7..3b27113 100644 --- a/lib/ext2fs/extent.c +++ b/lib/ext2fs/extent.c @@ -1010,14 +1010,8 @@ static errcode_t extent_node_split(ext2_extent_handle_t handle, goto done; } - if (!goal_blk) { - dgrp_t group = ext2fs_group_of_ino(handle->fs, handle->ino); - __u8 log_flex = handle->fs->super->s_log_groups_per_flex; - - if (log_flex) - group = group & ~((1 << (log_flex)) - 1); - goal_blk = ext2fs_group_first_block2(handle->fs, group); - } + if (!goal_blk) + goal_blk = ext2fs_find_inode_goal(handle->fs, handle->ino); retval = ext2fs_alloc_block2(handle->fs, goal_blk, block_buf, &new_node_pblk); if (retval) diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c index c4c7967..36b1810 100644 --- a/lib/ext2fs/mkdir.c +++ b/lib/ext2fs/mkdir.c @@ -69,7 +69,8 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, * Allocate a data block for the directory */ if (!inline_data) { - retval = ext2fs_new_block2(fs, 0, 0, &blk); + retval = ext2fs_new_block2(fs, ext2fs_find_inode_goal(fs, ino), + 0, &blk); if (retval) goto cleanup; } diff --git a/lib/ext2fs/symlink.c b/lib/ext2fs/symlink.c index b2ef66c..cb3a2e7 100644 --- a/lib/ext2fs/symlink.c +++ b/lib/ext2fs/symlink.c @@ -53,7 +53,8 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, */ fastlink = (target_len < sizeof(inode.i_block)); if (!fastlink) { - retval = ext2fs_new_block2(fs, 0, 0, &blk); + retval = ext2fs_new_block2(fs, ext2fs_find_inode_goal(fs, ino), + 0, &blk); if (retval) goto cleanup; retval = ext2fs_get_mem(fs->blocksize, &block_buf);