[PATCH RFC DRAFT v2 05/13] f2fs: move fscrypt to filesystem inode

Christian Brauner
2025-07-22T12:58:01Z

Move fscrypt data pointer into the filesystem's private inode and record
the offset from the embedded struct inode.

This will allow us to drop the fscrypt data pointer from struct inode
itself and move it into the filesystem's inode.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/f2fs/f2fs.h | 4 ++++
fs/f2fs/file.c | 4 ++++
fs/f2fs/inode.c | 1 +
fs/f2fs/namei.c | 25 +++++++++++++++++++++++++
fs/f2fs/super.c | 3 +++
5 files changed, 37 insertions(+)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9333a22b9a01..152990273c68 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -905,6 +905,9 @@ struct f2fs_inode_info {

unsigned int atomic_write_cnt;
loff_t original_i_size; /* original i_size before atomic write */
+#ifdef CONFIG_FS_ENCRYPTION
+ struct fscrypt_inode_info *i_fscrypt_info; /* filesystem encryption info */
+#endif
};

static inline void get_read_extent_info(struct extent_info *ext,
@@ -4297,6 +4300,7 @@ extern const struct inode_operations f2fs_dir_inode_operations;
extern const struct inode_operations f2fs_symlink_inode_operations;
extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
extern const struct inode_operations f2fs_special_inode_operations;
+extern const struct inode_operations f2fs_encrypted_nop_inode_operations;
extern struct kmem_cache *f2fs_inode_entry_slab;

/*
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 6bd3de64f2a8..f0003672a42c 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1150,6 +1150,10 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
}

const struct inode_operations f2fs_file_inode_operations = {
+#ifdef CONFIG_FS_ENCRYPTION
+ .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) -
+ offsetof(struct f2fs_inode_info, vfs_inode),
+#endif
.getattr = f2fs_getattr,
.setattr = f2fs_setattr,
.get_inode_acl = f2fs_get_acl,
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 083d52a42bfb..73bfb9853c25 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -583,6 +583,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
return inode;
}

+ inode->i_op = &f2fs_encrypted_nop_inode_operations;
if (is_meta_ino(sbi, ino))
goto make_now;

diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 07e333ee21b7..998b0c31f728 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -216,6 +216,13 @@ static void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
file_set_hot(inode);
}

+const struct inode_operations f2fs_encrypted_nop_inode_operations = {
+#ifdef CONFIG_FS_ENCRYPTION
+ .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) -
+ offsetof(struct f2fs_inode_info, vfs_inode),
+#endif
+};
+
static struct inode *f2fs_new_inode(struct mnt_idmap *idmap,
struct inode *dir, umode_t mode,
const char *name)
@@ -249,6 +256,8 @@ static struct inode *f2fs_new_inode(struct mnt_idmap *idmap,
fi->i_crtime = inode_get_mtime(inode);
inode->i_generation = get_random_u32();

+ inode->i_op = &f2fs_encrypted_nop_inode_operations;
+
if (S_ISDIR(inode->i_mode))
fi->i_current_depth = 1;

@@ -1325,6 +1334,10 @@ static int f2fs_encrypted_symlink_getattr(struct mnt_idmap *idmap,
}

const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
+#ifdef CONFIG_FS_ENCRYPTION
+ .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) -
+ offsetof(struct f2fs_inode_info, vfs_inode),
+#endif
.get_link = f2fs_encrypted_get_link,
.getattr = f2fs_encrypted_symlink_getattr,
.setattr = f2fs_setattr,
@@ -1332,6 +1345,10 @@ const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
};

const struct inode_operations f2fs_dir_inode_operations = {
+#ifdef CONFIG_FS_ENCRYPTION
+ .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) -
+ offsetof(struct f2fs_inode_info, vfs_inode),
+#endif
.create = f2fs_create,
.lookup = f2fs_lookup,
.link = f2fs_link,
@@ -1353,6 +1370,10 @@ const struct inode_operations f2fs_dir_inode_operations = {
};

const struct inode_operations f2fs_symlink_inode_operations = {
+#ifdef CONFIG_FS_ENCRYPTION
+ .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) -
+ offsetof(struct f2fs_inode_info, vfs_inode),
+#endif
.get_link = f2fs_get_link,
.getattr = f2fs_getattr,
.setattr = f2fs_setattr,
@@ -1360,6 +1381,10 @@ const struct inode_operations f2fs_symlink_inode_operations = {
};

const struct inode_operations f2fs_special_inode_operations = {
+#ifdef CONFIG_FS_ENCRYPTION
+ .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) -
+ offsetof(struct f2fs_inode_info, vfs_inode),
+#endif
.getattr = f2fs_getattr,
.setattr = f2fs_setattr,
.get_inode_acl = f2fs_get_acl,
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index bbf1dad6843f..9f8e5ae13dc9 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1453,6 +1453,9 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)

/* Will be used by directory only */
fi->i_dir_level = F2FS_SB(sb)->dir_level;
+#ifdef CONFIG_FS_ENCRYPTION
+ fi->i_fscrypt_info = NULL;
+#endif

return &fi->vfs_inode;
}

--
2.47.2