Target asynchronous scan [0/3]
James asked me to resend the patches for scsi-misc.
PATCH 1/3 Add Kconfig option for asynchronous SCSI scanning
Without this patch, the user has to add a kernel command line parameter to get asynchronous SCSI scanning. Now they can select the default at compile time and still override it at boot time if they need to.
--- drivers/scsi/Kconfig | 17 +++++++++++++++++ drivers/scsi/scsi_scan.c | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletions(-)
drivers/scsi/Kconfig +17 -0
@@ -216,6 +216,23 @@ config SCSI_LOGGING there should be no noticeable performance impact as long as you have logging turned off. +config SCSI_SCAN_ASYNC + bool "Asynchronous SCSI scanning" + depends on SCSI + help + The SCSI subsystem can probe for devices while the rest of the + system continues booting, and even probe devices on different + busses in parallel, leading to a significant speed-up. + If you have built SCSI as modules, enabling this option can + be a problem as the devices may not have been found by the + time your system expects them to have been. You can load the + scsi_wait_scan module to ensure that all scans have completed. + If you build your SCSI drivers into the kernel, then everything + will work fine if you say Y here. + + You can override this choice by specifying scsi_mod.scan="sync" + or "async" on the kernel's command line. + menu "SCSI Transports" depends on SCSI
drivers/scsi/scsi_scan.c +7 -1
@@ -89,7 +89,13 @@ module_param_named(max_luns, max_scsi_luMODULE_PARM_DESC (max_luns,"last scsi LUN (should be between 1 and 2^32-1)" ); -static char scsi_scan_type[6 ] ="sync" ; +#ifdef CONFIG_SCSI_SCAN_ASYNC +#define SCSI_SCAN_TYPE_DEFAULT "async" +#else +#define SCSI_SCAN_TYPE_DEFAULT "sync" +#endif + +static char scsi_scan_type[6 ] =SCSI_SCAN_TYPE_DEFAULT ;module_param_string (scan, scsi_scan_type,sizeof (scsi_scan_type),S_IRUGO );MODULE_PARM_DESC (scan,"sync, async or none" );
Signature · 1 line
1.4.3.3
PATCH 2/3 SCSI: Missing check for no scanning
In reply to Matthew WilcoxDrivers that called scsi_scan_target() instead of scsi_scan_host() were still adding devices; this needs to be under the control of userspace, not the driver.
--- drivers/scsi/scsi_scan.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/scsi/scsi_scan.c +3 -0
@@ -1539,6 +1539,9 @@ void scsi_scan_target(struct device *par {struct Scsi_Host *shost =dev_to_shost (parent); +if (strncmp (scsi_scan_type,"none" ,4 ) ==0 ) +return ; +if (!shost->async_scan)scsi_complete_async_scans ();
Signature · 1 line
1.4.3.3
PATCH 3/3 Make scsi_scan_host work for drivers which find their own targets
In reply to Matthew WilcoxFrom: Matthew Wilcox <[email protected]>
If a driver can find its own targets, it can now fill in scan_finished and (optionally) scan_start in the scsi_host_template. Then, when it calls scsi_scan_host(), it will be called back (from a thread if asynchronous discovery is enabled), first to start the scan, and then at intervals to check if the scan is completed.
Also make scsi_prep_async_scan and scsi_finish_async_scan static.
--- drivers/scsi/scsi_scan.c | 27 ++++++++++++++++++++------- include/scsi/scsi_host.h | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-)
drivers/scsi/scsi_scan.c +20 -7
@@ -1632,7 +1632,7 @@ static void scsi_sysfs_add_devices(struc* 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) +static struct async_scan_data *scsi_prep_async_scan (struct Scsi_Host *shost) {struct async_scan_data *data;
@@ -1676,7 +1676,7 @@ struct async_scan_data *scsi_prep_async_* This function announces all the devices it has found to the rest * of the system. */ -void scsi_finish_async_scan (struct async_scan_data *data) +static void scsi_finish_async_scan (struct async_scan_data *data) {struct Scsi_Host *shost;
@@ -1709,12 +1709,25 @@ void scsi_finish_async_scan(struct asynckfree (data); } -static int do_scan_async (void *_data) +static void do_scsi_scan_host (struct Scsi_Host *shost) { -struct async_scan_data *data = _data; -scsi_scan_host_selected (data->shost,SCAN_WILD_CARD ,SCAN_WILD_CARD , +if (shost->hostt->scan_finished) { +unsigned long start = jiffies; +if (shost->hostt->scan_start) + shost->hostt->scan_start (shost); + +while (!shost->hostt->scan_finished (shost, jiffies - start)) +msleep (10 ); + }else { +scsi_scan_host_selected (shost,SCAN_WILD_CARD ,SCAN_WILD_CARD ,SCAN_WILD_CARD ,0 ); + } +} +static int do_scan_async (void *_data) +{ +struct async_scan_data *data = _data; +do_scsi_scan_host (data->shost);scsi_finish_async_scan (data);return 0 ; }
@@ -1732,10 +1745,10 @@ void scsi_scan_host(struct Scsi_Host *sh data =scsi_prep_async_scan (shost);if (!data) { -scsi_scan_host_selected (shost,SCAN_WILD_CARD ,SCAN_WILD_CARD , -SCAN_WILD_CARD ,0 ); +do_scsi_scan_host (shost);return ; } +kthread_run (do_scan_async, data,"scsi_scan_%d" , shost->host_no); }EXPORT_SYMBOL (scsi_scan_host);
include/scsi/scsi_host.h +18 -0
@@ -241,6 +241,24 @@ struct scsi_host_template {void (* target_destroy)(struct scsi_target *);/* +* If a host has the ability to discover targets on its own instead +* of scanning the entire bus, it can fill in this function and +* call scsi_scan_host(). This function will be called periodically +* until it returns 1 with the scsi_host and the elapsed time of +* the scan in jiffies. +* +* Status: OPTIONAL +*/ +int (* scan_finished)(struct Scsi_Host *,unsigned long ); + +/* +* If the host wants to be called before the scan starts, but +* after the midlayer has set up ready for the scan, it can fill +* in this function. +*/ +void (* scan_start)(struct Scsi_Host *); + +/* * fill in this function to allow the queue depth of this host * to be changeable (on a per device basis). returns either * the current queue depth setting (may be different from what
Signature · 1 line
1.4.3.3