[PATCH v2 3/3] ext4: reimplement ext4_empty_dir() using is_dirent_block_empty

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The new function added in this patchset adds an efficient way to
check if a dirent block is empty. Based on that, reimplement
ext4_empty_dir().

This is a new patch added in V2.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@xxxxxxxxx>
---
 fs/ext4/namei.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 39360c442dad..dae7d15fba5c 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3179,6 +3179,7 @@ bool ext4_empty_dir(struct inode *inode)
 	struct buffer_head *bh;
 	struct ext4_dir_entry_2 *de;
 	struct super_block *sb;
+	ext4_lblk_t lblk;
 
 	if (ext4_has_inline_data(inode)) {
 		int has_inline_data = 1;
@@ -3218,34 +3219,26 @@ bool ext4_empty_dir(struct inode *inode)
 		brelse(bh);
 		return true;
 	}
-	offset += ext4_rec_len_from_disk(de->rec_len, sb->s_blocksize);
-	while (offset < inode->i_size) {
-		if (!(offset & (sb->s_blocksize - 1))) {
-			unsigned int lblock;
-			brelse(bh);
-			lblock = offset >> EXT4_BLOCK_SIZE_BITS(sb);
-			bh = ext4_read_dirblock(inode, lblock, EITHER);
-			if (bh == NULL) {
-				offset += sb->s_blocksize;
-				continue;
-			}
-			if (IS_ERR(bh))
-				return true;
-		}
-		de = (struct ext4_dir_entry_2 *) (bh->b_data +
-					(offset & (sb->s_blocksize - 1)));
-		if (ext4_check_dir_entry(inode, NULL, de, bh,
-					 bh->b_data, bh->b_size, offset)) {
-			offset = (offset | (sb->s_blocksize - 1)) + 1;
+	de = ext4_next_entry(de, sb->s_blocksize);
+	if (!is_empty_dirent_block(inode, bh, de)) {
+		brelse(bh);
+		return false;
+	}
+	brelse(bh);
+
+	for (lblk = 1; lblk < inode->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
+			lblk++) {
+		bh = ext4_read_dirblock(inode, lblk, EITHER);
+		if (bh == NULL)
 			continue;
-		}
-		if (le32_to_cpu(de->inode)) {
+		if (IS_ERR(bh))
+			return true;
+		if (!is_empty_dirent_block(inode, bh, NULL)) {
 			brelse(bh);
 			return false;
 		}
-		offset += ext4_rec_len_from_disk(de->rec_len, sb->s_blocksize);
+		brelse(bh);
 	}
-	brelse(bh);
 	return true;
 }
 
-- 
2.26.0.292.g33ef6b2f38-goog




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux