Skip to content

Commit

Permalink
initmpfs: make rootfs use tmpfs when CONFIG_TMPFS enabled
Browse files Browse the repository at this point in the history
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 <rob@landley.net>
Cc: Jeff Layton <jlayton@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Stephen Warren <swarren@nvidia.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Jim Cromie <jim.cromie@gmail.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
landley authored and torvalds committed Sep 11, 2013
1 parent 57f150a commit 16203a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions init/do_mounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <linux/fs_struct.h>
#include <linux/slab.h>
#include <linux/ramfs.h>
#include <linux/shmem_fs.h>

#include <linux/nfs_fs.h>
#include <linux/nfs_fs_sb.h>
Expand Down Expand Up @@ -598,7 +599,8 @@ static struct dentry *rootfs_mount(struct file_system_type *fs_type,
if (test_and_set_bit(0, &once))
return ERR_PTR(-ENODEV);

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 = {
Expand All @@ -614,7 +616,11 @@ int __init init_rootfs(void)
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);

Expand Down
4 changes: 4 additions & 0 deletions mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2819,6 +2819,10 @@ int __init shmem_init(void)
{
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;
Expand Down

0 comments on commit 16203a7

Please sign in to comment.