From patchwork Sat Oct 16 23:37:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 68060 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 612D0B70EF for ; Sun, 17 Oct 2010 10:37:38 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756798Ab0JPXhg (ORCPT ); Sat, 16 Oct 2010 19:37:36 -0400 Received: from thunk.org ([69.25.196.29]:38045 "EHLO thunker.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756799Ab0JPXhf (ORCPT ); Sat, 16 Oct 2010 19:37:35 -0400 Received: from root (helo=tytso-glaptop) by thunker.thunk.org with local-esmtp (Exim 4.50 #1 (Debian)) id 1P7GJi-0006Oq-QM; Sat, 16 Oct 2010 19:37:34 -0400 Received: from tytso by tytso-glaptop with local (Exim 4.71) (envelope-from ) id 1P7GJh-0000Z5-P8; Sat, 16 Oct 2010 19:37:33 -0400 From: Theodore Ts'o To: Ext4 Developers List Cc: Theodore Ts'o , Brad Spengler Subject: [PATCH 2/2] ext4: Use search_dirblock() in ext4_dx_find_entry() Date: Sat, 16 Oct 2010 19:37:33 -0400 Message-Id: <1287272253-2140-2-git-send-email-tytso@mit.edu> X-Mailer: git-send-email 1.7.1 In-Reply-To: <20101016233513.GA31722@thunk.org> References: <20101016233513.GA31722@thunk.org> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on thunker.thunk.org); SAEximRunCond expanded to false Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Use the search_dirblock() in ext4_dx_find_entry(). It makes the code easier to read, and it takes advantage of common code. It also saves 100 bytes or so of text space. Signed-off-by: "Theodore Ts'o" Cc: Brad Spengler --- fs/ext4/namei.c | 33 ++++++++++++--------------------- 1 files changed, 12 insertions(+), 21 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index ff89449..eb8b794 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -974,39 +974,30 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct q struct super_block * sb = dir->i_sb; struct dx_hash_info hinfo; struct dx_frame frames[2], *frame; - struct ext4_dir_entry_2 *de, *top; struct buffer_head *bh; ext4_lblk_t block; int retval; - int namelen = d_name->len; - const u8 *name = d_name->name; if (!(frame = dx_probe(d_name, dir, &hinfo, frames, err))) return NULL; do { block = dx_get_block(frame->at); - if (!(bh = ext4_bread (NULL,dir, block, 0, err))) + if (!(bh = ext4_bread(NULL, dir, block, 0, err))) goto errout; - de = (struct ext4_dir_entry_2 *) bh->b_data; - top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize - - EXT4_DIR_REC_LEN(0)); - for (; de < top; de = ext4_next_entry(de, sb->s_blocksize)) { - int off = (block << EXT4_BLOCK_SIZE_BITS(sb)) - + ((char *) de - bh->b_data); - - if (!ext4_check_dir_entry(dir, de, bh, off)) { - brelse(bh); - *err = ERR_BAD_DX_DIR; - goto errout; - } - if (ext4_match(namelen, name, de)) { - *res_dir = de; - dx_release(frames); - return bh; - } + retval = search_dirblock(bh, dir, d_name, + block << EXT4_BLOCK_SIZE_BITS(sb), + res_dir); + if (retval == 1) { /* Success! */ + dx_release(frames); + return bh; } brelse(bh); + if (retval == -1) { + *err = ERR_BAD_DX_DIR; + goto errout; + } + /* Check to see if we should continue to search */ retval = ext4_htree_next_block(dir, hinfo.hash, frame, frames, NULL);