Sysfs Fibre Channel Tools(updated for RHEL6)

It's a FC tool set I've been using for years, very useful, just updated to reflect RHEL6 latest kernel.
Tested on kernel2.6.32-358.14, using Emulex and Qlogic cards. Should be good for other types of HBA too, just add vendor info to ls_fc_luns



You can still download its origional version from the link below, but unfortunally there is no update for RHEL6
http://dims.ncsa.illinois.edu/set/san/src/sysfs_fc_tools.tgz

Scripts to simplify attaching, displaying, deleting fibre channel luns using 2.6 kernel sysfs features.

You can download the scripts from
http://fibrevillage.com/files/sysfs_fc_tools.tgz
It includs 4 scripts:

lip_fc_hosts
ls_fc_luns
scan_fc_luns
delete_fc_luns

Simply put them to /usr/local/sbin, then it will work for you. Here are some examples:

lip_fc_hosts

Send lip to all local FC HBAs.

# ./lip_fc_hosts
+ [[ -f /sys/class/fc_host/host5/issue_lip ]]
+ echo 1
+ 1> /sys/class/fc_host/host5/issue_lip
+ [[ -f /sys/class/fc_host/host6/issue_lip ]]
+ echo 1
+ 1> /sys/class/fc_host/host6/issue_lip

scan_fc_luns

 Scan all local FC HBAs for new luns and present them to the kernel.

./scan_fc_luns

ls_fc_luns

 List HBA WWPN, target WWPN, kernel device name, scsi H:B:T:L tuple and scsi_id for all fibre channel luns.

# ./ls_fc_luns
HBA  0x21000024ff3434e4  host5
0x21000024ff3434e4 0x20370080e52d2652 5:0:0:0 sdb 360080e50002d26520000067a4f7a3fb8 30
0x21000024ff3434e4 0x20370080e52d2652 5:0:0:1 sdc 360080e50002d2124000006d14f7a3f92 30
0x21000024ff3434e4 0x20370080e52d2652 5:0:0:10 sdl 360080e50002d26520000068e4f7a4022 30
0x21000024ff3434e4 0x20370080e52d2652 5:0:0:11 sdm 360080e50002d2124000006e54f7a3ffe 30
0x21000024ff3434e4 0x20370080e52d2652 5:0:0:2 sdd 360080e50002d26520000067e4f7a3fcc 30
0x21000024ff3434e4 0x20370080e52d2652 5:0:0:3 sde 360080e50002d2124000006d54f7a3fa6 30
...

delete_fc_luns

Delete (detach) all fibre channel luns from the system.

./delete_fc_luns
+ fn=/sys/class/scsi_host/host5/device/subsystem/devices/5:0:0:0/delete
+ [[ -f /sys/class/scsi_host/host5/device/subsystem/devices/5:0:0:0/delete ]]
+ echo 1
+ 1> /sys/class/scsi_host/host5/device/subsystem/devices/5:0:0:0/delete
+ fn=/sys/class/scsi_host/host5/device/subsystem/devices/5:0:0:1/delete
+ [[ -f /sys/class/scsi_host/host5/device/subsystem/devices/5:0:0:1/delete ]]
+ echo 1
+ 1> /sys/class/scsi_host/host5/device/subsystem/devices/5:0:0:1/delete

How it works

The tool requires linux 2.6 kernel and sysfs pseudo filesystem, it parses the scsi devices info from sysfs and do according actions.

systool is a utility that uses APIs provided by libsysfs to gather sysfs information, view system device information by bus, class, and topology.

Nothing can't be done manually,  to add,remove,rescan scsi devices, see another article Hot add remove rescan scsi devices on linux

What if the code doesn't work for your HBA card

The code provided above is good for most popular HBA cards, in case your HBA card is not supported, just add your HBA vendor code into the script, the script will work for you then.

How to get Vendor code?

Once yoou have the vendor code for different type of HBA card, then add it to ls_fc_lun function get_hba_wwpn or drop me an e-mail.

# lspci -nvms 15:00.0
Device:    15:00.0
Class:    0c04
Vendor:    1077
Device:    2532
SVendor:    1077
SDevice:    015d
PhySlot:    2
Rev:    02

Note: more info about lspci, see lspci-useful-examples

For how to get HBA info, see check HBA card and its driver info on Linux