Tuesday, 3 January 2017

SCSI user scan, SCSI device addition Linux internals

Looked upon the code how iscsid scan works. __scsi_scan_target is the key function which does the SCSI scan.
This function first it tries to probe and add LUN 0 using scsi_probe_and_add_lun function.

Dec 24 03:24:28 localhost kernel: [<ffffffff813e8c94>] scsi_probe_and_add_lun+0x3f4/0xc80
Dec 24 03:24:28 localhost kernel: [<ffffffff815e5a51>] ? printk+0x77/0x8e
Dec 24 03:24:28 localhost kernel: [<ffffffff813e9a0e>] __scsi_scan_target+0x13e/0x270
Dec 24 03:24:28 localhost kernel: [<ffffffff813e9c30>] scsi_scan_target+0xf0/0x110
Dec 24 03:24:28 localhost kernel: [<ffffffffa050eedf>] iscsi_user_scan_session.part.13+0x10f/0x150 [scsi_transport_iscsi]
Dec 24 03:24:28 localhost kernel: [<ffffffffa050ef20>] ? iscsi_user_scan_session.part.13+0x150/0x150 [scsi_transport_iscsi]
Dec 24 03:24:28 localhost kernel: [<ffffffffa050ef41>] iscsi_user_scan_session+0x21/0x30 [scsi_transport_iscsi]
Dec 24 03:24:28 localhost kernel: [<ffffffff813b1b63>] device_for_each_child+0x53/0x90
Dec 24 03:24:28 localhost kernel: [<ffffffffa050cb6c>] iscsi_user_scan+0x3c/0x60 [scsi_transport_iscsi]
Dec 24 03:24:28 localhost kernel: [<ffffffff813eb835>] store_scan+0xa5/0x100
Dec 24 03:24:28 localhost kernel: [<ffffffff813b1138>] dev_attr_store+0x18/0x30
Dec 24 03:24:28 localhost kernel: [<ffffffff81225686>] sysfs_write_file+0xc6/0x140
Dec 24 03:24:28 localhost kernel: [<ffffffff811afa7d>] vfs_write+0xbd/0x1e0
Dec 24 03:24:28 localhost kernel: [<ffffffff811b04c8>] SyS_write+0x58/0xb0
Dec 24 03:24:28 localhost kernel: [<ffffffff815fc9d9>] system_call_fastpath+0x16/0x1b



scsi_probe_and_add_lun function will :
1. allocate scsi_device data structure
2. call scsi_probe_lun and send SCSI enquiries to LUN 0.
3. call scsi_add_lun to fill the scsi_device data structure from the enquiries done.
this data structure is added using scsi_sysfs_add_sdev function.


Then it tries to send SCSI report LUN command to get the number of LUNS in function scsi_report_lun_scan. This function finds the number of LUNs and again tries to add all the LUNs using scsi_probe_and_add_lun function.

scsi_sysfs_add_sdev function adds the devices by calling scsi_target_add and device_add for scsi_device.

This device_add calls the drivers' probe function (sd_probe) :

Dec 24 03:24:28 localhost kernel: [<ffffffffa01d77d0>] sd_probe+0x320/0x380 [sd_mod]
Dec 24 03:24:28 localhost kernel: [<ffffffff813b6917>] driver_probe_device+0x87/0x390
Dec 24 03:24:28 localhost kernel: [<ffffffff813b6c20>] ? driver_probe_device+0x390/0x390
Dec 24 03:24:28 localhost kernel: [<ffffffff813b6c5b>] __device_attach+0x3b/0x40
Dec 24 03:24:28 localhost kernel: [<ffffffff813b477b>] bus_for_each_drv+0x6b/0xb0
Dec 24 03:24:28 localhost kernel: [<ffffffff813b6818>] device_attach+0x88/0xa0
Dec 24 03:24:28 localhost kernel: [<ffffffff813b5b18>] bus_probe_device+0x98/0xc0
Dec 24 03:24:28 localhost kernel: [<ffffffff813b3584>] device_add+0x4c4/0x7a0
Dec 24 03:24:28 localhost kernel: [<ffffffff813c2ebc>] ? __pm_runtime_resume+0x5c/0x80
Dec 24 03:24:28 localhost kernel: [<ffffffff813eba9c>] scsi_sysfs_add_sdev+0xac/0x320
Dec 24 03:24:28 localhost kernel: [<ffffffff813e9317>] scsi_probe_and_add_lun+0xa77/0xc80
Dec 24 03:24:28 localhost kernel: [<ffffffff815eceff>] scsi_report_lun_scan+0x39a/0x5f1
Dec 24 03:24:28 localhost kernel: [<ffffffff813e9a24>] __scsi_scan_target+0x154/0x270
Dec 24 03:24:28 localhost kernel: [<ffffffff813e9c30>] scsi_scan_target+0xf0/0x110
Dec 24 03:24:28 localhost kernel: [<ffffffffa050eedf>] iscsi_user_scan_session.part.13+0x10f/0x150 [scsi_transport_iscsi]
Dec 24 03:24:28 localhost kernel: [<ffffffffa050ef20>] ? iscsi_user_scan_session.part.13+0x150/0x150 [scsi_transport_iscsi]
Dec 24 03:24:28 localhost kernel: [<ffffffffa050ef41>] iscsi_user_scan_session+0x21/0x30 [scsi_transport_iscsi]
Dec 24 03:24:28 localhost kernel: [<ffffffff813b1b63>] device_for_each_child+0x53/0x90
Dec 24 03:24:28 localhost kernel: [<ffffffffa050cb6c>] iscsi_user_scan+0x3c/0x60 [scsi_transport_iscsi]
Dec 24 03:24:28 localhost kernel: [<ffffffff813eb835>] store_scan+0xa5/0x100
Dec 24 03:24:28 localhost kernel: [<ffffffff813b1138>] dev_attr_store+0x18/0x30
Dec 24 03:24:28 localhost kernel: [<ffffffff81225686>] sysfs_write_file+0xc6/0x140
Dec 24 03:24:28 localhost kernel: [<ffffffff811afa7d>] vfs_write+0xbd/0x1e0
Dec 24 03:24:28 localhost kernel: [<ffffffff811b04c8>] SyS_write+0x58/0xb0
Dec 24 03:24:28 localhost kernel: [<ffffffff815fc9d9>] system_call_fastpath+0x16/0x1b


linux-3.14.69\drivers\scsi\sd.c

This sd_probe function allocates the disk and launches thread sd_probe_async.
async_schedule_domain(sd_probe_async, sdkp, &scsi_sd_probe_domain);

sd_probe_async calls add_disk and prints the message :
"Attached SCSI %sdisk"


Good link with info to enable SCSI logging :
https://www.novell.com/support/kb/doc.php?id=7007138

For only scan logs :
put this line :
dev.scsi.logging_level = 0x000001C0
in /etc/sysctl.conf
Run sysctl -p to make this change effective immediately

Also from /proc also we can enable disable logs :
echo 0x1FFFFFFF > /proc/sys/dev/scsi/logging_level
echo 0 > /proc/sys/dev/scsi/logging_level

No comments:

Post a Comment