]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/95zfcp_rules/parse-zfcp.sh
fix(zfcp_rules): correct shellcheck regression when parsing ccw args
[thirdparty/dracut.git] / modules.d / 95zfcp_rules / parse-zfcp.sh
CommitLineData
add1ea88 1#!/bin/bash
d6f0467e
HR
2
3create_udev_rule() {
4 local ccw=$1
5 local wwpn=$2
6 local lun=$3
7 local _rule=/etc/udev/rules.d/51-zfcp-${ccw}.rules
d6f0467e 8 local _cu_type _dev_type
d6f0467e 9
032ecd95
HH
10 if [ -x /sbin/cio_ignore ] && cio_ignore -i "$ccw" > /dev/null; then
11 cio_ignore -r "$ccw"
5e7bbe43
HR
12 fi
13
032ecd95
HH
14 if [ -e /sys/bus/ccw/devices/"${ccw}" ]; then
15 read -r _cu_type < /sys/bus/ccw/devices/"${ccw}"/cutype
16 read -r _dev_type < /sys/bus/ccw/devices/"${ccw}"/devtype
d6f0467e 17 fi
9a52c3fd
HH
18 if [ "$_cu_type" != "1731/03" ]; then
19 return 0
d6f0467e 20 fi
9a52c3fd
HH
21 if [ "$_dev_type" != "1732/03" ] && [ "$_dev_type" != "1732/04" ]; then
22 return 0
d6f0467e
HR
23 fi
24
9ea66e56 25 [ -z "$wwpn" ] || [ -z "$lun" ] && return
032ecd95 26 m=$(sed -n "/.*${wwpn}.*${lun}.*/p" "$_rule")
9a52c3fd 27 if [ -z "$m" ]; then
032ecd95 28 cat >> "$_rule" << EOF
d6f0467e
HR
29ACTION=="add", KERNEL=="rport-*", ATTR{port_name}=="$wwpn", SUBSYSTEMS=="ccw", KERNELS=="$ccw", ATTR{[ccw/$ccw]$wwpn/unit_add}="$lun"
30EOF
31 fi
32}
33
16931f52
LG
34if [[ -f /sys/firmware/ipl/ipl_type ]] \
35 && [[ $(< /sys/firmware/ipl/ipl_type) == "fcp" ]]; then
c8e53123 36 (
4a9b165d 37 read -r _wwpn < /sys/firmware/ipl/wwpn
38 read -r _lun < /sys/firmware/ipl/lun
39 read -r _ccw < /sys/firmware/ipl/device
c8e53123 40
032ecd95 41 create_udev_rule "$_ccw" "$_wwpn" "$_lun"
c8e53123
HR
42 )
43fi
44
d6f0467e
HR
45for zfcp_arg in $(getargs rd.zfcp); do
46 (
8b0791fa 47 OLDIFS="$IFS"
d6f0467e 48 IFS=","
032ecd95 49 # shellcheck disable=SC2086
d6f0467e 50 set $zfcp_arg
8b0791fa 51 IFS="$OLDIFS"
032ecd95 52 create_udev_rule "$1" "$2" "$3"
d6f0467e
HR
53 )
54done
55
56for zfcp_arg in $(getargs root=) $(getargs resume=); do
57 (
58 case $zfcp_arg in
59 /dev/disk/by-path/ccw-*)
60 ccw_arg=${zfcp_arg##*/}
9be4be7a 61 ;;
d6f0467e 62 esac
9a52c3fd 63 if [ -n "$ccw_arg" ]; then
8b0791fa 64 OLDIFS="$IFS"
d6f0467e 65 IFS="-"
5d2bda46
IK
66 # shellcheck disable=SC2086
67 set -- $ccw_arg
8b0791fa 68 IFS="$OLDIFS"
c8e53123
HR
69 _wwpn=${4%:*}
70 _lun=${4#*:}
032ecd95 71 create_udev_rule "$2" "$wwpn" "$lun"
d6f0467e
HR
72 fi
73 )
74done