#!/bin/sh
#
# Name: sysfs_scan_rport
# Copyright: (c)Copyright 2006 Hewlett-Packard Development Company, L.P.
#
# Description: Given a particular SCSI host, generate a list
#              of rports for that host 
#
# Revision History
#
# CD    08/29/06 Initial Development

# Check to make sure we have an argument

if [ $# -ne 1 ]
then
	exit 0
fi

INST=$1
DIRTOSCAN=/sys/class/scsi_host/host${INST}/device

# Get a list of rports

RPORTS=`ls $DIRTOSCAN 2>/dev/null | grep rport`

for i in $RPORTS
do
	FCREMOTEPORTDIR=`ls $DIRTOSCAN/$i | grep fc_remote_ports`
	
	# Prepent the absolute path name
	FCREMOTEPORTDIR=$DIRTOSCAN/$i/$FCREMOTEPORTDIR	
	
	# Check to see if the rport is a target; if it is then print out
	# the nodename and portname of that port

	if [ "`cat $FCREMOTEPORTDIR/roles 2>/dev/null`" = "FCP Target" ]
	then
		NODENAME=`cat $FCREMOTEPORTDIR/node_name`
		PORTNAME=`cat $FCREMOTEPORTDIR/port_name`
		echo "$i=$NODENAME:$PORTNAME"
	fi 
done
