lkml.org 
[lkml]   [2008]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC/PATCH] usb-storage: wait for device scanning before mounting root
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);

\
 
 \ /
  Last update: 2008-04-24 22:25    [from the cache]
©2003-2011 Jasper Spaans