public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
@ 2013-07-16 23:45 Rob Landley
  2013-07-16 23:45 ` [PATCH 1/5] initmpfs v2: replace MS_NOUSER in initramfs Rob Landley
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Rob Landley @ 2013-07-16 23:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Alexander Viro, Al Viro, Andrew Morton, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
Specify rootfstype=ramfs to get the old initramfs behavior.

The previous initramfs code provided a fairly crappy root filesystem:
didn't let you --bind mount directories out of it, reported zero
size/usage so it didn't show up in "df" and couldn't run things like
rpm that query available space before proceeding, would fill up all
available memory and panic the system if you wrote too much to it...

Using tmpfs instead provides a much better root filesystem.

Changes from v1: use test_and_set_bit() for "once" logic.

Changes from this morning's send: none, just hopefully not screwing
up the message-id this time trying to make it a reply to another message
via cut and paste...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/5] initmpfs v2: replace MS_NOUSER in initramfs
  2013-07-16 23:45 [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
@ 2013-07-16 23:45 ` Rob Landley
  2013-07-16 23:45 ` [PATCH 2/5] initmpfs v2: Move bdi setup from init_rootfs to init_ramfs Rob Landley
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Rob Landley @ 2013-07-16 23:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Al Viro, Eric W. Biederman, Andrew Morton

From: Rob Landley <rob@landley.net>

Mounting MS_NOUSER prevents --bind mounts from rootfs. Prevent new rootfs
mounts with a different mechanism that doesn't affect bind mounts.

Signed-off-by: Rob Landley <rob@landley.net>
---

 fs/ramfs/inode.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index c24f1e1..14b9c35 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -247,7 +247,12 @@ struct dentry *ramfs_mount(struct file_system_type *fs_type,
 static struct dentry *rootfs_mount(struct file_system_type *fs_type,
 	int flags, const char *dev_name, void *data)
 {
-	return mount_nodev(fs_type, flags|MS_NOUSER, data, ramfs_fill_super);
+	static unsigned long once;
+
+	if (test_and_set_bit(1, &once))
+		return ERR_PTR(-ENODEV);
+
+	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
 }
 
 static void ramfs_kill_sb(struct super_block *sb)

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/5] initmpfs v2: Move bdi setup from init_rootfs to init_ramfs
  2013-07-16 23:45 [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
  2013-07-16 23:45 ` [PATCH 1/5] initmpfs v2: replace MS_NOUSER in initramfs Rob Landley
@ 2013-07-16 23:45 ` Rob Landley
  2013-07-16 23:45 ` [PATCH 3/5] initmpfs v2: Move rootfs code from fs/ramfs/ to init/ Rob Landley
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Rob Landley @ 2013-07-16 23:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Al Viro, Eric W. Biederman, Andrew Morton

From: Rob Landley <rob@landley.net>

Even though ramfs hasn't got a backing device, commit e0bf68ddec4f added one
anyway, and put the initialization in init_rootfs() since that's the first
user, leaving it out of init_ramfs() to avoid duplication.

But initmpfs uses init_tmpfs() instead, so move the init into the filesystem's
init function, add a "once" guard to prevent duplicate initialization, and
call the filesystem init from rootfs init.

This goes part of the way to allowing ramfs to be built as a module.

Signed-off-by: Rob Landley <rob@landley.net>
---

 fs/ramfs/inode.c |   23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

