Skip to content

Commit

Permalink
debugfs: move ->automount into debugfs_inode_info
Browse files Browse the repository at this point in the history
... 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>
  • Loading branch information
Al Viro authored and Greg Kroah-Hartman committed Jan 15, 2025
1 parent 268b361 commit bacaaf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
21 changes: 5 additions & 16 deletions fs/debugfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 = {
Expand Down Expand Up @@ -642,38 +642,27 @@ 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);
}

inode = debugfs_get_inode(dentry->d_sb);
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);
Expand Down
19 changes: 9 additions & 10 deletions fs/debugfs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
};
};

Expand Down

0 comments on commit bacaaf8

Please sign in to comment.