linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] turn device_init() into an initcall
@ 2001-05-15 15:56 Alexander Viro
  2001-05-15 16:36 ` Alexander Viro
  2001-05-16 11:47 ` Alexander Viro
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Viro @ 2001-05-15 15:56 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

	Patch below turns device_init() into initcall. Current tree
calls it from fs/partitions/check.c::partitions_setup() - definitely
odd place for that stuff.

	Another thing done by partition_setup() is {init,}rd_load(). I.e.
setting the contents of /dev/ram0 from initrd or floppies. That beast
should be done after _all_ drivers' initialization, indeed - it belongs with
mount_root()/mount_devfs()/etc. I took it to main/init.c - that way
it's guaranteed to be called after all drivers initialization code and
that's where we do the rest of late-boot stuff. partition_setup() is gone
now.

	It allows to get mount_root() logics cleaned. Old sequence was
device_init()
load initrd
register filesystems
do initcalls for devices
play with do_mount

	New one is
register filesystems
device_init()
other initcalls for devices
load initrd
do_mount
	and that's not only obviously saner, but also allows to clean up
do_mount/loading initrd logics (do_mount also has stuff with loading
ramdisks, etc.). Besides, it allows to start turning functions called
from device_init() into initcalls, thus getting rid of ifdef dungpiles
in them.

	Patch is against 2.4.5-pre1, but applies to -pre2 as well.
Please, apply.
								Al

diff -urN S5-pre1/drivers/block/genhd.c S5-pre1-device_init/drivers/block/genhd.c
--- S5-pre1/drivers/block/genhd.c	Fri Feb 16 18:37:04 2001
+++ S5-pre1-device_init/drivers/block/genhd.c	Wed May  2 21:09:30 2001
@@ -31,7 +31,7 @@
 extern int cpqarray_init(void);
 extern void ieee1394_init(void);
 
-void __init device_init(void)
+int __init device_init(void)
 {
 #ifdef CONFIG_PARPORT
 	parport_init();
@@ -64,4 +64,7 @@
 #ifdef CONFIG_VT
 	console_map_init();
 #endif
+	return 0;
 }
+
+__initcall(device_init);
diff -urN S5-pre1/fs/partitions/check.c S5-pre1-device_init/fs/partitions/check.c
--- S5-pre1/fs/partitions/check.c	Thu Feb 22 06:45:26 2001
+++ S5-pre1-device_init/fs/partitions/check.c	Wed May  2 21:09:30 2001
@@ -33,10 +33,7 @@
 #include "ibm.h"
 #include "ultrix.h"
 
-extern void device_init(void);
 extern int *blk_size[];
-extern void rd_load(void);
-extern void initrd_load(void);
 
 struct gendisk *gendisk_head;
 int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
@@ -438,19 +435,3 @@
 		blk_size[dev->major] = dev->sizes;
 	}
 }
