]> git.pld-linux.org Git - packages/EMCpower.git/blame - PowerPath.init
- just add it here
[packages/EMCpower.git] / PowerPath.init
CommitLineData
1f5c2a50
ER
1#!/bin/sh
2#
3# chkconfig: 2345 02 98
4# description: Loads and configures the EMC PowerPath drivers.
5#
6# ###################################################################
7# Copyright (c) 2000, EMC Corporation. All Rights Reserved.
8#
9# Most Recent Author: Raghu Adabala
10# Previous Authors: Raghu Adabala and Ed Goggin
11#
12# Contents:
13# Redhat support for load and configure of EMC PowerPath drivers
14# ###################################################################
15#
16
17# @(#) $Header$
18
19# Source function library.
20. /etc/rc.d/init.d/functions
21
22
23# Functions to preserve exceptional command status return values
24
25rc_reset()
26{
27 rc_cmd_stat=0
28 rc_script_stat=0
29}
30
31rc_check()
32{
33 rc_cmd_stat=$?
34 test $rc_cmd_stat -ne 0 && rc_script_stat=$rc_cmd_stat
35 return $rc_cmd_stat
36}
37
38rc_status()
39{
40 rc_check
41
42 if [ "$1" = "-v" ]
43 then
44 case "$rc_script_stat" in
45 0)
46 ok
47 ;;
48 *)
49 fail
50 ;;
51 esac
52 fi
53 return $rc_script_stat
54}
55
56rc_exit()
57{
58 exit $rc_script_stat
59}
60
61#
62# ###################################################################
63# Copyright (c) 2005, EMC Corporation. All Rights Reserved.
64#
65#
66# Contents:
67# This scripts loads and configures the EMC PowerPath driver(s) on
68# bootup and uloads PowerPath on shutdown.
69# ###################################################################
70#
71
72# @(#) $Header$
73
74PATH=/usr/bin/:/bin:/sbin:/usr/sbin
75
76# the following are the internationalization specific lines
77TEXTDOMAIN=PowerPath
78export TEXTDOMAIN
79export RPM_INSTALL_PREFIX
80# end of internationalization
81
82pp_stop_lvm()
83{
84 if test -x /sbin/vgchange -a -x /sbin/vgscan ; then
85 open_vol=""
86 vgname=`vgdisplay 2>/dev/null| grep "VG Name" | sed -e 's/VG Name/ /g'`
87 for i in $vgname
88 do
89 pv=`vgdisplay -v $i 2>/dev/null| grep "PV Name" | awk '{ print $3 }' | grep emcpower`
90 if [ "$pv" != "" ] ; then
91 err_stop=`/sbin/vgchange -a n $i 2>&1 | grep "open logical volume"`
92 if [ "$err_stop" != "" ]; then
93 if [ "$open_vol" = "" ]; then
94 nls "Following LVM volume groups are in use:"
95 open_vol=$err_stop
96 fi
97 var1=$i
98 var2=`echo $pv`
99 echo "`nls " Volume Group: \\$var1 (\\$var2)"`"
100 fi
101 fi
102 done
103 fi
104 if [ "$open_vol" != "" ]; then
105 nls "These open logical volume devices use LUNs from Powerpath managed devices,"
106 nls "Please re-issue the command after closing these volumes."
107 return 1
108 fi
109 return 0
110}
111
112pp_start_lvm()
113{
114 if test -x /sbin/vgchange -a -x /sbin/vgscan ; then
115 /sbin/vgscan > /dev/null 2>&1
116 /sbin/vgchange -a y > /dev/null 2>&1
117 if [ $? -eq 5 ]; then ## "no volume groups" ==> success
118 /bin/true
119 fi
120 fi
121}
122# Wait for /dev/emcpower to appear.
123# $1 is the number of seconds to wait.
124
125dev_emcpower_is_back()
126{
127 /bin/bash -c "for ((cnt=$1/3; \$cnt > 0; cnt--)); do \
128 test -c /dev/emcpower && break; \
129 sleep 3; \
130 done; \
131 test -c /dev/emcpower"
132}
133
134
135# Start 32 bit Emulation library before powerpath startup for ia64
136start_32bit_emulation()
137{
138 /etc/init.d/ia32el start > /dev/null 2>&1
139 rc_check
140
141 if rc_status ; then
142 nls "\nSuccessfully started 32-bit emulation library"
143 else
144 nls "\nError in starting 32-bit emulation library"
145 fi
146}
147
148# Configure PowerPath paths
149
150configure_pp()
151{
152 if [ -f /etc/emcp_devicesDB.dat ]; then
153 if [ -f /etc/emcp_devicesDB.idx ]; then
154 /sbin/emcpmgr map -p > /dev/null 2>&1
155 rc_check
156 fi
157 fi
158
159 ## If the system has no license, config error is ok.
160
161 if /sbin/emcpreg -l 2>&1 | /usr/bin/grep '^Key' > /dev/null 2>&1; then
162 /sbin/powermt config > /dev/null 2>&1
163 else
164 /sbin/powermt config > /dev/null 2>&1
165 /bin/true
166 fi
167 rc_check
168
169 #
170 # Wait for udev to finish creating emcpower devices
171 #
172 pdfound=1
173 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
174 pdfound=1
175 for pd in `/bin/ls -d /sys/block/emcpower* 2> /dev/null`; do
176 bpd=`basename $pd`
177 if [ ! -e /dev/$bpd ]; then
178 pdfound=0
179 sleep 2
180 break;
181 fi
182 done
183 if [ "$pdfound" -eq 1 ]; then
184 break
185 fi
186 done
187 if [ "$pdfound" -eq 0 ]; then
188 [ 1 = 0 ]
189 rc_check
190 fi
191
192 /sbin/powermt load > /dev/null 2>&1
193 rc_check
194 /sbin/emcpmgr map > /dev/null 2>&1
195 rc_check
196 /sbin/powercf -C > /dev/null 2>&1
197 /sbin/powermt save > /dev/null 2>&1
198 rc_check
199 /sbin/powermt register > /dev/null 2>&1
200 rc_check
201 /sbin/powermig transition -startup -noprompt > /dev/null 2>&1
202 rc_check
203 pp_start_lvm
204}
205
206# Check for naviagent and powermt before stopping PowerPath
207
208ok_to_stop()
209{
210 ps -C naviagent >> /dev/null
211 if [ $? -eq 0 ]; then
212 nls "Navisphere agent is running."
213 eval echo "$(nls "Please stop the agent and then re-issue \$script_name stop.")"
214 return 1
215 fi
216
217 ps -C powermt >> /dev/null
218 if [ $? -eq 0 ]; then
219 nls "The powermt command is running."
220 eval echo "$(nls "Please stop powermt and then re-issue \$script_name stop.")"
221 return 1
222 fi
223
224 mig_info=`/sbin/powermig info -all`
225 if [ $? -eq 0 ]; then
226 echo "$mig_info" | grep 'No migrations found' > /dev/null
227 if test $? -ne 0 ; then
228 nls "PowerPath migrations are present."
229 eval echo "$(nls "Please cleanup the migrations and then re-issue \$script_name stop.")"
230 return 1
231 fi
232 fi
233
234 if pp_stop_lvm ; then
235 return 0
236 fi
237 return 1
238}
239
240# Load the extensions. Dependencies will load base driver.
241
242load_drivers()
243{
244 for d in `cat $ext; cat $mgr`
245 do
246 /sbin/modprobe -q -s --first-time $d
247 rc_check
248 if [ $? -ne 0 ] ; then
249 eval echo "$(nls "PowerPath could not load module \$d")"
250 break
251 fi
252 done
253
254 if dev_emcpower_is_back 60; then
255 recreate_emcpower_device
256 /sbin/powercf -K > /dev/null 2>&1
257 rc_check
258 else
259 rc_check
260 unload_drivers
261 fi
262
263 if rc_status ; then
264 /sbin/modprobe -q -s --first-time emcpioc
265 rc_check
266 if [ $? -eq 0 ] ; then
267 /sbin/modprobe -r -q -s --first-time emcpioc
268 fi
269 fi
270}
271
272# Unload drivers and extensions.
273
274unload_drivers()
275{
276 do_unload=0
277 retry=4
278 powermt prep_drv_unload > /dev/null 2>&1
279
280
281 ###
282 ### At this point, we really want the driver unload to succeed
283 ### Try hard to make it happen.
284 ###
285 while [ $retry -gt 0 ]
286 do
287 powermt remove dev=all 2> /var/tmp/.pp_exit
288 devr=$?
289 cat /var/tmp/.pp_exit | grep "not found" > /dev/null 2>&1
290 cdevs=$?
291 zerolen=`cat /var/tmp/.pp_exit | wc -c`
292 rm /var/tmp/.pp_exit
293 # reset rc status since we are not willing to
294 # report an error just yet.
295 rc_reset
296 if [ $devr -eq 0 ] ; then
297 do_unload=1
298 retry=0 #success
299 else
300 if [ $cdevs -eq 0 -o $zerolen -eq 0 ] ; then
301 do_unload=1
302 retry=0 #success
303 else
304 sleep 5
305 retry=`expr $retry - 1`
306 #nls "PowerPath devices are open."
307 #eval echo "$(nls "Please close these devices and then re-issue \$script_name stop.")"
308 #/bin/false
309 #uerr=$?
310 #return $uerr
311 fi
312 fi
313 done
314
315
316
317 if [ $do_unload -eq 1 ] ; then
318 /sbin/modprobe -r -q -s `cat $mgr; cat $ext; echo emcp emcplib`
319 uerr=$?
320 return $uerr
321 else
322 nls "PowerPath devices are open."
323 eval echo "$(nls "Please close these devices and then re-issue \$script_name stop.")"
324 /bin/false
325 uerr=$?
326 return $uerr
327 fi
328
329 nls "PowerPath could not unload PowerPath modules."
330 uerr=1
331 return $uerr
332}
333
334recreate_emcpower_device()
335{
336 #
337 # Create /dev/emcpower based on CURRENT misc driver.
338 # These values can be different when PP loads from RD.
339 #
340 rm -f /dev/emcpower
341 mmaj=`cat /sys/class/misc/emcpower/dev | awk -F : '{print $1}'`
342 mmin=`cat /sys/class/misc/emcpower/dev | awk -F : '{print $2}'`
343 mknod /dev/emcpower c $mmaj $mmin > /dev/null
344
345 if [ $? -ne 0 ]; then
346 nls "failed to create emcpower device"
347 fi
348
349}
350
351rc_reset
352script_name=PowerPath
353ext=/etc/emc/.drivers_ext
354mgr=/etc/emc/.drivers_mgr
355
356case "$1" in
357 start)
358 msg_starting "PowerPath"
359
360 ###
361 # Start the 32-bit emulation for ia64
362 ###
363 #if [ "`uname -m`" == "ia64" ]; then
364 # start_32bit_emulation
365 #fi
366
367 ###
368 # Load PP iff it is not already loaded.
369 ###
370 if rc_status ; then
371 lsmod | grep -w '^emcp' > /dev/null
372 if [ $? -ne 0 ]; then
373 load_drivers
374 else
375 if dev_emcpower_is_back 60; then
376 recreate_emcpower_device
377 /sbin/powercf -K > /dev/null 2>&1
378 rc_check
379 else
380 rc_check
381 unload_drivers
382 fi
383 # remove PIOC if it was loaded during RD boot.
384 lsmod | grep emcpioc > /dev/null
385 if [ $? -eq 0 ]; then
386 /sbin/rmmod emcpioc > /dev/null
387 fi
388 fi
389
390 if rc_status ; then
391 if dev_emcpower_is_back 60; then
392 configure_pp
393 else
394 rc_check
395 unload_drivers
396 fi
397 else
398 nls "PowerPath: unable to load PowerPath modules."
399 unload_drivers
400 fi
401 fi
402 rc_status -v
403 ;;
404
405 stop)
406 msg_stopping "PowerPath"
407 lsmod | grep -w '^emcp' > /dev/null
408 if test $? -ne 0; then
409 nls "PowerPath is not running"
410 else
411 #
412 # Tresspass can happen if new devices are added or some devices
413 # are removed by "powermt remove" before "PowerPath stop". The
414 # reason is that vgscan used by us issues "read" to all block
415 # devices.
416 # We configure all devices to avoid unnecessary trespass.
417 #
418 /sbin/powermt config > /dev/null 2>&1
419 if ok_to_stop; then
420 /sbin/powermt save > /dev/null 2>&1
421 rc_check
422 /sbin/emcpmgr unmap > /dev/null 2>&1
423 rc_check
424 /sbin/powermt remove dev=all 2> /var/tmp/.pp_exit
425 devr=$?
426 cat /var/tmp/.pp_exit | grep "not found" > /dev/null 2>&1
427 cdevs=$?
428 zerolen=`cat /var/tmp/.pp_exit | wc -c`
429 rm /var/tmp/.pp_exit
430
431 # reset rc status since we are not willing to quit
432 rc_reset
433 if [ $devr -eq 0 ] ; then
434 unload_drivers
435 rc_check
436 if [ $? -ne 0 ] ; then
437 nls "PowerPath could not unload PowerPath modules."
438 fi
439 else
440 if [ $cdevs -eq 0 -o $zerolen -eq 0 ] ; then
441 unload_drivers
442 rc_check
443 if [ $? -ne 0 ] ; then
444 nls "PowerPath could not unload PowerPath modules."
445 fi
446 else
447 nls "PowerPath devices are open."
448 eval echo "$(nls "Please close these devices and then re-issue \$script_name stop.")"
449 /sbin/emcpmgr map -p > /dev/null 2>&1
450 /sbin/powermt config > /dev/null 2>&1
451 /sbin/powermt load > /dev/null 2>&1
452 /bin/false
453 fi
454 fi
455 else
456 /bin/false ## not ok_to_stop
457 fi
458 fi
459 rc_status -v
460 ;;
461 *)
462 msg_usage "$0 {start|stop}"
463 exit 3
464 ;;
465esac
466
467rc_exit
468# vim:ts=4:sw=4:et
This page took 0.111685 seconds and 4 git commands to generate.