]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
vfs: Provide a mount_pseudo-replacement for the new mount API
authorDavid Howells <dhowells@redhat.com>
Mon, 25 Mar 2019 16:38:23 +0000 (16:38 +0000)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 25 May 2019 22:00:04 +0000 (18:00 -0400)
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

fs/libfs.c
include/linux/pseudo_fs.h [new file with mode: 0644]

index 030e545f586eaa3a21f7e5509f31aa83d0343793..edef70d3543868ac95a739818129231ac7c42a58 100644 (file)
@@ -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)
diff --git a/include/linux/pseudo_fs.h b/include/linux/pseudo_fs.h
new file mode 100644 (file)
index 0000000..eceda1d
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef __LINUX_PSEUDO_FS__
+#define __LINUX_PSEUDO_FS__
+
+#include <linux/fs_context.h>
+
+struct pseudo_fs_context {
+       const struct super_operations *ops;
+       const struct xattr_handler **xattr;
+       const struct dentry_operations *dops;
+       unsigned long magic;
+};
+
+struct pseudo_fs_context *init_pseudo(struct fs_context *fc,
+                                     unsigned long magic);
+
+#endif