Archive

Archive for the ‘Internals’ Category

Linux: How to query the WWPN of Fibre Channel HBA ports

October 8th, 2011 Matthias Pölzinger No comments

Problem description:

The WWPNs (World Wide Port Numbers) of your HBAs are required e.g. in order to configure Fibre Channel LUN Access. You want to use Linux instruments to access this information in order to avoid rebooting the servers and access the information from BIOS or any other utility.

 
Problem resolution:

Current Linux kernel versions provide relevant information about FC HBAs through the sysfs Filesystem mounted at /sys. The location for detailed information depends on your Linux OS version. For CentOS / Red Hat Enterprise Linux / Oracle Linux 5 the path is /sys/class/scsi_host/host*/device/fc_host*/, but for Version 6 it changed to /sys/class/fc_host/host*/ which makes it easier to separate between SCSI controllers and FC HBAs.

Example for Centos / RHEL / Oracle Linux 5:

[root@initso01 ~]# ls -al /sys/class/scsi_host/host5/device/fc_host:host5/
total 0
drwxr-xr-x 4 root root    0 Oct  5 17:03 .
drwxr-xr-x 6 root root    0 Oct  5 17:03 ..
lrwxrwxrwx 1 root root    0 Oct  5 17:03 device -> ../../../devices/pci0000:00/0000:00:03.0/0000:15:00.0/host5
-r--r--r-- 1 root root 4096 Oct  7 10:07 fabric_name
--w------- 1 root root 4096 Oct  7 10:07 issue_lip
-r--r--r-- 1 root root 4096 Oct  7 10:07 max_npiv_vports
-r--r--r-- 1 root root 4096 Oct  7 10:07 node_name
-r--r--r-- 1 root root 4096 Oct  7 10:07 npiv_vports_inuse
-r--r--r-- 1 root root 4096 Oct  7 10:07 port_id
-r--r--r-- 1 root root 4096 Oct  7 10:07 port_name
-r--r--r-- 1 root root 4096 Oct  7 10:07 port_state
-r--r--r-- 1 root root 4096 Oct  7 10:07 port_type
drwxr-xr-x 2 root root    0 Oct  7 10:07 power
-r--r--r-- 1 root root 4096 Oct  7 10:07 speed
drwxr-xr-x 2 root root    0 Oct  7 10:07 statistics
lrwxrwxrwx 1 root root    0 Oct  5 17:04 subsystem -> ../../fc_host
-r--r--r-- 1 root root 4096 Oct  7 10:07 supported_classes
-r--r--r-- 1 root root 4096 Oct  7 10:07 supported_speeds
-r--r--r-- 1 root root 4096 Oct  7 10:07 symbolic_name
-rw-r--r-- 1 root root 4096 Oct  7 10:07 system_hostname
-rw-r--r-- 1 root root 4096 Oct  7 10:07 tgtid_bind_type
-rw-r--r-- 1 root root 4096 Oct  5 17:03 uevent
--w------- 1 root root 4096 Oct  7 10:07 vport_create
--w------- 1 root root 4096 Oct  7 10:07 vport_delete
[root@initso01 ~]#

 
These fc_host directories can be used to to determine the port speed:

[root@initso01 ~]# for i in `ls /sys/class/scsi_host/host*/device/fc_host*/speed`; do echo $i; echo "==============="; cat $i; done
/sys/class/scsi_host/host5/device/fc_host:host5/speed
===============
unknown
/sys/class/scsi_host/host6/device/fc_host:host6/speed
===============
4 Gbit
/sys/class/scsi_host/host7/device/fc_host:host7/speed
===============
unknown
/sys/class/scsi_host/host8/device/fc_host:host8/speed
===============
4 Gbit
[root@initso01 ~]#

 
or to query the WWPN of each port:

[root@initso01 ~]# for i in `ls /sys/class/scsi_host/host*/device/fc_host*/port_name`; do echo $i; echo "==============="; cat $i; done
/sys/class/scsi_host/host5/device/fc_host:host5/port_name
===============
0x21000024ff2e30ce
/sys/class/scsi_host/host6/device/fc_host:host6/port_name
===============
0x21000024ff2e30cf
/sys/class/scsi_host/host7/device/fc_host:host7/port_name
===============
0x21000024ff2e30cc
/sys/class/scsi_host/host8/device/fc_host:host8/port_name
===============
0x21000024ff2e30cd
[root@initso01 ~]#

 
Just omit the hexidecimal prefix “0x” and you have the WWPN for each Fibre Channel HBA port.

 
Example for Centos / RHEL / Oracle Linux 6:

[root@initso02 ~]# ls -al /sys/class/fc_host/host1/
total 0
drwxr-xr-x. 4 root root    0 Aug 11 07:11 .
drwxr-xr-x. 3 root root    0 Aug 11 07:11 ..
-rw-r--r--. 1 root root 4096 Aug 13 10:29 dev_loss_tmo
lrwxrwxrwx. 1 root root    0 Aug 13 10:29 device -> ../../../host1
-r--r--r--. 1 root root 4096 Aug 13 10:29 fabric_name
--w-------. 1 root root 4096 Aug 13 10:29 issue_lip
-r--r--r--. 1 root root 4096 Aug 13 10:29 max_npiv_vports
-r--r--r--. 1 root root 4096 Aug 13 10:29 node_name
-r--r--r--. 1 root root 4096 Aug 13 10:29 npiv_vports_inuse
-r--r--r--. 1 root root 4096 Aug 13 10:29 port_id
-r--r--r--. 1 root root 4096 Aug 13 10:14 port_name
-r--r--r--. 1 root root 4096 Aug 13 10:29 port_state
-r--r--r--. 1 root root 4096 Aug 13 10:29 port_type
drwxr-xr-x. 2 root root    0 Aug 13 10:29 power
-r--r--r--. 1 root root 4096 Aug 13 10:29 speed
drwxr-xr-x. 2 root root    0 Aug 13 10:29 statistics
lrwxrwxrwx. 1 root root    0 Aug 11 07:11 subsystem -> ../../../../../../../class/fc_host
-r--r--r--. 1 root root 4096 Aug 13 10:29 supported_classes
-r--r--r--. 1 root root 4096 Aug 13 10:29 supported_speeds
-r--r--r--. 1 root root 4096 Aug 13 10:29 symbolic_name
-rw-r--r--. 1 root root 4096 Aug 13 10:29 system_hostname
-rw-r--r--. 1 root root 4096 Aug 13 10:29 tgtid_bind_type
-rw-r--r--. 1 root root 4096 Aug 11 07:11 uevent
--w-------. 1 root root 4096 Aug 13 10:29 vport_create
--w-------. 1 root root 4096 Aug 13 10:29 vport_delete
[root@initso02 ~]#

 
As with Version 5 these fc_host directories can be used to to determine the port speed:

[root@initso02 ~]# for i in `ls /sys/class/fc_host/host*/speed`; do echo $i; echo "==============="; cat $i; done
/sys/class/fc_host/host1/speed
===============
4 Gbit
/sys/class/fc_host/host2/speed
===============
4 Gbit
[root@initso02 ~]#

 
or to query the WWPN of each port:

[root@initso02 ~]# for i in `ls /sys/class/fc_host/host*/port_name`; do echo $i; echo "==============="; cat $i; done
/sys/class/fc_host/host1/port_name
===============
0x24000024ee09a545
/sys/class/fc_host/host2/port_name
===============
0x24000024ee09a578
[root@initso02 ~]#

 
Just omit the hexidecimal prefix "0x" as with Version 5 and you have the WWPN for each Fibre Channel HBA port.