-
-int __init partition_setup(void)
-{
-	device_init();
-
-#ifdef CONFIG_BLK_DEV_RAM
-#ifdef CONFIG_BLK_DEV_INITRD
-	if (initrd_start && mount_initrd) initrd_load();
-	else
-#endif
-	rd_load();
-#endif
-	return 0;
-}
-
-__initcall(partition_setup);
diff -urN S5-pre1/init/main.c S5-pre1-device_init/init/main.c
--- S5-pre1/init/main.c	Wed May  2 11:16:38 2001
+++ S5-pre1-device_init/init/main.c	Wed May  2 21:09:30 2001
@@ -638,9 +638,6 @@
  */
 static void __init do_basic_setup(void)
 {
-#ifdef CONFIG_BLK_DEV_INITRD
-	int real_root_mountflags;
-#endif
 
 	/*
 	 * Tell the world that we're going to be the grim
@@ -707,13 +704,6 @@
 	/* Networking initialization needs a process context */ 
 	sock_init();
 
-#ifdef CONFIG_BLK_DEV_INITRD
-	real_root_dev = ROOT_DEV;
-	real_root_mountflags = root_mountflags;
-	if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
-	else mount_initrd =0;
-#endif
-
 	start_context_thread();
 	do_initcalls();
 
@@ -724,6 +714,33 @@
 #ifdef CONFIG_PCMCIA
 	init_pcmcia_ds();		/* Do this last */
 #endif
+}
+
+extern void rd_load(void);
+extern void initrd_load(void);
+
+/*
+ * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
+ */
+static void prepare_namespace(void)
+{
+#ifdef CONFIG_BLK_DEV_INITRD
+	int real_root_mountflags = ROOT_DEV;
+	real_root_mountflags = root_mountflags;
+	if (!initrd_start)
+		mount_initrd = 0;
+	if (mount_initrd)
+		root_mountflags &= ~MS_RDONLY;
+#endif
+
+#ifdef CONFIG_BLK_DEV_RAM
+#ifdef CONFIG_BLK_DEV_INITRD
+	if (mount_initrd)
+		initrd_load();
+	else
+#endif
+	rd_load();
+#endif
 
 	/* Mount the root filesystem.. */
 	mount_root();
@@ -755,6 +772,8 @@
 {
 	lock_kernel();
 	do_basic_setup();
+
+	prepare_namespace();
 
 	/*
 	 * Ok, we have completed the initial bootup, and



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

* Re: [PATCH] turn device_init() into an initcall
  2001-05-15 15:56 [PATCH] turn device_init() into an initcall Alexander Viro
@ 2001-05-15 16:36 ` Alexander Viro
  2001-05-15 17:06   ` Alexander Viro
  2001-05-16 11:47 ` Alexander Viro
  1 sibling, 1 reply; 5+ messages in thread
From: Alexander Viro @ 2001-05-15 16:36 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel



On Tue, 15 May 2001, Alexander Viro wrote:

> ramdisks, etc.). Besides, it allows to start turning functions called
> from device_init() into initcalls, thus getting rid of ifdef dungpiles
> in them.

... and here's the next part. Takes parport_init() out of device_init().
Since we have no initcalls in parport/* we don't break the ordering.
Please, apply - it's incremental to previous.

diff -urN S5-pre2-init-0/drivers/Makefile S5-pre2-init/drivers/Makefile
--- S5-pre2-init-0/drivers/Makefile	Fri Feb 16 21:09:52 2001
+++ S5-pre2-init/drivers/Makefile	Tue May 15 12:15:41 2001
@@ -9,7 +9,7 @@
 mod-subdirs :=	dio mtd sbus video macintosh usb input telephony sgi i2o ide \
 		scsi md ieee1394 pnp isdn atm fc4 net/hamradio i2c acpi
 
-subdir-y :=	block char net parport sound misc media cdrom
+subdir-y :=	parport block char net sound misc media cdrom
 subdir-m :=	$(subdir-y)
 
 
diff -urN S5-pre2-init-0/drivers/block/genhd.c S5-pre2-init/drivers/block/genhd.c
--- S5-pre2-init-0/drivers/block/genhd.c	Tue May 15 12:15:13 2001
+++ S5-pre2-init/drivers/block/genhd.c	Tue May 15 12:18:29 2001
@@ -17,7 +17,6 @@
 #include <linux/blk.h>
 #include <linux/init.h>
 
-extern int parport_init(void);
 extern int chr_dev_init(void);
 extern int blk_dev_init(void);
 #ifdef CONFIG_BLK_DEV_DAC960
@@ -33,9 +32,6 @@
 
 int __init device_init(void)
 {
-#ifdef CONFIG_PARPORT
-	parport_init();
-#endif
 	chr_dev_init();
 	blk_dev_init();
 	sti();
diff -urN S5-pre2-init-0/drivers/parport/init.c S5-pre2-init/drivers/parport/init.c
--- S5-pre2-init-0/drivers/parport/init.c	Fri Feb 16 22:53:48 2001
+++ S5-pre2-init/drivers/parport/init.c	Tue May 15 12:26:44 2001
@@ -165,6 +165,8 @@
 	return 0;
 }
 
+__initcall(parport_init);
+
 #endif
 
 /* Exported symbols for modules. */


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

* Re: [PATCH] turn device_init() into an initcall
  2001-05-15 16:36 ` Alexander Viro
@ 2001-05-15 17:06   ` Alexander Viro
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Viro @ 2001-05-15 17:06 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel



On Tue, 15 May 2001, Alexander Viro wrote:

> 
> 
> On Tue, 15 May 2001, Alexander Viro wrote:
> 
> > ramdisks, etc.). Besides, it allows to start turning functions called
> > from device_init() into initcalls, thus getting rid of ifdef dungpiles
> > in them.
> 
> ... and here's the next part. Takes parport_init() out of device_init().
> Since we have no initcalls in parport/* we don't break the ordering.
> Please, apply - it's incremental to previous.

One more - chr_dev_init() becomes initcall. However, I'd really like
to see this one reviewed from the ordering POV. It may break things -
we might need to move some stuff around. FWIW it works for me, but I don't
have a lot of hardware, so that doesn't say much.

Folks, please look into that - previous patches allow to turn device
initialization into initcalls and it's a Good Thing(tm). Just look
at device_init(), chr_dev_init() and blk_dev_init() - each of them is
a hive of ifdefs.

Linus, your comments?
							Al


diff -urN S5-pre2-init-1/drivers/Makefile S5-pre2-init/drivers/Makefile
--- S5-pre2-init-1/drivers/Makefile	Tue May 15 12:36:34 2001
+++ S5-pre2-init/drivers/Makefile	Tue May 15 12:51:55 2001
@@ -9,7 +9,7 @@
 mod-subdirs :=	dio mtd sbus video macintosh usb input telephony sgi i2o ide \
 		scsi md ieee1394 pnp isdn atm fc4 net/hamradio i2c acpi
 
-subdir-y :=	parport block char net sound misc media cdrom
+subdir-y :=	parport char block net sound misc media cdrom
 subdir-m :=	$(subdir-y)
 
 
diff -urN S5-pre2-init-1/drivers/block/genhd.c S5-pre2-init/drivers/block/genhd.c
--- S5-pre2-init-1/drivers/block/genhd.c	Tue May 15 12:36:34 2001
+++ S5-pre2-init/drivers/block/genhd.c	Tue May 15 12:52:21 2001
@@ -17,7 +17,6 @@
 #include <linux/blk.h>
 #include <linux/init.h>
 
-extern int chr_dev_init(void);
 extern int blk_dev_init(void);
 #ifdef CONFIG_BLK_DEV_DAC960
 extern void DAC960_Initialize(void);
@@ -32,7 +31,6 @@
 
 int __init device_init(void)
 {
-	chr_dev_init();
 	blk_dev_init();
 	sti();
 #ifdef CONFIG_I2O
diff -urN S5-pre2-init-1/drivers/char/Makefile S5-pre2-init/drivers/char/Makefile
--- S5-pre2-init-1/drivers/char/Makefile	Sat Apr 28 02:12:49 2001
+++ S5-pre2-init/drivers/char/Makefile	Tue May 15 12:52:48 2001
@@ -16,7 +16,7 @@
 
 O_TARGET := char.o
 
-obj-y	 += tty_io.o n_tty.o tty_ioctl.o mem.o raw.o pty.o misc.o random.o
+obj-y	 += mem.o tty_io.o n_tty.o tty_ioctl.o raw.o pty.o misc.o random.o
 
 # All of the (potential) objects that export symbols.
 # This list comes from 'grep -l EXPORT_SYMBOL *.[hc]'.
diff -urN S5-pre2-init-1/drivers/char/mem.c S5-pre2-init/drivers/char/mem.c
--- S5-pre2-init-1/drivers/char/mem.c	Sat Apr 28 02:12:50 2001
+++ S5-pre2-init/drivers/char/mem.c	Tue May 15 12:53:17 2001
@@ -653,3 +653,5 @@
 #endif
 	return 0;
 }
+
+__initcall(chr_dev_init);


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

* [PATCH] turn device_init() into an initcall
  2001-05-15 15:56 [PATCH] turn device_init() into an initcall Alexander Viro
  2001-05-15 16:36 ` Alexander Viro
@ 2001-05-16 11:47 ` Alexander Viro
  1 sibling, 0 replies; 5+ messages in thread
From: Alexander Viro @ 2001-05-16 11:47 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel


Damn.
/me writes a patch
/me tests and finds an obvious typo
/me fixes and diffs fixed (and tested) version
/me sends the original one.

My apologies. Correct patch (taken between clean tree and
result of make distclean on the tree that gave a kernel
that passes all tests) follows. Please, apply it.
							Al

diff -urN S5-pre2/drivers/block/genhd.c linux-test/drivers/block/genhd.c
--- S5-pre2/drivers/block/genhd.c	Mon Sep 18 01:16:35 2000
+++ linux-test/drivers/block/genhd.c	Wed May 16 05:34:24 2001
@@ -31,7 +31,7 @@
 extern int cpqarray_init(void);
 extern void ieee1394_init(void);
 
-void __init device_init(void)
+int __init device_init(void)
 {
 #ifdef CONFIG_PARPORT
 	parport_init();
@@ -64,4 +64,7 @@
 #ifdef CONFIG_VT
 	console_map_init();
 #endif
+	return 0;
 }
+
+__initcall(device_init);
diff -urN S5-pre2/fs/partitions/check.c linux-test/fs/partitions/check.c
--- S5-pre2/fs/partitions/check.c	Mon Feb 26 14:18:34 2001
+++ linux-test/fs/partitions/check.c	Wed May 16 05:34:24 2001
@@ -33,10 +33,7 @@
 #include "ibm.h"
 #include "ultrix.h"
 
-extern void device_init(void);
 extern int *blk_size[];
-extern void rd_load(void);
-extern void initrd_load(void);
 
 struct gendisk *gendisk_head;
 int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
@@ -438,19 +435,3 @@
 		blk_size[dev->major] = dev->sizes;
 	}
 }
-
-int __init partition_setup(void)
-{
-	device_init();
-
-#ifdef CONFIG_BLK_DEV_RAM
-#ifdef CONFIG_BLK_DEV_INITRD
-	if (initrd_start && mount_initrd) initrd_load();
-	else
-#endif
-	rd_load();
-#endif
-	return 0;
-}
-
-__initcall(partition_setup);
diff -urN S5-pre2/init/main.c linux-test/init/main.c
--- S5-pre2/init/main.c	Wed May 16 04:25:48 2001
+++ linux-test/init/main.c	Wed May 16 05:35:06 2001
@@ -638,9 +638,6 @@
  */
 static void __init do_basic_setup(void)
 {
-#ifdef CONFIG_BLK_DEV_INITRD
-	int real_root_mountflags;
-#endif
 
 	/*
 	 * Tell the world that we're going to be the grim
@@ -707,13 +704,6 @@
 	/* Networking initialization needs a process context */ 
 	sock_init();
 
-#ifdef CONFIG_BLK_DEV_INITRD
-	real_root_dev = ROOT_DEV;
-	real_root_mountflags = root_mountflags;
-	if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
-	else mount_initrd =0;
-#endif
-
 	start_context_thread();
 	do_initcalls();
 
@@ -724,6 +714,34 @@
 #ifdef CONFIG_PCMCIA
 	init_pcmcia_ds();		/* Do this last */
 #endif
+}
+
+extern void rd_load(void);
+extern void initrd_load(void);
+
+/*
+ * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
+ */
+static void prepare_namespace(void)
+{
+#ifdef CONFIG_BLK_DEV_INITRD
+	int real_root_mountflags = ROOT_DEV;
+	real_root_mountflags = root_mountflags;
+	if (!initrd_start)
+		mount_initrd = 0;
+	if (mount_initrd)
+		root_mountflags &= ~MS_RDONLY;
+	real_root_dev = ROOT_DEV;
+#endif
+
+#ifdef CONFIG_BLK_DEV_RAM
+#ifdef CONFIG_BLK_DEV_INITRD
+	if (mount_initrd)
+		initrd_load();
+	else
+#endif
+	rd_load();
+#endif
 
 	/* Mount the root filesystem.. */
 	mount_root();
@@ -755,6 +773,8 @@
 {
 	lock_kernel();
 	do_basic_setup();
+
+	prepare_namespace();
 
 	/*
 	 * Ok, we have completed the initial bootup, and


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

* [PATCH] turn device_init() into an initcall
@ 2001-05-03  1:21 Alexander Viro
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Viro @ 2001-05-03  1:21 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

	Patch below turns device_init() into initcall. Current tree
calls it from fs/partitions/check.c::partitions_setup() - definitely
odd place for that stuff.

	Another thing done by partition_setup() is {init,}rd_load(). I.e.
setting the contents of /dev/ram0 from initrd or floppies. That beast
should be done after _all_ drivers' initialization, indeed - it belongs with
mount_root()/mount_devfs()/etc. I took it to main/init.c - that way
it's guaranteed to be called after all drivers initialization code and
that's where we do the rest of late-boot stuff. partition_setup() is gone
now.

	Patch is against 2.4.5-pre1. Please, apply.
								Al

diff -urN S5-pre1/drivers/block/genhd.c S5-pre1-device_init/drivers/block/genhd.c
--- S5-pre1/drivers/block/genhd.c	Fri Feb 16 18:37:04 2001
+++ S5-pre1-device_init/drivers/block/genhd.c	Wed May  2 21:09:30 2001
@@ -31,7 +31,7 @@
 extern int cpqarray_init(void);
 extern void ieee1394_init(void);
 
-void __init device_init(void)
+int __init device_init(void)
 {
 #ifdef CONFIG_PARPORT
 	parport_init();
@@ -64,4 +64,7 @@
 #ifdef CONFIG_VT
 	console_map_init();
 #endif
+	return 0;
 }
+
+__initcall(device_init);
diff -urN S5-pre1/fs/partitions/check.c S5-pre1-device_init/fs/partitions/check.c
--- S5-pre1/fs/partitions/check.c	Thu Feb 22 06:45:26 2001
+++ S5-pre1-device_init/fs/partitions/check.c	Wed May  2 21:09:30 2001
@@ -33,10 +33,7 @@
 #include "ibm.h"
 #include "ultrix.h"
 
-extern void device_init(void);
 extern int *blk_size[];
-extern void rd_load(void);
-extern void initrd_load(void);
 
 struct gendisk *gendisk_head;
 int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
@@ -438,19 +435,3 @@
 		blk_size[dev->major] = dev->sizes;
 	}
 }
-
-int __init partition_setup(void)
-{
-	device_init();
-
-#ifdef CONFIG_BLK_DEV_RAM
-#ifdef CONFIG_BLK_DEV_INITRD
-	if (initrd_start && mount_initrd) initrd_load();
-	else
-#endif
-	rd_load();
-#endif
-	return 0;
-}
-
-__initcall(partition_setup);
diff -urN S5-pre1/init/main.c S5-pre1-device_init/init/main.c
--- S5-pre1/init/main.c	Wed May  2 11:16:38 2001
+++ S5-pre1-device_init/init/main.c	Wed May  2 21:09:30 2001
@@ -638,9 +638,6 @@
  */
 static void __init do_basic_setup(void)
 {
-#ifdef CONFIG_BLK_DEV_INITRD
-	int real_root_mountflags;
-#endif
 
 	/*
 	 * Tell the world that we're going to be the grim
@@ -707,13 +704,6 @@
 	/* Networking initialization needs a process context */ 
 	sock_init();
 
-#ifdef CONFIG_BLK_DEV_INITRD
-	real_root_dev = ROOT_DEV;
-	real_root_mountflags = root_mountflags;
-	if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
-	else mount_initrd =0;
-#endif
-
 	start_context_thread();
 	do_initcalls();
 
@@ -724,6 +714,33 @@
 #ifdef CONFIG_PCMCIA
 	init_pcmcia_ds();		/* Do this last */
 #endif
+}
+
+extern void rd_load(void);
+extern void initrd_load(void);
+
+/*
+ * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
+ */
+static void prepare_namespace(void)
+{
+#ifdef CONFIG_BLK_DEV_INITRD
+	int real_root_mountflags = ROOT_DEV;
+	real_root_mountflags = root_mountflags;
+	if (!initrd_start)
+		mount_initrd = 0;
+	if (mount_initrd)
+		root_mountflags &= ~MS_RDONLY;
+#endif
+
+#ifdef CONFIG_BLK_DEV_RAM
+#ifdef CONFIG_BLK_DEV_INITRD
+	if (mount_initrd)
+		initrd_load();
+	else
+#endif
+	rd_load();
+#endif
 
 	/* Mount the root filesystem.. */
 	mount_root();
@@ -755,6 +772,8 @@
 {
 	lock_kernel();
 	do_basic_setup();
+
+	prepare_namespace();
 
 	/*
 	 * Ok, we have completed the initial bootup, and


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

end of thread, other threads:[~2001-05-16 11:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-15 15:56 [PATCH] turn device_init() into an initcall Alexander Viro
2001-05-15 16:36 ` Alexander Viro
2001-05-15 17:06   ` Alexander Viro
2001-05-16 11:47 ` Alexander Viro
  -- strict thread matches above, loose matches on Subject: below --
2001-05-03  1:21 Alexander Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).