summaryrefslogtreecommitdiffstats
path: root/device_cio_free
diff options
context:
space:
mode:
authorDan Horák <dan@danny.cz>2010-03-25 15:44:11 +0100
committerDan Horák <dan@danny.cz>2010-03-25 15:44:11 +0100
commitbbde12a497fdc7d425a27c9bf8fe9f36ef1fd83b (patch)
tree9cf067d89c872bb2a8bd4dd087b15c685a95451b /device_cio_free
downloadutils-bbde12a497fdc7d425a27c9bf8fe9f36ef1fd83b.tar.gz
utils-bbde12a497fdc7d425a27c9bf8fe9f36ef1fd83b.tar.xz
utils-bbde12a497fdc7d425a27c9bf8fe9f36ef1fd83b.zip
initial import
Diffstat (limited to 'device_cio_free')
-rw-r--r--device_cio_free128
1 files changed, 128 insertions, 0 deletions
diff --git a/device_cio_free b/device_cio_free
new file mode 100644
index 0000000..0bfaa8a
--- /dev/null
+++ b/device_cio_free
@@ -0,0 +1,128 @@
+#!/bin/sh
+#
+# Copyright 2009 Red Hat, Inc.
+# License: GPLv2
+# Author: Dan Horak <dhorak@redhat.com>
+#
+# unblock devices listed in various config files
+#
+# it uses dasd and zfcp config file
+# config file syntax:
+# deviceno options
+# or
+# deviceno WWPN FCPLUN
+#
+# also processes the system ccw config file and network interface configurations
+#
+
+DASDCONFIG=/etc/dasd.conf
+ZFCPCONFIG=/etc/zfcp.conf
+ZNETCONFIG=/etc/ccw.conf
+BLACKLIST=/proc/cio_ignore
+VERBOSE=
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+usage()
+{
+ echo "$0 [-h|--help] [-V|--verbose]"
+ exit 1
+}
+
+# check how we were called
+case $(basename "$0") in
+ "dasd_cio_free")
+ CONFIG=$DASDCONFIG
+ MODE=dasd
+ ;;
+ "zfcp_cio_free")
+ CONFIG=$ZFCPCONFIG
+ MODE=zfcp
+ ;;
+ "znet_cio_free")
+ CONFIG=$ZNETCONFIG
+ MODE=znet
+ ;;
+ *)
+ echo "Error: unknown alias '$CMD'."
+ echo "Supported aliases are dasd_cio_free, zfcp_cio_free and znet_cio_free."
+ exit 1
+ ;;
+esac
+
+# process command line options
+if [ $# -gt 0 ]; then
+ case $1 in
+ -V|--verbose)
+ VERBOSE=yes
+ shift
+ ;;
+ -h|--help)
+ usage
+ ;;
+ *)
+ echo "Error: unknown option $1"
+ usage
+ ;;
+ esac
+fi
+
+if [ ! -f $BLACKLIST ]; then
+ echo "Error: $BLACKLIST kernel interface doesn't exist"
+ exit 2
+fi
+
+if [ $MODE = "dasd" -o $MODE = "zfcp" ]; then
+ # process the config file
+ if [ -f "$CONFIG" ]; then
+ tr "A-Z" "a-z" < $CONFIG | while read line; do
+ case $line in
+ \#*) ;;
+ *)
+ [ -z "$line" ] && continue
+ set $line
+ DEVICE=$1
+ [ $VERBOSE ] && echo "Freeing device $DEVICE"
+ echo "free $DEVICE" > $BLACKLIST 2> /dev/null || echo "Error: can't free device $DEVICE"
+ ;;
+ esac
+ done
+ fi
+fi
+
+if [ $MODE = "dasd" ]; then
+ # process the device list defined as option for the dasd module
+ DEVICES=$(modprobe --showconfig | grep "options[[:space:]]\+dasd_mod" | \
+ sed -e 's/.*[[:space:]]dasd=\([^[:space:]]*\).*/\1/' -e 's/([^)]*)//g' \
+ -e 's/nopav\|nofcx\|autodetect\|probeonly//g' -e 's/,,/,/g' -e 's/^,//' -e 's/,$//' | tr "A-Z" "a-z")
+
+ [ $VERBOSE ] && echo "Freeing device(s) $DEVICES"
+ echo "free $DEVICES" > $BLACKLIST 2> /dev/null || echo "Error: can't free device(s) $DEVICES"
+fi
+
+if [ $MODE = "znet" ]; then
+ # process the config file
+ if [ -f "$CONFIG" ]; then
+ tr "A-Z" "a-z" < $CONFIG | while read line; do
+ case $line in
+ \#*) ;;
+ *)
+ [ -z "$line" ] && continue
+ # grep 2 or 3 channels from beginning of each line
+ DEVICES=$(echo $line | egrep -o "^([0-9]\.[0-9]\.[a-f0-9]+,){1,2}([0-9]\.[0-9]\.[a-f0-9]+)")
+ if [ $DEVICES ]; then
+ [ $VERBOSE ] && echo "Freeing device(s) $DEVICES"
+ echo "free $DEVICES" > $BLACKLIST 2> /dev/null || echo "Error: can't free device(s) $DEVICES"
+ fi
+ ;;
+ esac
+ done
+ 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)
+ do
+ eval "$line"
+ DEVICES=$(echo $SUBCHANNELS | tr "A-Z" "a-z")
+ [ $VERBOSE ] && echo "Freeing device(s) $DEVICES"
+ echo "free $DEVICES" > $BLACKLIST 2> /dev/null || echo "Error: can't free device(s) $DEVICES"
+ done
+fi