Skip to contentSkip to conversation

async scsi scanning, version 11

PATCH In review Matthew Wilcox 3 participants 6 messages Sep 24, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 async scsi scanning, version 11

OK, this is the 11th version of this patch. Since the FC people don't seem to have time to look into why their drivers still take forever-and-a-day to initialise, I've dropped all the support for non-parallel-scsi from this version of the patch.

Still outstanding:

- The comment at the top of scsi_sysfs_add_devices(). I'd really like someone like James or Christoph to tell me what they prefer.

Other changes:
- I've rejigged how we wait for async scans to complete. Now we compile scsi_wait_scan in, even for the non-modular case. Fewer ifdefs, less mucking around in the Makefile, more commonality between the modular and non-modular cases.

----

Add ability to scan scsi busses asynchronously

Since it often takes around 20-30 seconds to scan a scsi bus, it's highly advantageous to do this in parallel with other things. The bulk of this patch is ensuring that devices don't change numbering, and that all devices are discovered prior to trying to start init. For those who build SCSI as modules, there's a new scsi_wait_scan module that will ensure all bus scans are finished.

This patch only handles drivers which call scsi_scan_host. Fibre Channel, SAS, SATA, USB and Firewire all need additional work.

Documentation/kernel-parameters.txt +5 -0
index 71d05f4..4ab1729 100644
@@ -1416,6 +1416,11 @@ running once the system is up.
 
 	scsi_logging=	[SCSI]
 
+	scsi_mod.scan=	[SCSI] sync (default) scans SCSI busses as they are
+			discovered.  async scans them in kernel threads,
+			allowing boot to proceed.  none ignores them, expecting
+			user space to do the scan.
+
 	selinux		[SELINUX] Disable or enable SELinux at boot time.
 			Format: { "0" | "1" }
 			See security/selinux/Kconfig help text.
drivers/scsi/Makefile +2 -0
index 1ef951b..38d0e25 100644
@@ -140,6 +140,8 @@ obj-$(CONFIG_CHR_DEV_SCH)	+= ch.o
 # This goes last, so that "real" scsi devices probe earlier
 obj-$(CONFIG_SCSI_DEBUG)	+= scsi_debug.o
 
+obj-$(CONFIG_SCSI)		+= scsi_wait_scan.o
+
 scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o constants.o \
 				   scsicam.o scsi_error.o scsi_lib.o \
 				   scsi_scan.o scsi_sysfs.o \
