forked from SUSE/s390-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zfcp_host_configure
186 lines (158 loc) · 4.95 KB
/
zfcp_host_configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/sh
#
# zfcp_host_configure
#
# Configures a zfcp host adapter
#
# Usage:
# zfcp_host_configure <ccwid> <online>
#
# ccwid = x.y.ssss where
# x is always 0 until IBM creates something that uses that number
# y is the logical channel subsystem (lcss) number. Most often this is 0, but it could be non-zero
# ssss is the four digit subchannel address of the device, in hexidecimal, with leading zeros.
# online = 0 to take the device offline
# 1 to bring the device online
#
# Return codes
# 1 sysfs not mounted
# 2 invalid value for <online>
# 3 device <ccwid> does not exist
# 4 module zfcp could not be loaded
# 5 adapter status could not be changed
# 6 wwpn ports still active
# 10 adapter active but allow_lun_scan active
#
if [ "${DEBUG}" != "yes" ]; then
DEBUG="no"
fi
DATUM=$(date)
add_channel_for_cio() {
echo "$* # $DATUM" >> /boot/zipl/active_devices.txt
}
remove_channel_for_cio() {
[ -w /boot/zipl/active_devices.txt ] && sed -i -e "/^$1/d" /boot/zipl/active_devices.txt
}
mesg () {
echo "$@"
}
debug_mesg () {
case "$DEBUG" in
yes) mesg "$@" ;;
*) ;;
esac
}
if [ $# -ne 2 ] ; then
echo "Usage: $0 <ccwid> <online>"
echo " ccwid = x.y.ssss where"
echo " x is always 0 until IBM creates something that uses that number"
echo " y is the logical channel subsystem (lcss) number. Most often this is 0, but it could be non-zero"
echo " ssss is the four digit subchannel address of the device, in hexidecimal, with leading zeros."
echo " online = 0 to take the device offline"
echo " 1 to bring the device online"
exit 1
fi
# Get the mount point for sysfs
while read MNTPT MNTDIR MNTSYS MNTTYPE; do
if test "$MNTSYS" = "sysfs"; then
SYSFS="$MNTDIR"
break;
fi
done </proc/mounts
if [ -z "$SYSFS" ]; then
mesg "/sysfs not present"
exit 1
fi
CCW_CHAN_ID=$1
ONLINE=$2
MODULE=zfcp
if [ -z "$CCW_CHAN_ID" ] ; then
mesg "No CCW device specified"
exit 1
fi
if [ -z "$ONLINE" ] || [ "$ONLINE" != "1" -a "$ONLINE" != "0" ]; then
mesg "Invalid device status $ONLINE"
exit 2
fi
_ccw_dir=${SYSFS}/bus/ccw/devices
_zfcp_dir="$_ccw_dir/$CCW_CHAN_ID"
if test ! -d "$_zfcp_dir" ; then
mesg "No device ${CCW_CHAN_ID}"
exit 3
fi
# Check whether we need to load the zfcp module
if test ! -d "${SYSFS}/bus/ccw/drivers/zfcp"; then
modprobe ${MODULE}
# Re-check whether module loading has succeeded
if test ! -d "${SYSFS}/bus/ccw/drivers/zfcp"; then
mesg "Could not load module ${MODULE}"
exit 4
fi
fi
RULES_DIR=/etc/udev/rules.d
RULES_FILE=51-zfcp-${CCW_CHAN_ID}.rules
ALREADY_ONLINE=0
# Check whether we need to do something
_zfcp_dev_status=$(cat $_zfcp_dir/online)
if [ "$_zfcp_dev_status" -eq "$ONLINE" ]; then
debug_mesg "zFCP adapter ${CCW_CHAN_ID} already in status ${ONLINE}"
ALREADY_ONLINE=1
fi
debug_mesg "Configuring device ${CCW_CHAN_ID}"
if [ -f ${RULES_DIR}/${RULES_FILE} ]; then
rm -f ${RULES_DIR}/${RULES_FILE}
fi
if [ "$ONLINE" -eq "1" ]; then
if [ "${ALREADY_ONLINE}" -eq "0" ]; then
# Activate the device
echo "$ONLINE" > $_zfcp_dir/online
# Now wait for the adapter to initialize
/sbin/udevadm settle
fi
for loop in 1 2 3 4 5 ; do
read status < /sys/bus/ccw/devices/$CCW_CHAN_ID/status
(( $status & 0x10000000 )) && break;
done
read wwpn_status < /sys/bus/ccw/devices/$CCW_CHAN_ID/status
if !(( $wwpn_status & 0x10000000 )) ; then
echo 0 > /sys/bus/ccw/devices/$CCW_CHAN_ID/online
mesg "Could not activate adapter, status $wwpn_status"
exit 5
fi
# Write the configuration file
if test -d ${RULES_DIR}; then
cat > ${RULES_DIR}/${RULES_FILE} <<EOF
# Configuration for the zfcp adapter at CCW ID ${CCW_CHAN_ID}
ACTION=="add", SUBSYSTEM=="ccw", KERNEL=="$CCW_CHAN_ID", IMPORT{program}="collect $CCW_CHAN_ID %k $CCW_CHAN_ID zfcp"
ACTION=="add", SUBSYSTEM=="drivers", KERNEL=="zfcp", IMPORT{program}="collect $CCW_CHAN_ID %k $CCW_CHAN_ID zfcp"
ACTION=="add", ENV{COLLECT_$CCW_CHAN_ID}=="0", ATTR{[ccw/$CCW_CHAN_ID]online}="1"
EOF
fi
add_channel_for_cio "${CCW_CHAN_ID}"
# Check whether we need to do something
read allow_lun_scan < /sys/module/zfcp/parameters/allow_lun_scan
if [ "$allow_lun_scan" = "Y" ] ; then
for host in ${_zfcp_dir}/host* ; do
[ -d $host ] || continue
hba_num=${host##*host}
done
# Automatic LUN scan is only possible on NPIV ports
read port_type < /sys/class/fc_host/host${hba_num}/port_type
if [ "$port_type" = "NPIV VPORT" ] ; then
exit 10;
fi
fi
else
echo "0" > ${_zfcp_dir}/online
# Re-read to check whether we have succeeded
_ccw_dev_status=$(cat $_zfcp_dir/online)
if [ "$_ccw_dev_status" -ne "$ONLINE" ]; then
mesg "Could not change status of device ${CCW_CHAN_ID} to $ONLINE"
exit 5
fi
echo "${CCW_CHAN_ID}" > /sys/bus/ccw/drivers/zfcp/unbind
echo "${CCW_CHAN_ID}" > /sys/bus/ccw/drivers/zfcp/bind
remove_channel_for_cio "${CCW_CHAN_ID}"
debug_mesg "zFCP adapter at ${CCW_CHAN_ID} deactivated"
fi
# EOF