debugfs: move ->automount into debugfs_inode_info
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 12 Jan 2025 08:06:46 +0000 (08:06 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 15 Jan 2025 12:14:35 +0000 (13:14 +0100)
... and don't bother with debugfs_fsdata for those.  Life's
simpler that way...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/r/20250112080705.141166-2-viro@zeniv.linux.org.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/debugfs/inode.c
fs/debugfs/internal.h

index 5d423bd92f93475bf96f575ffef1d2596d0b7cef..2f5afd7b1b942d3f9685ffd3e74e2fb6a61f5972 100644 (file)
@@ -246,8 +246,8 @@ static void debugfs_release_dentry(struct dentry *dentry)
        if ((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT)
                return;
 
-       /* check it wasn't a dir (no fsdata) or automount (no real_fops) */
-       if (fsd && (fsd->real_fops || fsd->short_fops)) {
+       /* check it wasn't a dir or automount (no fsdata) */
+       if (fsd) {
                WARN_ON(!list_empty(&fsd->cancellations));
                mutex_destroy(&fsd->cancellations_mtx);
        }
@@ -257,9 +257,9 @@ static void debugfs_release_dentry(struct dentry *dentry)
 
 static struct vfsmount *debugfs_automount(struct path *path)
 {
-       struct debugfs_fsdata *fsd = path->dentry->d_fsdata;
+       struct inode *inode = path->dentry->d_inode;
 
-       return fsd->automount(path->dentry, d_inode(path->dentry)->i_private);
+       return DEBUGFS_I(inode)->automount(path->dentry, inode->i_private);
 }
 
 static const struct dentry_operations debugfs_dops = {
@@ -642,23 +642,13 @@ struct dentry *debugfs_create_automount(const char *name,
                                        void *data)
 {
        struct dentry *dentry = start_creating(name, parent);
-       struct debugfs_fsdata *fsd;
        struct inode *inode;
 
        if (IS_ERR(dentry))
                return dentry;
 
-       fsd = kzalloc(sizeof(*fsd), GFP_KERNEL);
-       if (!fsd) {
-               failed_creating(dentry);
-               return ERR_PTR(-ENOMEM);
-       }
-
-       fsd->automount = f;
-
        if (!(debugfs_allow & DEBUGFS_ALLOW_API)) {
                failed_creating(dentry);
-               kfree(fsd);
                return ERR_PTR(-EPERM);
        }
 
@@ -666,14 +656,13 @@ struct dentry *debugfs_create_automount(const char *name,
        if (unlikely(!inode)) {
                pr_err("out of free dentries, can not create automount '%s'\n",
                       name);
-               kfree(fsd);
                return failed_creating(dentry);
        }
 
        make_empty_dir_inode(inode);
        inode->i_flags |= S_AUTOMOUNT;
        inode->i_private = data;
-       dentry->d_fsdata = fsd;
+       DEBUGFS_I(inode)->automount = f;
        /* directory inodes start off with i_nlink == 2 (for "." entry) */
        inc_nlink(inode);
        d_instantiate(dentry, inode);
index 5cb940b0b8f67bb9939aefda39f8520885d4c77e..a644e44a0ee42d353c74a34b3138f947b95af5b7 100644 (file)
@@ -13,6 +13,9 @@ struct file_operations;
 
 struct debugfs_inode_info {
        struct inode vfs_inode;
+       union {
+               debugfs_automount_t automount;
+       };
 };
 
 static inline struct debugfs_inode_info *DEBUGFS_I(struct inode *inode)
@@ -29,17 +32,13 @@ extern const struct file_operations debugfs_full_short_proxy_file_operations;
 struct debugfs_fsdata {
        const struct file_operations *real_fops;
        const struct debugfs_short_fops *short_fops;
-       union {
-               /* automount_fn is used when real_fops is NULL */
-               debugfs_automount_t automount;
-               struct {
-                       refcount_t active_users;
-                       struct completion active_users_drained;
+       struct {
+               refcount_t active_users;
+               struct completion active_users_drained;
 
-                       /* protect cancellations */
-                       struct mutex cancellations_mtx;
-                       struct list_head cancellations;
-               };
+               /* protect cancellations */
+               struct mutex cancellations_mtx;
+               struct list_head cancellations;
        };
 };