LUN Discovery in a Nutshell
The way the disk configuration is determined on a Windows system is by a process called “discovery”. If the disk configuration is ISCSI or Fibre the process is very similar. I will describe the process on each and you will see they are very similar. To simplify things this blog will not describe multipath facilities, the availability of multiple paths to a LUN/Target can cause storport to create more device objects than number of LUNs available.
First, let me explain some SCSI terminologies I will be using to describe this process:
Target - A SCSI target is an addressable unit that contains logical units (see LUN). A target can be described as a container of LUNs. The address can be an IP address as in the case of ISCSI or a 16 bit node address if fibre. Commands are sent to a target using its address.
LUN - A LUN is a logical unit that is in a target. A LUN most often describes a disk or tape unit inside a target. The LUN that is the target of a command is specified in the command packet.
Check Condition - A check condition is a status response to a SCSI command. There are a number of status codes a target can return, one of them is a check condition. A check condition requires the host to send a command called “request sense”. The target will respond with data containing sense codes defining the event that caused the check condition to occur.
Now let’s talk about the discovery process on the different mediums and how it is accomplished:
Whenever a scan is requested for a bus controlled by an iSCSI or Fibre Channel adapter, the Microsoft storport driver will attempt to send to all targets a “report LUNS” command. The response to a report LUNS command will contain information regarding all the LUNS on the target. Then storport will send “inquiry” commands to all LUNS reported to get specific LUN information. Even though the number of targets can be as high as 128, the time this takes is usually very short. The adapter keeps a table to translate OS Target ID to the Destination ID which is the actual address on the fabric (or SessionID in case of iscsi). The Adapter miniport driver creates this table from data it receives from the name server. No I/O is done if the command fails due to a nonexistent target.
The device object representing the LUN is built from the inquiry data received from the LUN. One device object will be built in storport for each LUN discovered.
The iSCSI discovery occurs the same way as far as sending the report LUN command to each target as done in Fibre. However, the discovery will happen when a connection is made to a target. When the iSCSI miniport driver successfully logs into a target it will notify the port driver to do a bus scan of the ISCSI adapter. The enumeration is identical as far as the scan itself.
Common question are:
What happens when I add a LUN to an existing target?
When a LUN is added, the target does not immediately notify the host. When an I/O is sent to an existing LUN, the I/O will get a “check condition” status. When the request sense is issued the sense data will indicate that the “report LUNS data has changed”. The port driver (usually storport) picks this up and the port driver will scan the bus and discover the new LUN. This would be the same for iSCSI and fibre. This means that if the target does not issue a check condition to notify the OS of a new LUN the LUN will not appear on the system and the user will need to manually scan for the new disk.
How does the operating system know that a new target was added?
If a new target is added on an iSCSI bus, the scan will be initiated after the miniport driver successfully logs in to the target. So what about fiber? When a new target is added to a fibre channel, the adapter will receive a RSCN (registered state change notification) packet from the fabric. This indication will be passed on to the port driver by the miniport (depending on adapter driver) to scan the bus. Then the new target will be picked up by the scan and the target will be sent a report LUNS to get the LUNS on the target. Again, this means if the miniport or the fibre does not notify the OS of a new target its devices will not appear on the system and the user will need to manually scan for the new disks.
Editor's Note: The external links provided in this article contained accurate information at the time of publication. For official information regarding the SCSI specification, please see the latest revision of the SAM working draft at http://www.t10.org/drafts.htm#sam4. The T10 webpage may ask for personal information and agreements before giving access to the drafts, this is outside of the control of The NtDebugging Blog.