3 # chkconfig: 2345 02 98
4 # description: Loads and configures the EMC PowerPath drivers.
6 # ###################################################################
7 # Copyright (c) 2000, EMC Corporation. All Rights Reserved.
9 # Most Recent Author: Raghu Adabala
10 # Previous Authors: Raghu Adabala and Ed Goggin
13 # Redhat support for load and configure of EMC PowerPath drivers
14 # ###################################################################
19 # Source function library.
20 . /etc/rc.d/init.d/functions
23 # Functions to preserve exceptional command status return values
34 test $rc_cmd_stat -ne 0 && rc_script_stat=$rc_cmd_stat
44 case "$rc_script_stat" in
53 return $rc_script_stat
62 # ###################################################################
63 # Copyright (c) 2005, EMC Corporation. All Rights Reserved.
67 # This scripts loads and configures the EMC PowerPath driver(s) on
68 # bootup and uloads PowerPath on shutdown.
69 # ###################################################################
74 PATH=/usr/bin/:/bin:/sbin:/usr/sbin
76 # the following are the internationalization specific lines
79 export RPM_INSTALL_PREFIX
80 # end of internationalization
84 if test -x /sbin/vgchange -a -x /sbin/vgscan ; then
86 vgname=`vgdisplay 2>/dev/null| grep "VG Name" | sed -e 's/VG Name/ /g'`
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:"
99 echo "`nls " Volume Group: \\$var1 (\\$var2)"`"
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."
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
122 # Wait for /dev/emcpower to appear.
123 # $1 is the number of seconds to wait.
125 dev_emcpower_is_back()
127 /bin/bash -c "for ((cnt=$1/3; \$cnt > 0; cnt--)); do \
128 test -c /dev/emcpower && break; \
131 test -c /dev/emcpower"
135 # Start 32 bit Emulation library before powerpath startup for ia64
136 start_32bit_emulation()
138 /etc/init.d/ia32el start > /dev/null 2>&1
142 nls "\nSuccessfully started 32-bit emulation library"
144 nls "\nError in starting 32-bit emulation library"
148 # Configure PowerPath paths
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
159 ## If the system has no license, config error is ok.
161 if /sbin/emcpreg -l 2>&1 | /usr/bin/grep '^Key' > /dev/null 2>&1; then
162 /sbin/powermt config > /dev/null 2>&1
164 /sbin/powermt config > /dev/null 2>&1
170 # Wait for udev to finish creating emcpower devices
173 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
175 for pd in `/bin/ls -d /sys/block/emcpower* 2> /dev/null`; do
177 if [ ! -e /dev/$bpd ]; then
183 if [ "$pdfound" -eq 1 ]; then
187 if [ "$pdfound" -eq 0 ]; then
192 /sbin/powermt load > /dev/null 2>&1
194 /sbin/emcpmgr map > /dev/null 2>&1
196 /sbin/powercf -C > /dev/null 2>&1
197 /sbin/powermt save > /dev/null 2>&1
199 /sbin/powermt register > /dev/null 2>&1
201 /sbin/powermig transition -startup -noprompt > /dev/null 2>&1
206 # Check for naviagent and powermt before stopping PowerPath
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.")"
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.")"
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.")"
234 if pp_stop_lvm ; then
240 # Load the extensions. Dependencies will load base driver.
244 for d in `cat $ext; cat $mgr`
246 /sbin/modprobe -q -s --first-time $d
248 if [ $? -ne 0 ] ; then
249 eval echo "$(nls "PowerPath could not load module \$d")"
254 if dev_emcpower_is_back 60; then
255 recreate_emcpower_device
256 /sbin/powercf -K > /dev/null 2>&1
263 /sbin/modprobe -q -s --first-time emcpioc
265 if [ $? -eq 0 ] ; then
266 /sbin/modprobe -r -q -s --first-time emcpioc
271 # Unload drivers and extensions.
277 powermt prep_drv_unload > /dev/null 2>&1
281 ### At this point, we really want the driver unload to succeed
282 ### Try hard to make it happen.
284 while [ $retry -gt 0 ]
286 powermt remove dev=all 2> /var/tmp/.pp_exit
288 cat /var/tmp/.pp_exit | grep "not found" > /dev/null 2>&1
290 zerolen=`cat /var/tmp/.pp_exit | wc -c`
292 # reset rc status since we are not willing to
293 # report an error just yet.
295 if [ $devr -eq 0 ] ; then
299 if [ $cdevs -eq 0 -o $zerolen -eq 0 ] ; then
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.")"
316 if [ $do_unload -eq 1 ] ; then
317 /sbin/modprobe -r -q -s `cat $mgr; cat $ext; echo emcp emcplib`
321 nls "PowerPath devices are open."
322 eval echo "$(nls "Please close these devices and then re-issue \$script_name stop.")"
328 nls "PowerPath could not unload PowerPath modules."
333 recreate_emcpower_device()
336 # Create /dev/emcpower based on CURRENT misc driver.
337 # These values can be different when PP loads from RD.
340 mmaj=`cat /sys/class/misc/emcpower/dev | awk -F : '{print $1}'`
341 mmin=`cat /sys/class/misc/emcpower/dev | awk -F : '{print $2}'`
342 mknod /dev/emcpower c $mmaj $mmin > /dev/null
344 if [ $? -ne 0 ]; then
345 nls "failed to create emcpower device"
351 script_name=PowerPath
352 ext=/etc/emc/.drivers_ext
353 mgr=/etc/emc/.drivers_mgr
357 msg_starting "PowerPath"
360 # Start the 32-bit emulation for ia64
362 #if [ "`uname -m`" == "ia64" ]; then
363 # start_32bit_emulation
367 # Load PP iff it is not already loaded.
370 lsmod | grep -w '^emcp' > /dev/null
371 if [ $? -ne 0 ]; then
374 if dev_emcpower_is_back 60; then
375 recreate_emcpower_device
376 /sbin/powercf -K > /dev/null 2>&1
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
389 if dev_emcpower_is_back 60; then
395 nls "PowerPath: unable to load PowerPath modules."
402 msg_stopping "PowerPath"
403 lsmod | grep -w '^emcp' > /dev/null
404 if test $? -ne 0; then
405 nls "PowerPath is not running"
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
412 # We configure all devices to avoid unnecessary trespass.
414 /sbin/powermt config > /dev/null 2>&1
416 /sbin/powermt save > /dev/null 2>&1
418 /sbin/emcpmgr unmap > /dev/null 2>&1
420 /sbin/powermt remove dev=all 2> /var/tmp/.pp_exit
422 cat /var/tmp/.pp_exit | grep "not found" > /dev/null 2>&1
424 zerolen=`cat /var/tmp/.pp_exit | wc -c`
427 # reset rc status since we are not willing to quit
429 if [ $devr -eq 0 ] ; then
432 if [ $? -ne 0 ] ; then
433 nls "PowerPath could not unload PowerPath modules."
436 if [ $cdevs -eq 0 -o $zerolen -eq 0 ] ; then
439 if [ $? -ne 0 ] ; then
440 nls "PowerPath could not unload PowerPath modules."
443 nls "PowerPath devices are open."
444 eval echo "$(nls "Please close these devices and then re-issue \$script_name stop.")"
445 /sbin/emcpmgr map -p > /dev/null 2>&1
446 /sbin/powermt config > /dev/null 2>&1
447 /sbin/powermt load > /dev/null 2>&1
452 /bin/false ## not ok_to_stop
458 msg_usage "$0 {start|stop}"