The following dmesg snippet demonstrates a misleading
detection message being produced by sd_detect() in sd.c:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
scsi0 : AdvanSys SCSI 3.3F: PCI Ultra 16 CDB: IO DC00/F, IRQ 10
scsi1 : AdvanSys SCSI 3.3F: PCI Ultra2-Wide: IO BC00/FF, IRQ 5
scsi2 : AdvanSys SCSI 3.3F: PCI Ultra-Wide: BIOS CC000/7FFF, IO B800/3F, IRQ 11
scsi : 3 hosts.
  Vendor: IBM       Model: DDRS-39130        Rev: S97B
  Type:   Direct-Access
Detected scsi disk sda at scsi0, channel 0, id 1, lun 0
  Vendor: QUANTUM   Model: EMPIRE_1080S      Rev: 1101
  Type:   Direct-Access                      ANSI SCSI revision: 02
Detected scsi disk sdb at scsi1, channel 0, id 1, lun 0
  Vendor: iomega    Model: jaz 1GB           Rev: H.62
  Type:   Direct-Access                      ANSI SCSI revision: 02
Detected scsi removable disk sdc at scsi2, channel 0, id 5, lun 0
SCSI device sda: hdwr sector= 512 bytes. Sectors= 17850000 [8715 MB] [8.7 GB]
 sda: sda1 sda2
SCSI device sdb: hdwr sector= 512 bytes. Sectors= 2109376 [1029 MB] [1.0 GB]
 sdb: sdb1
SCSI device sdc: hdwr sector= 512 bytes. Sectors= 2091050 [1021 MB] [1.0 GB]
sdc: Write Protect is off
 sdc: sdc1
advansys: advansys_reset: board 1: SCSI bus reset started...
advansys: advansys_reset: board 1: SCSI bus reset successful
scsi singledevice 1 0 1 0
  Vendor: QUANTUM   Model: EMPIRE_1080S      Rev: 1101
  Type:   Direct-Access                      ANSI SCSI revision: 02
Detected scsi disk sdc at scsi1, channel 0, id 1, lun 0
SCSI device sdb: hdwr sector= 512 bytes. Sectors= 2109376 [1029 MB] [1.0 GB]
 sdb: sdb1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The third last line claims that "sdc" has been detected
when it meant to say "sdb" as correctly stated in the
second last line.

All upper level scsi drivers share the same bug. The
reason is that they output that detection message from
their _detect() functions before they do the device
allocation in their _attach() functions.

The guess made by the _detect() function is correct most
of the time unless there is a hole in the existing 
allocation. Since the _detect() function may precede
the _init() function, it is not easy for _detect() to
get it right.

The attached patch (against lk 2.4.0) moves these messages 
from the _detect() functions to the _attach() functions. 
This will have the side effect of making the messages 
appear slightly later in the dmesg sequence.

BTW The same bug is present in the lk 2.2 series.

Doug Gilbert
--- linux/drivers/scsi/sd.c     Tue Oct  3 23:46:42 2000
+++ linux/drivers/scsi/sd.c240det       Tue Jan 16 14:26:44 2001
@@ -1185,16 +1185,9 @@
 
 static int sd_detect(Scsi_Device * SDp)
 {
-       char nbuff[6];
        if (SDp->type != TYPE_DISK && SDp->type != TYPE_MOD)
                return 0;
-
-       sd_devname(sd_template.dev_noticed++, nbuff);
-       printk("Detected scsi %sdisk %s at scsi%d, channel %d, id %d, lun %d\n",
-              SDp->removable ? "removable " : "",
-              nbuff,
-              SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
-
+       sd_template.dev_noticed++;
        return 1;
 }
 
@@ -1203,6 +1196,7 @@
         unsigned int devnum;
        Scsi_Disk *dpnt;
        int i;
+       char nbuff[6];
 
        if (SDp->type != TYPE_DISK && SDp->type != TYPE_MOD)
                return 0;
@@ -1226,6 +1220,10 @@
         SD_GENDISK(i).de_arr[devnum] = SDp->de;
         if (SDp->removable)
                SD_GENDISK(i).flags[devnum] |= GENHD_FL_REMOVABLE;
+       sd_devname(i, nbuff);
+       printk("Attached scsi %sdisk %s at scsi%d, channel %d, id %d, lun %d\n",
+              SDp->removable ? "removable " : "",
+              nbuff, SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
        return 0;
 }
 
--- linux/drivers/scsi/sr.c     Tue Jan  2 12:05:04 2001
+++ linux/drivers/scsi/sr.c240det       Tue Jan 16 14:32:50 2001
@@ -509,11 +509,7 @@
 
        if (SDp->type != TYPE_ROM && SDp->type != TYPE_WORM)
                return 0;
-
-       printk("Detected scsi CD-ROM sr%d at scsi%d, channel %d, id %d, lun %d\n",
-              sr_template.dev_noticed++,
-              SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
-
+       sr_template.dev_noticed++;
        return 1;
 }
 
@@ -542,6 +538,9 @@
        sr_template.nr_dev++;
        if (sr_template.nr_dev > sr_template.dev_max)
                panic("scsi_devices corrupt (sr)");
+
+       printk("Attached scsi CD-ROM sr%d at scsi%d, channel %d, id %d, lun %d\n",
+              i, SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
        return 0;
 }
 
--- linux/drivers/scsi/st.c     Tue Jan  2 12:45:10 2001
+++ linux/drivers/scsi/st.c240det       Tue Jan 16 14:32:00 2001
@@ -3495,7 +3495,7 @@
        Scsi_Tape *tpnt;
        ST_mode *STm;
        ST_partstat *STps;
-       int i, mode, target_nbr;
+       int i, mode, target_nbr, dev_num;
        unsigned long flags = 0;
        char *stp;
 
@@ -3573,6 +3573,7 @@
        }
        memset(tpnt, 0, sizeof(Scsi_Tape));
        scsi_tapes[i] = tpnt;
