From: David Howells <dhowells@redhat.com>
To: viro@zeniv.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, dhowells@redhat.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 02/38] vfs: Provide a mount_pseudo-replacement for fs_context
Date: Thu, 14 Mar 2019 16:09:17 +0000 [thread overview]
Message-ID: <155257975796.13720.9965979295958004676.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <155257972443.13720.11743171471060355965.stgit@warthog.procyon.org.uk>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-fsdevel@vger.kernel.org
---
fs/libfs.c | 93 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/fs_context.h | 7 +++
2 files changed, 100 insertions(+)
diff --git a/fs/libfs.c b/fs/libfs.c
index 0fb590d79f30..ceaf69c885c2 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -16,6 +16,7 @@
#include <linux/exportfs.h>
#include <linux/writeback.h>
#include <linux/buffer_head.h> /* sync_mapping_buffers */
+#include <linux/fs_context.h>
#include <linux/uaccess.h>
@@ -233,6 +234,98 @@ static const struct super_operations simple_super_operations = {
.statfs = simple_statfs,
};
+struct pseudo_fs_context {
+ struct qstr d_name;
+ const struct super_operations *ops;
+ const struct xattr_handler **xattr;
+ const struct dentry_operations *dops;
+ unsigned long magic;
+};
+
+static int pseudo_fs_get_tree(struct fs_context *fc)
+{
+ struct pseudo_fs_context *ctx = fc->fs_private;
+ struct super_block *s;
+ struct dentry *dentry;
+ struct inode *root;
+
+ s = sget_userns(fc->fs_type, NULL, set_anon_super, SB_KERNMOUNT|SB_NOUSER,
+ &init_user_ns, NULL);
+ if (IS_ERR(s))
+ return PTR_ERR(s);
+
+ s->s_maxbytes = MAX_LFS_FILESIZE;
+ s->s_blocksize = PAGE_SIZE;
+ s->s_blocksize_bits = PAGE_SHIFT;
+ s->s_magic = ctx->magic;
+ s->s_op = ctx->ops ?: &simple_super_operations;
+ s->s_xattr = ctx->xattr;
+ s->s_time_gran = 1;
+ root = new_inode(s);
+ if (!root)
+ goto Enomem;
+ /*
+ * since this is the first inode, make it number 1. New inodes created
+ * after this must take care not to collide with it (by passing
+ * max_reserved of 1 to iunique).
+ */
+ root->i_ino = 1;
+ root->i_mode = S_IFDIR | S_IRUSR | S_IWUSR;
+ root->i_atime = root->i_mtime = root->i_ctime = current_time(root);
+ dentry = __d_alloc(s, &ctx->d_name);
+ if (!dentry) {
+ iput(root);
+ goto Enomem;
+ }
+ d_instantiate(dentry, root);
+ s->s_root = dentry;
+ s->s_d_op = ctx->dops;
+ s->s_flags |= SB_ACTIVE;
+ fc->root = dget(s->s_root);
+ return 0;
+
+Enomem:
+ deactivate_locked_super(s);
+ return -ENOMEM;
+}
+
+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)
+ */
+int vfs_init_pseudo_fs_context(struct fs_context *fc,
+ const char *name,
+ const struct super_operations *ops,
+ const struct xattr_handler **xattr,
+ const struct dentry_operations *dops,
+ unsigned long magic)
+{
+ struct pseudo_fs_context *ctx;
+
+ ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+ if (!ctx)
+ return -ENOMEM;
+ ctx->d_name = (struct qstr)QSTR_INIT(name, strlen(name));
+ ctx->ops = ops;
+ ctx->xattr = xattr;
+ ctx->dops = dops;
+ ctx->magic = magic;
+ fc->fs_private = ctx;
+ fc->ops = &pseudo_fs_context_ops;
+ return 0;
+}
+EXPORT_SYMBOL(vfs_init_pseudo_fs_context);
+
/*
* Common helper for pseudo-filesystems (sockfs, pipefs, bdev - stuff that
* will never be mountable)
diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
index 98b44ad89378..a779022d06f5 100644
--- a/include/linux/fs_context.h
+++ b/include/linux/fs_context.h
@@ -121,6 +121,13 @@ extern int generic_parse_monolithic(struct fs_context *fc, void *data);
extern int vfs_get_tree(struct fs_context *fc);
extern void put_fs_context(struct fs_context *fc);
+extern int vfs_init_pseudo_fs_context(struct fs_context *fc,
+ const char *name,
+ const struct super_operations *ops,
+ const struct xattr_handler **xattr,
+ const struct dentry_operations *dops,
+ unsigned long magic);
+
/*
* sget() wrapper to be called from the ->get_tree() op.
*/
next prev parent reply other threads:[~2019-03-14 16:09 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <155257972443.13720.11743171471060355965.stgit@warthog.procyon.org.uk>
2019-03-14 16:09 ` [PATCH 01/38] vfs: Provide sb->s_iflags settings in fs_context struct David Howells
2019-03-14 16:09 ` David Howells [this message]
2019-03-14 16:09 ` [PATCH 03/38] vfs: Convert aio to fs_context David Howells
2019-03-14 16:09 ` [PATCH 04/38] vfs: Convert anon_inodes " David Howells
2019-03-14 16:09 ` [PATCH 05/38] vfs: Convert bdev " David Howells
2019-03-14 16:09 ` [PATCH 06/38] vfs: Convert nsfs " David Howells
2019-03-14 16:09 ` [PATCH 07/38] vfs: Convert pipe " David Howells
2019-03-14 16:09 ` [PATCH 08/38] vfs: Convert zsmalloc " David Howells
2019-03-14 16:10 ` [PATCH 09/38] vfs: Convert sockfs " David Howells
2019-03-14 16:10 ` [PATCH 10/38] vfs: Convert dax " David Howells
2019-03-14 16:10 ` [PATCH 11/38] vfs: Convert drm " David Howells
2019-03-14 16:10 ` [PATCH 12/38] vfs: Convert ia64 perfmon " David Howells
2019-03-14 16:10 ` [PATCH 13/38] vfs: Convert cxl " David Howells
2019-03-15 0:22 ` Andrew Donnellan
2019-03-22 7:42 ` Frederic Barrat
2019-03-14 16:10 ` [PATCH 14/38] vfs: Convert ocxlflash " David Howells
2019-03-19 14:53 ` Matthew R. Ochs
2019-03-14 16:10 ` [PATCH 15/38] vfs: Convert virtio_balloon " David Howells
2019-03-14 16:11 ` [PATCH 16/38] vfs: Convert btrfs_test " David Howells
2019-03-14 18:24 ` David Sterba
2019-03-14 16:11 ` [PATCH 17/38] vfs: Kill off mount_pseudo() and mount_pseudo_xattr() David Howells
2019-03-14 16:11 ` [PATCH 18/38] vfs: Use sget_fc() for pseudo-filesystems David Howells
2019-03-14 16:11 ` [PATCH 19/38] vfs: Convert binderfs to fs_context David Howells
2019-03-14 16:11 ` [PATCH 20/38] vfs: Convert nfsctl " David Howells
2019-03-14 17:29 ` J. Bruce Fields
2019-03-14 16:11 ` [PATCH 21/38] vfs: Convert rpc_pipefs " David Howells
2019-03-14 16:11 ` [PATCH 22/38] vfs: Kill off mount_ns() David Howells
2019-03-14 16:11 ` [PATCH 23/38] vfs: Kill sget_userns() David Howells
2019-03-14 16:12 ` [PATCH 24/38] vfs: Convert binfmt_misc to fs_context David Howells
2019-03-14 16:12 ` [PATCH 25/38] vfs: Convert configfs " David Howells
2019-03-14 16:12 ` [PATCH 26/38] vfs: Convert efivarfs " David Howells
2019-03-14 16:12 ` [PATCH 27/38] vfs: Convert fusectl " David Howells
2019-03-14 16:12 ` [PATCH 28/38] vfs: Convert qib_fs/ipathfs " David Howells
2019-03-14 16:12 ` [PATCH 29/38] vfs: Convert ibmasmfs " David Howells
2019-03-14 16:12 ` [PATCH 30/38] vfs: Convert oprofilefs " David Howells
2019-03-14 16:13 ` [PATCH 31/38] vfs: Convert gadgetfs " David Howells
2019-03-20 6:57 ` Felipe Balbi
2019-03-20 7:42 ` David Howells
2019-03-20 8:34 ` Felipe Balbi
2019-03-14 16:13 ` [PATCH 32/38] vfs: Convert xenfs " David Howells
2019-03-14 16:13 ` [PATCH 33/38] vfs: Convert openpromfs " David Howells
2019-03-14 16:13 ` [PATCH 34/38] vfs: Convert apparmorfs " David Howells
2019-03-14 16:13 ` [PATCH 35/38] vfs: Convert securityfs " David Howells
2019-03-14 16:13 ` [PATCH 36/38] vfs: Convert selinuxfs " David Howells
2019-03-14 16:13 ` [PATCH 37/38] vfs: Convert smackfs " David Howells
2019-03-14 16:13 ` [PATCH 38/38] tmpfs, devtmpfs, ramfs, rootfs: Convert " David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=155257975796.13720.9965979295958004676.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).