--- initold/fs/ramfs/inode.c	2013-06-28 15:12:03.205879730 -0500
+++ initold2/fs/ramfs/inode.c	2013-06-28 15:12:12.425880115 -0500
@@ -275,21 +275,34 @@
 
 static int __init init_ramfs_fs(void)
 {
-	return register_filesystem(&ramfs_fs_type);
+	static unsigned long once;
+	int err;
+
+	if (test_and_set_bit(1, &once))
+		return 0;
+
+	err = bdi_init(&ramfs_backing_dev_info);
+	if (err)
+		return err;
+
+	err = register_filesystem(&ramfs_fs_type);
+	if (err)
+		bdi_destroy(&ramfs_backing_dev_info);
+
+	return err;
 }
 module_init(init_ramfs_fs)
 
 int __init init_rootfs(void)
 {
-	int err;
+	int err = register_filesystem(&rootfs_fs_type);
 
-	err = bdi_init(&ramfs_backing_dev_info);
 	if (err)
 		return err;
 
-	err = register_filesystem(&rootfs_fs_type);
+	err = init_ramfs_fs();
 	if (err)
-		bdi_destroy(&ramfs_backing_dev_info);
+		unregister_filesystem(&rootfs_fs_type);
 
 	return err;
 }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/5] initmpfs v2: Move rootfs code from fs/ramfs/ to init/
  2013-07-16 23:45 [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
  2013-07-16 23:45 ` [PATCH 1/5] initmpfs v2: replace MS_NOUSER in initramfs Rob Landley
  2013-07-16 23:45 ` [PATCH 2/5] initmpfs v2: Move bdi setup from init_rootfs to init_ramfs Rob Landley
@ 2013-07-16 23:45 ` Rob Landley
  2013-07-16 23:45 ` [PATCH 4/5] initmpfs v2: Make rootfs use tmpfs when CONFIG_TMPFS enabled Rob Landley
  2013-07-16 23:45 ` [PATCH 5/5] initmpfs v2: Use initramfs if rootfstype= or root= specified Rob Landley
  4 siblings, 0 replies; 8+ messages in thread
From: Rob Landley @ 2013-07-16 23:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-fsdevel, Jeff Layton, Jens Axboe, Stephen Warren,
	Rusty Russell, Jim Cromie, Sam Ravnborg, Greg Kroah-Hartman,
	Andrew Morton, Eric W. Biederman, Alexander Viro

From: Rob Landley <rob@landley.net>

When the rootfs code was a wrapper around ramfs, having them in the same
file made sense. Now that it can wrap another filesystem type, move it
in with the init code instead.

This also allows a subsequent patch to access rootfstype= command line arg.

Signed-off-by: Rob Landley <rob@landley.net>
---

 fs/namespace.c        |    2 +-
 fs/ramfs/inode.c      |   32 +-------------------------------
 include/linux/init.h  |    1 +
 include/linux/ramfs.h |    2 +-
 init/do_mounts.c      |   32 ++++++++++++++++++++++++++++++++
 5 files changed, 36 insertions(+), 33 deletions(-)

--- initold/fs/namespace.c	2013-06-28 15:09:19.389872904 -0500
+++ initold2/fs/namespace.c	2013-06-28 15:16:05.261889820 -0500
@@ -17,7 +17,7 @@
 #include <linux/security.h>
 #include <linux/idr.h>
 #include <linux/acct.h>		/* acct_auto_close_mnt */
-#include <linux/ramfs.h>	/* init_rootfs */
+#include <linux/init.h>		/* init_rootfs */
 #include <linux/fs_struct.h>	/* get_fs_root et.al. */
 #include <linux/fsnotify.h>	/* fsnotify_vfsmount_delete */
 #include <linux/uaccess.h>
--- initold/fs/ramfs/inode.c	2013-06-28 15:15:37.549888666 -0500
+++ initold2/fs/ramfs/inode.c	2013-06-28 15:16:05.273889820 -0500
@@ -244,17 +244,6 @@
 	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
 }
 
-static struct dentry *rootfs_mount(struct file_system_type *fs_type,
-	int flags, const char *dev_name, void *data)
-{
-	static unsigned long once;
-
-	if (test_and_set_bit(1, &once))
-		return ERR_PTR(-ENODEV);
-
-	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
-}
-
 static void ramfs_kill_sb(struct super_block *sb)
 {
 	kfree(sb->s_fs_info);
@@ -267,13 +256,8 @@
 	.kill_sb	= ramfs_kill_sb,
 	.fs_flags	= FS_USERNS_MOUNT,
 };
-static struct file_system_type rootfs_fs_type = {
-	.name		= "rootfs",
-	.mount		= rootfs_mount,
-	.kill_sb	= kill_litter_super,
-};
 
-static int __init init_ramfs_fs(void)
+int __init init_ramfs_fs(void)
 {
 	static unsigned long once;
 	int err;
@@ -292,17 +276,3 @@
 	return err;
 }
 module_init(init_ramfs_fs)
-
-int __init init_rootfs(void)
-{
-	int err = register_filesystem(&rootfs_fs_type);
-
-	if (err)
-		return err;
-
-	err = init_ramfs_fs();
-	if (err)
-		unregister_filesystem(&rootfs_fs_type);
-
-	return err;
-}
--- initold/include/linux/init.h	2013-06-28 15:09:19.517872909 -0500
+++ initold2/include/linux/init.h	2013-06-28 15:16:05.321889821 -0500
@@ -153,6 +153,7 @@
 void setup_arch(char **);
 void prepare_namespace(void);
 void __init load_default_modules(void);
+int __init init_rootfs(void);
 
 extern void (*late_time_init)(void);
 
--- initold/include/linux/ramfs.h	2013-06-28 15:09:19.537872910 -0500
+++ initold2/include/linux/ramfs.h	2013-06-28 15:16:05.513889832 -0500
@@ -25,7 +25,7 @@
 
 extern const struct file_operations ramfs_file_operations;
 extern const struct vm_operations_struct generic_file_vm_ops;
-extern int __init init_rootfs(void);
+extern int __init init_ramfs_fs(void);
 
 int ramfs_fill_super(struct super_block *sb, void *data, int silent);
 
--- initold/init/do_mounts.c	2013-06-28 15:09:19.585872913 -0500
+++ initold2/init/do_mounts.c	2013-06-28 15:16:05.561889831 -0500
@@ -26,6 +26,7 @@
 #include <linux/async.h>
 #include <linux/fs_struct.h>
 #include <linux/slab.h>
+#include <linux/ramfs.h>
 
 #include <linux/nfs_fs.h>
 #include <linux/nfs_fs_sb.h>
@@ -588,3 +589,34 @@
 	sys_mount(".", "/", NULL, MS_MOVE, NULL);
 	sys_chroot(".");
 }
+
+static struct dentry *rootfs_mount(struct file_system_type *fs_type,
+	int flags, const char *dev_name, void *data)
+{
+	static unsigned long once;
+
+	if (test_and_set_bit(1, &once))
+		return ERR_PTR(-ENODEV);
+
+	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
+}
+
+static struct file_system_type rootfs_fs_type = {
+	.name		= "rootfs",
+	.mount		= rootfs_mount,
+	.kill_sb	= kill_litter_super,
+};
+
+int __init init_rootfs(void)
+{
+	int err = register_filesystem(&rootfs_fs_type);
+
+	if (err)
+		return err;
+
+	err = init_ramfs_fs();
+	if (err)
+		unregister_filesystem(&rootfs_fs_type);
+
+	return err;
+}
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index c24f1e1..3b9f114 100644

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/5] initmpfs v2: Make rootfs use tmpfs when CONFIG_TMPFS enabled.
  2013-07-16 23:45 [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
                   ` (2 preceding siblings ...)
  2013-07-16 23:45 ` [PATCH 3/5] initmpfs v2: Move rootfs code from fs/ramfs/ to init/ Rob Landley
@ 2013-07-16 23:45 ` Rob Landley
  2013-07-16 23:45 ` [PATCH 5/5] initmpfs v2: Use initramfs if rootfstype= or root= specified Rob Landley
  4 siblings, 0 replies; 8+ messages in thread
From: Rob Landley @ 2013-07-16 23:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, Al Viro, Greg Kroah-Hartman, Jens Axboe, Stephen Warren,
	Andrew Morton, Hugh Dickins

From: Rob Landley <rob@landley.net>

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>
---

 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 <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>
@@ -598,7 +597,8 @@
 	if (test_and_set_bit(1, &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 = {
@@ -614,7 +614,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
@@ -2816,6 +2816,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;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/5] initmpfs v2: Use initramfs if rootfstype= or root= specified.
  2013-07-16 23:45 [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
                   ` (3 preceding siblings ...)
  2013-07-16 23:45 ` [PATCH 4/5] initmpfs v2: Make rootfs use tmpfs when CONFIG_TMPFS enabled Rob Landley
@ 2013-07-16 23:45 ` Rob Landley
  2013-07-19 19:57   ` Andrew Morton
  4 siblings, 1 reply; 8+ messages in thread
From: Rob Landley @ 2013-07-16 23:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Al Viro, Greg Kroah-Hartman, Jens Axboe, Stephen Warren,
	Andrew Morton

From: Rob Landley <rob@landley.net>

Command line option rootfstype=ramfs to obtain old initramfs behavior,
and use ramfs instead of tmpfs for stub when root= defined (for cosmetic
reasons).

Signed-off-by: Rob Landley <rob@landley.net>
---

 init/do_mounts.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

--- initold/init/do_mounts.c	2013-06-29 13:27:00.485256840 -0500
+++ initwork/init/do_mounts.c	2013-06-29 13:34:17.925275072 -0500
@@ -591,16 +591,20 @@
 	sys_chroot(".");
 }
 
+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(1, &once))
 		return ERR_PTR(-ENODEV);
 
-	return mount_nodev(fs_type, flags, data,
-		IS_ENABLED(CONFIG_TMPFS) ? shmem_fill_super : ramfs_fill_super);
+	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 = {
@@ -616,9 +620,12 @@
 	if (err)
 		return err;
 
-	if (IS_ENABLED(CONFIG_TMPFS))
+	if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] &&
+		(!root_fs_names || strstr(root_fs_names, "tmpfs")))
+	{
 		err = shmem_init();
-	else
+		is_tmpfs = true;
+	} else
 		err = init_ramfs_fs();
 
 	if (err)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/5] initmpfs v2: Use initramfs if rootfstype= or root= specified.
  2013-07-16 23:45 ` [PATCH 5/5] initmpfs v2: Use initramfs if rootfstype= or root= specified Rob Landley
@ 2013-07-19 19:57   ` Andrew Morton
  2013-07-26  4:12     ` Rob Landley
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2013-07-19 19:57 UTC (permalink / raw)
  To: Rob Landley
  Cc: linux-kernel, Al Viro, Greg Kroah-Hartman, Jens Axboe,
	Stephen Warren

On Tue, 16 Jul 2013 16:45:39 -0700 (PDT) Rob Landley <rob@landley.net> wrote:

> Command line option rootfstype=ramfs to obtain old initramfs behavior,
> and use ramfs instead of tmpfs for stub when root= defined (for cosmetic
> reasons).

Could we get a Documentation/kernel-parameters.txt update please?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/5] initmpfs v2: Use initramfs if rootfstype= or root= specified.
  2013-07-19 19:57   ` Andrew Morton
@ 2013-07-26  4:12     ` Rob Landley
  0 siblings, 0 replies; 8+ messages in thread
