1#!/bin/bash 2# 3# fc_wwpn_id 4# 5# Generates device node names links based on FC WWPN 6# Copyright (c) 2016-2021 Hannes Reinecke, SUSE Linux GmbH 7# 8# This program is free software; you can redistribute it and/or modify it 9# under the terms of the GNU General Public License as published by the 10# Free Software Foundation version 2 of the License. 11# 12 13DEVPATH=$1 14SCSIPATH=$(cd -P "/sys$DEVPATH/device" || exit; echo "$PWD") 15 16d=$SCSIPATH 17[ -d "$d/scsi_disk" ] || exit 0 18target_lun=${d##*:} 19 20while [ -n "$d" ] ; do 21 d=${d%/*} 22 e=${d##*/} 23 case "$e" in 24 rport*) 25 rport=$e 26 rport_dir="/sys/class/fc_remote_ports/$rport" 27 if [ -d "$rport_dir" ] ; then 28 rport_wwpn=$(cat "$rport_dir/port_name") 29 fi 30 ;; 31 host*) 32 host=$e 33 host_dir="/sys/class/fc_host/$host" 34 if [ -d "$host_dir" ] ; then 35 host_wwpn=$(cat "$host_dir/port_name") 36 break; 37 fi 38 esac 39done 40 41if [ -n "$rport_wwpn" ] || [ -n "$host_wwpn" ] ; then 42 echo "FC_TARGET_LUN=$target_lun" 43fi 44 45if [ -n "$rport_wwpn" ] ; then 46 echo "FC_TARGET_WWPN=$rport_wwpn" 47fi 48 49if [ -n "$host_wwpn" ] ; then 50 echo "FC_INITIATOR_WWPN=$host_wwpn" 51fi 52