diff options
author | Dan Horák <dan@danny.cz> | 2010-03-25 15:44:50 +0100 |
---|---|---|
committer | Dan Horák <dan@danny.cz> | 2010-03-25 15:44:50 +0100 |
commit | 6510534606c3940390873580fca0b70cae4eea35 (patch) | |
tree | 4c2a82127b134f88c088f2dfa97d763418ef389d | |
parent | 6cbb2949f5b2c2d5eff141be21b53a0d3b6ca240 (diff) | |
download | utils-6510534606c3940390873580fca0b70cae4eea35.tar.gz utils-6510534606c3940390873580fca0b70cae4eea35.tar.xz utils-6510534606c3940390873580fca0b70cae4eea35.zip |
import 20100112
-rw-r--r-- | device_cio_free | 76 |
1 files changed, 49 insertions, 27 deletions
diff --git a/device_cio_free b/device_cio_free index 599f5ae..a17662b 100644 --- a/device_cio_free +++ b/device_cio_free @@ -22,10 +22,12 @@ BLACKLIST=/proc/cio_ignore VERBOSE= PATH=/bin:/usr/bin:/sbin:/usr/sbin ALL_DEVICES= +WAITING_TIMEOUT=60 # maximum time to wait for all devices to appear +WAITING_TOTAL=0 # actual time spent waiting for devices usage() { - echo "$0 [-h|--help] [-V|--verbose]" + echo "Usage: $CMD [-h|--help] [-V|--verbose]" exit 1 } @@ -39,7 +41,7 @@ free_device() DEV=$(echo $1 | tr "A-Z" "a-z") [ $VERBOSE ] && echo "Freeing device(s) $DEV" - if [ echo "free $DEV" > $BLACKLIST 2> /dev/null ]; then + if ! echo "free $DEV" > $BLACKLIST 2> /dev/null ; then echo "Error: can't free device(s) $DEV" else if [ -z $ALL_DEVICES ]; then @@ -59,12 +61,18 @@ wait_on_device() DEV=$1 DEVICE_ONLINE=/sys/bus/ccw/devices/$DEV/online - + [ $VERBOSE ] && echo "Waiting on device $DEV" [ -f "$DEVICE_ONLINE" ] && return for t in 1 2 3 4 5 do + if [ $WAITING_TOTAL -ge $WAITING_TIMEOUT ]; then + [ $VERBOSE ] && echo "Waiting timeout of $WAITING_TIMEOUT seconds reached" + break + fi + WAITING_TOTAL=$(($WAITING_TOTAL + $t)) + [ $VERBOSE ] && echo "Waiting additional $t second(s) and $WAITING_TOTAL second(s) in total" sleep $t [ -f "$DEVICE_ONLINE" ] && return done @@ -72,7 +80,8 @@ wait_on_device() } # check how we were called -case $(basename "$0") in +CMD=$(basename "$0") +case $CMD in "dasd_cio_free") CONFIG=$DASDCONFIG MODE=dasd @@ -148,14 +157,14 @@ if [ $MODE = "znet" ]; then *) [ -z "$line" ] && continue # grep 2 or 3 channels from beginning of each line - DEVICES=$(echo $line | egrep -i -o "^([0-9]\.[0-9]\.[a-f0-9]+,){1,2}([0-9]\.[0-9]\.[a-f0-9]+)") + DEVICES=$(echo $line | grep -E -i -o "^([0-9]\.[0-9]\.[a-f0-9]+,){1,2}([0-9]\.[0-9]\.[a-f0-9]+)") free_device $DEVICES ;; esac done < $CONFIG fi # process channels from network interface configurations - for line in $(egrep -i -h "^[[:space:]]*SUBCHANNELS=['\"]?([0-9]\.[0-9]\.[a-f0-9]+,){1,2}([0-9]\.[0-9]\.[a-f0-9]+)['\"]?([[:space:]]+#|[[:space:]]*$)" /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null) + for line in $(grep -E -i -h "^[[:space:]]*SUBCHANNELS=['\"]?([0-9]\.[0-9]\.[a-f0-9]+,){1,2}([0-9]\.[0-9]\.[a-f0-9]+)['\"]?([[:space:]]+#|[[:space:]]*$)" /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null) do eval "$line" free_device $SUBCHANNELS @@ -164,40 +173,53 @@ fi # wait until recently unblocked devices are ready # at this point we know the content of ALL_DEVICES is syntacticly correct +OLD_IFS=$IFS IFS="," set $ALL_DEVICES -while [ "$1" ] +for DEV in $* do - DEV="$1" IFS="." # get the lower bound for range or get the single device LOWER=${DEV%%-*} - read -a L <<< "$LOWER" - if [ ${#L[@]} -eq 1 ]; then - L[2]=${L[0]} - L[0]=0 - L[1]=0 + set $LOWER + if [ $# -eq 1 ]; then + L0=0 + L1=0 + L2=$(printf "%d" "0x$1") + else + L0=$(printf "%d" "0x$1") + L1=$(printf "%d" "0x$2") + L2=$(printf "%d" "0x$3") fi # get the upper bound for range or get the single device UPPER=${DEV##*-} - read -a U <<< "$UPPER" - if [ ${#U[@]} -eq 1 ]; then - U[2]=${U[0]} - U[0]=0 - U[1]=0 + set $UPPER + if [ $# -eq 1 ]; then + U0=0 + U1=0 + U2=$(printf "%d" "0x$1") + else + U0=$(printf "%d" "0x$1") + U1=$(printf "%d" "0x$2") + U2=$(printf "%d" "0x$3") fi + IFS=$OLD_IFS + # iterate thru all devices - for (( i=0x${L[0]}; i<=0x${U[0]}; i++ )); do - for (( j=0x${L[1]}; j<=0x${U[1]}; j++ )); do - for (( k=0x${L[2]}; k<=0x${U[2]}; k++ )); do - wait_on_device "$(printf %x.%x.%04x $i $j $k)" - done + for i in $(seq $L0 $U0); do + [ $i -eq $L0 ] && LJ=$L1 || LJ=0 + [ $i -eq $U0 ] && UJ=$U1 || UJ=3 + + for j in $(seq $LJ $UJ); do + [ $i -eq $L0 -a $j -eq $L1 ] && LK=$L2 || LK=0 + [ $i -eq $U0 -a $j -eq $U1 ] && UK=$U2 || UK=65535 + + for k in $(seq $LK $UK); do + wait_on_device "$(printf %x.%x.%04x $i $j $k)" + done + done done - done - - # go to the next device - shift done |