public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC/PATCH] usb-storage: wait for device scanning before mounting root
@ 2008-04-24 20:21 Pekka J Enberg
  2008-04-24 21:08 ` Alan Stern
  0 siblings, 1 reply; 32+ messages in thread
From: Pekka J Enberg @ 2008-04-24 20:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: dsd, mdharm-usb, linux-usb, vegardno

From: Pekka Enberg <penberg@cs.helsinki.fi>

Add a new kernel config option CONFIG_LATE_ROOT_MOUNT that makes the kernel
wait until background scanning of USB mass storage devices is complete before
attempting to mount the root filesystem.

The config option is an alternative to the root_delay= kernel parameter
solution people currently use to boot from USB mass storage devices.

Cc: Daniel Drake <dsd@gentoo.org>
Cc: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Cc: <linux-usb@vger.kernel.org>
Tested-by: Vegard Nossum <vegardno@ifi.uio.no>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
 drivers/usb/storage/usb.c |    3 +++
 include/linux/init.h      |   12 ++++++++++++
 init/Kconfig              |    5 +++++
 init/do_mounts.c          |   32 ++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+)

Index: linux-2.6/drivers/usb/storage/usb.c
===================================================================
--- linux-2.6.orig/drivers/usb/storage/usb.c
+++ linux-2.6/drivers/usb/storage/usb.c
@@ -928,6 +928,7 @@ static int usb_stor_scan_thread(void * _
 		/* Should we unbind if no devices were detected? */
 	}
 
+	complete_root_scan();
 	complete_and_exit(&us->scanning_done, 0);
 }
 
@@ -1007,12 +1008,14 @@ static int storage_probe(struct usb_inte
 		goto BadDevice;
 	}
 
+	begin_root_scan();
 	/* Start up the thread for delayed SCSI-device scanning */
 	th = kthread_create(usb_stor_scan_thread, us, "usb-stor-scan");
 	if (IS_ERR(th)) {
 		printk(KERN_WARNING USB_STORAGE 
 		       "Unable to start the device-scanning thread\n");
 		quiesce_and_remove_host(us);
+		complete_root_scan();
 		result = PTR_ERR(th);
 		goto BadDevice;
 	}
Index: linux-2.6/include/linux/init.h
===================================================================
--- linux-2.6.orig/include/linux/init.h
+++ linux-2.6/include/linux/init.h
@@ -147,6 +147,18 @@ extern unsigned int reset_devices;
 void setup_arch(char **);
 void prepare_namespace(void);
 
+#ifdef CONFIG_LATE_ROOT_MOUNT
+void begin_root_scan(void);
+void complete_root_scan(void);
+#else /* !CONFIG_LATE_ROOT_MOUNT */
+static inline void begin_root_scan(void)
+{
+}
+static inline void complete_root_scan(void)
+{
+}
+#endif /* CONFIG_LATE_ROOT_MOUNT */
+
 #endif
   
 #ifndef MODULE
Index: linux-2.6/init/Kconfig
===================================================================
--- linux-2.6.orig/init/Kconfig
+++ linux-2.6/init/Kconfig
@@ -473,6 +473,11 @@ config PID_NS
 	  Unless you want to work with an experimental feature
 	  say N here.
 
+config LATE_ROOT_MOUNT
+	bool "Wait for devices that do background scanning before mounting root"
+	help
+	  Say Y here if your root partition is, for example, on an USB disk.
+
 config BLK_DEV_INITRD
 	bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support"
 	depends on BROKEN || !FRV
Index: linux-2.6/init/do_mounts.c
===================================================================
--- linux-2.6.orig/init/do_mounts.c
+++ linux-2.6/init/do_mounts.c
@@ -326,6 +326,36 @@ void __init mount_root(void)
 #endif
 }
 
+#ifdef CONFIG_LATE_ROOT_MOUNT
+/*
+ * Late root mounting for devices that need background scanning.
+ */
+static DECLARE_COMPLETION(root_scan_done);
+static atomic_t nr_root_scans;
+
+void begin_root_scan(void)
+{
+	atomic_inc(&nr_root_scans);
+}
+
+void complete_root_scan(void)
+{
+	if (atomic_dec_and_test(&nr_root_scans))
+		complete(&root_scan_done);
+}
+
+static void __init wait_for_root_scan(void)
+{
+	if (atomic_read(&nr_root_scans))
+		wait_for_completion(&root_scan_done);
+}
+#else /* !CONFIG_LATE_ROOT_MOUNT */
+
+static inline void wait_for_root_scan(void)
+{
+}
+#endif /* CONFIG_LATE_ROOT_MOUNT */
+
 /*
  * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
  */
@@ -339,6 +369,8 @@ void __init prepare_namespace(void)
 		ssleep(root_delay);
 	}
 
+	wait_for_root_scan();
+
 	/* wait for the known devices to complete their probing */
 	while (driver_probe_done() != 0)
 		msleep(100);

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

end of thread, other threads:[~2008-06-20 16:40 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-24 20:21 [RFC/PATCH] usb-storage: wait for device scanning before mounting root Pekka J Enberg
2008-04-24 21:08 ` Alan Stern
2008-04-24 21:25   ` Pekka J Enberg
2008-04-24 22:56     ` Greg KH
2008-04-24 23:30       ` Matthew Dharm
2008-04-25  6:30         ` Pekka J Enberg
2008-04-25  7:04           ` Matthew Dharm
2008-04-25  8:19             ` Pekka J Enberg
2008-04-25 15:35               ` Matthew Dharm
2008-04-25 16:05               ` Greg KH
2008-04-25  6:09       ` Pekka J Enberg
2008-04-25  7:53     ` Stefan Richter
2008-04-25  8:15       ` Pekka J Enberg
2008-04-25  9:11         ` Matthew Wilcox
2008-06-19 18:23           ` Matthew Wilcox
2008-06-19 18:39             ` Stefan Richter
2008-06-19 18:43               ` Stefan Richter
2008-06-19 18:54               ` Matthew Wilcox
2008-06-19 19:52                 ` Matthew Dharm
2008-06-19 20:49                   ` Matthew Wilcox
2008-06-19 21:19                     ` Stefan Richter
2008-06-19 19:54                 ` Stefan Richter
2008-06-19 20:22                   ` Matthew Wilcox
2008-06-19 20:34                     ` Stefan Richter
2008-06-19 21:39             ` Alan Stern
2008-06-19 23:13               ` David Brownell
2008-06-20  9:53                 ` Gabor Gombas
2008-06-20 14:14                   ` Matthew Dharm
2008-06-20 15:15               ` Vegard Nossum
2008-06-20 15:31                 ` Matthew Wilcox
2008-06-20 15:42                 ` Alan Stern
2008-06-20 16:37                   ` Stefan Richter

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