]> err.no Git - linux-2.6/blobdiff - drivers/scsi/scsi_scan.c
[SCSI] scsi tgt: scsi target lib functionality
[linux-2.6] / drivers / scsi / scsi_scan.c
index aa1b1e0e9d22d7b394dd085f66dd2a8302c36e8b..4d656148bd6783354c669ce64b0854c2bf6bddb8 100644 (file)
@@ -89,7 +89,13 @@ module_param_named(max_luns, max_scsi_luns, int, S_IRUGO|S_IWUSR);
 MODULE_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");
@@ -1543,6 +1549,9 @@ void scsi_scan_target(struct device *parent, unsigned int channel,
 {
        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();
 
@@ -1633,7 +1642,7 @@ static void scsi_sysfs_add_devices(struct Scsi_Host *shost)
  * 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;
 
@@ -1677,7 +1686,7 @@ struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost)
  * 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;
 
@@ -1710,12 +1719,25 @@ void scsi_finish_async_scan(struct async_scan_data *data)
        kfree(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;
 }
@@ -1733,10 +1755,10 @@ void scsi_scan_host(struct Scsi_Host *shost)
 
        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);