summaryrefslogtreecommitdiff
path: root/fs/pidfs.c
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2024-03-01 12:26:03 +0300
committerChristian Brauner <brauner@kernel.org>2024-03-02 00:31:40 +0300
commite9c5263ce16d96311c118111ac779f004be8b473 (patch)
tree4657444a1bb7f15a4a52e5991a2673b80206c7ad /fs/pidfs.c
parent2558e3b23112adb82a558bab616890a790a38bc6 (diff)
downloadlinux-e9c5263ce16d96311c118111ac779f004be8b473.tar.xz
libfs: improve path_from_stashed()
Right now we pass a bunch of info that is fs specific which doesn't make a lot of sense and it bleeds fs sepcific details into the generic helper. nsfs and pidfs have slightly different needs when initializing inodes. Add simple operations that are stashed in sb->s_fs_info that both can implement. This also allows us to get rid of cleaning up references in the caller. All in all path_from_stashed() becomes way simpler. Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/pidfs.c')
-rw-r--r--fs/pidfs.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/fs/pidfs.c b/fs/pidfs.c
index d38b7a184994..8fd71a00be9c 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -193,6 +193,26 @@ static const struct dentry_operations pidfs_dentry_operations = {
.d_prune = stashed_dentry_prune,
};
+static void pidfs_init_inode(struct inode *inode, void *data)
+{
+ inode->i_private = data;
+ inode->i_flags |= S_PRIVATE;
+ inode->i_mode |= S_IRWXU;
+ inode->i_op = &pidfs_inode_operations;
+ inode->i_fop = &pidfs_file_operations;
+}
+
+static void pidfs_put_data(void *data)
+{
+ struct pid *pid = data;
+ put_pid(pid);
+}
+
+static const struct stashed_operations pidfs_stashed_ops = {
+ .init_inode = pidfs_init_inode,
+ .put_data = pidfs_put_data,
+};
+
static int pidfs_init_fs_context(struct fs_context *fc)
{
struct pseudo_fs_context *ctx;
@@ -203,6 +223,7 @@ static int pidfs_init_fs_context(struct fs_context *fc)
ctx->ops = &pidfs_sops;
ctx->dops = &pidfs_dentry_operations;
+ fc->s_fs_info = (void *)&pidfs_stashed_ops;
return 0;
}
@@ -225,10 +246,7 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
* for pseudo filesystems.
*/
ret = path_from_stashed(&pid->stashed, pid->ino, pidfs_mnt,
- &pidfs_file_operations, &pidfs_inode_operations,
get_pid(pid), &path);
- if (ret <= 0)
- put_pid(pid);
if (ret < 0)
return ERR_PTR(ret);