From: Rob Landley @ 2013-07-26  4:12 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Al Viro, Greg Kroah-Hartman, Jens Axboe,
	Stephen Warren

On 07/19/2013 02:57:18 PM, Andrew Morton wrote:
> On Tue, 16 Jul 2013 16:45:39 -0700 (PDT) Rob Landley  
> <rob@landley.net> wrote:
> 
> > Command line option rootfstype=ramfs to obtain old initramfs  
> behavior,
> > and use ramfs instead of tmpfs for stub when root= defined (for  
> cosmetic
> > reasons).
> 
> Could we get a Documentation/kernel-parameters.txt update please?

Sorry for the delay, traveling. Behind on email...

"rootfstype" is already documented in kernel parameters:

         rootfstype=     [KNL] Set root filesystem type

I just applied the existing definition to initramfs now that it has  
more than one filesystem option there. Do you want me to add a special  
case here to say that rootfstype= still works when the root filesystem  
is initramfs? Or would it instead make more sense to add:

Signed-off-by: Rob Landley <rob@landley.net>

Document that rootfstype= applies to initmpfs too.

--- a/Documentation/filesystems/ramfs-rootfs-initramfs.txt
+++ b/Documentation/filesystems/ramfs-rootfs-initramfs.txt
@@ -79,6 +79,9 @@ to just make sure certain lists can't become empty.
  Most systems just mount another filesystem over rootfs and ignore  
