Blame SOURCES/e2fsprogs-1.45.6-e2fsck-fix-indexed-dir-rehash-failure-with-metadata_.patch

a77133
From 5ddac7d248ad346b80702a397c886df4d1ec4f08 Mon Sep 17 00:00:00 2001
a77133
From: Jan Kara <jack@suse.cz>
a77133
Date: Thu, 13 Feb 2020 11:15:57 +0100
a77133
Subject: [PATCH 05/46] e2fsck: fix indexed dir rehash failure with
a77133
 metadata_csum enabled
a77133
Content-Type: text/plain
a77133
a77133
E2fsck directory rehashing code can fail with ENOSPC due to a bug in
a77133
ext2fs_htree_intnode_maxrecs() which fails to take metadata checksum
a77133
into account and thus e.g. e2fsck can decide to create 1 indirect level
a77133
of index tree when two are actually needed. Fix the logic to account for
a77133
metadata checksum.
a77133
a77133
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
a77133
Signed-off-by: Jan Kara <jack@suse.cz>
a77133
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
a77133
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
a77133
---
a77133
 lib/ext2fs/ext2fs.h | 8 +++++++-
a77133
 1 file changed, 7 insertions(+), 1 deletion(-)
a77133
a77133
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
a77133
index 32c75171..d9aec525 100644
a77133
--- a/lib/ext2fs/ext2fs.h
a77133
+++ b/lib/ext2fs/ext2fs.h
a77133
@@ -2040,7 +2040,13 @@ _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
a77133
 
a77133
 _INLINE_ int ext2fs_htree_intnode_maxrecs(ext2_filsys fs, int blocks)
a77133
 {
a77133
-	return blocks * ((fs->blocksize - 8) / sizeof(struct ext2_dx_entry));
a77133
+	int csum_size = 0;
a77133
+
a77133
+	if ((EXT2_SB(fs->super)->s_feature_ro_compat &
a77133
+	     EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) != 0)
a77133
+		csum_size = sizeof(struct ext2_dx_tail);
a77133
+	return blocks * ((fs->blocksize - (8 + csum_size)) /
a77133
+						sizeof(struct ext2_dx_entry));
a77133
 }
a77133
 
a77133
 /*
a77133
-- 
a77133
2.35.1
a77133