From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: adilger@dilger.ca, Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Subject: [PATCH v2 3/3] ext4: reimplement ext4_empty_dir() using is_dirent_block_empty
Date: Mon, 6 Apr 2020 23:46:16 -0700 [thread overview]
Message-ID: <20200407064616.221459-3-harshadshirwadkar@gmail.com> (raw)
In-Reply-To: <20200407064616.221459-1-harshadshirwadkar@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2020-04-07 6:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-07 6:46 [PATCH v2 1/3] ext4: return lblk from ext4_find_entry Harshad Shirwadkar
2020-04-07 6:46 ` [PATCH v2 2/3] ext4: shrink directories on dentry delete Harshad Shirwadkar
2020-04-07 16:51 ` Andreas Dilger
2020-04-07 6:46 ` Harshad Shirwadkar [this message]
2020-04-07 17:21 ` [PATCH v2 3/3] ext4: reimplement ext4_empty_dir() using is_dirent_block_empty Andreas Dilger
2020-04-08 9:31 ` Jan Kara
[not found] ` <c7a41ba13a3551fca25d7498b9d4542a104fac74.camel@gmail.com>
2025-09-27 8:11 ` Julian Sun
2025-09-28 3:46 ` Theodore Ts'o
2025-09-28 6:51 ` Julian Sun
2025-09-28 21:02 ` Theodore Ts'o
2025-09-28 21:23 ` [PATCH 1/2] ext4: return lblk from ext4_find_entry Theodore Ts'o
2025-09-28 21:23 ` [PATCH 2/2] ext4: shrink directories on dentry delete Theodore Ts'o
2025-09-29 2:33 ` [PATCH v2 3/3] ext4: reimplement ext4_empty_dir() using is_dirent_block_empty Julian Sun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200407064616.221459-3-harshadshirwadkar@gmail.com \
--to=harshadshirwadkar@gmail.com \
--cc=adilger@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).