f2fs: introduce F2FS_FEATURE_LOST_FOUND feature
Subsystems (4)
v5 cover f2fs: introduce F2FS_FEATURE_LOST_FOUND feature
v5->v4:
* add doc for new mount option test_dummy_encryption
* move test_dummy_encryption flag to f2fs_mount_info
* move DUMMY_ENCRYPTION_ENABLED check to parse_option
* remove readonly check since we don't enable encrypt feature forcelyv4->v3:
* split f2fs patch into 2: one for LOST_FOUND feature, another for test_dummy_encryption
* do not set enc_name if dir is not encrypted
* do not allow mounting with test_dummy_encryption if encrypt feature is not setv3->v2:
* fix test_dummy_encryptionv2->v1:
* introduce new mount option test_dummy_encryption
* add sysfs entry for LOST_FOUND feature
---8<---
This patchset introduces LOST_FOUND feature in f2fs. If the feature is enabled, f2fs should avoid to encrypt root directory.
A new mount option "test_dummy_encryption" is introduced, this is used by xfstests.
Thanks,
Sheng
Sheng Yong (3):
f2fs: introduce F2FS_FEATURE_LOST_FOUND feature
f2fs: introduce a new mount option test_dummy_encryption
ext4: do not allow mount with test_dummy_encryption if encrypt not set
Documentation/filesystems/f2fs.txt | 2 ++ fs/ext4/super.c | 7 +++---- fs/f2fs/dir.c | 4 +++- fs/f2fs/f2fs.h | 10 ++++++++++ fs/f2fs/namei.c | 9 ++++++--- fs/f2fs/super.c | 40 ++++++++++++++++++++++++++++++++++++++ fs/f2fs/sysfs.c | 7 +++++++ 7 files changed, 71 insertions(+), 8 deletions(-)
Signature · 1 line
2.16.2
RFC PATCH v5 1/3 f2fs: introduce F2FS_FEATURE_LOST_FOUND feature
This patch introduces a new feature, F2FS_FEATURE_LOST_FOUND, which is set by mkfs. mkfs creates a directory named lost+found, which saves unreachable files. If fsck finds a file which has no parent, or its parent is removed by fsck, the file will be placed under lost+found directory by fsck.
lost+found directory could not be encrypted. As a result, the root directory cannot be encrypted too. So if LOST_FOUND feature is enabled, let's avoid to encrypt root directory.
--- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/super.c | 12 ++++++++++++ fs/f2fs/sysfs.c | 7 +++++++ 3 files changed, 21 insertions(+)
fs/f2fs/f2fs.h +2 -0
@@ -144,6 +144,7 @@ struct f2fs_mount_info {#define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040#define F2FS_FEATURE_QUOTA_INO 0x0080#define F2FS_FEATURE_INODE_CRTIME 0x0100 +#define F2FS_FEATURE_LOST_FOUND 0x0200#define F2FS_HAS_FEATURE (sb, mask) \ ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -3214,6 +3215,7 @@ F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM);F2FS_FEATURE_FUNCS (flexible_inline_xattr,FLEXIBLE_INLINE_XATTR );F2FS_FEATURE_FUNCS (quota_ino,QUOTA_INO );F2FS_FEATURE_FUNCS (inode_crtime,INODE_CRTIME ); +F2FS_FEATURE_FUNCS (lost_found,LOST_FOUND );#ifdef CONFIG_BLK_DEV_ZONED static inline int get_blkz_type(struct f2fs_sb_info *sbi,
fs/f2fs/super.c +12 -0
@@ -1891,6 +1891,18 @@ static int f2fs_get_context(struct inode *inode, void *ctx, size_t len)static int f2fs_set_context (struct inode *inode,const void *ctx,size_t len,void *fs_data) { +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +/* +* Encrypting the root directory is not allowed because fsck +* expects lost+found directory to exist and remain unencrypted +* if LOST_FOUND feature is enabled. +* +*/ +if (f2fs_sb_has_lost_found (sbi->sb) && + inode->i_ino ==F2FS_ROOT_INO (sbi)) +return -EPERM ; +return f2fs_setxattr (inode,F2FS_XATTR_INDEX_ENCRYPTION ,F2FS_XATTR_NAME_ENCRYPTION_CONTEXT , ctx, len, fs_data,XATTR_CREATE );
fs/f2fs/sysfs.c +7 -0
@@ -116,6 +116,9 @@ static ssize_t features_show(struct f2fs_attr *a,if (f2fs_sb_has_inode_crtime (sb)) len +=snprintf (buf + len,PAGE_SIZE - len,"%s%s" , len ?", " :"" ,"inode_crtime" ); +if (f2fs_sb_has_lost_found (sb)) + len +=snprintf (buf + len,PAGE_SIZE - len,"%s%s" , + len ?", " :"" ,"lost_found" ); len +=snprintf (buf + len,PAGE_SIZE - len,"\n" );return len; }
@@ -292,6 +295,7 @@ enum feat_id {FEAT_FLEXIBLE_INLINE_XATTR ,FEAT_QUOTA_INO ,FEAT_INODE_CRTIME , + FEAT_LOST_FOUND, }; static ssize_t f2fs_feature_show(struct f2fs_attr *a,
@@ -307,6 +311,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a,case FEAT_FLEXIBLE_INLINE_XATTR :case FEAT_QUOTA_INO :case FEAT_INODE_CRTIME : +case FEAT_LOST_FOUND :return snprintf (buf,PAGE_SIZE ,"supported\n" ); }return 0 ;
@@ -386,6 +391,7 @@ F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM);F2FS_FEATURE_RO_ATTR (flexible_inline_xattr,FEAT_FLEXIBLE_INLINE_XATTR );F2FS_FEATURE_RO_ATTR (quota_ino,FEAT_QUOTA_INO );F2FS_FEATURE_RO_ATTR (inode_crtime,FEAT_INODE_CRTIME ); +F2FS_FEATURE_RO_ATTR (lost_found,FEAT_LOST_FOUND );#define ATTR_LIST (name) (&f2fs_attr_##name.attr)static struct attribute *f2fs_attrs[] = {
@@ -441,6 +447,7 @@ static struct attribute *f2fs_feat_attrs[] = {ATTR_LIST (flexible_inline_xattr),ATTR_LIST (quota_ino),ATTR_LIST (inode_crtime), +ATTR_LIST (lost_found), NULL, };
Signature · 1 line
2.16.2
RFC PATCH v5 2/3 f2fs: introduce a new mount option test_dummy_encryption
In reply to Sheng YongThis patch introduces a new mount option `test_dummy_encryption' to allow fscrypt to create a fake fscrypt context. This is used by xfstests.
--- Documentation/filesystems/f2fs.txt | 2 ++ fs/f2fs/dir.c | 4 +++- fs/f2fs/f2fs.h | 8 ++++++++ fs/f2fs/namei.c | 9 ++++++--- fs/f2fs/super.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 4 deletions(-)
Documentation/filesystems/f2fs.txt +2 -0
@@ -189,6 +189,8 @@ fsync_mode=%s Control the policy of fsync. Currently supports "posix" fsync will be heavy and behaves in line with xfs, ext4 and btrfs, where xfstest generic/342 will pass, but the performance will regress. +test_dummy_encryption Enable dummy encryption, which provides a fake fscrypt + context. The fake fscrypt context is used by xfstests. ================================================================================ DEBUGFS ENTRIES
fs/f2fs/dir.c +3 -1
@@ -361,6 +361,7 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir, struct page *dpage) {struct page *page; +int dummy_encrypt =DUMMY_ENCRYPTION_ENABLED (F2FS_I_SB (dir));int err;if (is_inode_flag_set (inode,FI_NEW_INODE )) {
@@ -387,7 +388,8 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,if (err) goto put_error; -if (f2fs_encrypted_inode (dir) &&f2fs_may_encrypt (inode)) { +if ((f2fs_encrypted_inode (dir) || dummy_encrypt) && +f2fs_may_encrypt (inode)) { err =fscrypt_inherit_context (dir, inode, page, false);if (err) goto put_error;
fs/f2fs/f2fs.h +8 -0
@@ -133,6 +133,7 @@ struct f2fs_mount_info {int whint_mode;int alloc_mode;/* segment allocation policy */ int fsync_mode;/* fsync policy */ +bool test_dummy_encryption;/* test dummy encryption */ };#define F2FS_FEATURE_ENCRYPT 0x0001
@@ -1077,6 +1078,13 @@ enum fsync_mode { FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ }; +#ifdef CONFIG_F2FS_FS_ENCRYPTION +#define DUMMY_ENCRYPTION_ENABLED (sbi) \ + (unlikely(F2FS_OPTION(sbi).test_dummy_encryption)) +#else +#define DUMMY_ENCRYPTION_ENABLED (sbi) (0) +#endif +struct f2fs_sb_info {struct super_block *sb;/* pointer to VFS super block */ struct proc_dir_entry *s_proc;/* proc entry */
fs/f2fs/namei.c +6 -3
@@ -78,7 +78,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)set_inode_flag (inode,FI_NEW_INODE );/* If the directory encrypted, then we should encrypt the inode. */ -if (f2fs_encrypted_inode (dir) &&f2fs_may_encrypt (inode)) +if ((f2fs_encrypted_inode (dir) ||DUMMY_ENCRYPTION_ENABLED (sbi)) && +f2fs_may_encrypt (inode))f2fs_set_encrypted_inode (inode);if (f2fs_sb_has_extra_attr (sbi->sb)) {
@@ -787,10 +788,12 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,static int f2fs_tmpfile (struct inode *dir,struct dentry *dentry,umode_t mode) { -if (unlikely (f2fs_cp_error (F2FS_I_SB (dir)))) +struct f2fs_sb_info *sbi =F2FS_I_SB (dir); + +if (unlikely (f2fs_cp_error (sbi)))return -EIO ; -if (f2fs_encrypted_inode (dir)) { +if (f2fs_encrypted_inode (dir) ||DUMMY_ENCRYPTION_ENABLED (sbi)) {int err =fscrypt_get_encryption_info (dir);if (err)return err;
fs/f2fs/super.c +28 -0
@@ -132,6 +132,7 @@ enum { Opt_whint, Opt_alloc, Opt_fsync, + Opt_test_dummy_encryption, Opt_err, };
@@ -188,6 +189,7 @@ static match_table_t f2fs_tokens = { {Opt_whint, "whint_mode=%s"}, {Opt_alloc, "alloc_mode=%s"}, {Opt_fsync, "fsync_mode=%s"}, + {Opt_test_dummy_encryption, "test_dummy_encryption"}, {Opt_err, NULL}, };
@@ -744,6 +746,21 @@ static int parse_options(struct super_block *sb, char *options) }kfree (name);break ; +case Opt_test_dummy_encryption: +#ifdef CONFIG_F2FS_FS_ENCRYPTION +if (!f2fs_sb_has_encrypt (sb)) { +f2fs_msg (sb,KERN_ERR ,"Encrypt feature is off" ); +return -EINVAL ; + } + +F2FS_OPTION (sbi).test_dummy_encryption = true; +f2fs_msg (sb,KERN_INFO , +"Test dummy encryption mode enabled" ); +#else +f2fs_msg (sb,KERN_INFO , +"Test dummy encryption mount option ignored" ); +#endif +break ;default : f2fs_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" or missing value",
@@ -1314,6 +1331,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)seq_printf (seq,",whint_mode=%s" ,"user-based" ); else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) seq_printf(seq, ",whint_mode=%s", "fs-based"); +#ifdef CONFIG_F2FS_FS_ENCRYPTION +if (F2FS_OPTION (sbi).test_dummy_encryption) +seq_puts (seq,",test_dummy_encryption" ); +#endif if (F2FS_OPTION (sbi).alloc_mode ==ALLOC_MODE_DEFAULT )seq_printf (seq,",alloc_mode=%s" ,"default" );
@@ -1335,6 +1356,7 @@ static void default_options(struct f2fs_sb_info *sbi)F2FS_OPTION (sbi).whint_mode =WHINT_MODE_OFF ;F2FS_OPTION (sbi).alloc_mode =ALLOC_MODE_DEFAULT ;F2FS_OPTION (sbi).fsync_mode =FSYNC_MODE_POSIX ; +F2FS_OPTION (sbi).test_dummy_encryption = false; sbi->readdir_ra =1 ;set_opt (sbi,BG_GC );
@@ -1908,6 +1930,11 @@ static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len, ctx, len, fs_data, XATTR_CREATE); } +static bool f2fs_dummy_context (struct inode *inode) +{ +return DUMMY_ENCRYPTION_ENABLED (F2FS_I_SB (inode)); +} +static unsigned f2fs_max_namelen (struct inode *inode) { return S_ISLNK(inode->i_mode) ?
@@ -1918,6 +1945,7 @@ static const struct fscrypt_operations f2fs_cryptops = { .key_prefix = "f2fs:", .get_context = f2fs_get_context, .set_context = f2fs_set_context, + .dummy_context = f2fs_dummy_context, .empty_dir = f2fs_empty_dir, .max_namelen = f2fs_max_namelen, };
Signature · 1 line
2.16.2
Re: [RFC PATCH v5 2/3] f2fs: introduce a new mount option test_dummy_encryption
Quoted 5 lines · Sheng Yong
This patch introduces a new mount option `test_dummy_encryption' to allow fscrypt to create a fake fscrypt context. This is used by xfstests.
Signed-off-by Sheng Yong <[email protected]>
Thanks,
RFC PATCH v5 3/3 ext4: do not allow mount with test_dummy_encryption if encrypt not set
In reply to Sheng YongWhen mounting with test_dummy_encryption option, if encrypt feature is not set, return fail instead of setting encrypt feature forcely.
--- fs/ext4/super.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/ext4/super.c +3 -4
@@ -4149,10 +4149,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount_wq; } -if (DUMMY_ENCRYPTION_ENABLED (sbi) && !sb_rdonly (sb) && - !ext4_has_feature_encrypt (sb)) { -ext4_set_feature_encrypt (sb); -ext4_commit_super (sb,1 ); +if (DUMMY_ENCRYPTION_ENABLED (sbi) && !ext4_has_feature_encrypt (sb)) { +ext4_msg (sb,KERN_ERR ,"Encrypt does not support" ); + goto failed_mount_wq; }/*
Signature · 1 line
2.16.2