Hi Ju Hyung,

On 2021/4/5 16:40, Park Ju Hyung wrote:
Mounting f2fs devices with future options leads to unwanted behaviors
incurring errors and data destruction.

Implement a long overdue safeguard to prevent mounting devices with
unsupported features.

This can be further extended to allow read-only mounts on certain
incompatible features, but that doesn't seem necessary for now with
how f2fs features has been added.

Thanks for the patch!

I have a RFC patch for this issue, but the patch doesn't being merged,
IIRC, Jaegeuk and I have divergence on implementation details, maybe we
could continue the discussion and work right now. :)

https://lkml.org/lkml/2019/7/29/623

Thanks,


Cc: [email protected]
Signed-off-by: Park Ju Hyung <[email protected]>
---
  fs/f2fs/f2fs.h  | 11 +++++++++++
  fs/f2fs/super.c | 10 ++++++++++
  2 files changed, 21 insertions(+)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e2d302ae3a46..12d274492d6f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -153,6 +153,9 @@ struct f2fs_mount_info {
        unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* 
extensions */
  };
+/*
+ * All features listed here should be appended to F2FS_SUPPORTED_FEATURES
+ */
  #define F2FS_FEATURE_ENCRYPT          0x0001
  #define F2FS_FEATURE_BLKZONED         0x0002
  #define F2FS_FEATURE_ATOMIC_WRITE     0x0004
@@ -168,6 +171,14 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_CASEFOLD         0x1000
  #define F2FS_FEATURE_COMPRESSION      0x2000
+/* Currently supported features by this version of f2fs */
+#define F2FS_SUPPORTED_FEATURES \
+       (F2FS_FEATURE_ENCRYPT | F2FS_FEATURE_BLKZONED | 
F2FS_FEATURE_ATOMIC_WRITE | \
+        F2FS_FEATURE_EXTRA_ATTR | F2FS_FEATURE_PRJQUOTA | 
F2FS_FEATURE_INODE_CHKSUM | \
+        F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | F2FS_FEATURE_QUOTA_INO | 
F2FS_FEATURE_INODE_CRTIME | \
+        F2FS_FEATURE_LOST_FOUND | F2FS_FEATURE_VERITY | F2FS_FEATURE_SB_CHKSUM 
| \
+        F2FS_FEATURE_CASEFOLD | F2FS_FEATURE_COMPRESSION)
+
  #define __F2FS_HAS_FEATURE(raw_super, mask)                           \
        ((raw_super->feature & cpu_to_le32(mask)) != 0)
  #define F2FS_HAS_FEATURE(sbi, mask)   __F2FS_HAS_FEATURE(sbi->raw_super, mask)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 82592b19b4e0..91d77985cf9b 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -3610,6 +3610,7 @@ static int f2fs_fill_super(struct super_block *sb, void 
*data, int silent)
        int recovery, i, valid_super_block;
        struct curseg_info *seg_i;
        int retry_cnt = 1;
+       __le32 unsupported;
try_onemore:
        err = -EINVAL;
@@ -3647,6 +3648,15 @@ static int f2fs_fill_super(struct super_block *sb, void 
*data, int silent)
        sb->s_fs_info = sbi;
        sbi->raw_super = raw_super;
+ /* check supported features */
+       unsupported = raw_super->feature & ~F2FS_SUPPORTED_FEATURES;
+       if (unsupported) {
+               f2fs_err(sbi, "unsupported features: 0x%x\n", unsupported);
+               f2fs_err(sbi, "please update your kernel or adjust the mkfs.f2fs 
option\n", unsupported);
+               err = -EOPNOTSUPP;
+               goto free_sb_buf;
+       }
+
        /* precompute checksum seed for metadata */
        if (f2fs_sb_has_inode_chksum(sbi))
                sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid,



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to