network: don't use "ifup -m"
[dracut.git] / modules.d / 80cms / cmssetup.sh
blob3b8750b610a41c683f4aa46eeca13e8f1f85579b
1 #!/bin/bash
3 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
5 function sysecho () {
6 file="$1"
7 shift
8 local i=1
9 while [ $i -le 10 ] ; do
10 if [ ! -f "$file" ]; then
11 sleep 1
12 i=$((i+1))
13 else
14 break
16 done
17 local status
18 read status < "$file"
19 if [[ ! $status == $* ]]; then
20 [ -f "$file" ] && echo $* > "$file"
24 function dasd_settle() {
25 local dasd_status=/sys/bus/ccw/devices/$1/status
26 if [ ! -f $dasd_status ]; then
27 return 1
29 local i=1
30 while [ $i -le 60 ] ; do
31 local status
32 read status < $dasd_status
33 case $status in
34 online|unformatted)
35 return 0 ;;
37 sleep 0.1
38 i=$((i+1)) ;;
39 esac
40 done
41 return 1
44 function dasd_settle_all() {
45 for dasdccw in $(while read line || [ -n "$line" ]; do echo "${line%%(*}"; done < /proc/dasd/devices) ; do
46 if ! dasd_settle $dasdccw ; then
47 echo $"Could not access DASD $dasdccw in time"
48 return 1
50 done
51 return 0
54 # prints a canonocalized device bus ID for a given devno of any format
55 function canonicalize_devno()
57 case ${#1} in
58 3) echo "0.0.0${1}" ;;
59 4) echo "0.0.${1}" ;;
60 *) echo "${1}" ;;
61 esac
62 return 0
65 # read file from CMS and write it to /tmp
66 function readcmsfile() # $1=dasdport $2=filename
68 local dev
69 local numcpus
70 local devname
71 local ret=0
72 if [ $# -ne 2 ]; then return; fi
73 # precondition: udevd created dasda block device node
74 if ! dasd_cio_free -d $1 ; then
75 echo $"DASD $1 could not be cleared from device blacklist"
76 return 1
79 modprobe dasd_mod dasd=$CMSDASD
80 modprobe dasd_eckd_mod
81 udevadm settle
83 # precondition: dasd_eckd_mod driver incl. dependencies loaded,
84 # dasd_mod must be loaded without setting any DASD online
85 dev=$(canonicalize_devno $1)
86 numcpus=$(
87 while read line || [ -n "$line" ]; do
88 if strstr "$line" "# processors"; then
89 echo ${line##*:};
90 break;
91 fi;
92 done < /proc/cpuinfo
95 if [ ${numcpus} -eq 1 ]; then
96 echo 1 > /sys/bus/ccw/devices/$dev/online
97 else
98 if ! sysecho /sys/bus/ccw/devices/$dev/online 1; then
99 echo $"DASD $dev could not be set online"
100 return 1
102 udevadm settle
103 if ! dasd_settle $dev ; then
104 echo $"Could not access DASD $dev in time"
105 return 1
109 udevadm settle
111 devname=$(cd /sys/bus/ccw/devices/$dev/block; set -- *; [ -b /dev/$1 ] && echo $1)
112 devname=${devname:-dasda}
114 [[ -d /mnt ]] || mkdir /mnt
115 if cmsfs-fuse --to=UTF-8 -a /dev/$devname /mnt; then
116 cat /mnt/$2 > /run/initramfs/$2
117 umount /mnt || umount -l /mnt
118 udevadm settle
119 else
120 echo $"Could not read conf file $2 on CMS DASD $1."
121 ret=1
124 if ! sysecho /sys/bus/ccw/devices/$dev/online 0; then
125 echo $"DASD $dev could not be set offline again"
126 #return 1
128 udevadm settle
130 # unbind all dasds to unload the dasd modules for a clean start
131 ( cd /sys/bus/ccw/drivers/dasd-eckd; for i in *.*; do echo $i > unbind;done)
132 udevadm settle
133 modprobe -r dasd_eckd_mod
134 udevadm settle
135 modprobe -r dasd_diag_mod
136 udevadm settle
137 modprobe -r dasd_mod
138 udevadm settle
139 return $ret
142 processcmsfile()
144 source /tmp/cms.conf
145 SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')"
147 if [[ $NETTYPE ]]; then
149 echo -n $NETTYPE,$SUBCHANNELS
150 [[ $PORTNAME ]] && echo -n ",portname=$PORTNAME"
151 [[ $LAYER2 ]] && echo -n ",layer2=$LAYER2"
152 [[ "$NETTYPE" = "ctc" ]] && [[ $CTCPROT ]] && echo -n ",protocol=$CTCPROT"
153 echo
154 ) >> /etc/ccw.conf
156 OLDIFS=$IFS
157 IFS=,
158 read -a subch_array <<< "indexzero,$SUBCHANNELS"
159 IFS=$OLDIFS
160 devbusid=${subch_array[1]}
161 if [ "$NETTYPE" = "ctc" ]; then
162 driver="ctcm"
163 else
164 driver=$NETTYPE
167 printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="%s", KERNELS=="%s", ENV{INTERFACE}=="?*", RUN+="/sbin/initqueue --onetime --unique --name cmsifup-$env{INTERFACE} /sbin/cmsifup $env{INTERFACE}"\n' "$driver" "$devbusid" > /etc/udev/rules.d/99-cms.rules
168 # remove the default net rules
169 rm -f -- /etc/udev/rules.d/91-default-net.rules
170 [[ -f /etc/udev/rules.d/90-net.rules ]] \
171 || printf 'SUBSYSTEM=="net", ACTION=="online", RUN+="/sbin/initqueue --onetime --env netif=$env{INTERFACE} source_hook initqueue/online"\n' >> /etc/udev/rules.d/99-cms.rules
172 udevadm control --reload
173 znet_cio_free
176 if [[ $DASD ]] && [[ $DASD != "none" ]]; then
177 echo $DASD | normalize_dasd_arg > /etc/dasd.conf
178 echo "options dasd_mod dasd=$DASD" > /etc/modprobe.d/dasd_mod.conf
179 dasd_cio_free
182 unset _do_zfcp
183 for i in ${!FCP_*}; do
184 echo "${!i}" | while read port rest || [ -n "$port" ]; do
185 case $port in
186 *.*.*)
188 *.*)
189 port="0.$port"
192 port="0.0.$port"
194 esac
195 echo $port $rest >> /etc/zfcp.conf
196 done
197 _do_zfcp=1
198 done
199 [[ $_do_zfcp ]] && zfcp_cio_free
200 unset _do_zfcp
203 [[ $CMSDASD ]] || CMSDASD=$(getarg "CMSDASD=")
204 [[ $CMSCONFFILE ]] || CMSCONFFILE=$(getarg "CMSCONFFILE=")
206 # Parse configuration
207 if [ -n "$CMSDASD" -a -n "$CMSCONFFILE" ]; then
208 if readcmsfile $CMSDASD $CMSCONFFILE; then
209 ln -s /run/initramfs/$CMSCONFFILE /tmp/$CMSCONFFILE
210 ln -s /run/initramfs/$CMSCONFFILE /tmp/cms.conf
211 processcmsfile