On Apr 7, 2020, at 12:46 AM, Harshad Shirwadkar <harshadshirwadkar@xxxxxxxxx> wrote: > > 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> Again, a very minor style change iff patch is refreshed. Reviewed-by: Andreas Dilger <adilger@xxxxxxxxx> While looking at this code, I noticed that ext4_empty_dir() considers a directory without a "." or ".." entry to be empty. I see this was changed in 64d4ce8923 ("ext4: fix ext4_empty_dir() for directories with holes"). I can understand that we want to not die on corrupted leaf blocks, but it isn't clear to me that it is a good idea to allow deleting an entire directory tree if the first block has an error (missing "." or ".." as the first and second entries) but is otherwise valid. There were definitely bugs in the past that made "." or ".." not be the first and second entries. That isn't a problem in this patch, but seems dangerous in general. It doesn't seem like the directory shrinking would trigger this case, since it is checking for individual empty blocks rather than using ext4_empty_dir(). > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > @@ -3218,34 +3219,26 @@ bool ext4_empty_dir(struct inode *inode) > brelse(bh); > return true; > } > + 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++) { (style) should be aligned after '(' on previous line > + 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; > } Cheers, Andreas
Attachment:
signature.asc
Description: Message signed with OpenPGP