diff options
Diffstat (limited to 'ccw_init')
-rw-r--r-- | ccw_init | 162 |
1 files changed, 130 insertions, 32 deletions
@@ -1,24 +1,75 @@ -#!/bin/bash +#! /bin/sh [ -z "$DEVPATH" ] && exit 0 [ "$SUBSYSTEM" != "ccw" ] && exit 0 -NOLOCALE="yes" +[ -e /etc/ccw.conf ] && MODE="dracut" || MODE="normal" -. /etc/sysconfig/network-scripts/network-functions - -# First, determine our channel +get_config_line_by_subchannel() +{ + local CHANNEL + CHANNEL="$1" + while read line; do + IFS=, + set $line + for i in $@; do + if [ "$CHANNEL" = "$i" ]; then + echo $line + return 0 + fi + done + if [ "$CHANNEL" = "$2" ]; then + echo $line + return 0 + fi + done < /etc/ccw.conf + return 1 +} CHANNEL=${DEVPATH##*/} -CONFIG=$(get_config_by_subchannel $CHANNEL) +if [ $MODE = "dracut" ]; then + CONFIG_LINE=$(get_config_line_by_subchannel $CHANNEL) + + [ $? -ne 0 -o -z "$CONFIG_LINE" ] && break + + set $CONFIG_LINE + NETTYPE=$1 + shift + SUBCHANNELS="$1" + OPTIONS="" + shift + while [ $# -gt 0 ]; do + case $1 in + *=*) OPTIONS="$OPTIONS $1";; + [0-9]*) SUBCHANNELS="$SUBCHANNELS,$1";; + esac + shift + done +elif [ $MODE = "normal" ]; then + NOLOCALE="yes" -if [ -n "$CONFIG" ]; then - cd /etc/sysconfig/network-scripts - source_config + . /etc/sysconfig/network-scripts/network-functions + + CONFIG_FILE=$(get_config_by_subchannel $CHANNEL) + + if [ -n "$CONFIG_FILE" ]; then + . $CONFIG_FILE + else + exit 1 + fi +else + echo "Unknown mode=$MODE" + exit 1 fi + +# now we have extracted these variables from the config files: +# SUBCHANNELS +# OPTIONS + # put LAYER2 option into its own variable +ORIG_OPTIONS=$OPTIONS set $OPTIONS OPTIONS="" while [ $# -gt 0 ]; do @@ -29,9 +80,25 @@ while [ $# -gt 0 ]; do shift done +# translate variables from the interface config files to OPTIONS +if [ -n "$PORTNAME" ]; then + if [ "$NETTYPE" = "lcs" ]; then + OPTIONS="$OPTIONS portno=$PORTNAME" + else + OPTIONS="$OPTIONS portname=$PORTNAME" + fi +fi +if [ "$NETTYPE" = "ctc" -a -n "$CTCPROT" ]; then + OPTIONS="$OPTIONS protocol=$CTCPROTO" +fi + # SUBCHANNELS is only set on mainframe ccwgroup devices [ -z "$SUBCHANNELS" -o -z "$NETTYPE" ] && exit 0 -DIR="/sys/bus/ccwgroup/drivers/$NETTYPE" +if [ "$NETTYPE" = "ctc" ]; then + DIR="/sys/bus/ccwgroup/drivers/ctcm" +else + DIR="/sys/bus/ccwgroup/drivers/$NETTYPE" +fi i=0 while [ $i -lt 20 ]; do @@ -43,34 +110,65 @@ done # driver missing or not loaded [ ! -e $DIR ] && exit 0 -SYSDIR="$DIR/${SUBCHANNELS//,*/}" +CHANNEL1=${SUBCHANNELS//,*/} +SYSDIR="$DIR/$CHANNEL1" + [ -e $SYSDIR ] && exit 0 -echo "$SUBCHANNELS" > $DIR/group -i=0 -while [ $i -lt 20 ]; do - [ -e $SYSDIR ] && break - sleep 0.1 - i=$(($i+1)) -done +# check if the interface is already online +if [ -e $SYSDIR/online ]; then + read on <$SYSDIR/online + [ "$on" = "1" ] && exit 0 +fi -# first set layer2, other options may depend on it -[ -n "$LAYER2" ] && echo $LAYER2 > $SYSDIR/layer2 +DRIVER=$(readlink $DEVPATH/driver) +DRIVER=${DRIVER##*/} +CHANNEL2=${SUBCHANNELS##*,} +if [ "$DRIVER" = "lcs" -a "$NETTYPE" = "ctc" ]; then + echo "$CHANNEL" > /sys/bus/ccw/drivers/lcs/unbind + echo "$CHANNEL" > /sys/bus/ccw/drivers/ctcm/bind + echo "$CHANNEL2" > /sys/bus/ccw/drivers/lcs/unbind + echo "$CHANNEL2" > /sys/bus/ccw/drivers/ctcm/bind +fi +if [ "$DRIVER" = "ctcm" -a "$NETTYPE" = "lcs" ]; then + echo "$CHANNEL" > /sys/bus/ccw/drivers/ctcm/unbind + echo "$CHANNEL" > /sys/bus/ccw/drivers/lcs/bind + echo "$CHANNEL2" > /sys/bus/ccw/drivers/ctcm/unbind + echo "$CHANNEL2" > /sys/bus/ccw/drivers/lcs/bind +fi -if [ -n "$PORTNAME" ]; then - if [ "$NETTYPE" = "lcs" ]; then - [ -e $SYSDIR/portno ] && echo "$PORTNAME" > $SYSDIR/portno - else - [ -e $SYSDIR/portname ] && echo "$PORTNAME" > $SYSDIR/portname - fi +if [ ! -e $SYSDIR ]; then + echo "$SUBCHANNELS" > $DIR/group + i=0 + while [ $i -lt 20 ]; do + [ -e $SYSDIR ] && break + sleep 0.1 + i=$(($i+1)) + done + + [ ! -e $SYSDIR ] && exit 1 fi -if [ "$NETTYPE" = "ctc" -a -n "$CTCPROT" ]; then - echo "$CTCPROT" > $SYSDIR/protocol + +# check if the interface is already online +if [ -e $SYSDIR/online ]; then + read on <$SYSDIR/online + [ "$on" = "1" ] && exit 0 fi + +# first set layer2, other options may depend on it +[ -n "$LAYER2" ] && echo $LAYER2 > $SYSDIR/layer2 + if [ -n "$OPTIONS" ]; then - - for i in $OPTIONS; do - echo "${i//*=/}" > "$SYSDIR/${i//=*/}" - done + for i in $OPTIONS; do + OPT=${i%%=*} + VAL=${i##*=} + if [ -e "$SYSDIR/$OPT" ]; then + echo "$VAL" > "$SYSDIR/$OPT" || \ + echo "Could not set value \"$VAL\" for OPTION \"$OPT\" with SUBCHANNELS \"$SUBCHANNELS\"" + else + echo "OPTION \"$OPT\" does not exist for SUBCHANNELS \"$SUBCHANNELS\"" + fi + done fi + [ -e $SYSDIR/online ] && echo 1 > $SYSDIR/online |