it.  The
  amount of space an empty instance of ramfs takes up is tiny.

+If CONFIG_TMPFS is enabled, rootfs will use tmpfs instead of ramfs by  
default.
+To force ramfs, add "rootfstype=ramfs" to the kernel command line.
+
  What is initramfs?
  ------------------


(What I _didn't_ do yet is hook up rootflags= to initmpfs, so you can  
specify size= as something other than 50%. Partly because if you have  
an empty cpio archive and the rootflags= applies to ext3 or something,  
those flags could potentially confuse tmpfs with unknown options and  
throw errors. And partly because mount -o remount,size=20% works fine  
after the fact, so it's not time critical and I easily can do a  
follow-up patch. The one potential downside is if you want to have a  
cpio archive eat more than 50% of the kernel's memory, it'll fail to  
extract into tmpfs with the size limits. But the rootfstype=ramfs  
downgrade also works around that for now...)

There are a number of follow up patches I could do, but the basic  
functionality doesn't depend on them...

Rob

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-07-26  4:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-16 23:45 [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
2013-07-16 23:45 ` [PATCH 1/5] initmpfs v2: replace MS_NOUSER in initramfs Rob Landley
2013-07-16 23:45 ` [PATCH 2/5] initmpfs v2: Move bdi setup from init_rootfs to init_ramfs Rob Landley
2013-07-16 23:45 ` [PATCH 3/5] initmpfs v2: Move rootfs code from fs/ramfs/ to init/ Rob Landley
2013-07-16 23:45 ` [PATCH 4/5] initmpfs v2: Make rootfs use tmpfs when CONFIG_TMPFS enabled Rob Landley
2013-07-16 23:45 ` [PATCH 5/5] initmpfs v2: Use initramfs if rootfstype= or root= specified Rob Landley
2013-07-19 19:57   ` Andrew Morton
2013-07-26  4:12     ` Rob Landley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox