-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzfcp_host_configure
More file actions
executable file
·163 lines (140 loc) · 4.32 KB
/
zfcp_host_configure
File metadata and controls
executable file
·163 lines (140 loc) · 4.32 KB
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
#!/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 "$@"
}
exit_on_err() {
if [ "$2" == "online" ] || [ "$2" == "offline" ]; then
_state="5"
fi
case "$1" in
0) return 0 ;;
*) exit $_state ;;
esac
}
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
#Throw error if SYSFS is not present
grep -qe ^'sysfs /sys' < /proc/mounts
if [ $? -ne 0 ]; then
mesg "/sysfs not present"
exit 1
fi
#initial variables
CCW_CHAN_ID=$1
ONLINE=$2
MODULE=zfcp
ALREADY_ONLINE=0
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=/sys/bus/ccw/devices
_zfcp_dir="$_ccw_dir/$CCW_CHAN_ID"
if test ! -d "$_zfcp_dir" ; then #to be replaced
mesg "No device ${CCW_CHAN_ID}"
exit 3
fi
# Check whether we need to do something
_zfcp_dev_status=$(lszdev ${CCW_CHAN_ID} -i | grep online | grep -o '[0-9]*' | head -1)
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 [ "$ONLINE" -eq "1" ]; then
if [ "${ALREADY_ONLINE}" -eq "0" ]; then
# Activate the device
chzdev --enable zfcp-host ${CCW_CHAN_ID}
# 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 #to be replaced
(( $status & 0x10000000 )) && break;
done
read wwpn_status < /sys/bus/ccw/devices/$CCW_CHAN_ID/status #to be replaced
if !(( $wwpn_status & 0x10000000 )) ; then
chzdev --disable zfcp-host ${CCW_CHAN_ID}
mesg "Could not activate adapter, status $wwpn_status"
exit 5
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 #to be replaced
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 #to be replaced
if [ "$port_type" = "NPIV VPORT" ] ; then
exit 10;
fi
fi
else
chzdev --disable zfcp-host ${CCW_CHAN_ID}
# Re-read to check whether we have succeeded
_zfcp_dev_status=$(lszdev ${CCW_CHAN_ID} -i | grep online | grep -o '[0-9]*' | head -1)
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 #to be replaced
echo "${CCW_CHAN_ID}" > /sys/bus/ccw/drivers/zfcp/bind #to be replaced
remove_channel_for_cio "${CCW_CHAN_ID}"
debug_mesg "zFCP adapter at ${CCW_CHAN_ID} deactivated"
fi
exit 0