[PATCH RFC DRAFT v2 10/13] btrfs: move fsverity to filesystem inode

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

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

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

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/btrfs/btrfs_inode.h | 3 +++
fs/btrfs/inode.c | 20 +++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index a79fa0726f1d..10852d13fa00 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -339,6 +339,9 @@ struct btrfs_inode {

struct rw_semaphore i_mmap_lock;
struct inode vfs_inode;
+#ifdef CONFIG_FS_VERITY
+ struct fsverity_info *i_fsverity_info;
+#endif
};

static inline u64 btrfs_get_first_dir_index_to_log(const struct btrfs_inode *inode)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index c0c778243bf1..634be0e32759 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7873,7 +7873,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
INIT_LIST_HEAD(&ei->delalloc_inodes);
INIT_LIST_HEAD(&ei->delayed_iput);
init_rwsem(&ei->i_mmap_lock);
-
+#ifdef CONFIG_FS_VERITY
+ ei->i_fsverity_info = NULL;
+#endif
return inode;
}

@@ -10410,6 +10412,10 @@ struct btrfs_inode *btrfs_find_first_inode(struct btrfs_root *root, u64 min_ino)
}

static const struct inode_operations btrfs_dir_inode_operations = {
+#ifdef CONFIG_FS_VERITY
+ .i_fsverity = offsetof(struct btrfs_inode, i_fsverity_info) -
+ offsetof(struct btrfs_inode, vfs_inode),
+#endif
.getattr = btrfs_getattr,
.lookup = btrfs_lookup,
.create = btrfs_create,
@@ -10471,6 +10477,10 @@ static const struct address_space_operations btrfs_aops = {
};

static const struct inode_operations btrfs_file_inode_operations = {
+#ifdef CONFIG_FS_VERITY
+ .i_fsverity = offsetof(struct btrfs_inode, i_fsverity_info) -
+ offsetof(struct btrfs_inode, vfs_inode),
+#endif
.getattr = btrfs_getattr,
.setattr = btrfs_setattr,
.listxattr = btrfs_listxattr,
@@ -10483,6 +10493,10 @@ static const struct inode_operations btrfs_file_inode_operations = {
.fileattr_set = btrfs_fileattr_set,
};
static const struct inode_operations btrfs_special_inode_operations = {
+#ifdef CONFIG_FS_VERITY
+ .i_fsverity = offsetof(struct btrfs_inode, i_fsverity_info) -
+ offsetof(struct btrfs_inode, vfs_inode),
+#endif
.getattr = btrfs_getattr,
.setattr = btrfs_setattr,
.permission = btrfs_permission,
@@ -10492,6 +10506,10 @@ static const struct inode_operations btrfs_special_inode_operations = {
.update_time = btrfs_update_time,
};
static const struct inode_operations btrfs_symlink_inode_operations = {
+#ifdef CONFIG_FS_VERITY
+ .i_fsverity = offsetof(struct btrfs_inode, i_fsverity_info) -
+ offsetof(struct btrfs_inode, vfs_inode),
+#endif
.get_link = page_get_link,
.getattr = btrfs_getattr,
.setattr = btrfs_setattr,

--
2.47.2