5e5efa
#!/bin/bash
5e5efa
#
5e5efa
# fc_wwpn_id
5e5efa
#
5e5efa
# Generates device node names links based on FC WWPN
5e5efa
# Copyright (c) 2016 Hannes Reinecke, SUSE Linux GmbH
5e5efa
#
5e5efa
# This program is free software; you can redistribute it and/or modify it
5e5efa
# under the terms of the GNU General Public License as published by the
5e5efa
# Free Software Foundation version 2 of the License.
5e5efa
#
5e5efa
5e5efa
DEVPATH=$1
5e5efa
SCSIPATH=$(cd -P "/sys$DEVPATH/device" || exit; echo "$PWD")
5e5efa
5e5efa
d=$SCSIPATH
5e5efa
[ -d "$d/scsi_disk" ] || exit 0
5e5efa
target_lun=${d##*:}
5e5efa
5e5efa
while [ -n "$d" ] ; do
5e5efa
    d=${d%/*}
5e5efa
    e=${d##*/}
5e5efa
    case "$e" in
5e5efa
	rport*)
5e5efa
	    rport=$e
5e5efa
	    rport_dir="/sys/class/fc_remote_ports/$rport"
5e5efa
	    if [ -d "$rport_dir" ] ; then
5e5efa
		rport_wwpn=$(cat "$rport_dir/port_name")
5e5efa
	    fi
5e5efa
	    ;;
5e5efa
	host*)
5e5efa
	    host=$e
5e5efa
	    host_dir="/sys/class/fc_host/$host"
5e5efa
	    if [ -d "$host_dir" ] ; then
5e5efa
		host_wwpn=$(cat "$host_dir/port_name")
5e5efa
		break;
5e5efa
	    fi
5e5efa
    esac
5e5efa
done
5e5efa
e3e58c
if [ -n "$rport_wwpn" ] || [ -n "$host_wwpn" ] ; then
e3e58c
    echo "FC_TARGET_LUN=$target_lun"
e3e58c
fi
5e5efa
5e5efa
if [ -n "$rport_wwpn" ] ; then
5e5efa
    echo "FC_TARGET_WWPN=$rport_wwpn"
5e5efa
fi
5e5efa
5e5efa
if [ -n "$host_wwpn" ] ; then
5e5efa
    echo "FC_INITIATOR_WWPN=$host_wwpn"
5e5efa
fi