3 # Enable a newly installed package to run or enable an existing package
4 # to run after a kernal upgrade.
9 type -P gettext.sh > /dev/null 2>&1 && \
10 type -p gettext >/dev/null 2>&1
26 TEXTDOMAINDIR=$PPBASE/i18n/catalog
28 export RPM_INSTALL_PREFIX
44 ### DO NOT REMOVE THE FOLLOWING LINE
45 #####################################################################
46 ### Start of Global variable section.
47 #####################################################################
49 # Temp directory used by the %pre section. (Before $PP_I_DIR exists.)
53 # Default installation directory for emcpower
55 PP_I_DIR=/etc/opt/emcpower
57 # The file name of the device file used to control the power path drivers
59 # created by sysfs in 2.6.
60 #POWER_DEV=/dev/emcpower
62 # Installation log file
64 POWER_LOG=$PP_I_DIR/log
66 # Installation temporary file directory.
68 POWER_TMP_DIR=$PP_I_DIR/.tmp
70 # Backup archives used in case an installation is aborted in mid-stream
72 POWER_BACKUP_ARCHIVE=$PP_I_DIR/.archive.tar
73 POWER_BACKUP_ARCHIVE_NEW=$PP_I_DIR/.archive_NEW.tar
74 archive_dir=$RPM_INSTALL_PREFIX/etc/emc/archive
76 # Patch log file in case of patch errors
78 PATCH_LOG=$PP_I_DIR/patch.log
82 modprobe_file=/etc/modprobe.conf.pp
83 #####################################################################
84 ### End of Global variable section.
85 #####################################################################
88 #-----------------------------------------------------------------------
89 # Restore system to the state that existed before this script ran.
90 # First, execute the commands in the undo list in reverse order, then
91 # untar archived files.
92 #-----------------------------------------------------------------------
95 awk '{print NR,$0}' $POWER_TMP_DIR/undolist | \
97 cut -d' ' -f2- > $POWER_TMP_DIR/undo.sh
98 sh $POWER_TMP_DIR/undo.sh
100 tar -x --absolute-names --file $POWER_TMP_DIR/rollbackfiles.tar
103 #-----------------------------------------------------------------------
104 # Delete the files containing rollback information
105 #-----------------------------------------------------------------------
108 rm -f $POWER_TMP_DIR/rollbackfiles.tar
109 rm -f $POWER_TMP_DIR/undolist
110 rm -f $POWER_TMP_DIR/undo.sh
113 #-----------------------------------------------------------------------
114 # Save a directory and contained files in the rollback archive
115 #-----------------------------------------------------------------------
116 save_dirtree_for_rollback()
123 tar --append --preserve-permissions --absolute-names \
124 --file $POWER_TMP_DIR/rollbackfiles.tar $pathname
127 #-----------------------------------------------------------------------
128 # Save a file or directory in the rollback archive
129 #-----------------------------------------------------------------------
137 tar --append --preserve-permissions --absolute-names \
138 --no-recursion --file $POWER_TMP_DIR/rollbackfiles.tar $pathname
141 #-----------------------------------------------------------------------
142 # Add a shell command, for execution during rollback, to the undo list
143 #-----------------------------------------------------------------------
146 echo "cd `pwd`; $*" >> $POWER_TMP_DIR/undolist
149 #-----------------------------------------------------------------------
150 # Move a file in such a way that the original source and destination
151 # files are restored by rollback.
152 #-----------------------------------------------------------------------
158 dest=$2/`basename $1`
162 if [ -f "$dest" ]; then
163 save_for_rollback $dest
165 add_to_undolist rm -f "$dest"
170 #-----------------------------------------------------------------------
171 # Copy a new file over an old one,in such a way that the old file
172 # can be restored during rollback.
173 #-----------------------------------------------------------------------
178 dest=$2/`basename $1`
182 if [ -f "$dest" ]; then
183 save_for_rollback $dest
185 add_to_undolist rm -f "$dest"
190 #-----------------------------------------------------------------------
191 # Save a file in the rollback archive and then delete it.
192 #-----------------------------------------------------------------------
201 #-----------------------------------------------------------------------
202 # Save a directory and contained files in the rollback archive and then
204 #-----------------------------------------------------------------------
208 save_dirtree_for_rollback $1
213 #-----------------------------------------------------------------------
214 # Make a directory in such a way that it will be removed during rollback.
215 # All non-existent directories in the given path are created. If the
216 # directory already exists, do nothing.
217 #-----------------------------------------------------------------------
220 if [ ! -d "$1" ]; then
221 make_dir2 $1 && chmod 755 $1 && chown root:root $1
227 if test ! -d "$1" && make_dir2 `dirname $1`; then
228 add_to_undolist rmdir $1
233 #-----------------------------------------------------------------------
234 # Copy a kernel module and set file pwermissions, group and owner
235 #-----------------------------------------------------------------------
238 copy_file "$1" "$2" && chmod 644 "$2" && chown root:root "$2"
241 #-----------------------------------------------------------------------
242 # Compare the vermagic string of the pp base driver to the vermagic string
243 # of the scsi_mod driver.
244 # input: path to PowerPath base driver, in package area.
245 # return 0 for matching strings.
246 #-----------------------------------------------------------------------
248 verify_driver_vermagic()
252 local ref_mod_version
255 ref_driver=`lsmod | cut -d' ' -f1 | tail -1`
256 ref_mod_version=`modinfo $ref_driver | \
257 sed -n '/^vermagic:/s/^vermagic: *//p'`
258 pp_mod_version=`modinfo $pp_drv_path | \
259 sed -n '/^vermagic:/s/^vermagic: *//p'`
260 ref_mod_version=`echo $ref_mod_version | cut -d' ' -f2-`
261 pp_mod_version=`echo $pp_mod_version | cut -d' ' -f2-`
262 if [ "$pp_mod_version" = "$ref_mod_version" ]
270 #-----------------------------------------------------------------------
271 # Recursively load all modules on the command line, in the order given.
272 # If any module fails to load, all previously loaded modules are unloaded
273 # and a non-zero status is returned. After all modules are loaded, emcpioc
275 #-----------------------------------------------------------------------
279 local mod=`basename "$1" .ko.gz`
286 if lsmod | grep emcpioc > /dev/null
301 report_error 'PowerPath could not load module $mod'
306 #-----------------------------------------------------------------------
307 # Run "preinstall" checks to make sure the running system is compatible
309 #-----------------------------------------------------------------------
310 validate_install_target()
312 ## Check - Require effective UID of root
314 if [ $(id -u) != 0 ]; then
315 report_error "You must be root to install PowerPath."
319 ## Check - Only install on a 2.6 kernel
321 expr `uname -r` : '2\.6' > /dev/null
322 if [ $? -ne 0 ]; then
323 report_error "This PowerPath package does not support this kernel."
329 if expr \( "$EXPECTED_VENDOR" : ".*$VENDOR" \) = 0 >/dev/null; then
330 report_error 'This package requires a $VENDOR_NAME Platform.'
336 check_vendor_rev $EXPECTED_OS_REV
338 report_error 'This package requires $VENDOR_NAME $VENDOR_OS_NAME.'
342 ## Check hardware platform
344 if [ "`uname -m`" != "$EXPECTED_ISA" ]; then
346 'This package requires the $VENDOR_NAME $EXPECTED_ISA kernel.'
350 ## Check - Make sure no devices are in use.
352 if [ "`/sbin/lsmod | grep -w emcp`" != "" ]; then
353 /sbin/powermt save > /dev/null 2>&1
354 /sbin/powermt remove dev=all > /dev/null 2>&1
355 if [ "`powermt display dev=all 2>&1 | grep "not found"`" = "" ]; then
357 "Unable to remove devices from the PowerPath configuration."
359 "Please make sure no PowerPath devices are in use and retry."
360 /sbin/powermt config > /dev/null 2>&1
361 /sbin/powermt load > /dev/null 2>&1
364 /sbin/powermt config > /dev/null 2>&1
365 /sbin/powermt load > /dev/null 2>&1
368 ## Check driver vermagic
370 verify_driver_vermagic /lib/modules/$(uname -r)/kernel/drivers/block/emcp.ko.gz
372 report_error 'PowerPath driver version magic mismatch'
377 #-----------------------------------------------------------------------
378 # Compare the version recorded in the saved powermt.custom file with the
379 # version in $1. If the two versions match, return true.
380 #-----------------------------------------------------------------------
381 matching_saved_config_version()
385 if [ -f $archive_dir/powermt.custom.saved ]; then
386 Mmp=`expr "$1" : '\([0-9]\.[0-9]\.[0-9]\)'`
387 saved=`head -1 $archive_dir/powermt.custom.saved | cut -d: -f3`
388 if [ "$saved" = "$Mmp" ]; then
398 #-----------------------------------------------------------------------
399 # Move files from the PowerPath archive directory to their normal
400 # installed locations.
401 #-----------------------------------------------------------------------
402 restore_configuration_files()
404 for file in /etc/emc/mpaa.lams \
405 /etc/emc/mpaa.excluded \
406 /etc/emcp_registration
408 if [ -f $archive_dir/`basename $file`.saved ]; then
409 move_file $archive_dir/`basename $file`.saved $file
413 if test "$PP_VERSION" || \
414 matching_saved_config_version $NEW_PP_VERSION; then
415 for file in /etc/powermt.custom \
416 /etc/emcp_devicesDB.dat \
417 /etc/emcp_devicesDB.idx
419 if [ -f $archive_dir/`basename $file`.saved ]; then
420 move_file $archive_dir/`basename $file`.saved $file
424 if [ -f $archive_dir/*.FCS ]; then
425 for file in $archive_dir/*.FCS
433 #-----------------------------------------------------------------------
434 # tps_managed_classes - Return a true status if third party software
435 # is installed to manage the array named in $1. Otherwise return a
437 #-----------------------------------------------------------------------
442 test -d /opt/DynamicLinkManager/bin
445 test -d /usr/src/Autopath
448 test -d /opt/IBMsdd/bin
451 test -d /etc/CPQswsp/modules
459 #-----------------------------------------------------------------------
460 # prev_unmanaged - Return a true status if the array named in $2
461 # is marked "unmanaged" in the mpaa.lams file named in $1
462 #-----------------------------------------------------------------------
465 grep -w $2 $1 2>/dev/null | grep -w unmanaged > /dev/null 2>&1
468 #-----------------------------------------------------------------------
469 # If no mpaa.lams file exists, create one. Otherwise create a temporary
470 # mpaa.lams file, compare it to the existing file and replace the
471 # existing file with the temporary one if the two files differ. Also,
472 # create an empty mpaa.excluded if one doesn't exist
473 #-----------------------------------------------------------------------
476 local lams_file="/etc/emc/mpaa.lams"
477 local lams_excluded_file="/etc/emc/mpaa.excluded"
480 if [ -f "$lams_file" ]; then
482 lams_new=${lams_file}.tmp
488 echo "global:version:$PP_VERSION" > $lams_new
489 for array in symm clariion hpxp hitachi hphsx ess invista
491 if tps_managed $array || prev_unmanaged $lam_ref $array
493 echo "unmanaged:$array" >> $lams_new
495 echo "managed:$array" >> $lams_new
499 if [ "$lams_new" = "${lams_file}.tmp" ]; then
500 if /usr/bin/diff -q $lams_file $lams_new >/dev/null 2>&1; then
503 mv -f $lams_new $lams_file
506 add_to_undolist rm -f $lams_file
509 if [ ! -f "$lams_excluded_file" ]; then
510 echo "global:version:$PP_VERSION" > $lams_excluded_file
511 add_to_undolist rm -f $lams_excluded_file
515 #-----------------------------------------------------------------------
516 # Add lines to /etc/modprobe.conf.pp to coordinate filter driver, hba
517 # driver and emcp loading
518 #-----------------------------------------------------------------------
519 modprobe_add_pp_lines()
521 local begin_tag='#begin-hba-'
522 local end_tag='#end-hba-'
526 modprobe_hba=' /sbin/modprobe pp_hba;'
530 install_hba="$install_hba /sbin/modprobe $hba;"
534 if grep "^${begin_tag}$1" $modprobe_file > /dev/null; then
535 return # Lines for this hba are already in place
537 # Lines indented with tab!!
538 cat <<-EOF >> $modprobe_file
540 install emcp /sbin/modprobe pp_hba; /sbin/modprobe emcp --ignore-install
541 install pp_hba ${install_hba}
547 #-----------------------------------------------------------------------
548 # Create dependencies between HBA drivers and power path drivers.
549 #-----------------------------------------------------------------------
550 create_hba_dependencies()
552 local added_dependency=FALSE
553 local searchDir=/lib/modules/`uname -r`
557 qlaHbaName=`find /proc/scsi -name qla2xxx | sed -e 's/\/proc\/scsi\///'`
558 emulexHbaName=`find /proc/scsi -name lpfc* | sed -e 's/\/proc\/scsi\///'`
559 if [ "$qlaHbaName" ]; then
560 qla_hbas=`lsmod | cut -d' ' -f1 | grep qla | grep -v qla2xxx`
561 modprobe_add_pp_lines $qla_hbas
562 added_dependency=TRUE
565 # We no longer support mixed vendor types, so we will not add the
566 # emulex driver if the qla driver exists.
568 if [ "$emulexHbaName" != "" -a "$added_dependency" = FALSE ]; then
570 modloc=`find $searchDir -name ${emulexHbaName}.ko -print`
571 if [ "$modloc" != "" ]; then
572 modprobe_add_pp_lines $emulexHbaName
577 #-----------------------------------------------------------------------
578 # Add PowerPath parameters to modprobe.conf.pp file
579 #-----------------------------------------------------------------------
580 update_driver_parameters()
582 local lams_file="/etc/emc/mpaa.lams"
583 local lams_excluded_file="/etc/emc/mpaa.excluded"
585 ## Attach the PP file to modprobe.conf
587 grep '^##*BEGINPP' /etc/modprobe.conf >/dev/null 2>&1
588 if [ $? -ne 0 ]; then
589 save_for_rollback /etc/modprobe.conf
590 cat <<-EOF >> /etc/modprobe.conf ## Lines indented with tabs!!!
592 include /etc/modprobe.conf.pp
597 copy_file /etc/modprobe.d/$(uname -r)/EMCpower.conf $modprobe_file
599 ## Update the managedclass parameter line
601 mng_class=`awk -F: '$1 ~ /^managed$/ {print $2}' $lams_file | \
604 -e 's/^/options emcp managedclass=/'`
606 grep "options emcp managedclass" $modprobe_file > /dev/null 2>&1
607 if test $? -ne 0 ; then
608 echo "$mng_class" >> $modprobe_file
610 sed -i "s/^options emcp managedclass=.*/${mng_class}/" \
614 ## Update the excludedvolumes parameter line.
616 if [ `wc -l $lams_excluded_file | awk '{print $1}'` -gt 1 ] ; then
617 excluded=`awk -F: '{print $2","}' $lams_excluded_file |\
621 if [ "$excluded" ] ; then
622 if grep "options emcp excludedvolumes" \
623 $modprobe_file > /dev/null 2>&1 ; then
624 sed -i "/excludedvolumes/c\
625 options emcp excludedvolumes=$excluded" $modprobe_file
627 echo "options emcp excludedvolumes=$excluded" >> $modprobe_file
633 ## Link hba drivers and powerpath drivers
635 create_hba_dependencies
638 #-----------------------------------------------------------------------
639 # update_boot_logic - Tie PowerPath start into system startup logic.
640 #-----------------------------------------------------------------------
645 MDFILE=/etc/init.d/boot.md
646 grep boot.powerpath $MDFILE >> /dev/null 2>>/dev/null
647 if [ $? -eq 1 ]; then
648 save_for_rollback $MDFILE
649 string=`grep "# Required-Start:" $MDFILE`
650 sed --in-place -e "s/$string/$string boot.powerpath/" $MDFILE
651 if [ -x /sbin/insserv ]; then
657 ETCFILE=/etc/rc.d/rc.sysinit
658 grep BEGINPP $ETCFILE >> /dev/null 2>>/dev/null
659 if [ $? -eq 1 ]; then
660 save_for_rollback $ETCFILE
661 sed --in-place -e '/remount,rw \//a \
663 # Configure and initialize PowerPath.\
664 if [ -f /etc/init.d/PowerPath ]; then\
665 /etc/init.d/PowerPath start\
673 #-----------------------------------------------------------------------
674 # Delete old modules in all /lib/modules subdirectories, then install
676 #-----------------------------------------------------------------------
677 install_driver_modules()
679 return # already cames from rpm package
680 for os in /lib/modules/*
683 /lib/modules/`uname -r`)
684 for modpath in $os/powerpath/*
690 remove_dirtree $os/powerpath
693 for modpath in $os/extra/emcp*
699 ## Install new modules.
701 MODULE_BASE=/lib/modules/`uname -r`
703 test -d $MODULE_BASE/powerpath || make_dir $MODULE_BASE/powerpath
705 for mod in `ls $PPBASE/bin/driver/$TAG`
707 copy_mod $PPBASE/bin/driver/$TAG/$mod $MODULE_BASE/powerpath/$mod
713 ##-------------------------------- Main ------------------------------##
715 PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH
717 cmd_path=`dirname $0`
718 PPBASE=`(cd $cmd_path;pwd)`
720 test -f $PP_I_DIR/.pp_version && PP_VERSION=`cat $PP_I_DIR/.pp_version`
721 test -f $PP_I_DIR/.new_pp_version && \
722 NEW_PP_VERSION=`cat $PP_I_DIR/.new_pp_version`
723 test -f $PP_I_DIR/.os_version && OS_VERSION=`cat $PP_I_DIR/.os_version`
725 VENDOR=`rpm --showrc | awk '$2 == "_vendor" {print $3}'`
728 ### DO NOT REMOVE THE FOLLOWING LINE
729 # SuSE x86_64 specific:
734 VENDOR_OS_NAME=SLES10SP1
737 MIN_UPGRADE_REV=5.0.0
741 if [ "`awk '/Ac/{print 1}' /etc/pld-release`" == "1" ]
743 sles_version=$EXPECTED_OS_REV
747 test "$1" = "$sles_version"
750 #-----------------------------------------------------------------------
751 # identify_platform -
752 # Determine the set of drivers files compatible with the /lib/modules
753 # subdirectory passed as an argument and echo the tag for that set of
755 #-----------------------------------------------------------------------
762 *-smp) platform=sles${EXPECTED_OS_REV}smp_x8664 ;;
763 *-xen) platform=sles${EXPECTED_OS_REV}xensmp_x8664 ;;
765 if [ "$1" = `uname -r` ]
767 pre_error "This PowerPath package only supports the SuSE SLES x86_64 smp kernel"
773 test "$platform" && echo $platform
781 validate_install_target
783 make_dir /etc/emc/ppme
785 test "$NEW_PP_VERSION" && restore_configuration_files
789 update_driver_parameters
791 install_driver_modules
793 ## Load new modules. Emcplib and emcp first, emcpdm and emcpioc last
794 ## with everything else in between.
796 load_all_modules `cd /lib/modules/$(uname -r)/kernel/drivers/block/; ls emc* | \
797 awk '/^emcplib.ko.gz$/ {order[$1]=1; next}
798 /^emcp.ko.gz$/ {order[$1]=2; next}
799 /^emcpdm.ko.gz$/ {order[$1]=4; next}
800 /^emcpioc.ko.gz$/ {order[$1]=5; next}
801 /^emcp/ {order[$1]=3; next}
802 END { for (mod in order) print order[mod],mod;}' |\
806 ## If error loading modules, roll back everything done to this point and
807 ## return an error status.
811 report_error "Error loading PowerPath kernel modules"
818 ## If kernel has changed make sure PowerPath will still start at boot time
820 if [ "$OS_VERSION" != `uname -r` ]; then
826 report_error "Error installing PowerPath"
832 ## Update state info in /etc/opt/emcpower
834 rm -f $PP_I_DIR/.os_version
835 uname -r > $PP_I_DIR/.os_version
836 rm -f $PP_I_DIR/.prev_pp_version
837 if [ -f $PP_I_DIR/.new_pp_version ]
839 test -f $PP_I_DIR/.pp_version && \
840 mv -f $PP_I_DIR/.pp_version $PP_I_DIR/.prev_pp_version
841 mv $PP_I_DIR/.new_pp_version $PP_I_DIR/.pp_version