Mapping from iSCSI session to device.

I was monitoring my system, so I knew the file was /dev/sdb was the new iSCSI target I was trying to turn into a file system. TO provide it, I ran:

iscsiadm -m session --print=3

And saw:

...
		scsi4 Channel 00 Id 0 Lun: 0
		scsi4 Channel 00 Id 0 Lun: 1
			Attached scsi disk sdb		State: running

But what did that do? Using Strace helped me sort it a little. I worked backwards.

stat("/sys/subsystem/scsi/devices/4:0:0:1", 0x7ffc3aab0a50) = -1 ENOENT (No such file or directory)
stat("/sys/bus/scsi/devices/4:0:0:1", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
lstat("/sys/bus/scsi/devices/4:0:0:1/state", {st_mode=S_IFREG|0644, st_size=4096, ...}) = 0
open("/sys/bus/scsi/devices/4:0:0:1/state", O_RDONLY) = 3
read(3, "running\n", 256)               = 8
close(3)                                = 0
write(1, "\t\t\tAttached scsi disk sdb\t\tState"..., 42			Attached scsi disk sdb		State: running

But looking in the file /sys/bus/scsi/devices/4:0:0:1/state I saw only the word “Running” so it must have found the device earlier.

Looking at the complete list of files opened is illuminating, although too long to list here. It starts by enumerating through /sys/class/iscsi_session and hits
/sys/class/iscsi_session/session3. Under /sys/class/iscsi_session/session3/device/target4:0:0 I found:

$ ls -la /sys/class/iscsi_session/session3/device/target4:0:0  
total 0
drwxr-xr-x. 5 root root    0 Feb  3 13:04 .
drwxr-xr-x. 6 root root    0 Feb  3 13:04 ..
drwxr-xr-x. 6 root root    0 Feb  3 13:04 4:0:0:0
drwxr-xr-x. 8 root root    0 Feb  3 13:04 4:0:0:1
drwxr-xr-x. 2 root root    0 Feb  3 14:03 power
lrwxrwxrwx. 1 root root    0 Feb  3 13:04 subsystem -> ../../../../../bus/scsi
-rw-r--r--. 1 root root 4096 Feb  3 13:04 uevent

And, following the symlink:

[ansible@dialga ~]$ ls -la /sys/bus/scsi/devices/4:0:0:1/block
total 0
drwxr-xr-x. 3 root root 0 Feb  3 13:35 .
drwxr-xr-x. 8 root root 0 Feb  3 13:04 ..
drwxr-xr-x. 8 root root 0 Feb  3 13:35 sdb

Notice that /sys/bus/scsi/devices/4:0:0:0/ does not have a subfile called block.

There is probably more to the link than this, but it should be enough to connect the dots. Not sure if there is a way to reverse it short of listing the devices under /sys/bus/scsi/devices/ .

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.