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

kernfs: move the last knowledge of sysfs out from kernfs

There is still one residue of sysfs remaining: the sb_magic
SYSFS_MAGIC. However this should be kernfs user specific,
so this patch moves it out. Kerrnfs user should specify their
magic number while mouting.

Signed-off-by: Jianyu Zhan <nasa4836@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jianyu Zhan and committed by
Greg Kroah-Hartman
26fc9cd2 9f70a401

+20 -12
+6 -5
fs/kernfs/mount.c
··· 62 62 return NULL; 63 63 } 64 64 65 - static int kernfs_fill_super(struct super_block *sb) 65 + static int kernfs_fill_super(struct super_block *sb, unsigned long magic) 66 66 { 67 67 struct kernfs_super_info *info = kernfs_info(sb); 68 68 struct inode *inode; ··· 71 71 info->sb = sb; 72 72 sb->s_blocksize = PAGE_CACHE_SIZE; 73 73 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 74 - sb->s_magic = SYSFS_MAGIC; 74 + sb->s_magic = magic; 75 75 sb->s_op = &kernfs_sops; 76 76 sb->s_time_gran = 1; 77 77 ··· 132 132 * @fs_type: file_system_type of the fs being mounted 133 133 * @flags: mount flags specified for the mount 134 134 * @root: kernfs_root of the hierarchy being mounted 135 + * @magic: file system specific magic number 135 136 * @new_sb_created: tell the caller if we allocated a new superblock 136 137 * @ns: optional namespace tag of the mount 137 138 * ··· 144 143 * The return value can be passed to the vfs layer verbatim. 145 144 */ 146 145 struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, 147 - struct kernfs_root *root, bool *new_sb_created, 148 - const void *ns) 146 + struct kernfs_root *root, unsigned long magic, 147 + bool *new_sb_created, const void *ns) 149 148 { 150 149 struct super_block *sb; 151 150 struct kernfs_super_info *info; ··· 170 169 if (!sb->s_root) { 171 170 struct kernfs_super_info *info = kernfs_info(sb); 172 171 173 - error = kernfs_fill_super(sb); 172 + error = kernfs_fill_super(sb, magic); 174 173 if (error) { 175 174 deactivate_locked_super(sb); 176 175 return ERR_PTR(error);
+3 -1
fs/sysfs/mount.c
··· 13 13 #define DEBUG 14 14 15 15 #include <linux/fs.h> 16 + #include <linux/magic.h> 16 17 #include <linux/mount.h> 17 18 #include <linux/init.h> 18 19 #include <linux/user_namespace.h> ··· 39 38 } 40 39 41 40 ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET); 42 - root = kernfs_mount_ns(fs_type, flags, sysfs_root, &new_sb, ns); 41 + root = kernfs_mount_ns(fs_type, flags, sysfs_root, 42 + SYSFS_MAGIC, &new_sb, ns); 43 43 if (IS_ERR(root) || !new_sb) 44 44 kobj_ns_drop(KOBJ_NS_TYPE_NET, ns); 45 45 return root;
+8 -5
include/linux/kernfs.h
··· 301 301 302 302 const void *kernfs_super_ns(struct super_block *sb); 303 303 struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, 304 - struct kernfs_root *root, bool *new_sb_created, 305 - const void *ns); 304 + struct kernfs_root *root, unsigned long magic, 305 + bool *new_sb_created, const void *ns); 306 306 void kernfs_kill_sb(struct super_block *sb); 307 307 308 308 void kernfs_init(void); ··· 395 395 396 396 static inline struct dentry * 397 397 kernfs_mount_ns(struct file_system_type *fs_type, int flags, 398 - struct kernfs_root *root, bool *new_sb_created, const void *ns) 398 + struct kernfs_root *root, unsigned long magic, 399 + bool *new_sb_created, const void *ns) 399 400 { return ERR_PTR(-ENOSYS); } 400 401 401 402 static inline void kernfs_kill_sb(struct super_block *sb) { } ··· 454 453 455 454 static inline struct dentry * 456 455 kernfs_mount(struct file_system_type *fs_type, int flags, 457 - struct kernfs_root *root, bool *new_sb_created) 456 + struct kernfs_root *root, unsigned long magic, 457 + bool *new_sb_created) 458 458 { 459 - return kernfs_mount_ns(fs_type, flags, root, new_sb_created, NULL); 459 + return kernfs_mount_ns(fs_type, flags, root, 460 + magic, new_sb_created, NULL); 460 461 } 461 462 462 463 #endif /* __LINUX_KERNFS_H */
+3 -1
kernel/cgroup.c
··· 33 33 #include <linux/init_task.h> 34 34 #include <linux/kernel.h> 35 35 #include <linux/list.h> 36 + #include <linux/magic.h> 36 37 #include <linux/mm.h> 37 38 #include <linux/mutex.h> 38 39 #include <linux/mount.h> ··· 1605 1604 if (ret) 1606 1605 return ERR_PTR(ret); 1607 1606 1608 - dentry = kernfs_mount(fs_type, flags, root->kf_root, &new_sb); 1607 + dentry = kernfs_mount(fs_type, flags, root->kf_root, 1608 + CGROUP_SUPER_MAGIC, &new_sb); 1609 1609 if (IS_ERR(dentry) || !new_sb) 1610 1610 cgroup_put(&root->cgrp); 1611 1611 return dentry;