Skip to contentSkip to conversation

fs: ext4: skip journal state if fs has metadata_csum

PATCH New Arnaud Ferraris 3 participants 3 messages Apr 22, 2020 – Apr 28, 2020 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: ext4: skip journal state if fs has metadata_csum

As u-boot doesn't support the metadata_csum feature, writing to a filesystem with this feature enabled will fail, as expected. However, during the process, a journal state check is performed, which could result in:
- a fs recovery if the fs wasn't umounted properly
- the fs being marked dirty

Both these cases result in a superblock change, leading to a mismatch between the superblock checksum and its contents. Therefore, Linux will consider the filesystem heavily corrupted and will require e2fsck to be run manually to boot.

By bypassing the journal state check, this patch ensures the superblock won't be corrupted if the filesystem has metadata_csum feature enabled.

---

 fs/ext4/ext4_journal.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ext4/ext4_journal.c +3 -0
index 3559daf11d..f8524e5a99 100644
@@ -409,6 +409,9 @@ int ext4fs_check_journal_state(int recovery_flag)
 	char *temp_buff1 = NULL;
 	struct ext_filesystem *fs = get_fs();
 
+	if (le32_to_cpu(fs->sb->feature_ro_compat) & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
+		return 0;
+
 	temp_buff = zalloc(fs->blksz);
 	if (!temp_buff)
 		return -ENOMEM;
Signature · 1 line
2.26.1
#1 lore raw

PATCH 1/1 fs: ext4: skip journal state if fs has metadata_csum

Quoted 12 lines · Arnaud Ferraris

As u-boot doesn't support the metadata_csum feature, writing to a filesystem with this feature enabled will fail, as expected. However, during the process, a journal state check is performed, which could result in:
- a fs recovery if the fs wasn't umounted properly
- the fs being marked dirty

Both these cases result in a superblock change, leading to a mismatch between the superblock checksum and its contents. Therefore, Linux will consider the filesystem heavily corrupted and will require e2fsck to be run manually to boot.

Quoted 4 lines

By bypassing the journal state check, this patch ensures the superblock won't be corrupted if the filesystem has metadata_csum feature enabled.

Quoted 10 lines

---

  fs/ext4/ext4_journal.c | 3 +++
  1 file changed, 3 insertions(+)
fs/ext4/ext4_journal.c +0 -0
index 3559daf11d..f8524e5a99 100644

fs/ext4/ext4_journal.c int ext4fs_check_journal_state(int recovery_flag) · line 417

Quoted 9 lines
fs/ext4/ext4_journal.c +3 -0
@@ -409,6 +409,9 @@ int ext4fs_check_journal_state(int recovery_flag)
  	char *temp_buff1 = NULL;
  	struct ext_filesystem *fs = get_fs();
 
+	if (le32_to_cpu(fs->sb->feature_ro_compat) & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
+		return 0;
+
  	temp_buff = zalloc(fs->blksz);
  	if (!temp_buff)
  		return -ENOMEM;

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#2 lore raw

PATCH 1/1 fs: ext4: skip journal state if fs has metadata_csum

In reply to Arnaud Ferraris
Quoted 12 lines · Arnaud Ferraris

As u-boot doesn't support the metadata_csum feature, writing to a filesystem with this feature enabled will fail, as expected. However, during the process, a journal state check is performed, which could result in:
- a fs recovery if the fs wasn't umounted properly
- the fs being marked dirty

Both these cases result in a superblock change, leading to a mismatch between the superblock checksum and its contents. Therefore, Linux will consider the filesystem heavily corrupted and will require e2fsck to be run manually to boot.

Quoted 4 lines

By bypassing the journal state check, this patch ensures the superblock won't be corrupted if the filesystem has metadata_csum feature enabled.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200428/d6915e35/attachment.sig>