Scanning SCSI controllers for new LUNs on Centos and Fedora Linux hosts

While building out a new ESX guest, I had to scan for a new SCSI device I added. To scan a SCSI controller for new LUNs, you can echo the “- – -” string to the SCSI controller’s scan sysfs node:

$ echo “- – -” > /sys/class/scsi_host/host0/scan

Now you may be asking yourself, what do those three dashes mean? Well, here is the answer from the Linux 2.6.31 kernel source (I had to look this up to recall):

static int scsi_scan(struct Scsi_Host *shost, const char *str)
{
        char s1[15], s2[15], s3[15], junk;
        unsigned int channel, id, lun;
        int res;

        res = sscanf(str, "%10s %10s %10s %c", s1, s2, s3, &junk);
        if (res != 3)
                return -EINVAL;
        if (check_set(&channel, s1))
                return -EINVAL;
        if (check_set(&id, s2))
                return -EINVAL;
        if (check_set(&lun, s3))
                return -EINVAL;
        if (shost->transportt->user_scan)
                res = shost->transportt->user_scan(shost, channel, id, lun);
        else
                res = scsi_scan_host_selected(shost, channel, id, lun, 1);
        return res;
}

As you can see above, the three values passed to the scan value are the channel, id and lun number you want to scan. The “-” equates to a wild card, which causes all of the channels, ids and luns to be scanned. The more I dig into the Linux kernel source code, the more I realize just how cool the Linux kernel is. I think it’s about time to write a device driver. :)

2 thoughts on “Scanning SCSI controllers for new LUNs on Centos and Fedora Linux hosts”

  1. Does scanning all SCSI controller’s for new LUNS produce a short i/o outage or is it safe to scan for new LUN’s on a PRODUCTION system during business hours.

Leave a Reply

Your email address will not be published. Required fields are marked *