-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdasd_configure
More file actions
executable file
·313 lines (283 loc) · 8.87 KB
/
dasd_configure
File metadata and controls
executable file
·313 lines (283 loc) · 8.87 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#! /bin/sh
#
# dasd_configure
# $Id: dasd_configure,v 1.10 2004/11/26 15:50:48 hare Exp $
#
# Copyright (c) 2001-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# Configures or deconfigures a DASD device
#
# Usage:
# dasd_configure [-f -t <dasd_type> ] <ccwid> <online> [use_diag]
#
# -f force creation of udev rules, do not check values in /sys.
# -t DASD type. Must be provided if -f is used.
# 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
# use_diag = 0 to _not_ use z/VM DIAG250 I/O, which is the default
# 1 to use z/VM DIAG250 I/O
#
# Return values:
# 1 If the "Usage:" line is displayed, not enough parameters specified.
# 1 sysfs not mounted (if the "Usage:" line is not displayed).
# 2 Invalid status for <online>
# 3 No device found for <ccwid>
# 4 Could not change state of the device
# 5 Device is not a DASD
# 6 Could not load module
# 7 Failed to activate DASD
# 8 DASD not formatted
# 9 Only dasd-fba or dasd-eckd is supported.
#
if [ "${DEBUG}" != "yes" ]; then
DEBUG="no"
fi
exitcode=0
DASD_FORCE=0
DASD_TYPE="unknown"
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="4"
fi
case "$1" in
0) return 0 ;;
7) exit 4 ;;
*) exit $_state ;;
esac
}
debug_mesg () {
case "$DEBUG" in
yes) mesg "$@" ;;
*) ;;
esac
}
if [ $# -lt 2 ] ; then
echo "Usage: $0 [options] <ccwid> <online> [use_diag]"
echo
echo " -f force creation of udev rules, do not check values in /sys."
echo " -t DASD type. Must be provided if -f is used."
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"
echo " use_diag = 0 to _not_ use z/VM DIAG250 I/O, which is the default"
echo " 1 to use z/VM DIAG250 I/O"
exit 1
fi
while [ $# -gt 0 ] ; do
case "$1" in
-f) # force creation of udev rules, do not check values in /sys
DASD_FORCE=1
;;
-t*) # drive type. Must be provided if -f is used.
if [ "$1" = "-t" ] ; then
if [ "$2" = "dasd-eckd" -o "$2" = "dasd-fba" ]; then
DASD_TYPE=$2
shift
else
debug_mesg "Only dasd-eckd or dasd-fba are supported."
exit 9
fi
fi
;;
*)
break;
;;
esac
shift
done
if [ $DASD_FORCE -eq 0 ]; then
grep -qe ^'sysfs /sys' < /proc/mounts
if [ $? -ne 0 ]; then
mesg "/sysfs not present"
exit 1
fi
else
CCW_CHAN_NAME=$DASD_TYPE
case $DASD_TYPE in
*eckd)
DISCIPLINE=ECKD
;;
*fba)
DISCIPLINE=FBA
;;
*)
mesg "Only dasd-eckd or dasd-fba are supported."
exit 9
;;
esac
fi # First instance of if [ $DASD_FORCE -eq 0 ]
CCW_CHAN_ID=$1
ONLINE=$2
USE_DIAG=$3
[ -z "$USE_DIAG" ] && USE_DIAG=0
if [ -z "$ONLINE" ] || [ "$ONLINE" -ne "1" -a "$ONLINE" -ne "0" ]; then
mesg "Invalid device status $ONLINE"
mesg "It must be a zero or a one."
exit 2
fi
if [ $DASD_FORCE -eq 0 ]; then
_ccw_dir=/sys/bus/ccw/devices
debug_mesg "Configuring device ${CCW_CHAN_ID}"
_ccw_status_dir="$_ccw_dir/$CCW_CHAN_ID"
if ! -d "$_ccw_status_dir" ; then #to be replaced
if test "$ONLINE" -eq 1 ; then
mesg "No device ${CCW_CHAN_ID}"
exit 3
fi
_ccw_dev_status=0
else
CCW_CHAN_NAME=$(lszdev ${CCW_CHAN_ID} -c TYPE -n)
if [ -z "$CCW_CHAN_NAME" ]; then
mesg "Not a DASD device (cu $_cutype, dev $_devtype)"
exit 5
fi
_ccw_dev_status=$(lszdev ${CCW_CHAN_ID} -i | grep online | grep -o '[0-9]*' | head -1)
fi # if test ! -d "$_ccw_status_dir"
#
# We check whether we are running under z/VM by looking for the string
# "Control Program: z/VM" in /proc/sysinfo
#
/bin/grep "Control Program: z/VM" /proc/sysinfo 2>&1 > /dev/null
if [ -x /sbin/vmcp -a $? -eq 0 ]; then
# Unconditionally load the vmcp module, loader might be broken
[ -x /sbin/modprobe ] && /sbin/modprobe -q vmcp
# Wait until udev is settled
[ -x /sbin/udevadm ] && /sbin/udevadm settle --timeout=30
# Check read-only status of virtual DASDs from z/VM
if /sbin/vmcp q v dasd > /dasd_attr.lst 2> /dev/null; then
while read x dev type label attr1 attr2 rest; do
dev=`echo $dev|tr A-F a-f`
if test "$type" = "ON"; then
attr="$attr2"
else
attr="$attr1"
fi
if [ "$CCW_CHAN_ID" = "0.0.$dev" ]; then
if test "$attr" = "R/O"; then
_ccw_use_readonly="1"
fi
fi
done < /dasd_attr.lst
fi
rm -f /dasd_attr.lst
fi # if [ -x /sbin/vmcp -a $? -eq 0 ]
if [ "$ONLINE" -eq 1 ]; then
# Check whether we need to do something
_ccw_use_diag=$(lszdev ${CCW_CHAN_ID} -i | grep "use_diag" | grep -o '[0-9]*' | head -1)
if [ "$_ccw_use_diag" -ne "$USE_DIAG" ] &&
[ "$_ccw_dev_status" -eq 1 ] ; then
# We need to change the DIAG access mode
# so we have to set the device offline first
debug_mesg "Setting device offline for DIAG access"
chzdev --disable $CCW_CHAN_ID
exit_on_err $? offline
fi
if [ "$_ccw_dev_status" -eq 0 ]; then
# Set readonly access if detected
if [ "$_ccw_use_readonly" ]; then
debug_mesg "Setting device read-only"
_opts="${_opts} readonly=1"
fi
if [ "$USE_DIAG" -eq 1 ]; then
# Load the diag module if possible
[ -x /sbin/modprobe ] && /sbin/modprobe -q dasd_diag_mod
_has_dasd_diag=$(/bin/sed -n '/^dasd_diag_mod/p' /proc/modules)
if [ "$_has_dasd_diag" ]; then
# DIAG mode is special:
# We can only be sure if DIAG is available
# _after_ we have activated the device
debug_mesg "Activating DIAG access mode"
_ccw_use_diag=$(lszdev ${CCW_CHAN_ID} -i | grep "use_diag" | grep -o '[0-9]*' | head -1)
# Set the device online
debug_mesg "Setting device online"
chzdev --enable $CCW_CHAN_ID use_diag=1
# Re-read device status
_ccw_dev_status=$(lszdev ${CCW_CHAN_ID} -i | grep online | grep -o '[0-9]*' | head -1)
if [ "$_ccw_dev_status" -eq 0 ]; then
mesg "Could not activate DIAG access mode for device ${CCW_CHAN_ID}"
USE_DIAG=0
# Set the device online
debug_mesg "Setting device online"
chzdev --enable $CCW_CHAN_ID use_diag=$USE_DIAG
exit_on_err $? online
else
MODULE=dasd_diag_mod
fi
else
debug_mesg "DIAG mode not available"
USE_DIAG=0
# Set the device online
debug_mesg "Setting device online"
chzdev --enable $CCW_CHAN_ID
exit_on_err $? online
fi # if [ "$_has_dasd_diag" ];
else
if [ "$_ccw_use_diag" -eq 1 ] ; then
debug_mesg "Deactivating DIAG access mode"
_ccw_use_diag=$(lszdev ${CCW_CHAN_ID} -i | grep "use_diag" | grep -o '[0-9]*' | head -1)
fi
# Set the device online
debug_mesg "Setting device online"
chzdev --enable $CCW_CHAN_ID use_diag=0
exit_on_err $? online
fi # if [ "$USE_DIAG" -eq 1 ]
# Wait for the device to come online
read _dasd_state < $_ccw_status_dir/status #to be replaced
i=0
while [ "$_dasd_state" != "online" ] ; do
if [ "$_dasd_state" = "unformatted" ] ; then
mesg "Device ${CCW_CHAN_ID} is unformatted"
exitcode=8
break
fi
[ $i -gt 30 ] && break
i=$(expr $i + 1)
sleep .1
read _dasd_state < $_ccw_status_dir/status #to be replaced
done
else
debug_mesg "Device ${CCW_CHAN_ID} is already online"
fi # if [ "$_ccw_dev_status" -eq 0 ]
read _dasd_state < $_ccw_status_dir/status #to be replaced
if [ "$_dasd_state" != "online" ] && [ "$_dasd_state" != "unformatted" ] ; then
mesg "Failed to activate device ${CCW_CHAN_ID}, device in state $_dasd_state"
exit 7
fi
else
if [ "$_ccw_dev_status" -eq 1 ]; then
# Set the device offline
debug_mesg "Setting device offline"
chzdev --disable ${CCW_CHAN_ID}
exit_on_err $? offline
fi
if [ -d "$_ccw_status_dir" ] ; then
# Always disabling DIAG access
chzdev ${CCW_CHAN_ID} -q use_diag=0
fi
# Set readonly access if detected
if [ "$_ccw_use_readonly" ]; then
debug_mesg "Setting device read-only"
chzdev ${CCW_CHAN_ID} -q readonly=1
fi
fi # if [ "$ONLINE" -eq 1 ]
# Wait until udev is settled
[ -x /sbin/udevadm ] && /sbin/udevadm settle --timeout=30
fi # Second instance of if [ $DASD_FORCE -eq 0 ]
exit $exitcode