don't bother with registering rootfs
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 30 May 2019 21:48:35 +0000 (17:48 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 5 Jul 2019 02:01:59 +0000 (22:01 -0400)
init_mount_tree() can get to rootfs_fs_type directly and that simplifies
a lot of things.  We don't need to register it, we don't need to look
it up *and* we don't need to bother with preventing subsequent userland
mounts.  That's the way we should've done that from the very beginning.

There is a user-visible change, namely the disappearance of "rootfs"
from /proc/filesystems.  Note that it's been unmountable all along
and it didn't show up in /proc/mounts; however, it *is* a user-visible
change and theoretically some script might've been using its presence
in /proc/filesystems to tell 2.4.11+ from earlier kernels.

*IF* any complaints about behaviour change do show up, we could fake
it in /proc/filesystems.  I very much doubt we'll have to, though.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namespace.c
include/linux/init.h
init/do_mounts.c

index 1141641dff9605b6f729080a31e1f1d82f337fea..2db2f4c36c509415c0b5d33a8ecece06834d3755 100644 (file)
@@ -3686,13 +3686,8 @@ static void __init init_mount_tree(void)
        struct mount *m;
        struct mnt_namespace *ns;
        struct path root;
-       struct file_system_type *type;
 
-       type = get_fs_type("rootfs");
-       if (!type)
-               panic("Can't find rootfs type");
-       mnt = vfs_kern_mount(type, 0, "rootfs", NULL);
-       put_filesystem(type);
+       mnt = vfs_kern_mount(&rootfs_fs_type, 0, "rootfs", NULL);
        if (IS_ERR(mnt))
                panic("Can't create rootfs");
 
index 5255069f5a9fa101819ac397cb09e14a3cde6d21..cbe93521397e7cea6ff1558479d0193cdd6aa213 100644 (file)
@@ -137,6 +137,8 @@ extern initcall_entry_t __con_initcall_start[], __con_initcall_end[];
 /* Used for contructor calls. */
 typedef void (*ctor_fn_t)(void);
 
+struct file_system_type;
+
 /* Defined in init/main.c */
 extern int do_one_initcall(initcall_t fn);
 extern char __initdata boot_command_line[];
@@ -147,6 +149,7 @@ extern unsigned int reset_devices;
 void setup_arch(char **);
 void prepare_namespace(void);
 int __init init_rootfs(void);
+extern struct file_system_type rootfs_fs_type;
 
 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
 extern bool rodata_enabled;
index c170d8b309b1c989f64b6ab133f4d5ef9e9c3915..e7f0b0f18cce35af3994314e36b69803cd08665a 100644 (file)
@@ -629,19 +629,15 @@ static bool is_tmpfs;
 static struct dentry *rootfs_mount(struct file_system_type *fs_type,
        int flags, const char *dev_name, void *data)
 {
-       static unsigned long once;
        void *fill = ramfs_fill_super;
 
-       if (test_and_set_bit(0, &once))
-               return ERR_PTR(-ENODEV);
-
        if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs)
                fill = shmem_fill_super;
 
        return mount_nodev(fs_type, flags, data, fill);
 }
 
-static struct file_system_type rootfs_fs_type = {
+struct file_system_type rootfs_fs_type = {
        .name           = "rootfs",
        .mount          = rootfs_mount,
        .kill_sb        = kill_litter_super,
@@ -649,19 +645,12 @@ static struct file_system_type rootfs_fs_type = {
 
 int __init init_rootfs(void)
 {
-       int err = register_filesystem(&rootfs_fs_type);
-
-       if (err)
-               return err;
+       int err = 0;
 
        if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] &&
                (!root_fs_names || strstr(root_fs_names, "tmpfs"))) {
                err = shmem_init();
                is_tmpfs = true;
        }
-
-       if (err)
-               unregister_filesystem(&rootfs_fs_type);
-
        return err;
 }