drivers/scsi/scsi_priv.h +3 -0
index 5d023d4..f458c2f 100644
@@ -39,6 +39,9 @@ static inline void scsi_log_completion(s
 	{ };
 #endif
 
+/* scsi_scan.c */
+int scsi_complete_async_scans(void);
+
 /* scsi_devinfo.c */
 extern int scsi_get_device_flags(struct scsi_device *sdev,
 				 const unsigned char *vendor,
drivers/scsi/scsi_scan.c +192 -6

258 lines not on this page · raw message

drivers/scsi/scsi_wait_scan.c new file +31 -0
new file mode 100644
index 0000000..f7aea46
@@ -0,0 +1,31 @@
+/*
+ * scsi_wait_scan.c
+ *
+ * Copyright (C) 2006 James Bottomley <[email protected]>
+ *
+ * This is a simple module to wait until all the async scans are
+ * complete.  The idea is to use it in initrd/initramfs scripts.  You
+ * modprobe it after all the modprobes of the root SCSI drivers and it
+ * will wait until they have all finished scanning their busses before
+ * allowing the boot to proceed
+ */
+
+#include <linux/module.h>
+#include "scsi_priv.h"
+
+static int __init wait_scan_init(void)
+{
+	scsi_complete_async_scans();
+	return 0;
+}
+
+static void __exit wait_scan_exit(void)
+{
+}
+ 
+MODULE_DESCRIPTION("SCSI wait for scans");
+MODULE_AUTHOR("James Bottomley");
+MODULE_LICENSE("GPL");
+ 
+late_initcall(wait_scan_init);
+module_exit(wait_scan_exit);
include/scsi/scsi_host.h +3 -0
index 39c6f8c..5aaa7d6 100644
@@ -552,6 +552,9 @@ struct Scsi_Host {
 	/* task mgmt function in progress */
 	unsigned tmf_in_progress:1;
 
+	/* Are we currently performing an async scan? */
+	unsigned async_scan:1;
+
 	/*
 	 * Optional work queue to be utilized by the transport
 	 */
#1 lore raw

drivers/scsi/scsi_scan.c MODULE_PARM_DESC(inq_timeout, · line 137

Quoted 12 lines · Matthew Wilcox
drivers/scsi/scsi_scan.c +12 -0
+
+int scsi_complete_async_scans(void)
+{
+	struct async_scan_data *data;
+
+	do {
+		if (list_empty(&scanning_hosts))
+			return 0;
+		data = kmalloc(sizeof(*data), GFP_KERNEL);
+		if (!data)
+			msleep(1);
+	} while (!data);

does __GFP_NOFAIL or __GFP_REPEAT have the desired effect here?

Dave

#2 lore raw
Quoted 15 lines · Dave Jones

drivers/scsi/scsi_scan.c MODULE_PARM_DESC(inq_timeout, · line 137

Quoted 12 lines · Matthew Wilcox
drivers/scsi/scsi_scan.c +12 -0
+
+int scsi_complete_async_scans(void)
+{
+	struct async_scan_data *data;
+
+	do {
+		if (list_empty(&scanning_hosts))
+			return 0;
+		data = kmalloc(sizeof(*data), GFP_KERNEL);
+		if (!data)
+			msleep(1);
+	} while (!data);

does __GFP_NOFAIL or __GFP_REPEAT have the desired effect here?

Well ... that would probably be OK. But I think it's actually preferable to not use it. See, the scan might finish while we're waiting for memory, and if it does, then we don't need to allocate memory after all. This is totally quibbling over the most unlikely of scenarios though, so I have no problem with making the change if we just want to exemplify best practice here.

#3 lore raw
In reply to Matthew Wilcox
Quoted 8 lines · On Sun, 24 Sep 2006 13:06:24 -0600 Matthew Wilcox wrote:

OK, this is the 11th version of this patch. Since the FC people don't seem to have time to look into why their drivers still take forever-and-a-day to initialise, I've dropped all the support for non-parallel-scsi from this version of the patch.

Still outstanding:

Quoted 8 lines

- The comment at the top of scsi_sysfs_add_devices(). I'd really like someone like James or Christoph to tell me what they prefer.

Other changes:
- I've rejigged how we wait for async scans to complete. Now we compile scsi_wait_scan in, even for the non-modular case. Fewer ifdefs, less mucking around in the Makefile, more commonality between the modular and non-modular cases.

Do parts of Documentation/scsi/scsi_low_mid_api.txt need to be updated also?
or are all of these changes outside of the low_mid realm?

drivers/scsi/scsi_scan.c int scsi_scan_host_selected(struct Scsi_ · line 1621

Quoted 11 lines
drivers/scsi/scsi_scan.c +11 -0
+/**
+ * scsi_prep_async_scan - prepare for an async scan
+ * @shost: the host which will be scanned
+ * Returns: a cookie to be passed to scsi_finish_async_scan()
+ *
+ * Tells the midlayer this host is going to do an asynchronous scan.
+ * It reserves the host's position in the scanning list and ensures
+ * that other asynchronous scans started after this one won't affect the
+ * ordering of the discovered devices.
+ */
+struct async_scan_data * scsi_prep_async_scan(struct Scsi_Host *shost)

whitespace violation (*scsi_prep_async_scan)

Quoted 1 line

+{

and thanks for adding/using kernel-doc.

---
~Randy

#4 lore raw
Quoted 3 lines · Randy Dunlap

Do parts of Documentation/scsi/scsi_low_mid_api.txt need to be updated also?
or are all of these changes outside of the low_mid realm?

There's no interface changes at this point. Once we start to get into fixing the FC/SAS drivers, there'll be some documenting to be done.

Quoted 3 lines
Quoted 1 line

+struct async_scan_data * scsi_prep_async_scan(struct Scsi_Host *shost)

whitespace violation (*scsi_prep_async_scan)

Hmm? Wouldn't that be a function pointer? Did you mean to say I should use:

struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost)

? I don't particularly mind either way.

Quoted 1 line

and thanks for adding/using kernel-doc.

I like it. Documenting an earlier version of the interface made me realise it had bad semantics, so I fixed it rather than try to document its quirks.

#5 lore raw
Quoted 10 lines · On Sun, 24 Sep 2006 14:40:01 -0600 Matthew Wilcox wrote:
Quoted 3 lines
Quoted 1 line

+struct async_scan_data * scsi_prep_async_scan(struct Scsi_Host *shost)

whitespace violation (*scsi_prep_async_scan)

Hmm? Wouldn't that be a function pointer? Did you mean to say I should use:

struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost)

? I don't particularly mind either way.

yes, sorry about the shorthand.

---
~Randy