Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

David Howells and committed by
Al Viro
31d6d5ce c80fa7c8

+62
+46
fs/libfs.c
··· 16 16 #include <linux/exportfs.h> 17 17 #include <linux/writeback.h> 18 18 #include <linux/buffer_head.h> /* sync_mapping_buffers */ 19 + #include <linux/fs_context.h> 20 + #include <linux/pseudo_fs.h> 19 21 20 22 #include <linux/uaccess.h> 21 23 ··· 236 234 static const struct super_operations simple_super_operations = { 237 235 .statfs = simple_statfs, 238 236 }; 237 + 238 + static int pseudo_fs_get_tree(struct fs_context *fc) 239 + { 240 + struct pseudo_fs_context *ctx = fc->fs_private; 241 + struct dentry *root; 242 + 243 + root = mount_pseudo_xattr(fc->fs_type, 244 + ctx->ops, ctx->xattr, 245 + ctx->dops, ctx->magic); 246 + if (IS_ERR(root)) 247 + return PTR_ERR(root); 248 + 249 + fc->root = root; 250 + return 0; 251 + } 252 + 253 + static void pseudo_fs_free(struct fs_context *fc) 254 + { 255 + kfree(fc->fs_private); 256 + } 257 + 258 + static const struct fs_context_operations pseudo_fs_context_ops = { 259 + .free = pseudo_fs_free, 260 + .get_tree = pseudo_fs_get_tree, 261 + }; 262 + 263 + /* 264 + * Common helper for pseudo-filesystems (sockfs, pipefs, bdev - stuff that 265 + * will never be mountable) 266 + */ 267 + struct pseudo_fs_context *init_pseudo(struct fs_context *fc, 268 + unsigned long magic) 269 + { 270 + struct pseudo_fs_context *ctx; 271 + 272 + ctx = kzalloc(sizeof(struct pseudo_fs_context), GFP_KERNEL); 273 + if (likely(ctx)) { 274 + ctx->magic = magic; 275 + fc->fs_private = ctx; 276 + fc->ops = &pseudo_fs_context_ops; 277 + } 278 + return ctx; 279 + } 280 + EXPORT_SYMBOL(init_pseudo); 239 281 240 282 /* 241 283 * Common helper for pseudo-filesystems (sockfs, pipefs, bdev - stuff that
+16
include/linux/pseudo_fs.h
··· 1 + #ifndef __LINUX_PSEUDO_FS__ 2 + #define __LINUX_PSEUDO_FS__ 3 + 4 + #include <linux/fs_context.h> 5 + 6 + struct pseudo_fs_context { 7 + const struct super_operations *ops; 8 + const struct xattr_handler **xattr; 9 + const struct dentry_operations *dops; 10 + unsigned long magic; 11 + }; 12 + 13 + struct pseudo_fs_context *init_pseudo(struct fs_context *fc, 14 + unsigned long magic); 15 + 16 + #endif