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

SYSFS=needed
cd /etc/hotplug
. hotplug.functions


_ccw_status_dir="${SYSFS}${DEVPATH}"

CHAN_ID=$(basename $_ccw_status_dir)

case $ACTION in
    register|add)
	for i in 1 2 3 4 5 ; do
	    if [ -d "$_ccw_status_dir/cdev0" ]; then
		REAL_DEVPATH=$(cd -P ${_ccw_status_dir}/cdev0; echo $PWD)
	    	break;
	    fi
	    mesg "Waiting for cdev0 of device $CHAN_ID"
	    sleep 1
	done
	if [ "$REAL_DEVPATH" ]; then
	    mesg "Configuring channel $CHAN_ID for event 'ccwgroup'"
	    hwup ccwgroup-devpath-${REAL_DEVPATH} -o hotplug
	else
	    mesg "Cannot configure device $CHAN_ID: No cdev0"
	fi
	;;
    unregister|remove)
	# Nothing to be done, device is already gone
	debug_mesg CCWGROUP $ACTION event nothing to do
	;;

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

esac