+       dev_num = i;
 
        for (mode = 0; mode < ST_NBR_MODES; ++mode) {
            char name[8];
@@ -3653,6 +3654,9 @@
 
        st_template.nr_dev++;
        write_unlock_irqrestore(&st_dev_arr_lock, flags);
+       printk(KERN_WARNING
+       "Attached scsi tape st%d at scsi%d, channel %d, id %d, lun %d\n",
+              dev_num, SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
 
        /* See if we need to allocate more static buffers */
        target_nbr = st_template.nr_dev;
@@ -3673,12 +3677,7 @@
 {
        if (SDp->type != TYPE_TAPE || st_incompatible(SDp))
                return 0;
-
-       printk(KERN_WARNING
-       "Detected scsi tape st%d at scsi%d, channel %d, id %d, lun %d\n",
-              st_template.dev_noticed++,
-              SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
-
+        st_template.dev_noticed++;
        return 1;
 }
 
--- linux/drivers/scsi/sg.c     Fri Jan  5 10:14:03 2001
+++ linux/drivers/scsi/sg.c240det       Tue Jan 16 14:30:14 2001
@@ -19,7 +19,7 @@
  */
 #include <linux/config.h>
 #ifdef CONFIG_PROC_FS
- static char * sg_version_str = "Version: 3.1.17 (20001002)";
+ static char * sg_version_str = "Version: 3.1.17 (20010116)";
 #endif
  static int sg_version_num = 30117; /* 2 digits for each component */
 /*
@@ -1109,19 +1109,6 @@
 
 static int sg_detect(Scsi_Device * scsidp)
 {
-    switch (scsidp->type) {
-        case TYPE_DISK:
-        case TYPE_MOD:
-        case TYPE_ROM:
-        case TYPE_WORM:
-        case TYPE_TAPE: break;
-        default:
-        printk("Detected scsi generic sg%d at scsi%d,"
-                " channel %d, id %d, lun %d, type %d\n",
-               sg_template.dev_noticed,
-              scsidp->host->host_no, scsidp->channel,
-               scsidp->id, scsidp->lun, scsidp->type);
-    }
     sg_template.dev_noticed++;
     return 1;
 }
@@ -1240,6 +1227,18 @@
     sg_template.nr_dev++;
     sg_dev_arr[k] = sdp;
     write_unlock_irqrestore(&sg_dev_arr_lock, iflags);
+    switch (scsidp->type) {
+        case TYPE_DISK:
+        case TYPE_MOD:
+        case TYPE_ROM:
+        case TYPE_WORM:
+        case TYPE_TAPE: break;
+        default:
+        printk("Attached scsi generic sg%d at scsi%d,"
+                " channel %d, id %d, lun %d, type %d\n",
+               k, scsidp->host->host_no, scsidp->channel,
+               scsidp->id, scsidp->lun, scsidp->type);
+    }
     return 0;
 }
 

Reply via email to