Home | History | Annotate | Download | only in stmsboot
      1   7498     James #!/sbin/sh -p
      2      0    stevel #
      3      0    stevel # CDDL HEADER START
      4      0    stevel #
      5      0    stevel # The contents of this file are subject to the terms of the
      6   2097  sjelinek # Common Development and Distribution License (the "License").
      7   2097  sjelinek # You may not use this file except in compliance with the License.
      8      0    stevel #
      9      0    stevel # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10      0    stevel # or http://www.opensolaris.org/os/licensing.
     11      0    stevel # See the License for the specific language governing permissions
     12      0    stevel # and limitations under the License.
     13      0    stevel #
     14      0    stevel # When distributing Covered Code, include this CDDL HEADER in each
     15      0    stevel # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16      0    stevel # If applicable, add the following below this CDDL HEADER, with the
     17      0    stevel # fields enclosed by brackets "[]" replaced with your own identifying
     18      0    stevel # information: Portions Copyright [yyyy] [name of copyright owner]
     19      0    stevel #
     20      0    stevel # CDDL HEADER END
     21      0    stevel #
     22      0    stevel #
     23   9009  Yongfeng # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     24      0    stevel # Use is subject to license terms.
     25      0    stevel #
     26   4073      jmcp #
     27      0    stevel PATH=/usr/bin:/usr/sbin:$PATH; export PATH
     28      0    stevel STMSBOOTUTIL=/lib/mpxio/stmsboot_util
     29      0    stevel STMSMETHODSCRIPT=/lib/svc/method/mpxio-upgrade
     30   4022  jw149990 KDRVCONF=
     31   4022  jw149990 DRVCONF=
     32   4022  jw149990 TMPDRVCONF=
     33   4022  jw149990 TMPDRVCONF_MPXIO_ENTRY=
     34   7878  Yongfeng TMPDRVCONF_SATA_ENTRY=
     35   4022  jw149990 DRVLIST=
     36   4022  jw149990 GUID=
     37      0    stevel VFSTAB=/etc/vfstab
     38      0    stevel SAVEDIR=/etc/mpxio
     39   8101     James BOOTDEVICES=$SAVEDIR/boot-devices
     40      0    stevel RECOVERFILE=$SAVEDIR/recover_instructions
     41      0    stevel SVCCFG_RECOVERY=$SAVEDIR/svccfg_recover
     42  10696     David SUPPORTED_DRIVERS="fp|mpt|mpt_sas|pmcs"
     43   4022  jw149990 USAGE=`gettext "Usage: stmsboot [-D $SUPPORTED_DRIVERS] -e | -d | -u | -L | -l controller_number"`
     44   2636     ramat TEXTDOMAIN=SUNW_OST_OSCMD
     45   2636     ramat export TEXTDOMAIN
     46   7498     James STMSINSTANCE=svc:system/device/mpxio-upgrade:default
     47   4022  jw149990 STMSBOOT=/usr/sbin/stmsboot
     48   4022  jw149990 BOOTADM=/sbin/bootadm
     49   4022  jw149990 MOUNT=/usr/sbin/mount
     50   7498     James EEPROM=/usr/sbin/eeprom
     51   4022  jw149990 EGREP=/usr/bin/egrep
     52   4022  jw149990 GREP=/usr/bin/grep
     53   4022  jw149990 AWK=/usr/bin/awk
     54   7498     James CP=/usr/bin/cp
     55   8101     James DF=/usr/bin/df
     56   7498     James LS=/usr/bin/ls
     57   7498     James MV=/usr/bin/mv
     58   7498     James RM=/usr/bin/rm
     59   4022  jw149990 SORT=/usr/bin/sort
     60   4022  jw149990 UNIQ=/usr/bin/uniq
     61   4022  jw149990 EXPR=/usr/bin/expr
     62   7498     James MKDIR=/usr/bin/mkdir
     63   7498     James REBOOT=/usr/sbin/reboot
     64   4073      jmcp SED=/usr/bin/sed
     65   4073      jmcp SVCPROP=/usr/bin/svcprop
     66   4073      jmcp SVCCFG=/usr/sbin/svccfg
     67   4073      jmcp SVCS=/usr/bin/svcs
     68   4073      jmcp SVCADM=/usr/sbin/svcadm
     69      0    stevel 
     70   7498     James NOW=`/usr/bin/date +%G%m%d_%H%M`
     71   3385  qh201292 MACH=`/usr/bin/uname -p`
     72   7498     James BOOTENV_FILE=bootenv.rc
     73   4022  jw149990 reboot_needed=0
     74   7498     James new_bootpath=""
     75   7498     James CLIENT_TYPE_PHCI=""
     76   7498     James CLIENT_TYPE_VHCI="/scsi_vhci"
     77  10882   Jianfei new_rootdev=""
     78  10882   Jianfei svm_md_device=""
     79   4022  jw149990 
     80      0    stevel #
     81   4022  jw149990 # Copy all entries (including comments) from source driver.conf
     82   4022  jw149990 # to destination driver.conf except those entries which contain
     83   4022  jw149990 # the mpxio-disable property.
     84      0    stevel # Take into consideration entries that spawn more than one line.
     85      0    stevel #
     86      0    stevel # $1	source driver.conf file
     87      0    stevel # $2	destination driver.conf file
     88      0    stevel #
     89      0    stevel # Returns 0 on success, non zero on failure.
     90      0    stevel #
     91      0    stevel delete_mpxio_disable_entries()
     92      0    stevel {
     93   7498     James 	# be careful here, we've got embedded \t characters
     94   7498     James 	# in sed's pattern space.
     95   7498     James 	$SED '
     96      0    stevel 		/^[ 	]*#/{ p
     97      0    stevel 			      d
     98      0    stevel 			    }
     99      0    stevel 		s/[ 	]*$//
    100      0    stevel 		/^$/{ p
    101      0    stevel 		      d
    102      0    stevel 		    }
    103   3385  qh201292 		/mpxio-disable[ 	]*=.*;$/{ w '$3'
    104   7878  Yongfeng 						  d
    105   7878  Yongfeng 						}
    106   7878  Yongfeng 		/disable-sata-mpxio[ 	]*=.*;$/{ w '$4'
    107   3385  qh201292 						  d
    108   3385  qh201292 						}
    109      0    stevel 		/;$/{ p
    110      0    stevel 		      d
    111      0    stevel 		    }
    112      0    stevel 		:rdnext
    113      0    stevel 		N
    114      0    stevel 		s/[ 	]*$//
    115      0    stevel 		/[^;]$/b rdnext
    116   3385  qh201292 		/mpxio-disable[ 	]*=/{ s/\n/ /g
    117   3385  qh201292 					      w '$3'
    118   3385  qh201292 					      d
    119   3385  qh201292 					    }
    120   3385  qh201292 		' $1 > $2
    121      0    stevel 
    122      0    stevel 	return $?
    123      0    stevel }
    124      0    stevel 
    125      0    stevel #
    126      0    stevel # backup the last saved copy of the specified files.
    127      0    stevel # $*	files to backup
    128      0    stevel #
    129      0    stevel backup_lastsaved()
    130      0    stevel {
    131      0    stevel 	for file in $*
    132      0    stevel 	do
    133   7498     James 		newfile=`basename $file`
    134   7498     James 		$CP $file $SAVEDIR/$newfile.$cmd.$NOW
    135      0    stevel 	done
    136      0    stevel }
    137      0    stevel 
    138      0    stevel #
    139      0    stevel # build recover instructions
    140      0    stevel #
    141      0    stevel # $1	1 to include boot script in the instructions
    142      0    stevel #	0 otherwise
    143      0    stevel #
    144      0    stevel build_recover()
    145      0    stevel {
    146      0    stevel 	gettext "Instructions to recover your previous STMS configuration (if in case the system does not boot):\n\n" > $RECOVERFILE
    147      0    stevel 	echo "\tboot net \c"  >> $RECOVERFILE
    148      0    stevel 	gettext "(or from a cd/dvd/another disk)\n" >> $RECOVERFILE
    149      0    stevel 	echo "\tfsck <your-root-device>" >> $RECOVERFILE
    150      0    stevel 	echo "\tmount <your-root-device> /mnt" >> $RECOVERFILE
    151      0    stevel 
    152  10882   Jianfei 	if [ "$cmd" = "update" ]; then
    153      0    stevel 		gettext "\tUndo the modifications you made to STMS configuration.\n\tFor example undo any changes you made to " >> $RECOVERFILE
    154   4022  jw149990 		echo "/mnt$KDRVCONF." >> $RECOVERFILE
    155      0    stevel 	else
    156   7498     James 		echo "\tcp /mnt${SAVEDIR}/$DRVCONF.$cmd.$NOW /mnt$KDRVCONF" >> $RECOVERFILE
    157      0    stevel 	fi
    158      0    stevel 
    159   4073      jmcp 	if [ $1 -eq 1 ]; then
    160   7498     James 		echo "\tcp /mnt${SAVEDIR}/vfstab.$cmd.$NOW /mnt$VFSTAB" >> $RECOVERFILE
    161      0    stevel 
    162      0    stevel 		echo "repository /mnt/etc/svc/repository.db" > $SVCCFG_RECOVERY
    163      0    stevel 		echo "select $STMSINSTANCE" >> $SVCCFG_RECOVERY
    164      0    stevel 		echo "setprop general/enabled=false" >> $SVCCFG_RECOVERY
    165      0    stevel 		echo "exit" >> $SVCCFG_RECOVERY
    166      0    stevel 
    167   4073      jmcp 		echo "\t$SVCCFG -f /mnt$SVCCFG_RECOVERY" >> $RECOVERFILE
    168   3385  qh201292 
    169  10882   Jianfei 		if [ -n "$new_bootpath" -a "$MACH" = "i386" ]; then
    170   7498     James 			echo "\tcp /mnt${SAVEDIR}/bootenv.rc.$cmd.$NOW /mnt/boot/solaris/$BOOTENV_FILE" >> $RECOVERFILE
    171   3385  qh201292 		fi
    172      0    stevel 	fi
    173      0    stevel 
    174   4022  jw149990 	rootdisk=`$MOUNT | $GREP "/ on " | cut -f 3 -d " "`
    175      0    stevel 	echo "\tumount /mnt\n\treboot\n\n${rootdisk} \c" >> $RECOVERFILE
    176      0    stevel 	gettext "was your root device,\nbut it could be named differently after you boot net.\n" >> $RECOVERFILE
    177      0    stevel }
    178   7498     James 
    179      0    stevel 
    180      0    stevel #
    181      0    stevel # Arrange for /etc/vfstab and dump configuration to be updated
    182      0    stevel # during the next reboot. If the cmd is "enable" or "disable", copy
    183   4022  jw149990 # $TMPDRVCONF to $KDRVCONF.
    184      0    stevel #
    185      0    stevel # Returns 0 on success, 1 on failure.
    186      0    stevel #
    187      0    stevel update_sysfiles()
    188      0    stevel {
    189   4022  jw149990 
    190   7498     James 	gettext "WARNING: This operation will require a reboot.\n"
    191   7498     James 	gettext "Do you want to continue ? [y/n] (default: y) "
    192      0    stevel 	read response
    193      0    stevel 
    194  10882   Jianfei 	if [ -n "$response" -a "$response" != "y" -a \
    195  10882   Jianfei 	    "$response" != "Y" ]; then
    196   4022  jw149990 		for d in $DRVLIST; do
    197   4022  jw149990 			TMPDRVCONF=/var/run/tmp.$d.conf.$$
    198   7498     James 			$RM -f $TMPDRVCONF > /dev/null 2>&1
    199   4022  jw149990 		done;
    200   4022  jw149990 		return 0;
    201      0    stevel 	fi
    202      0    stevel 
    203   4073      jmcp 	# set need_bootscript to the number of drivers that
    204   4073      jmcp 	# we support.
    205   4073      jmcp 	need_bootscript=`echo $SUPPORTED_DRIVERS|$AWK -F"|" '{print NF}'`
    206   4022  jw149990 
    207  10882   Jianfei 	if [ "$cmd" = "enable" -o "$cmd" = "disable" ]; then
    208      0    stevel 
    209   4022  jw149990 		for d in $DRVLIST; do
    210   4022  jw149990 			DRVCONF=$d.conf
    211   4022  jw149990 			KDRVCONF=/kernel/drv/$d.conf
    212   4022  jw149990 			TMPDRVCONF=/var/run/tmp.$d.conf.$$
    213      0    stevel 
    214   7498     James 			$CP $KDRVCONF $SAVEDIR/`basename $KDRVCONF`.$cmd.$NOW
    215   4073      jmcp 			if [ -f $TMPDRVCONF ]; then
    216   7498     James 				$CP $TMPDRVCONF $KDRVCONF
    217   7498     James 				$RM -f $TMPDRVCONF
    218   4073      jmcp 			else
    219   4073      jmcp 				# if $TMPDRVCONF doesn't exist, then we
    220   4073      jmcp 				# haven't made any changes to it
    221   4073      jmcp 				continue;
    222   4073      jmcp 			fi
    223   4022  jw149990 
    224   4022  jw149990 			#
    225   4022  jw149990 			# there is no need to update the system files in the following
    226   4022  jw149990 			# cases:
    227   4022  jw149990 			# - we are enabling mpxio and the system has no configured
    228   4022  jw149990 			#   disks accessible by phci paths.
    229   4022  jw149990 			# - we are disabling mpxio and the system has no configured
    230   4022  jw149990 			#   disks accessible by vhci paths.
    231   4022  jw149990 			#
    232   4022  jw149990 
    233   4073      jmcp 			# Function to setup the CLIENT_TYPE_PHCI string based on
    234   4073      jmcp 			# the list of drivers that we're operating on. The variable
    235   4073      jmcp 			# depends upon the pathname of the parent node in the 
    236   4073      jmcp 			# device tree, which can be different on x86/x64 and sparc.
    237   4073      jmcp 
    238   7498     James 			CLIENT_TYPE_PHCI=`$STMSBOOTUTIL -D $d -N`;
    239   4073      jmcp 
    240  10882   Jianfei 			if [ -z "$CLIENT_TYPE_PHCI" ]; then
    241   4022  jw149990 				continue;
    242   4022  jw149990 			fi
    243   4022  jw149990 
    244  10882   Jianfei 			if [ "$cmd" = "enable" ]; then
    245   7498     James 				$LS -l /dev/dsk/*s2 2> /dev/null | \
    246   4022  jw149990 				    $EGREP -s "$CLIENT_TYPE_PHCI"
    247   4022  jw149990 			else
    248   7498     James 				$LS -l /dev/dsk/*s2 2> /dev/null | \
    249   4022  jw149990 				    $EGREP -s "$CLIENT_TYPE_VHCI"
    250   4022  jw149990 			fi
    251   4022  jw149990 
    252   4022  jw149990 			if [ $? -ne 0 ]; then
    253   4073      jmcp 				need_bootscript=`$EXPR $need_bootscript - 1`
    254   4022  jw149990 			fi
    255   4022  jw149990 		done
    256   4022  jw149990 	fi
    257   4022  jw149990 
    258   4073      jmcp 	if [ $need_bootscript -gt 0 ]; then
    259   4073      jmcp 		need_bootscript=1
    260  10882   Jianfei 		if [  -n "$new_bootpath" -a "$MACH" = "i386" ]; then
    261   3385  qh201292 			#only update bootpath for x86.
    262   7498     James 			$CP /boot/solaris/$BOOTENV_FILE $SAVEDIR/$BOOTENV_FILE.$cmd.$NOW
    263   7498     James 			$EEPROM bootpath="$new_bootpath"
    264   3385  qh201292 		fi
    265  10882   Jianfei 
    266  10882   Jianfei 		if [ "$svm_md_device" != "NOT_MAPPED" ]; then
    267  10882   Jianfei 			# Enable the mpxio-upgrade service for the reboot
    268  10882   Jianfei 			$SVCADM disable -t $STMSINSTANCE
    269  10882   Jianfei 			$SVCCFG -s $STMSINSTANCE "setprop general/enabled=true"
    270  10882   Jianfei 		fi
    271   4073      jmcp 	else
    272   4073      jmcp 		need_bootscript=0
    273      0    stevel 	fi
    274      0    stevel 
    275      0    stevel 	build_recover $need_bootscript
    276      0    stevel 
    277  10882   Jianfei 	if [ "$MACH" = "i386" ]; then
    278   4022  jw149990 		$BOOTADM update-archive
    279   4022  jw149990 	fi
    280   4022  jw149990 
    281      0    stevel 	gettext "The changes will come into effect after rebooting the system.\nReboot the system now ? [y/n] (default: y) "
    282      0    stevel 	read response
    283      0    stevel 
    284  10882   Jianfei 	if [ -z "$response" -o "$response" = "y" -o \
    285  10882   Jianfei 	    "$response" = "Y" ]; then
    286   7498     James 		$REBOOT
    287      0    stevel 	fi
    288      0    stevel 
    289      0    stevel 	return 0
    290      0    stevel }
    291   7498     James 
    292      0    stevel 
    293      0    stevel #
    294      0    stevel # Enable or disable mpxio as specified by the cmd.
    295      0    stevel # Returns 0 on success, 1 on failure.
    296      0    stevel #
    297   4022  jw149990 # Args: $cmd = {enable | disable}
    298  10696     David #	$d = {fp | mpt | mpt_sas | pmcs}
    299   4022  jw149990 #
    300   4022  jw149990 # the global variable $DRVLIST is used
    301   4022  jw149990 #
    302      0    stevel configure_mpxio()
    303      0    stevel {
    304   7498     James 	# be careful here, we've got embedded \t characters
    305   7498     James 	# in sed's pattern space.
    306   3385  qh201292 	mpxiodisableno='mpxio-disable[ 	]*=[ 	]*"no"[ 	]*;'
    307   3385  qh201292 	mpxiodisableyes='mpxio-disable[ 	]*=[ 	]*"yes"[ 	]*;'
    308   7878  Yongfeng 	satadisableno='disable-sata-mpxio[ 	]*=[ 	]*"no"[ 	]*;'
    309   7878  Yongfeng 	satadisableyes='disable-sata-mpxio[ 	]*=[ 	]*"yes"[ 	]*;'
    310   3385  qh201292 
    311  10882   Jianfei 	if [ "$cmd" = "enable" ]; then
    312   3385  qh201292 		mpxiodisable_cur_entry=$mpxiodisableyes
    313   7878  Yongfeng 		satadisable_cur_entry=$satadisableyes
    314      0    stevel 		propval=no
    315   4022  jw149990 		msg=`gettext "STMS already enabled"`
    316      0    stevel 	else
    317   3385  qh201292 		mpxiodisable_cur_entry=$mpxiodisableno
    318   7878  Yongfeng 		satadisable_cur_entry=$satadisableno
    319      0    stevel 		propval=yes
    320   4022  jw149990 		msg=`gettext "STMS already disabled"`
    321      0    stevel 	fi
    322      0    stevel 
    323   4022  jw149990 	DRVCONF=$d.conf
    324   4022  jw149990 	KDRVCONF=/kernel/drv/$d.conf
    325   4022  jw149990 	TMPDRVCONF=/var/run/tmp.$d.conf.$$
    326   4022  jw149990 	TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$;
    327   7878  Yongfeng 	TMPDRVCONF_SATA_ENTRY=/var/run/tmp.$d.conf.sataentry.$$;
    328   4022  jw149990 
    329   7878  Yongfeng 	if delete_mpxio_disable_entries $KDRVCONF $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY $TMPDRVCONF_SATA_ENTRY; then
    330   4022  jw149990 
    331   4022  jw149990 		if [ -s $TMPDRVCONF_MPXIO_ENTRY ]; then
    332   4022  jw149990 			# $DRVCONF does have mpxiodisable entries
    333   4022  jw149990 			$EGREP -s "$mpxiodisable_cur_entry" $TMPDRVCONF_MPXIO_ENTRY
    334   7878  Yongfeng 			if [ $? -eq 0 ]; then
    335   7878  Yongfeng 				reboot_needed=`$EXPR $reboot_needed + 1`
    336   7878  Yongfeng 			else
    337   3385  qh201292 				# if all mpxiodisable entries are no/yes for
    338   3385  qh201292 				# enable/disable mpxio, notify the user
    339   7878  Yongfeng 				$EGREP -s "$satadisable_cur_entry" $TMPDRVCONF_SATA_ENTRY
    340  10882   Jianfei 				if [ $? -eq 0 -a "$d" = "mpt" ]; then
    341   7878  Yongfeng 					reboot_needed=`$EXPR $reboot_needed + 1`
    342   7878  Yongfeng 				else
    343   7878  Yongfeng 					$RM -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY $TMPDRVCONF_SATA_ENTRY > /dev/null 2>&1
    344  11127  Yongfeng 					return 0;
    345   7878  Yongfeng 				fi
    346   3385  qh201292 			fi
    347   4022  jw149990 
    348   4022  jw149990 			# If mpxiodisable entries do not exist, always continue update
    349      0    stevel 		fi
    350      0    stevel 	else
    351   7878  Yongfeng 		$RM -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY $TMPDRVCONF_SATA_ENTRY > /dev/null 2>&1
    352   4022  jw149990 		gettext "failed to update " 1>&2
    353   4022  jw149990 		echo "$KDRVCONF." 1>&2 
    354      0    stevel 		gettext "No changes were made to your STMS configuration.\n" 1>&2
    355      0    stevel 		return 1
    356      0    stevel 	fi
    357   3385  qh201292 
    358   9329   Jianfei 	rm $TMPDRVCONF_MPXIO_ENTRY $TMPDRVCONF_SATA_ENTRY > /dev/null 2>&1
    359   4022  jw149990 	echo "mpxio-disable=\"${propval}\";" >> $TMPDRVCONF
    360  10882   Jianfei 	if [ "$d" = "mpt" ]; then
    361   9329   Jianfei 		echo "disable-sata-mpxio=\"${propval}\";" >> $TMPDRVCONF
    362   9329   Jianfei 	fi
    363   3385  qh201292 
    364      0    stevel }
    365      0    stevel 
    366      0    stevel setcmd()
    367      0    stevel {
    368  10882   Jianfei 	if [ "$cmd" = "none" ]; then
    369      0    stevel 		cmd=$1
    370      0    stevel 	else
    371      0    stevel 		echo "$USAGE" 1>&2
    372      0    stevel 		exit 2
    373      0    stevel 	fi
    374      0    stevel }
    375   3385  qh201292 
    376   4022  jw149990 #
    377   7498     James # Need to update bootpath on x86 if boot system from FC disk
    378   7498     James # Only update bootpath here when mpxio is enabled
    379   7498     James # If mpxio is currently disabled, then we'll update bootpath in the
    380   7498     James # mpxio-upgrade service method on reboot.
    381   4022  jw149990 #
    382   4022  jw149990 
    383   3385  qh201292 get_newbootpath_for_stmsdev() {
    384  10882   Jianfei 	if [ "$cmd" = "enable" ]; then
    385   3385  qh201292 		return 0
    386   3385  qh201292 	fi
    387   3385  qh201292 
    388   7498     James 	cur_bootpath=`$STMSBOOTUTIL -b`
    389   7498     James 	if [ $? != 0 ]; then
    390   3385  qh201292 		return 1
    391   3385  qh201292 	fi
    392   3385  qh201292 
    393   7498     James 	# Since on x64 platforms the eeprom command doesn't update the
    394   7498     James 	# kernel, the file /boot/solaris/bootenv.rc and the kernel's
    395   7498     James 	# bootpath variable have a good chance of differing. We do some
    396   7498     James 	# extra handwaving to get the correct bootpath variable setting. 
    397   7498     James 
    398   7498     James 	ONDISKVER=`$AWK '/bootpath/ {print $3}' /boot/solaris/bootenv.rc|\
    399   7498     James 		$SED -e"s,',,g"`
    400  10882   Jianfei 	if [ "$ONDISKVER" != "$cur_bootpath" ]; then
    401   7498     James 		cur_bootpath="$ONDISKVER"
    402   3385  qh201292 	fi
    403   3385  qh201292 
    404   7498     James 	NEWBOOTPATH=""
    405   7498     James 	for path in $cur_bootpath; do
    406   7498     James 		mapped=`$STMSBOOTUTIL -p $path`
    407   7498     James 		if [ "$mapped" != "NOT_MAPPED" ]; then
    408   7498     James 			if [ "$mapped" != "$path" ]; then
    409   7498     James 				NEWBOOTPATH=`echo "$path " | \
    410   7498     James 				   $SED -e"s|$path|$mapped|"`" $NEWBOOTPATH"
    411   7498     James 			else
    412   7498     James 				NEWBOOTPATH="$NEWBOOTPATH $path"
    413   7498     James 			fi
    414   7498     James 		fi
    415   7498     James 	done
    416   7498     James 	# now strip off leading and trailing space chars
    417   7498     James 	new_bootpath=`echo $NEWBOOTPATH`
    418   7498     James 	return 0
    419   4022  jw149990 }
    420   4022  jw149990 
    421   4022  jw149990 #
    422   4022  jw149990 # Emit a warning message to the user that by default we
    423   4022  jw149990 # operate on all multipath-capable controllers that are
    424   4022  jw149990 # attached to the system, and that if they want to operate
    425  10696     David # on only a specific controller type (fp|mpt|mpt_sas|pmcs|....) then 
    426   4022  jw149990 # they need to re-invoke stmsboot with "-D $driver" in
    427   4022  jw149990 # their argument list
    428   4022  jw149990 #
    429   4022  jw149990 
    430   4022  jw149990 emit_driver_warning_msg() {
    431   4022  jw149990 
    432   4022  jw149990 	# for each driver that we support, grab the list
    433   4022  jw149990 	# of controllers attached to the system.
    434   4022  jw149990 
    435   4073      jmcp 	echo ""
    436   4675      jmcp 	gettext "WARNING: stmsboot operates on each supported multipath-capable controller\n"
    437   4675      jmcp 	gettext "         detected in a host. In your system, these controllers are\n\n"
    438   4022  jw149990 
    439   4073      jmcp 	for WARNDRV in `echo $SUPPORTED_DRIVERS| $SED -e"s,|, ,g"`; do
    440   7498     James 		$STMSBOOTUTIL -D $WARNDRV -n
    441   4022  jw149990 	done;
    442   4022  jw149990 	
    443   4022  jw149990 	echo ""
    444   4675      jmcp 	gettext "If you do NOT wish to operate on these controllers, please quit stmsboot\n"
    445  10696     David 	gettext "and re-invoke with -D { fp | mpt | mpt_sas | pmcs} to specify which controllers you wish\n"
    446   4675      jmcp 	gettext "to modify your multipathing configuration for.\n"
    447   4022  jw149990 
    448   4073      jmcp 	echo ""
    449   4675      jmcp 	gettext "Do you wish to continue? [y/n] (default: y) " 
    450   4022  jw149990 	read response
    451   4022  jw149990 
    452  10882   Jianfei 	if [ -n "$response" -a "$response" != "Y" -a \
    453  10882   Jianfei 	    "$response" != "y" ]; then
    454   4022  jw149990 		exit
    455   4022  jw149990 	fi
    456   4022  jw149990 }
    457      0    stevel 
    458   7498     James 
    459   7498     James #
    460   7498     James #
    461   7498     James # main starts here
    462   7498     James #
    463   7498     James 
    464      0    stevel cmd=none
    465      0    stevel # process options
    466   4022  jw149990 while getopts D:geduLl: c
    467      0    stevel do
    468      0    stevel 	case $c in
    469      0    stevel 	e)	setcmd enable;;
    470      0    stevel 	d)	setcmd disable;;
    471      0    stevel 	u)	setcmd update;;
    472      0    stevel 	L)	setcmd listall;;
    473      0    stevel 	l)	setcmd list
    474      0    stevel 		controller=$OPTARG;;
    475   4022  jw149990 	D)	DRV=$OPTARG;;
    476   4022  jw149990 	g)	GUID="-g";;
    477      0    stevel 	\?)	echo "$USAGE" 1>&2
    478      0    stevel 		exit 2;;
    479      0    stevel 	esac
    480      0    stevel done
    481      0    stevel 
    482  10882   Jianfei if [ "$cmd" = "none" ]; then
    483      0    stevel 	echo "$USAGE" 1>&2
    484      0    stevel 	exit 2
    485      0    stevel fi
    486      0    stevel 
    487  10882   Jianfei if [ -z "$DRV" ]; then
    488  10696     David 	DRVLIST="fp mpt mpt_sas pmcs"
    489   4022  jw149990 else
    490   4022  jw149990 	DRVLIST=$DRV
    491   4022  jw149990 fi
    492   4022  jw149990 
    493   4317      jmcp USERID=`id | $EGREP "uid=0"`
    494   4317      jmcp if [ -z "$USERID" ]; then
    495      0    stevel 	gettext "You must be super-user to run this script.\n" 1>&2
    496      0    stevel 	exit 1
    497      0    stevel fi
    498      0    stevel 
    499      0    stevel # just a sanity check
    500      0    stevel if [ ! -f $STMSBOOTUTIL -o ! -f $STMSMETHODSCRIPT ]; then
    501      0    stevel 	fmt=`gettext "Can't find %s and/or %s"`
    502      0    stevel 	printf "$fmt\n" "$STMSBOOTUTIL" "$STMSMETHODSCRIPT" 1>&2
    503      0    stevel 	exit 1
    504      0    stevel fi
    505      0    stevel 
    506   4022  jw149990 # If the old sun4u-specific SMF method is found, remove it
    507   4073      jmcp $SVCCFG -s "platform/sun4u/mpxio-upgrade:default" < /dev/null > /dev/null 2>&1
    508   4073      jmcp if [ $? -eq 0 ]; then
    509   4073      jmcp 	$SVCCFG delete "platform/sun4u/mpxio-upgrade:default" > /dev/null 2>&1
    510   4022  jw149990 fi
    511   4022  jw149990 
    512   4022  jw149990 # now import the new service, if necessary
    513   4073      jmcp $SVCPROP -q $STMSINSTANCE < /dev/null > /dev/null 2>&1
    514   4022  jw149990 if [ $? -ne 0 ]; then
    515   4022  jw149990 	if [ -f /var/svc/manifest/system/device/mpxio-upgrade.xml ]; then
    516   4073      jmcp 		$SVCCFG import /var/svc/manifest/system/device/mpxio-upgrade.xml
    517   4022  jw149990 		if [ $? -ne 0 ]; then
    518  10882   Jianfei 
    519   4675      jmcp 			fmt=`gettext "Unable to import the %s service"`
    520   4022  jw149990 			printf "$fmt\n" "$STMSINSTANCE" 1>&2
    521   4022  jw149990 			exit 1
    522   4022  jw149990 		else
    523   4022  jw149990 			fmt=`gettext "Service %s imported successfully, continuing"`
    524   4022  jw149990 			printf "$fmt\n" "$STMSINSTANCE" 1>&2
    525   4022  jw149990 		fi
    526   4022  jw149990 	else
    527   4022  jw149990 		fmt=`gettext "Service %s does not exist on this host"`
    528   4022  jw149990  		printf "$fmt\n" "$STMSINSTANCE" 1>&2
    529   4022  jw149990 		exit 1
    530   4022  jw149990 	fi
    531      0    stevel fi
    532      0    stevel 
    533   7498     James 
    534   7498     James # make sure we can stash our data somewhere private
    535   7498     James if [ ! -d $SAVEDIR ]; then
    536   7498     James 	$MKDIR -p $SAVEDIR
    537   7498     James fi
    538   7498     James # prime the cache
    539   7498     James $STMSBOOTUTIL -i
    540   7498     James 
    541   7498     James 
    542  10882   Jianfei if [ "$cmd" = "enable" -o "$cmd" = "disable" -o "$cmd" = "update" ]; then
    543      0    stevel 	#
    544      0    stevel 	# The bootup script doesn't work on cache-only-clients as the script
    545   2097  sjelinek 	# is executed before the plumbing for cachefs mounting of root is done.
    546      0    stevel 	#
    547   4022  jw149990 	if $MOUNT -v | $EGREP -s " on / type (nfs|cachefs) "; then
    548   7498     James 		gettext "This command option is not supported on systems with an nfs or cachefs mounted root filesystem.\n" 1>&2
    549      0    stevel 		exit 1
    550   4073      jmcp 	fi
    551   4073      jmcp 
    552   4073      jmcp 	# if the user has left the system with the mpxio-upgrade service
    553   4073      jmcp 	# in a temporarily disabled state (ie, service is armed for the next
    554   4073      jmcp 	# reboot), then let them know. We need to ensure that the system is
    555   4073      jmcp 	# is in a sane state before allowing any further invocations, so 
    556   4073      jmcp 	# try to get the system admin to do so
    557   4073      jmcp 
    558   7498     James 	ISARMED=`$SVCS -l $STMSINSTANCE|$GREP "enabled.*false.*temporary"`
    559   7498     James 	if [ ! $? ]; then
    560   4073      jmcp 		echo ""
    561   4675      jmcp 		gettext "You need to reboot the system in order to complete\n"
    562   4675      jmcp 		gettext "the previous invocation of stmsboot.\n"
    563   4073      jmcp 		echo ""
    564   4675      jmcp 		gettext "Do you wish to reboot the system now? (y/n, default y) "
    565   4073      jmcp 		read response
    566   4073      jmcp 
    567  10882   Jianfei 		if [ -z "$response" -o "x$response" = "Y" -o \
    568  10882   Jianfei 		    "$response" = "y" ]; then
    569   7498     James 			$REBOOT
    570   4073      jmcp 		else
    571   4675      jmcp 			echo ""
    572   4675      jmcp 			gettext "Please reboot this system before continuing\n"
    573   4675      jmcp 			echo ""
    574   4073      jmcp 			exit 1
    575   4073      jmcp 		fi
    576      0    stevel 	fi
    577      0    stevel 
    578   7498     James 	#
    579   7498     James 	# keep a copy of the last saved files, useful for manual
    580   7498     James 	# recovery in case of a problem.
    581   7498     James 	#
    582   7498     James 	for d in $DRVLIST; do
    583   7498     James 		DRVCONF=$d.conf
    584   7498     James 		KDRVCONF=/kernel/drv/$d.conf
    585   7498     James 		TMPDRVCONF=/var/run/tmp.$d.conf.$$
    586   7498     James 		TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$;
    587  10882   Jianfei 		if [ "$MACH" = "sparc" ]; then
    588   7498     James 			backup_lastsaved $KDRVCONF $VFSTAB
    589   7498     James 		else
    590   7498     James 			backup_lastsaved $KDRVCONF $VFSTAB /boot/solaris/$BOOTENV_FILE
    591   7498     James 		fi
    592   7498     James 	done
    593      0    stevel fi
    594      0    stevel 
    595  10882   Jianfei if [ "$cmd" = "enable" -o "$cmd" = "disable" ]; then
    596   4022  jw149990 
    597   4022  jw149990 	msgneeded=`echo "$DRVLIST" |grep " "`
    598   4022  jw149990 	if [ -n "$msgneeded" ]; then
    599   4022  jw149990 		emit_driver_warning_msg
    600   4022  jw149990 	fi
    601   4022  jw149990 	for d in $DRVLIST; do
    602   4022  jw149990 		configure_mpxio $cmd $d
    603   4022  jw149990 	done
    604   4022  jw149990 
    605   4022  jw149990 	if [ $reboot_needed -ne 0 ]; then
    606   4022  jw149990 		# Need to update bootpath on x86 if our boot device is
    607   4022  jw149990 		# now accessed through mpxio.
    608   4022  jw149990 		# Only update bootpath before reboot when mpxio is enabled
    609   4022  jw149990 		# If mpxio is currently disabled, we will update bootpath
    610   4022  jw149990 		# on reboot in the mpxio-upgrade service
    611   4022  jw149990 		
    612  10882   Jianfei 		if [ "$cmd" = "disable" ]; then
    613  10882   Jianfei 			if [ "$MACH" = "i386" ]; then
    614   8101     James 				get_newbootpath_for_stmsdev
    615   8101     James 				if [ $? -ne 0 ]; then
    616   8101     James 					$RM -f $TMPDRVCONF > /dev/null 2>&1
    617   8101     James 					gettext "failed to update bootpath.\n" 1>&2
    618   8101     James 					gettext "No changes were made to your STMS configuration.\n" 1>&2
    619   8101     James 					return 1
    620   8101     James 				fi
    621   4022  jw149990 			fi
    622   8101     James 			# If we're not using ZFS root then we need
    623   8101     James 			# to keep track of what / maps to in case
    624   8101     James 			# it's an active-active device and we boot from
    625   8101     James 			# the other path
    626   8101     James 			ROOTSCSIVHCI=`$DF /|$AWK -F":" '{print $1}' | \
    627   8101     James 			    $AWK -F"(" '{print $2}'| \
    628   9329   Jianfei 			    $SED -e"s,dsk,rdsk," -e"s,s.[ ]*),,"`
    629   8101     James 			$STMSBOOTUTIL -L | $GREP $ROOTSCSIVHCI | \
    630   8101     James 			    $AWK '{print $1}' | $SED -e"s,rdsk,dsk,g" \
    631   8101     James 			    >$BOOTDEVICES
    632   4022  jw149990 		fi
    633  10882   Jianfei 		new_rootdev=`$DF /|$AWK -F":" '{print $1}' | \
    634  10882   Jianfei 			$AWK -F"(" '{print $2}'| \
    635  10882   Jianfei 			$SED -e"s,dsk,rdsk," -e"s,[ ]*),,"`
    636  10882   Jianfei 		svm_md_device=`$STMSBOOTUTIL -m $new_rootdev`
    637   4022  jw149990 		update_sysfiles
    638   4022  jw149990 	else
    639   4022  jw149990 		echo "STMS is already ${cmd}d. No changes or reboots needed"
    640   4022  jw149990 	fi
    641   4022  jw149990 
    642   4022  jw149990 
    643  10882   Jianfei elif [ "$cmd" = "update" ]; then
    644  10882   Jianfei 	if [ "$MACH" = "i386" ]; then
    645   3385  qh201292 	# In this case we always change the bootpath to phci-based
    646   3385  qh201292 	# path first. bootpath will later be modified in mpxio-upgrade
    647   3385  qh201292 	# to the vhci-based path if mpxio is enabled on root.
    648   3385  qh201292 		get_newbootpath_for_stmsdev
    649   3385  qh201292 		if [ $? -ne 0 ]; then
    650   3385  qh201292 			gettext "failed to update bootpath.\n" 1>&2
    651   3385  qh201292 			return 1
    652   3385  qh201292 		fi
    653   3385  qh201292 	fi
    654      0    stevel 	update_sysfiles
    655   4022  jw149990 
    656  10882   Jianfei elif [ "$cmd" = "list" ]; then
    657   4022  jw149990 		$STMSBOOTUTIL $GUID -l $controller
    658      0    stevel else
    659   4022  jw149990 		$STMSBOOTUTIL $GUID -L
    660      0    stevel fi
    661      0    stevel 
    662      0    stevel exit $?
    663