Locating WWPNs on Linux servers


I do a lot of storage-related work, and often times need to grab WWPNs to zone hosts and to mask storage. To gather the WWPNs I would often times use the following script on my RHEL and CentOS servers:

#!/bin/sh

FC_PATH="/sys/class/fc_host"

for fc_adapter in `ls ${FC_PATH}`; do
    echo "${FC_PATH}/${fc_adapter}:"
    NAME=$(awk '{print $1}' ${FC_PATH}/${fc_adapter}/symbolic_name )
    echo " $NAME `cat ${FC_PATH}/${fc_adapter}/port_name`"
done

This produced consolidated output similar to:

$ print_wwpns

/sys/class/fc_host/host5:
QLE2562 0x21000024ff45afc2
/sys/class/fc_host/host6:
QLE2562 0x21000024ff45afc3

While doing some research I came across sysfsutils, which contains the incredibly useful systool utility. This nifty little tool allows you to query sysfs values, and can be used to display all of the sysfs attributes for your FC adapters:

$ systool -c fc_host -v

Class = "fc_host"

Class Device = "host5"
Class Device path = "/sys/class/fc_host/host5"
fabric_name = "0x200a547fee9e5e01"
issue_lip =
node_name = "0x20000024ff45afc2"
port_id = "0x0a00c0"
port_name = "0x21000024ff45afc2"
port_state = "Online"
port_type = "NPort (fabric via point-to-point)"
speed = "8 Gbit"
supported_classes = "Class 3"
supported_speeds = "1 Gbit, 2 Gbit, 4 Gbit, 8 Gbit"
symbolic_name = "QLE2562 FW:v5.06.03 DVR:v8.03.07.09.05.08-k"
system_hostname = ""
tgtid_bind_type = "wwpn (World Wide Port Name)"
uevent =

Class Device = "host6"
Class Device path = "/sys/class/fc_host/host6"
fabric_name = "0x2014547feeba9381"
issue_lip =
node_name = "0x20000024ff45afc3"
port_id = "0x9700a0"
port_name = "0x21000024ff45afc3"
port_state = "Online"
port_type = "NPort (fabric via point-to-point)"
speed = "8 Gbit"
supported_classes = "Class 3"
supported_speeds = "1 Gbit, 2 Gbit, 4 Gbit, 8 Gbit"
symbolic_name = "QLE2562 FW:v5.06.03 DVR:v8.03.07.09.05.08-k"
system_hostname = ""
tgtid_bind_type = "wwpn (World Wide Port Name)"
uevent =

This output is extremely useful for storage administrators, and provides everything you need in a nice consolidated form. +1 for systool!

This article was posted by Matty on 2012-12-19 20:42:00 -0400 -0400