]> git.pld-linux.org Git - packages/EMCpower.git/blob - PowerPath.init
- add PLDized enable script, R: diff
[packages/EMCpower.git] / PowerPath.init
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
25 rc_reset()
26 {
27     rc_cmd_stat=0
28     rc_script_stat=0
29 }
30
31 rc_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
38 rc_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
56 rc_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
74 PATH=/usr/bin/:/bin:/sbin:/usr/sbin
75
76 # the following are the internationalization specific lines
77 TEXTDOMAIN=PowerPath
78 export TEXTDOMAIN
79 export RPM_INSTALL_PREFIX
80 # end of internationalization
81
82 pp_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
112 pp_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
125 dev_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
136 start_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
150 configure_pp()
151 {
152     if [ -f /etc/emcp_devicesDB.dat ]; then 
153         if [ -f /etc/emcp_devicesDB.idx ]; then
154             /etc/opt/emcpower/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     /etc/opt/emcpower/emcpmgr map       > /dev/null 2>&1
195     rc_check
196     /etc/opt/emcpower/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
208 ok_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
242 load_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         /etc/opt/emcpower/powercf -K        > /dev/null 2>&1
257         rc_check
258     else
259         rc_check
260     fi
261
262     if rc_status ; then
263         /sbin/modprobe -q -s --first-time emcpioc
264         rc_check
265         if [ $? -eq 0 ] ; then
266             /sbin/modprobe -r -q -s --first-time emcpioc
267         fi
268     fi
269 }
270
271 # Unload drivers and extensions.
272
273 unload_drivers()
274 {
275     do_unload=0
276     retry=4
277     powermt prep_drv_unload > /dev/null 2>&1
278
279
280     ###
281     ### At this point, we really want the driver unload to succeed
282     ### Try hard to make it happen.
283     ###
284     while [ $retry -gt 0 ]
285     do
286     powermt remove dev=all 2> /var/tmp/.pp_exit
287     devr=$?
288     cat /var/tmp/.pp_exit | grep "not found" > /dev/null 2>&1
289     cdevs=$?
290     zerolen=`cat /var/tmp/.pp_exit | wc -c`
291     rm /var/tmp/.pp_exit
292     # reset rc status since we are not willing to
293     # report an error just yet.
294     rc_reset
295     if [ $devr -eq 0 ] ; then
296          do_unload=1
297          retry=0 #success
298     else
299          if [ $cdevs -eq 0 -o $zerolen -eq 0 ] ; then
300             do_unload=1
301             retry=0 #success
302          else
303             sleep 5
304             retry=`expr $retry - 1`
305             #nls "PowerPath devices are open."
306             #eval echo "$(nls "Please close these devices and then re-issue \$script_name stop.")"
307             #/bin/false
308             #uerr=$?
309             #return $uerr
310          fi
311     fi
312     done
313
314
315     
316     if [ $do_unload -eq 1 ] ; then
317        /sbin/modprobe -r -q -s  `cat $mgr; cat $ext; echo emcp emcplib`
318        uerr=$?
319        return $uerr
320     else
321        nls "PowerPath devices are open."
322        eval echo "$(nls "Please close these devices and then re-issue \$script_name stop.")"
323        /bin/false
324        uerr=$?
325        return $uerr
326     fi
327
328     nls "PowerPath could not unload PowerPath modules."
329     uerr=1
330     return $uerr
331 }
332
333 recreate_emcpower_device()
334 {
335     #
336     # Create /dev/emcpower based on CURRENT misc driver.
337     # These values can be different when PP loads from RD.
338     #
339     mmaj=`awk -F: '{print $1}' /sys/class/misc/emcpower/dev`
340     mmin=`awk -F: '{print $2}' /sys/class/misc/emcpower/dev`
341     rm -f /dev/emcpower
342     mknod /dev/emcpower c $mmaj $mmin
343
344     if [ $? -ne 0 ]; then
345         nls "failed to create emcpower device"
346     fi
347
348 }
349
350 rc_reset
351 script_name=PowerPath
352 ext=/etc/emc/.drivers_ext
353 mgr=/etc/emc/.drivers_mgr
354
355 case "$1" in
356     start)
357         msg_starting "PowerPath"
358
359         ###
360         # Start the 32-bit emulation for ia64
361         ###
362         #if [ "`uname -m`" == "ia64" ]; then
363          #   start_32bit_emulation
364         #fi
365
366         ###
367         # Load PP iff it is not already loaded.
368         ###
369         if rc_status ; then
370             lsmod | grep -w '^emcp' > /dev/null
371             if [ $? -ne 0 ]; then
372                 load_drivers
373         else
374                 if dev_emcpower_is_back 60; then
375                     recreate_emcpower_device
376                     /etc/opt/emcpower/powercf -K        > /dev/null 2>&1
377                     rc_check
378                 else
379                     rc_check
380                 fi
381             # remove PIOC if it was loaded during RD boot.
382                 lsmod | grep emcpioc > /dev/null
383             if [ $? -eq 0 ]; then
384                 /sbin/rmmod emcpioc > /dev/null
385                 fi
386             fi
387
388             if rc_status ; then
389                 if dev_emcpower_is_back 60; then
390                     configure_pp
391                 else
392                     rc_check
393                 fi
394             else
395                 nls "PowerPath: unable to load PowerPath modules."
396             fi
397         fi
398         rc_status -v
399         ;;
400
401     stop)
402         msg_stopping "PowerPath"
403         lsmod | grep -w '^emcp' > /dev/null
404         if test $? -ne 0; then
405             nls "PowerPath is not running"
406         else
407             #
408             # Tresspass can happen if new devices are added or some devices 
409             # are removed by "powermt remove" before "PowerPath stop". The 
410             # reason is that vgscan used by us issues "read" to all block 
411             # devices. 
412             # We configure all devices to avoid unnecessary trespass.
413             #
414             /sbin/powermt config > /dev/null 2>&1
415             if ok_to_stop; then
416                 /sbin/powermt save > /dev/null 2>&1
417                 rc_check
418                 /etc/opt/emcpower/emcpmgr unmap > /dev/null 2>&1
419                 rc_check
420                 /sbin/powermt remove dev=all 2> /var/tmp/.pp_exit
421                 devr=$?
422                 cat /var/tmp/.pp_exit | grep "not found" > /dev/null 2>&1
423                 cdevs=$?
424                 zerolen=`cat /var/tmp/.pp_exit | wc -c`
425                 rm /var/tmp/.pp_exit
426
427                 # reset rc status since we are not willing to quit
428                 rc_reset
429                 if [ $devr -eq 0 ] ; then
430                     unload_drivers
431                     rc_check
432                     if [ $? -ne 0 ] ; then
433                                                 nls "PowerPath could not unload PowerPath modules."
434                     fi
435                 else
436                     if [ $cdevs -eq 0 -o $zerolen -eq 0 ] ; then
437                         unload_drivers
438                         rc_check
439                         if [ $? -ne 0 ] ; then
440                             nls "PowerPath could not unload PowerPath modules."
441                         fi
442                     else
443                         nls "PowerPath devices are open."
444                         eval echo "$(nls "Please close these devices and then re-issue \$script_name stop.")"
445                         /etc/opt/emcpower/emcpmgr map -p > /dev/null 2>&1
446                         /sbin/powermt config    > /dev/null 2>&1
447                                                 /sbin/powermt load      > /dev/null 2>&1
448                         /bin/false
449                     fi
450                 fi
451             else
452                 /bin/false  ## not ok_to_stop
453             fi
454         fi
455         rc_status -v
456         ;;
457     *)
458         msg_usage "$0 {start|stop}"
459         exit 3
460         ;;
461 esac
462
463 rc_exit
464 # vim:ts=4:sw=4:et
This page took 0.134089 seconds and 3 git commands to generate.