From: Rob Landley Subject: [PATCH 4/5] initmpfs: Make rootfs use tmpfs when CONFIG_TMPFS enabled. To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Cc: Al Viro Cc: Greg Kroah-Hartman Cc: Jens Axboe Cc: Stephen Warren Cc: Andrew Morton Cc: Hugh Dickins From: Rob Landley Conditionally call the appropriate fs_init function and fill_super functions. Add a use once guard to shmem_init() to simply succeed on a second call. (Note that IS_ENABLED() is a compile time constant so dead code elimination removes unused function calls when CONFIG_TMPFS is disabled.) Signed-off-by: Rob Landley --- init/do_mounts.c | 10 ++++++++-- mm/shmem.c | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) --- initold/init/do_mounts.c 2013-06-27 00:02:26.283442977 -0500 +++ initwork/init/do_mounts.c 2013-06-27 00:45:21.599550312 -0500 @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -600,7 +599,8 @@ else once++; - return mount_nodev(fs_type, flags, data, ramfs_fill_super); + return mount_nodev(fs_type, flags, data, + IS_ENABLED(CONFIG_TMPFS) ? shmem_fill_super : ramfs_fill_super); } static struct file_system_type rootfs_fs_type = { @@ -616,7 +616,11 @@ if (err) return err; - err = init_ramfs_fs(); + if (IS_ENABLED(CONFIG_TMPFS)) + err = shmem_init(); + else + err = init_ramfs_fs(); + if (err) unregister_filesystem(&rootfs_fs_type); --- initold/mm/shmem.c 2013-06-25 13:09:22.215743137 -0500 +++ initwork/mm/shmem.c 2013-06-27 00:16:58.195479317 -0500 @@ -2787,6 +2787,10 @@ { int error; + /* If rootfs called this, don't re-init */ + if (shmem_inode_cachep) + return 0; + error = bdi_init(&shmem_backing_dev_info); if (error) goto out4;