From patchwork Wed Oct 26 07:34:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Ma X-Patchwork-Id: 121842 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 A2487B6F81 for ; Wed, 26 Oct 2011 18:41:52 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754858Ab1JZHlW (ORCPT ); Wed, 26 Oct 2011 03:41:22 -0400 Received: from oproxy9.bluehost.com ([69.89.24.6]:38264 "HELO oproxy9.bluehost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1754805Ab1JZHlU (ORCPT ); Wed, 26 Oct 2011 03:41:20 -0400 Received: (qmail 10751 invoked by uid 0); 26 Oct 2011 07:41:20 -0000 Received: from unknown (HELO box585.bluehost.com) (66.147.242.185) by oproxy9.bluehost.com with SMTP; 26 Oct 2011 07:41:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tao.ma; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=MhoONCkX8bKMRCWiKEln81v1K1iW/W/Vqut/DWbuvdg=; b=J46reESO9MmSagaIcdp31qJTd8VA5GWrr7dB+piTHeANmTZC7AE/3tv0+nVrCY8QLtYZ/vai134/1+Tuflp3ja0/lkaNOMA4kEYQjcz5+yiQXtpFdY9QqDrphpIgd1nn; Received: from [182.92.247.2] (helo=tma-laptop1.taobao.ali.com) by box585.bluehost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1RIy1E-0006OI-Ax; Wed, 26 Oct 2011 01:35:25 -0600 From: Tao Ma To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, linux-kernel@vger.kernel.org, adilger@dilger.ca Subject: [PATCH V1 16/17] ext4: let ext4_rename handle inline dir. Date: Wed, 26 Oct 2011 15:34:27 +0800 Message-Id: <1319614468-11227-16-git-send-email-tm@tao.ma> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1319614468-11227-1-git-send-email-tm@tao.ma> References: <4EA7B788.3040503@tao.ma> <1319614468-11227-1-git-send-email-tm@tao.ma> X-Identified-User: {1390:box585.bluehost.com:colyli:tao.ma} {sentby:smtp auth 182.92.247.2 authed with tm@tao.ma} Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Tao Ma In case of we rename a dir, ext4_rename has to read the dir block and change its dotdot's information. The old ext4_rename encapsulated the dir_block read into itself. So this patch try to add a new function ext4_get_dir_block which get the dir buffer information so the ext4_rename can handle it properly. Signed-off-by: Tao Ma --- fs/ext4/namei.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 44 insertions(+), 6 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 343af6c..cb1b396 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2777,6 +2777,43 @@ retry: (ext4_next_entry((struct ext4_dir_entry_2 *)(buffer), size)->inode) /* + * Try to find buffer head where contains the parent block. + * It should be the inode block if it is inlined or the 1st block + * if it is a normal dir. + */ +static struct buffer_head *ext4_get_dir_block(handle_t *handle, + struct inode *inode, + void **buf, + int *buf_size, + int *retval) +{ + struct buffer_head *bh; + void *inline_start; + int inline_size; + struct ext4_iloc iloc; + + if (!ext4_has_inline_data(inode)) { + bh = ext4_bread(handle, inode, 0, 0, retval); + if (!bh) + return NULL; + *buf = bh->b_data; + *buf_size = inode->i_sb->s_blocksize; + return bh; + } + + *retval = ext4_get_inode_loc(inode, &iloc); + if (*retval) + return NULL; + + inline_start = ext4_get_inline_data_pos(inode, &iloc); + inline_size = ext4_get_max_inline_size(inode); + + *buf = inline_start; + *buf_size = inline_size; + return iloc.bh; +} + +/* * Anybody can rename anything with this: the permission checks are left to the * higher-level routines. */ @@ -2787,7 +2824,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *old_inode, *new_inode; struct buffer_head *old_bh, *new_bh, *dir_bh; struct ext4_dir_entry_2 *old_de, *new_de; - int retval, force_da_alloc = 0; + int buf_size, retval, force_da_alloc = 0; + void *dir_buf = NULL; dquot_initialize(old_dir); dquot_initialize(new_dir); @@ -2834,11 +2872,12 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, goto end_rename; } retval = -EIO; - dir_bh = ext4_bread(handle, old_inode, 0, 0, &retval); + dir_bh = ext4_get_dir_block(handle, old_inode, + &dir_buf, &buf_size, &retval); if (!dir_bh) goto end_rename; - if (le32_to_cpu(PARENT_INO(dir_bh->b_data, - old_dir->i_sb->s_blocksize)) != old_dir->i_ino) + if (le32_to_cpu(PARENT_INO(dir_buf, + buf_size)) != old_dir->i_ino) goto end_rename; retval = -EMLINK; if (!new_inode && new_dir != old_dir && @@ -2918,8 +2957,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, old_dir->i_ctime = old_dir->i_mtime = ext4_current_time(old_dir); ext4_update_dx_flag(old_dir); if (dir_bh) { - PARENT_INO(dir_bh->b_data, new_dir->i_sb->s_blocksize) = - cpu_to_le32(new_dir->i_ino); + PARENT_INO(dir_buf, buf_size) = cpu_to_le32(new_dir->i_ino); BUFFER_TRACE(dir_bh, "call ext4_handle_dirty_metadata"); retval = ext4_handle_dirty_metadata(handle, old_inode, dir_bh); if (retval) {