@@ -169,6 +169,7 @@ prototypes::
int (*freeze_fs) (struct super_block *);
int (*unfreeze_fs) (struct super_block *);
int (*statfs) (struct dentry *, struct kstatfs *);
+ int (*get_fsid) (struct inode *, __kernel_fsid_t *);
int (*remount_fs) (struct super_block *, int *, char *);
void (*umount_begin) (struct super_block *);
int (*show_options)(struct seq_file *, struct dentry *);
@@ -193,6 +194,7 @@ sync_fs: read
freeze_fs: write
unfreeze_fs: write
statfs: maybe(read) (see below)
+get_fsid: no
remount_fs: write
umount_begin: no
show_options: no (namespace_sem)
@@ -267,6 +267,7 @@ filesystem. The following members are defined:
enum freeze_wholder who);
int (*unfreeze_fs) (struct super_block *);
int (*statfs) (struct dentry *, struct kstatfs *);
+ int (*get_fsid) (struct inode *, __kernel_fsid_t *);
int (*remount_fs) (struct super_block *, int *, char *);
void (*umount_begin) (struct super_block *);
@@ -374,6 +375,9 @@ or bottom half).
``statfs``
called when the VFS needs to get filesystem statistics.
+``get_fsid``
+ called when the VFS needs to get only the f_fsid member of statfs.
+
``remount_fs``
called when the filesystem is remounted. This is called with
the kernel lock held
@@ -69,11 +69,25 @@ static int statfs_by_dentry(struct dentry *dentry, struct kstatfs *buf)
return retval;
}
+int inode_get_fsid(struct inode *inode, __kernel_fsid_t *fsid)
+{
+ if (!inode->i_sb->s_op->get_fsid)
+ return -EOPNOTSUPP;
+
+ return inode->i_sb->s_op->get_fsid(inode, fsid);
+}
+EXPORT_SYMBOL(inode_get_fsid);
+
int vfs_get_fsid(struct dentry *dentry, __kernel_fsid_t *fsid)
{
struct kstatfs st;
int error;
+ /* Avoid statfs if fs supports cheaper get_fsid() */
+ error = inode_get_fsid(d_inode(dentry), fsid);
+ if (!error)
+ return 0;
+
error = statfs_by_dentry(dentry, &st);
if (error)
return error;
@@ -2008,6 +2008,7 @@ struct super_operations {
int (*thaw_super) (struct super_block *, enum freeze_holder who);
int (*unfreeze_fs) (struct super_block *);
int (*statfs) (struct dentry *, struct kstatfs *);
+ int (*get_fsid)(struct inode *, __kernel_fsid_t *);
int (*remount_fs) (struct super_block *, int *, char *);
void (*umount_begin) (struct super_block *);
@@ -43,7 +43,9 @@ struct kstatfs {
#define ST_RELATIME 0x1000 /* update atime relative to mtime/ctime */
#define ST_NOSYMFOLLOW 0x2000 /* do not follow symlinks */
+struct inode;
struct dentry;
+extern int inode_get_fsid(struct inode *inode, __kernel_fsid_t *fsid);
extern int vfs_get_fsid(struct dentry *dentry, __kernel_fsid_t *fsid);
static inline __kernel_fsid_t u64_to_fsid(u64 v)
If implemented, get_fsid() can be used as a cheaper way of getting the f_fsid memeber of kstatfs, for callers that only care about fsid. fanotify is going to make use of that to get btrfs fsid from inode on every event. Suggested-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20230920110429.f4wkfuls73pd55pv@quack3/ Signed-off-by: Amir Goldstein <amir73il@gmail.com> --- Documentation/filesystems/locking.rst | 2 ++ Documentation/filesystems/vfs.rst | 4 ++++ fs/statfs.c | 14 ++++++++++++++ include/linux/fs.h | 1 + include/linux/statfs.h | 2 ++ 5 files changed, 23 insertions(+)