summaryrefslogtreecommitdiff
path: root/fs/nsfs.c
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2024-03-01 10:26:03 +0100
committerChristian Brauner <brauner@kernel.org>2024-03-01 22:31:40 +0100
commite9c5263ce16d96311c118111ac779f004be8b473 (patch)
tree4657444a1bb7f15a4a52e5991a2673b80206c7ad /fs/nsfs.c
parent2558e3b23112adb82a558bab616890a790a38bc6 (diff)
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/nsfs.c')
-rw-r--r--fs/nsfs.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/fs/nsfs.c b/fs/nsfs.c
index 2ce229af34e9..7aaafb5cb9fc 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -50,19 +50,13 @@ static void nsfs_evict(struct inode *inode)
int ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb,
void *private_data)
{
- int ret;
struct ns_common *ns;
ns = ns_get_cb(private_data);
if (!ns)
return -ENOENT;
- ret = path_from_stashed(&ns->stashed, ns->inum, nsfs_mnt,
- &ns_file_operations, NULL, ns, path);
- if (ret <= 0)
- ns->ops->put(ns);
- if (ret < 0)
- return ret;
- return 0;
+
+ return path_from_stashed(&ns->stashed, ns->inum, nsfs_mnt, ns, path);
}
struct ns_get_path_task_args {
@@ -108,9 +102,7 @@ int open_related_ns(struct ns_common *ns,
}
err = path_from_stashed(&relative->stashed, relative->inum, nsfs_mnt,
- &ns_file_operations, NULL, relative, &path);
- if (err <= 0)
- relative->ops->put(relative);
+ relative, &path);
if (err < 0) {
put_unused_fd(fd);
return err;
@@ -207,6 +199,24 @@ static const struct super_operations nsfs_ops = {
.show_path = nsfs_show_path,
};
+static void nsfs_init_inode(struct inode *inode, void *data)
+{
+ inode->i_private = data;
+ inode->i_mode |= S_IRUGO;
+ inode->i_fop = &ns_file_operations;
+}
+
+static void nsfs_put_data(void *data)
+{
+ struct ns_common *ns = data;
+ ns->ops->put(ns);
+}
+
+static const struct stashed_operations nsfs_stashed_ops = {
+ .init_inode = nsfs_init_inode,
+ .put_data = nsfs_put_data,
+};
+
static int nsfs_init_fs_context(struct fs_context *fc)
{
struct pseudo_fs_context *ctx = init_pseudo(fc, NSFS_MAGIC);
@@ -214,6 +224,7 @@ static int nsfs_init_fs_context(struct fs_context *fc)
return -ENOMEM;
ctx->ops = &nsfs_ops;
ctx->dops = &ns_dentry_operations;
+ fc->s_fs_info = (void *)&nsfs_stashed_ops;
return 0;
}