From d28c8ba4d260ebd0ea73045d85fe2c6e4a87c61a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 14 Oct 2014 02:39:18 -0400 Subject: [PATCH] add patch check-s_chksum_driver-when-looking-for-bg-csum-presence --- ...chksum_driver-when-looking-for-bg-csum-presence | 59 ++++++++++++++++++++++ series | 1 + timestamps | 7 +-- 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 check-s_chksum_driver-when-looking-for-bg-csum-presence diff --git a/check-s_chksum_driver-when-looking-for-bg-csum-presence b/check-s_chksum_driver-when-looking-for-bg-csum-presence new file mode 100644 index 00000000..f6a1b8aa --- /dev/null +++ b/check-s_chksum_driver-when-looking-for-bg-csum-presence @@ -0,0 +1,59 @@ +ext4: check s_chksum_driver when looking for bg csum presence + +From: "Darrick J. Wong" + +Convert the ext4_has_group_desc_csum predicate to look for a checksum +driver instead of the metadata_csum flag and change the bg checksum +calculation function to look for GDT_CSUM before taking the crc16 +path. + +Without this patch, if we mount with ^uninit_bg,^metadata_csum and +later metadata_csum gets turned on by accident, the block group +checksum functions will incorrectly assume that checksumming is +enabled (metadata_csum) but that crc16 should be used +(!s_chksum_driver). This is totally wrong, so fix the predicate +and the checksum formula selection. + +(Granted, if the metadata_csum feature bit gets enabled on a live FS +then something underhanded is going on, but we could at least avoid +writing garbage into the on-disk fields.) + +Signed-off-by: Darrick J. Wong +Signed-off-by: Theodore Ts'o +Reviewed-by: Dmitry Monakhov +--- + fs/ext4/ext4.h | 4 ++-- + fs/ext4/super.c | 4 ++++ + 2 files changed, 6 insertions(+), 2 deletions(-) + +diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h +index fb6aadf..db38ca0f 100644 +--- a/fs/ext4/ext4.h ++++ b/fs/ext4/ext4.h +@@ -2367,8 +2367,8 @@ extern int ext4_register_li_request(struct super_block *sb, + static inline int ext4_has_group_desc_csum(struct super_block *sb) + { + return EXT4_HAS_RO_COMPAT_FEATURE(sb, +- EXT4_FEATURE_RO_COMPAT_GDT_CSUM | +- EXT4_FEATURE_RO_COMPAT_METADATA_CSUM); ++ EXT4_FEATURE_RO_COMPAT_GDT_CSUM) || ++ (EXT4_SB(sb)->s_chksum_driver != NULL); + } + + static inline int ext4_has_metadata_csum(struct super_block *sb) +diff --git a/fs/ext4/super.c b/fs/ext4/super.c +index 6ae47d4..de38a96 100644 +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -2032,6 +2032,10 @@ static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, + } + + /* old crc16 code */ ++ if (!(sbi->s_es->s_feature_ro_compat & ++ cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM))) ++ return 0; ++ + offset = offsetof(struct ext4_group_desc, bg_checksum); + + crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); + diff --git a/series b/series index e092a4d0..19ba737d 100644 --- a/series +++ b/series @@ -75,6 +75,7 @@ fix-reservation-overflow-in-ext4_da_write_begin delete-useless-comments-about-ext4_move_extents replace-open-coded-mdata_csum-feature-to-helper-function move-error-report-out-of-atomic-context +check-s_chksum_driver-when-looking-for-bg-csum-presence ########################################## # unstable patches diff --git a/timestamps b/timestamps index a3fd3df9..999206a7 100755 --- a/timestamps +++ b/timestamps @@ -104,6 +104,7 @@ touch -d @1413071477 fix-reservation-overflow-in-ext4_da_write_begin touch -d @1413071794 delete-useless-comments-about-ext4_move_extents touch -d @1413185776 replace-open-coded-mdata_csum-feature-to-helper-function touch -d @1413186132 move-error-report-out-of-atomic-context -touch -d @1413186641 series -touch -d @1413186939 status -touch -d @1413187237 timestamps +touch -d @1413268549 check-s_chksum_driver-when-looking-for-bg-csum-presence +touch -d @1413268586 series +touch -d @1413268591 status +touch -d @1413268751 timestamps -- 2.11.4.GIT