#!/bin/bash
# vim: syntax=sh
#
# SCSI_HOST hotplug policy agent for Linux 2.6 kernels
# $Id: scsi_host.agent 269 2004-08-16 13:07:06Z hare $
#
# Kernel SCSI_HOST hotplug params include:
#	
#	ACTION=%s [register or unregister]
#       DEVPATH=%s [sysfs-path of the device]
#

SYSFS=needed

cd /etc/hotplug
. hotplug.functions


case $ACTION in
    register|add)
	# hwconfig interaction
	WAIT_MAX=5
	while [ ! -e ${SYSFS}${DEVPATH}/device ] ; do
		test $((WAIT_MAX--)) -le 0 && break
		sleep 1
	done
	if [ -e ${SYSFS}${DEVPATH}/device ] ; then
		REAL_DEVPATH=$(cd ${SYSFS}${DEVPATH}/device; /bin/pwd)
		REAL_DEVPATH=$(cd ${REAL_DEVPATH}/..; /bin/pwd)
		export REAL_DEVPATH
	fi
	
	if [ -f "${REAL_DEVPATH}/cutype" ] ; then
	    # This is a zfcp adapter
	    SCSI_HOST_DEV="zfcp"
	    SCSI_HOST_ID=$(basename $REAL_DEVPATH)
	fi

	if [ -z "$SCSI_HOST_DEV" ] ; then
	    debug_mesg "Unknown scsi_host type"
	    exit 0
	else
	    debug_mesg "Configuring $SCSI_HOST_DEV on ID $SCSI_HOST_ID $REAL_DEVPATH"
	    hwup scsi__host-devpath-${REAL_DEVPATH} -o hotplug
	fi
	;;
    unregister|remove)
	exit 0
	;;

    *)
	debug_mesg SCSI_HOST $ACTION event not supported
	exit 1 ;;

esac
