From patchwork Fri Sep 14 11:25:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Ma X-Patchwork-Id: 183899 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 403972C0089 for ; Fri, 14 Sep 2012 21:34:21 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752436Ab2INLeQ (ORCPT ); Fri, 14 Sep 2012 07:34:16 -0400 Received: from oproxy8-pub.bluehost.com ([69.89.22.20]:60529 "HELO oproxy8-pub.bluehost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752386Ab2INLeJ (ORCPT ); Fri, 14 Sep 2012 07:34:09 -0400 Received: (qmail 29447 invoked by uid 0); 14 Sep 2012 11:34:08 -0000 Received: from unknown (HELO box585.bluehost.com) (66.147.242.185) by oproxy8.bluehost.com with SMTP; 14 Sep 2012 11:34:08 -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:To:From; bh=OnENd2zbeq4jozDzTw+r+Vd1/sowsaAtE/HvO2yQGMY=; b=RxkAfolllikJlYjCGOI4CiZpEuLDeIdbNX+vMDXUf+Fa4uIt5cW/cH+zRvGiLxqMI31jwAAgRYWUy0UJVwrvKiOvjNmhanOpbPUn+AmrH5S8vUkPWFn0XsJDHc3pxsIl; Received: from [182.92.247.2] (port=60014 helo=tma-laptop1.taobao.ali.com) by box585.bluehost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1TCU1g-0001sO-2k for linux-ext4@vger.kernel.org; Fri, 14 Sep 2012 05:25:36 -0600 From: Tao Ma To: linux-ext4@vger.kernel.org Subject: [PATCH V6 17/23] ext4: let empty_dir handle inline dir. Date: Fri, 14 Sep 2012 19:25:05 +0800 Message-Id: <1347621911-4104-17-git-send-email-tm@tao.ma> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1347621911-4104-1-git-send-email-tm@tao.ma> References: <1347621512-3660-1-git-send-email-tm@tao.ma> <1347621911-4104-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 empty_dir is used when deleting a dir. So it should handle inline dir properly. Signed-off-by: Tao Ma --- fs/ext4/inline.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/namei.c | 8 +++++ fs/ext4/xattr.h | 6 +++ 3 files changed, 104 insertions(+), 0 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 21c8957..5bf1326 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -1559,6 +1559,96 @@ out: return err; } +/* + * Get the inline dentry at offset. + */ +static inline struct ext4_dir_entry_2 * +ext4_get_inline_entry(struct inode *inode, + struct ext4_iloc *iloc, + unsigned int offset, + void **inline_start, + int *inline_size) +{ + void *inline_pos; + + BUG_ON(offset > ext4_get_inline_size(inode)); + + if (offset < EXT4_MIN_INLINE_DATA_SIZE) { + inline_pos = (void *)ext4_raw_inode(iloc)->i_block; + *inline_size = EXT4_MIN_INLINE_DATA_SIZE; + } else { + inline_pos = ext4_get_inline_xattr_pos(inode, iloc); + offset -= EXT4_MIN_INLINE_DATA_SIZE; + *inline_size = ext4_get_inline_size(inode) - + EXT4_MIN_INLINE_DATA_SIZE; + } + + if (inline_start) + *inline_start = inline_pos; + return (struct ext4_dir_entry_2 *)(inline_pos + offset); +} + +int empty_inline_dir(struct inode *dir, int *has_inline_data) +{ + int err, inline_size; + struct ext4_iloc iloc; + void *inline_pos; + unsigned int offset; + struct ext4_dir_entry_2 *de; + int ret = 1; + + err = ext4_get_inode_loc(dir, &iloc); + if (err) { + EXT4_ERROR_INODE(dir, "error %d getting inode %lu block", + err, dir->i_ino); + return 1; + } + + down_read(&EXT4_I(dir)->xattr_sem); + if (!ext4_has_inline_data(dir)) { + *has_inline_data = 0; + goto out; + } + + de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block; + if (!le32_to_cpu(de->inode)) { + ext4_warning(dir->i_sb, + "bad inline directory (dir #%lu) - no `..'", + dir->i_ino); + ret = 1; + goto out; + } + + offset = EXT4_INLINE_DOTDOT_SIZE; + while (offset < dir->i_size) { + de = ext4_get_inline_entry(dir, &iloc, offset, + &inline_pos, &inline_size); + if (ext4_check_dir_entry(dir, NULL, de, + iloc.bh, inline_pos, + inline_size, offset)) { + ext4_warning(dir->i_sb, + "bad inline directory (dir #%lu) - " + "inode %u, rec_len %u, name_len %d" + "inline size %d\n", + dir->i_ino, le32_to_cpu(de->inode), + le16_to_cpu(de->rec_len), de->name_len, + inline_size); + ret = 1; + goto out; + } + if (le32_to_cpu(de->inode)) { + ret = 0; + goto out; + } + offset += ext4_rec_len_from_disk(de->rec_len, inline_size); + } + +out: + up_read(&EXT4_I(dir)->xattr_sem); + brelse(iloc.bh); + return ret; +} + int ext4_destroy_inline_data(handle_t *handle, struct inode *inode) { int ret; diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index bdb7403..f2a4ba6 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2387,6 +2387,14 @@ static int empty_dir(struct inode *inode) struct super_block *sb; int err = 0; + if (ext4_has_inline_data(inode)) { + int has_inline_data = 1; + + err = empty_inline_dir(inode, &has_inline_data); + if (has_inline_data) + return err; + } + sb = inode->i_sb; if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) || !(bh = ext4_bread(NULL, inode, 0, 0, &err))) { diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h index 62a242a..2791d9a 100644 --- a/fs/ext4/xattr.h +++ b/fs/ext4/xattr.h @@ -180,6 +180,7 @@ extern int ext4_delete_inline_entry(handle_t *handle, struct ext4_dir_entry_2 *de_del, struct buffer_head *bh, int *has_inline_data); +extern int empty_inline_dir(struct inode *dir, int *has_inline_data); # else /* CONFIG_EXT4_FS_XATTR */ static inline int @@ -379,6 +380,11 @@ static inline int ext4_delete_inline_entry(handle_t *handle, { return 0; } + +static inline int empty_inline_dir(struct inode *dir, int *has_inline_data) +{ + return 0; +} # endif /* CONFIG_EXT4_FS_XATTR */ #ifdef CONFIG_EXT4_FS_SECURITY