Skip to contentSkip to conversation

e2fsck: process empty directory if large_dir and inline_data set

PATCH Applied Artem Blagodarenko 2 participants 2 messages Jun 14, 2019 – Jun 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 e2fsck: process empty directory if large_dir and inline_data set

Doing a forced check on an ext4 file system with inline_data and large_dir results in lots of fsck messages. To reproduce:

truncate -s 100000000 ext4.img
misc/mke2fs -t ext4 -I 512 -O 'inline_data,large_dir' ext4.img mkdir m
sudo mount ext4.img m
mkdir m/aa
sudo umount m
e2fsck/e2fsck -f -n ext4.img

The last command gives this output:

[root@localhost e2fsprogs-kernel]# e2fsck/e2fsck -f -n ext4-2.img e2fsck 1.45.2 (27-May-2019)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
'..' in /aa (12) is <The NULL inode> (0), should be / (2). Fix? no

Pass 4: Checking reference counts
Inode 2 ref count is 4, should be 3. Fix? no

Inode 12 ref count is 2, should be 1. Fix? no

Pass 5: Checking group summary information

ext4-2.img: ********** WARNING: Filesystem still has errors **********

ext4-2.img: 12/24384 files (0.0% non-contiguous), 17874/97656 blocks

Rootcause of this issue is large_dir optimization that is not appropriate for inline_data.

Let's not optimize it if inline_data is set.

---
 e2fsck/pass2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
e2fsck/pass2.c +2 -1
index a7d9c47d..8b40e93d 100644
@@ -980,7 +980,8 @@ static int check_dir_block(ext2_filsys fs,
 	 * very large and then the files are deleted. For now, all that is
 	 * needed is to avoid e2fsck filling in these holes as part of
 	 * feature flag. */
-	if (db->blk == 0 && ext2fs_has_feature_largedir(fs->super))
+	if (db->blk == 0 && ext2fs_has_feature_largedir(fs->super) &&
+	    !ext2fs_has_feature_inline_data(fs->super))
 		return 0;
 
 	if (db->blk == 0 && !inline_data_size) {
Signature · 1 line
2.14.3
#1 lore raw
Quoted 11 lines · Artem Blagodarenko

Doing a forced check on an ext4 file system with inline_data and large_dir results in lots of fsck messages. To reproduce:
...

Rootcause of this issue is large_dir optimization that is not appropriate for inline_data.

Let's not optimize it if inline_data is set.

Thanks, applied, although I corrected the commit description. The initial description now reads:

e2fsck: correctly handle inline directories when large_dir is enabled.

Historically, e2fsck has required that directories not contain holes. (In fact, as of this writing, ext4 still requires this to be the case.) Commit ae9efd05a98 ("e2fsck: 3 level hash tree directory optimization") removed this requirement if the large_dir feature is enabled; however, the way it was done caused it to incorrectly handle inline directories.

To reproduce the problem fixed by this commit:
...

BTW, Removing the directory hole check in commit ae9efd05a98 for file systems with the large_dir feature enabled was a wee bit optimistic, since the kernel will still mark the file system as corrupted.

Fixing the kernel so that it doesn't complain about directories with holes is going to be a bit more complicated than just removing the check in __ext4_read_dirblock():

	if (!bh) {
		ext4_error_inode(inode, func, line, block,
				 "Directory hole found");
		return ERR_PTR(-EFSCORRUPTED);
	}

(That's because we have to fix all of the callers of ext4_read_dirblock() to handle the case where it returns NULL if there is no directory block at that specified location.)

I should have caught that when reviewing the e2fsprogs commit; my bad. At this point, we should just fix the kernel so it can handle directories with holes (both for large_dir and non-large_dir directories).

- Ted