summaryrefslogtreecommitdiff
path: root/fs/libfs.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2019-03-25 19:38:23 +0300
committerAl Viro <viro@zeniv.linux.org.uk>2019-05-26 01:00:04 +0300
commit31d6d5ce53400d6dc58e29ddd8dc184b3ba89d66 (patch)
tree3d2a12d63794b5ab86295001c711d63591e71ffa /fs/libfs.c
parentc80fa7c8301c10ad10d997b9e86b4aeac5923b3e (diff)
downloadlinux-31d6d5ce53400d6dc58e29ddd8dc184b3ba89d66.tar.xz
vfs: Provide a mount_pseudo-replacement for the new mount API
Provide a function, init_pseudo(), that provides a common infrastructure for converting pseudo-filesystems that can never be mountable. [AV: once all users of mount_pseudo_xattr() get converted, it will be folded into pseudo_fs_get_tree()] Signed-off-by: David Howells <dhowells@redhat.com> cc: linux-fsdevel@vger.kernel.org
Diffstat (limited to 'fs/libfs.c')
-rw-r--r--fs/libfs.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/fs/libfs.c b/fs/libfs.c
index 030e545f586e..edef70d35438 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -16,6 +16,8 @@
#include <linux/exportfs.h>
#include <linux/writeback.h>
#include <linux/buffer_head.h> /* sync_mapping_buffers */
+#include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
#include <linux/uaccess.h>
@@ -235,6 +237,50 @@ static const struct super_operations simple_super_operations = {
.statfs = simple_statfs,
};
+static int pseudo_fs_get_tree(struct fs_context *fc)
+{
+ struct pseudo_fs_context *ctx = fc->fs_private;
+ struct dentry *root;
+
+ root = mount_pseudo_xattr(fc->fs_type,
+ ctx->ops, ctx->xattr,
+ ctx->dops, ctx->magic);
+ if (IS_ERR(root))
+ return PTR_ERR(root);
+
+ fc->root = root;
+ return 0;
+}
+
+static void pseudo_fs_free(struct fs_context *fc)
+{
+ kfree(fc->fs_private);
+}
+
+static const struct fs_context_operations pseudo_fs_context_ops = {
+ .free = pseudo_fs_free,
+ .get_tree = pseudo_fs_get_tree,
+};
+
+/*
+ * Common helper for pseudo-filesystems (sockfs, pipefs, bdev - stuff that
+ * will never be mountable)
+ */
+struct pseudo_fs_context *init_pseudo(struct fs_context *fc,
+ unsigned long magic)
+{
+ struct pseudo_fs_context *ctx;
+
+ ctx = kzalloc(sizeof(struct pseudo_fs_context), GFP_KERNEL);
+ if (likely(ctx)) {
+ ctx->magic = magic;
+ fc->fs_private = ctx;
+ fc->ops = &pseudo_fs_context_ops;
+ }
+ return ctx;
+}
+EXPORT_SYMBOL(init_pseudo);
+
/*
* Common helper for pseudo-filesystems (sockfs, pipefs, bdev - stuff that
* will never be mountable)