diff options
author | Junling Zheng <zhengjunling@huawei.com> | 2018-09-28 08:25:56 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-09-30 21:34:18 -0400 |
commit | d440c52d3151a28358f4c2d52d8583a0aa54ab83 (patch) | |
tree | 0ccc0848a20f769546b9023cf8139ac2b63e294a /fs/f2fs | |
parent | 274bd9ba39425610fdb9a6827602197a5cd27cd8 (diff) |
f2fs: support superblock checksum
Now we support crc32 checksum for superblock.
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r-- | fs/f2fs/f2fs.h | 2 | ||||
-rw-r--r-- | fs/f2fs/super.c | 28 | ||||
-rw-r--r-- | fs/f2fs/sysfs.c | 7 |
3 files changed, 37 insertions, 0 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 19243678d5d9..668836c2d678 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -148,6 +148,7 @@ struct f2fs_mount_info { | |||
148 | #define F2FS_FEATURE_INODE_CRTIME 0x0100 | 148 | #define F2FS_FEATURE_INODE_CRTIME 0x0100 |
149 | #define F2FS_FEATURE_LOST_FOUND 0x0200 | 149 | #define F2FS_FEATURE_LOST_FOUND 0x0200 |
150 | #define F2FS_FEATURE_VERITY 0x0400 /* reserved */ | 150 | #define F2FS_FEATURE_VERITY 0x0400 /* reserved */ |
151 | #define F2FS_FEATURE_SB_CHKSUM 0x0800 | ||
151 | 152 | ||
152 | #define F2FS_HAS_FEATURE(sb, mask) \ | 153 | #define F2FS_HAS_FEATURE(sb, mask) \ |
153 | ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) | 154 | ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) |
@@ -3431,6 +3432,7 @@ F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); | |||
3431 | F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); | 3432 | F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); |
3432 | F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); | 3433 | F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); |
3433 | F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); | 3434 | F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); |
3435 | F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); | ||
3434 | 3436 | ||
3435 | #ifdef CONFIG_BLK_DEV_ZONED | 3437 | #ifdef CONFIG_BLK_DEV_ZONED |
3436 | static inline int get_blkz_type(struct f2fs_sb_info *sbi, | 3438 | static inline int get_blkz_type(struct f2fs_sb_info *sbi, |
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 218695e44bd4..a44913224e3b 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -2178,6 +2178,26 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, | |||
2178 | (bh->b_data + F2FS_SUPER_OFFSET); | 2178 | (bh->b_data + F2FS_SUPER_OFFSET); |
2179 | struct super_block *sb = sbi->sb; | 2179 | struct super_block *sb = sbi->sb; |
2180 | unsigned int blocksize; | 2180 | unsigned int blocksize; |
2181 | size_t crc_offset = 0; | ||
2182 | __u32 crc = 0; | ||
2183 | |||
2184 | /* Check checksum_offset and crc in superblock */ | ||
2185 | if (le32_to_cpu(raw_super->feature) & F2FS_FEATURE_SB_CHKSUM) { | ||
2186 | crc_offset = le32_to_cpu(raw_super->checksum_offset); | ||
2187 | if (crc_offset != | ||
2188 | offsetof(struct f2fs_super_block, crc)) { | ||
2189 | f2fs_msg(sb, KERN_INFO, | ||
2190 | "Invalid SB checksum offset: %zu", | ||
2191 | crc_offset); | ||
2192 | return 1; | ||
2193 | } | ||
2194 | crc = le32_to_cpu(raw_super->crc); | ||
2195 | if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) { | ||
2196 | f2fs_msg(sb, KERN_INFO, | ||
2197 | "Invalid SB checksum value: %u", crc); | ||
2198 | return 1; | ||
2199 | } | ||
2200 | } | ||
2181 | 2201 | ||
2182 | if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) { | 2202 | if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) { |
2183 | f2fs_msg(sb, KERN_INFO, | 2203 | f2fs_msg(sb, KERN_INFO, |
@@ -2635,6 +2655,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi, | |||
2635 | int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) | 2655 | int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) |
2636 | { | 2656 | { |
2637 | struct buffer_head *bh; | 2657 | struct buffer_head *bh; |
2658 | __u32 crc = 0; | ||
2638 | int err; | 2659 | int err; |
2639 | 2660 | ||
2640 | if ((recover && f2fs_readonly(sbi->sb)) || | 2661 | if ((recover && f2fs_readonly(sbi->sb)) || |
@@ -2643,6 +2664,13 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) | |||
2643 | return -EROFS; | 2664 | return -EROFS; |
2644 | } | 2665 | } |
2645 | 2666 | ||
2667 | /* we should update superblock crc here */ | ||
2668 | if (!recover && f2fs_sb_has_sb_chksum(sbi->sb)) { | ||
2669 | crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi), | ||
2670 | offsetof(struct f2fs_super_block, crc)); | ||
2671 | F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc); | ||
2672 | } | ||
2673 | |||
2646 | /* write back-up superblock first */ | 2674 | /* write back-up superblock first */ |
2647 | bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1); | 2675 | bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1); |
2648 | if (!bh) | 2676 | if (!bh) |
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index f5a545437b81..b777cbdd796b 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c | |||
@@ -117,6 +117,9 @@ static ssize_t features_show(struct f2fs_attr *a, | |||
117 | if (f2fs_sb_has_lost_found(sb)) | 117 | if (f2fs_sb_has_lost_found(sb)) |
118 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", | 118 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
119 | len ? ", " : "", "lost_found"); | 119 | len ? ", " : "", "lost_found"); |
120 | if (f2fs_sb_has_sb_chksum(sb)) | ||
121 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", | ||
122 | len ? ", " : "", "sb_checksum"); | ||
120 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | 123 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
121 | return len; | 124 | return len; |
122 | } | 125 | } |
@@ -334,6 +337,7 @@ enum feat_id { | |||
334 | FEAT_QUOTA_INO, | 337 | FEAT_QUOTA_INO, |
335 | FEAT_INODE_CRTIME, | 338 | FEAT_INODE_CRTIME, |
336 | FEAT_LOST_FOUND, | 339 | FEAT_LOST_FOUND, |
340 | FEAT_SB_CHECKSUM, | ||
337 | }; | 341 | }; |
338 | 342 | ||
339 | static ssize_t f2fs_feature_show(struct f2fs_attr *a, | 343 | static ssize_t f2fs_feature_show(struct f2fs_attr *a, |
@@ -350,6 +354,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a, | |||
350 | case FEAT_QUOTA_INO: | 354 | case FEAT_QUOTA_INO: |
351 | case FEAT_INODE_CRTIME: | 355 | case FEAT_INODE_CRTIME: |
352 | case FEAT_LOST_FOUND: | 356 | case FEAT_LOST_FOUND: |
357 | case FEAT_SB_CHECKSUM: | ||
353 | return snprintf(buf, PAGE_SIZE, "supported\n"); | 358 | return snprintf(buf, PAGE_SIZE, "supported\n"); |
354 | } | 359 | } |
355 | return 0; | 360 | return 0; |
@@ -434,6 +439,7 @@ F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR); | |||
434 | F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); | 439 | F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); |
435 | F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME); | 440 | F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME); |
436 | F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); | 441 | F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); |
442 | F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM); | ||
437 | 443 | ||
438 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) | 444 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) |
439 | static struct attribute *f2fs_attrs[] = { | 445 | static struct attribute *f2fs_attrs[] = { |
@@ -493,6 +499,7 @@ static struct attribute *f2fs_feat_attrs[] = { | |||
493 | ATTR_LIST(quota_ino), | 499 | ATTR_LIST(quota_ino), |
494 | ATTR_LIST(inode_crtime), | 500 | ATTR_LIST(inode_crtime), |
495 | ATTR_LIST(lost_found), | 501 | ATTR_LIST(lost_found), |
502 | ATTR_LIST(sb_checksum), | ||
496 | NULL, | 503 | NULL, |
497 | }; | 504 | }; |
498 | 505 | ||