xref: /titanic_53/usr/src/cmd/stmsboot/stmsboot.sh (revision 815dd9170b31c7359f1b3fbe11df4da223766647)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
66deb031bSsjelinek# Common Development and Distribution License (the "License").
76deb031bSsjelinek# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
235a4c37c9Sqh201292# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
27*815dd917Sjmcp#
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gatePATH=/usr/bin:/usr/sbin:$PATH; export PATH
307c478bd9Sstevel@tonic-gateSTMSBOOTUTIL=/lib/mpxio/stmsboot_util
317c478bd9Sstevel@tonic-gateSTMSMETHODSCRIPT=/lib/svc/method/mpxio-upgrade
3260fffc19Sjw149990KDRVCONF=
3360fffc19Sjw149990DRVCONF=
3460fffc19Sjw149990TMPDRVCONF=
3560fffc19Sjw149990TMPDRVCONF_MPXIO_ENTRY=
3660fffc19Sjw149990DRVLIST=
3760fffc19Sjw149990GUID=
387c478bd9Sstevel@tonic-gateVFSTAB=/etc/vfstab
397c478bd9Sstevel@tonic-gateSAVEDIR=/etc/mpxio
407c478bd9Sstevel@tonic-gateRECOVERFILE=$SAVEDIR/recover_instructions
417c478bd9Sstevel@tonic-gateSVCCFG_RECOVERY=$SAVEDIR/svccfg_recover
4260fffc19Sjw149990SUPPORTED_DRIVERS="fp|mpt"
4360fffc19Sjw149990USAGE=`gettext "Usage: stmsboot [-D $SUPPORTED_DRIVERS] -e | -d | -u | -L | -l controller_number"`
44aca6e9ccSramatTEXTDOMAIN=SUNW_OST_OSCMD
45aca6e9ccSramatexport TEXTDOMAIN
465a4c37c9Sqh201292STMSINSTANCE=system/device/mpxio-upgrade:default
4760fffc19Sjw149990STMSBOOT=/usr/sbin/stmsboot
4860fffc19Sjw149990BOOTADM=/sbin/bootadm
4960fffc19Sjw149990MOUNT=/usr/sbin/mount
5060fffc19Sjw149990EGREP=/usr/bin/egrep
5160fffc19Sjw149990GREP=/usr/bin/grep
5260fffc19Sjw149990AWK=/usr/bin/awk
5360fffc19Sjw149990SORT=/usr/bin/sort
5460fffc19Sjw149990UNIQ=/usr/bin/uniq
5560fffc19Sjw149990EXPR=/usr/bin/expr
56*815dd917SjmcpSED=/usr/bin/sed
57*815dd917SjmcpSVCPROP=/usr/bin/svcprop
58*815dd917SjmcpSVCCFG=/usr/sbin/svccfg
59*815dd917SjmcpSVCS=/usr/bin/svcs
60*815dd917SjmcpSVCADM=/usr/sbin/svcadm
617c478bd9Sstevel@tonic-gate
625a4c37c9Sqh201292MACH=`/usr/bin/uname -p`
635a4c37c9Sqh201292BOOTENV_FILE=/boot/solaris/bootenv.rc
6460fffc19Sjw149990
6560fffc19Sjw149990CLIENT_TYPE_VHCI="/scsi_vhci.*/ssd@|/scsi_vhci.*/disk@"
6660fffc19Sjw149990# The phci client type egrep string will change based on the
6760fffc19Sjw149990# drivers which we are operating on, and the cpu architecture
6860fffc19Sjw149990# and we call stmsboot_util -n -D $drv to get that string
6960fffc19Sjw149990CLIENT_TYPE_PHCI=
7060fffc19Sjw149990reboot_needed=0
7160fffc19Sjw149990
727c478bd9Sstevel@tonic-gate#
7360fffc19Sjw149990# Copy all entries (including comments) from source driver.conf
7460fffc19Sjw149990# to destination driver.conf except those entries which contain
7560fffc19Sjw149990# the mpxio-disable property.
767c478bd9Sstevel@tonic-gate# Take into consideration entries that spawn more than one line.
777c478bd9Sstevel@tonic-gate#
787c478bd9Sstevel@tonic-gate# $1	source driver.conf file
797c478bd9Sstevel@tonic-gate# $2	destination driver.conf file
807c478bd9Sstevel@tonic-gate#
817c478bd9Sstevel@tonic-gate# Returns 0 on success, non zero on failure.
827c478bd9Sstevel@tonic-gate#
837c478bd9Sstevel@tonic-gatedelete_mpxio_disable_entries()
847c478bd9Sstevel@tonic-gate{
857c478bd9Sstevel@tonic-gate	sed '
867c478bd9Sstevel@tonic-gate		/^[ 	]*#/{ p
877c478bd9Sstevel@tonic-gate			      d
887c478bd9Sstevel@tonic-gate			    }
897c478bd9Sstevel@tonic-gate		s/[ 	]*$//
907c478bd9Sstevel@tonic-gate		/^$/{ p
917c478bd9Sstevel@tonic-gate		      d
927c478bd9Sstevel@tonic-gate		    }
935a4c37c9Sqh201292		/mpxio-disable[ 	]*=.*;$/{ w '$3'
945a4c37c9Sqh201292						  d
955a4c37c9Sqh201292						}
967c478bd9Sstevel@tonic-gate		/;$/{ p
977c478bd9Sstevel@tonic-gate		      d
987c478bd9Sstevel@tonic-gate		    }
997c478bd9Sstevel@tonic-gate		:rdnext
1007c478bd9Sstevel@tonic-gate		N
1017c478bd9Sstevel@tonic-gate		s/[ 	]*$//
1027c478bd9Sstevel@tonic-gate		/[^;]$/b rdnext
1035a4c37c9Sqh201292		/mpxio-disable[ 	]*=/{ s/\n/ /g
1045a4c37c9Sqh201292					      w '$3'
1055a4c37c9Sqh201292					      d
1065a4c37c9Sqh201292					    }
1075a4c37c9Sqh201292		' $1 > $2
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate	return $?
1107c478bd9Sstevel@tonic-gate}
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate#
1137c478bd9Sstevel@tonic-gate# backup the last saved copy of the specified files.
1147c478bd9Sstevel@tonic-gate# $*	files to backup
1157c478bd9Sstevel@tonic-gate#
1167c478bd9Sstevel@tonic-gatebackup_lastsaved()
1177c478bd9Sstevel@tonic-gate{
1187c478bd9Sstevel@tonic-gate	for file in $*
1197c478bd9Sstevel@tonic-gate	do
1207c478bd9Sstevel@tonic-gate		file=`basename $file`
1217c478bd9Sstevel@tonic-gate		if [ -f $SAVEDIR/$file ]; then
1227c478bd9Sstevel@tonic-gate			mv $SAVEDIR/$file $SAVEDIR/${file}.old
1237c478bd9Sstevel@tonic-gate		fi
1247c478bd9Sstevel@tonic-gate	done
1257c478bd9Sstevel@tonic-gate}
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate#
1287c478bd9Sstevel@tonic-gate# build recover instructions
1297c478bd9Sstevel@tonic-gate#
1307c478bd9Sstevel@tonic-gate# $1	1 to include boot script in the instructions
1317c478bd9Sstevel@tonic-gate#	0 otherwise
1327c478bd9Sstevel@tonic-gate#
1337c478bd9Sstevel@tonic-gatebuild_recover()
1347c478bd9Sstevel@tonic-gate{
1357c478bd9Sstevel@tonic-gate	gettext "Instructions to recover your previous STMS configuration (if in case the system does not boot):\n\n" > $RECOVERFILE
1367c478bd9Sstevel@tonic-gate	echo "\tboot net \c"  >> $RECOVERFILE
1377c478bd9Sstevel@tonic-gate	gettext "(or from a cd/dvd/another disk)\n" >> $RECOVERFILE
1387c478bd9Sstevel@tonic-gate	echo "\tfsck <your-root-device>" >> $RECOVERFILE
1397c478bd9Sstevel@tonic-gate	echo "\tmount <your-root-device> /mnt" >> $RECOVERFILE
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate	if [ "x$cmd" = xupdate ]; then
1427c478bd9Sstevel@tonic-gate		gettext "\tUndo the modifications you made to STMS configuration.\n\tFor example undo any changes you made to " >> $RECOVERFILE
14360fffc19Sjw149990		echo "/mnt$KDRVCONF." >> $RECOVERFILE
1447c478bd9Sstevel@tonic-gate	else
14560fffc19Sjw149990		echo "\tcp /mnt${SAVEDIR}/$DRVCONF /mnt$KDRVCONF" >> $RECOVERFILE
1467c478bd9Sstevel@tonic-gate	fi
1477c478bd9Sstevel@tonic-gate
148*815dd917Sjmcp	if [ $1 -eq 1 ]; then
1497c478bd9Sstevel@tonic-gate		echo "\tcp /mnt${SAVEDIR}/vfstab /mnt$VFSTAB" >> $RECOVERFILE
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate		echo "repository /mnt/etc/svc/repository.db" > $SVCCFG_RECOVERY
1527c478bd9Sstevel@tonic-gate		echo "select $STMSINSTANCE" >> $SVCCFG_RECOVERY
1537c478bd9Sstevel@tonic-gate		echo "setprop general/enabled=false" >> $SVCCFG_RECOVERY
1547c478bd9Sstevel@tonic-gate		echo "exit" >> $SVCCFG_RECOVERY
1557c478bd9Sstevel@tonic-gate
156*815dd917Sjmcp		echo "\t$SVCCFG -f /mnt$SVCCFG_RECOVERY" >> $RECOVERFILE
1575a4c37c9Sqh201292
1585a4c37c9Sqh201292		if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then
1595a4c37c9Sqh201292			echo "\tcp /mnt${SAVEDIR}/bootenv.rc /mnt$BOOTENV_FILE" >> $RECOVERFILE
1605a4c37c9Sqh201292		fi
1617c478bd9Sstevel@tonic-gate	fi
1627c478bd9Sstevel@tonic-gate
16360fffc19Sjw149990	rootdisk=`$MOUNT | $GREP "/ on " | cut -f 3 -d " "`
1647c478bd9Sstevel@tonic-gate	echo "\tumount /mnt\n\treboot\n\n${rootdisk} \c" >> $RECOVERFILE
1657c478bd9Sstevel@tonic-gate	gettext "was your root device,\nbut it could be named differently after you boot net.\n" >> $RECOVERFILE
1667c478bd9Sstevel@tonic-gate}
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate#
1697c478bd9Sstevel@tonic-gate# Arrange for /etc/vfstab and dump configuration to be updated
1707c478bd9Sstevel@tonic-gate# during the next reboot. If the cmd is "enable" or "disable", copy
17160fffc19Sjw149990# $TMPDRVCONF to $KDRVCONF.
1727c478bd9Sstevel@tonic-gate#
1737c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure.
1747c478bd9Sstevel@tonic-gate#
1757c478bd9Sstevel@tonic-gateupdate_sysfiles()
1767c478bd9Sstevel@tonic-gate{
17760fffc19Sjw149990
1787c478bd9Sstevel@tonic-gate	gettext "WARNING: This operation will require a reboot.\nDo you want to continue ? [y/n] (default: y) "
1797c478bd9Sstevel@tonic-gate	read response
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate	if [ "x$response" != x -a "x$response" != xy -a \
1827c478bd9Sstevel@tonic-gate	    "x$response" != xY ]; then
18360fffc19Sjw149990		for d in $DRVLIST; do
18460fffc19Sjw149990			TMPDRVCONF=/var/run/tmp.$d.conf.$$
18560fffc19Sjw149990			rm -f $TMPDRVCONF > /dev/null 2>&1
18660fffc19Sjw149990		done;
18760fffc19Sjw149990		return 0;
1887c478bd9Sstevel@tonic-gate	fi
1897c478bd9Sstevel@tonic-gate
190*815dd917Sjmcp	# set need_bootscript to the number of drivers that
191*815dd917Sjmcp	# we support.
192*815dd917Sjmcp	need_bootscript=`echo $SUPPORTED_DRIVERS|$AWK -F"|" '{print NF}'`
19360fffc19Sjw149990
1947c478bd9Sstevel@tonic-gate	if [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then
19560fffc19Sjw149990
19660fffc19Sjw149990		for d in $DRVLIST; do
19760fffc19Sjw149990			DRVCONF=$d.conf
19860fffc19Sjw149990			KDRVCONF=/kernel/drv/$d.conf
19960fffc19Sjw149990			TMPDRVCONF=/var/run/tmp.$d.conf.$$
20060fffc19Sjw149990
20160fffc19Sjw149990			cp $KDRVCONF $SAVEDIR
202*815dd917Sjmcp			if [ -f $TMPDRVCONF ]; then
20360fffc19Sjw149990				cp $TMPDRVCONF $KDRVCONF
204*815dd917Sjmcp				rm -f $TMPDRVCONF
205*815dd917Sjmcp			else
206*815dd917Sjmcp				# if $TMPDRVCONF doesn't exist, then we
207*815dd917Sjmcp				# haven't made any changes to it
208*815dd917Sjmcp				continue;
209*815dd917Sjmcp			fi
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate			#
2127c478bd9Sstevel@tonic-gate			# there is no need to update the system files in the following
2137c478bd9Sstevel@tonic-gate			# cases:
2147c478bd9Sstevel@tonic-gate			# - we are enabling mpxio and the system has no configured
2157c478bd9Sstevel@tonic-gate			#   disks accessible by phci paths.
2167c478bd9Sstevel@tonic-gate			# - we are disabling mpxio and the system has no configured
2177c478bd9Sstevel@tonic-gate			#   disks accessible by vhci paths.
2187c478bd9Sstevel@tonic-gate			#
21960fffc19Sjw149990
220*815dd917Sjmcp			# Function to setup the CLIENT_TYPE_PHCI string based on
221*815dd917Sjmcp			# the list of drivers that we're operating on. The variable
222*815dd917Sjmcp			# depends upon the pathname of the parent node in the
223*815dd917Sjmcp			# device tree, which can be different on x86/x64 and sparc.
224*815dd917Sjmcp
225*815dd917Sjmcp			CLIENT_TYPE_PHCI=`$STMSBOOTUTIL -D $d -n`;
226*815dd917Sjmcp
22760fffc19Sjw149990			if [ "x$CLIENT_TYPE_PHCI" = "x" ]; then
22860fffc19Sjw149990				continue;
22960fffc19Sjw149990			fi
23060fffc19Sjw149990
23160fffc19Sjw149990			if [ "x$cmd" = "xenable" ]; then
2327c478bd9Sstevel@tonic-gate				ls -l /dev/dsk/*s2 2> /dev/null | \
23360fffc19Sjw149990				    $EGREP -s "$CLIENT_TYPE_PHCI"
2347c478bd9Sstevel@tonic-gate			else
2357c478bd9Sstevel@tonic-gate				ls -l /dev/dsk/*s2 2> /dev/null | \
23660fffc19Sjw149990				    $EGREP -s "$CLIENT_TYPE_VHCI"
2377c478bd9Sstevel@tonic-gate			fi
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate			if [ $? -ne 0 ]; then
240*815dd917Sjmcp				need_bootscript=`$EXPR $need_bootscript - 1`
24160fffc19Sjw149990			fi
24260fffc19Sjw149990		done
24360fffc19Sjw149990	fi
24460fffc19Sjw149990
24560fffc19Sjw149990	# if we're an x86/x64 machine and our bootpath is on fibrechannel
24660fffc19Sjw149990	# then we cannot disable mpxio for that controller. Yet.....
24760fffc19Sjw149990	# This code block is an ugly hack and when we either get full-time
24860fffc19Sjw149990	# mpxio for all devices, or devfsadm gets re-written then we can
24960fffc19Sjw149990	# remove it. For now, though, we have to see the beauty in ugly.
25060fffc19Sjw149990
25160fffc19Sjw149990	if [ "x$MACH" = "xi386" ]; then
25260fffc19Sjw149990		BOOTPATH=`/usr/sbin/eeprom bootpath | $AWK -F"=" '{print $2}'`
25360fffc19Sjw149990		FPBOOT=`echo "$BOOTPATH" | $GREP "/fp@"`
25460fffc19Sjw149990		if [ ! -z "$FPBOOT" ]; then
25560fffc19Sjw149990			NEWP=`/usr/bin/dirname $BOOTPATH`
25660fffc19Sjw149990			NNEWP=`/usr/bin/dirname $NEWP`
25760fffc19Sjw149990
25860fffc19Sjw149990			# check that we haven't already got this entry
25960fffc19Sjw149990			# in /kernel/drv/fp.conf.
26060fffc19Sjw149990
26160fffc19Sjw149990			EXISTP=`$GREP "^name.*$NNEWP" /kernel/drv/fp.conf`
26260fffc19Sjw149990			if [ $? != 0 ]; then
26360fffc19Sjw149990				cat >>/kernel/drv/fp.conf << EOF
26460fffc19Sjw149990# This entry must be the last one in the fp.conf file
26560fffc19Sjw149990# to ensure that the boot path mpxio setting is not
26660fffc19Sjw149990# accidentally overridden
26760fffc19Sjw149990name="fp" parent="$NNEWP" port=0 mpxio-disable="no";
26860fffc19Sjw149990EOF
26960fffc19Sjw149990			fi
2707c478bd9Sstevel@tonic-gate		fi
2717c478bd9Sstevel@tonic-gate	fi
2727c478bd9Sstevel@tonic-gate
273*815dd917Sjmcp	if [ $need_bootscript -gt 0 ]; then
274*815dd917Sjmcp		need_bootscript=1
2755a4c37c9Sqh201292		if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then
2765a4c37c9Sqh201292			#only update bootpath for x86.
2775a4c37c9Sqh201292			cp $BOOTENV_FILE $SAVEDIR
27860fffc19Sjw149990			/usr/sbin/eeprom bootpath=$new_bootpath
2795a4c37c9Sqh201292		fi
2807c478bd9Sstevel@tonic-gate		#
2817c478bd9Sstevel@tonic-gate		# Enable the mpxio-upgrade service, but don't run it now.
2827c478bd9Sstevel@tonic-gate		# The service will run during the next reboot and will do
2837c478bd9Sstevel@tonic-gate		# the actual job of modifying the system files.
2847c478bd9Sstevel@tonic-gate		#
285*815dd917Sjmcp		$SVCADM disable -t $STMSINSTANCE
286*815dd917Sjmcp		$SVCCFG -f - << EOF
2877c478bd9Sstevel@tonic-gateselect $STMSINSTANCE
2887c478bd9Sstevel@tonic-gatesetprop general/enabled = true
2897c478bd9Sstevel@tonic-gateEOF
290*815dd917Sjmcp	else
291*815dd917Sjmcp		need_bootscript=0
2927c478bd9Sstevel@tonic-gate	fi
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate	build_recover $need_bootscript
2957c478bd9Sstevel@tonic-gate
29660fffc19Sjw149990	if [ "x$MACH" = "xi386" ]; then
29760fffc19Sjw149990		$BOOTADM update-archive
29860fffc19Sjw149990	fi
29960fffc19Sjw149990
3007c478bd9Sstevel@tonic-gate	gettext "The changes will come into effect after rebooting the system.\nReboot the system now ? [y/n] (default: y) "
3017c478bd9Sstevel@tonic-gate	read response
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate	if [ "x$response" = x -o "x$response" = xy -o \
3047c478bd9Sstevel@tonic-gate	    "x$response" = xY ]; then
30560fffc19Sjw149990		/usr/sbin/reboot
3067c478bd9Sstevel@tonic-gate	fi
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate	return 0
3097c478bd9Sstevel@tonic-gate}
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate#
3127c478bd9Sstevel@tonic-gate# Enable or disable mpxio as specified by the cmd.
3137c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure.
3147c478bd9Sstevel@tonic-gate#
31560fffc19Sjw149990# Args: $cmd = {enable | disable}
31660fffc19Sjw149990#	$d = {fp | mpt}
31760fffc19Sjw149990#
31860fffc19Sjw149990# the global variable $DRVLIST is used
31960fffc19Sjw149990#
3207c478bd9Sstevel@tonic-gateconfigure_mpxio()
3217c478bd9Sstevel@tonic-gate{
3225a4c37c9Sqh201292	mpxiodisableno='mpxio-disable[ 	]*=[ 	]*"no"[ 	]*;'
3235a4c37c9Sqh201292	mpxiodisableyes='mpxio-disable[ 	]*=[ 	]*"yes"[ 	]*;'
3245a4c37c9Sqh201292
3257c478bd9Sstevel@tonic-gate	if [ "x$cmd" = xenable ]; then
3265a4c37c9Sqh201292		mpxiodisable_cur_entry=$mpxiodisableyes
3277c478bd9Sstevel@tonic-gate		propval=no
32860fffc19Sjw149990		msg=`gettext "STMS already enabled"`
3297c478bd9Sstevel@tonic-gate	else
3305a4c37c9Sqh201292		mpxiodisable_cur_entry=$mpxiodisableno
3317c478bd9Sstevel@tonic-gate		propval=yes
33260fffc19Sjw149990		msg=`gettext "STMS already disabled"`
3337c478bd9Sstevel@tonic-gate	fi
3347c478bd9Sstevel@tonic-gate
33560fffc19Sjw149990	DRVCONF=$d.conf
33660fffc19Sjw149990	KDRVCONF=/kernel/drv/$d.conf
33760fffc19Sjw149990	TMPDRVCONF=/var/run/tmp.$d.conf.$$
33860fffc19Sjw149990	TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$;
33960fffc19Sjw149990
34060fffc19Sjw149990	echo "Checking mpxio status for driver $d"
34160fffc19Sjw149990	if delete_mpxio_disable_entries $KDRVCONF $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY; then
34260fffc19Sjw149990
34360fffc19Sjw149990		if [ -s $TMPDRVCONF_MPXIO_ENTRY ]; then
34460fffc19Sjw149990			# $DRVCONF does have mpxiodisable entries
34560fffc19Sjw149990			$EGREP -s "$mpxiodisable_cur_entry" $TMPDRVCONF_MPXIO_ENTRY
3465a4c37c9Sqh201292			if [ $? -ne 0 ]; then
3475a4c37c9Sqh201292				# if all mpxiodisable entries are no/yes for
3485a4c37c9Sqh201292				# enable/disable mpxio, notify the user
34960fffc19Sjw149990				rm -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1
35060fffc19Sjw149990				continue;
35160fffc19Sjw149990			else
35260fffc19Sjw149990				reboot_needed=`$EXPR $reboot_needed + 1`
3537c478bd9Sstevel@tonic-gate			fi
35460fffc19Sjw149990
35560fffc19Sjw149990			# If mpxiodisable entries do not exist, always continue update
3565a4c37c9Sqh201292		fi
3577c478bd9Sstevel@tonic-gate	else
35860fffc19Sjw149990		rm -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1
3597c478bd9Sstevel@tonic-gate		gettext "failed to update " 1>&2
36060fffc19Sjw149990		echo "$KDRVCONF." 1>&2
3617c478bd9Sstevel@tonic-gate		gettext "No changes were made to your STMS configuration.\n" 1>&2
3627c478bd9Sstevel@tonic-gate		return 1
3637c478bd9Sstevel@tonic-gate	fi
3645a4c37c9Sqh201292
36560fffc19Sjw149990	rm $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1
36660fffc19Sjw149990	echo "mpxio-disable=\"${propval}\";" >> $TMPDRVCONF
3675a4c37c9Sqh201292
3687c478bd9Sstevel@tonic-gate}
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gatesetcmd()
3717c478bd9Sstevel@tonic-gate{
3727c478bd9Sstevel@tonic-gate	if [ "x$cmd" = xnone ]; then
3737c478bd9Sstevel@tonic-gate		cmd=$1
3747c478bd9Sstevel@tonic-gate	else
3757c478bd9Sstevel@tonic-gate		echo "$USAGE" 1>&2
3767c478bd9Sstevel@tonic-gate		exit 2
3777c478bd9Sstevel@tonic-gate	fi
3787c478bd9Sstevel@tonic-gate}
3797c478bd9Sstevel@tonic-gate
38060fffc19Sjw149990#
3815a4c37c9Sqh201292#Need to update bootpath on x86 if boot system from FC disk
3825a4c37c9Sqh201292#Only update bootpath here when mpxio is enabled
3835a4c37c9Sqh201292#If mpxio is disabled currently, will update bootpath in mpxio-upgrade
38460fffc19Sjw149990#
38560fffc19Sjw149990
3865a4c37c9Sqh201292get_newbootpath_for_stmsdev() {
3875a4c37c9Sqh201292	if [ "x$cmd" = "xenable" ]; then
3885a4c37c9Sqh201292		return 0
3895a4c37c9Sqh201292	fi
3905a4c37c9Sqh201292
39160fffc19Sjw149990	cur_bootpath=`eeprom bootpath | \
39260fffc19Sjw149990	    sed 's/bootpath=[ 	]*//g' | sed 's/[ 	]*$//'`
3935a4c37c9Sqh201292	if [ "x$cur_bootpath" = "x" ]; then
3945a4c37c9Sqh201292		gettext "failed to get bootpath by eeprom\n" 1>&2
3955a4c37c9Sqh201292		return 1
3965a4c37c9Sqh201292	fi
3975a4c37c9Sqh201292
3985a4c37c9Sqh201292	#only update bootpath for STMS path
39960fffc19Sjw149990	echo $cur_bootpath|$EGREP $CLIENT_TYPE_VHCI > /dev/null 2>&1
4005a4c37c9Sqh201292	if [ $? -eq 1 ]; then
4015a4c37c9Sqh201292		return 0
4025a4c37c9Sqh201292	fi
4035a4c37c9Sqh201292
4045a4c37c9Sqh201292	new_bootpath=`$STMSBOOTUTIL -p /devices$cur_bootpath`
4055a4c37c9Sqh201292	if [ $? -ne 0 ]; then
4065a4c37c9Sqh201292		new_bootpath=""
4075a4c37c9Sqh201292		return 1
4085a4c37c9Sqh201292	fi
40960fffc19Sjw149990
41060fffc19Sjw149990	# we replace "sd" with "disk" if we need to work on the eeprom
41160fffc19Sjw149990	# bootpath setting, since fibre-channel devices will report as
41260fffc19Sjw149990	# being attached via "disk" and not "sd". One day we'll have a
41360fffc19Sjw149990	# truly unified and architecture-independent view of the device
41460fffc19Sjw149990	# tree, and this block will be redundant
41560fffc19Sjw149990	fp_bootpath=`echo $new_bootpath|grep fp.*sd`
41660fffc19Sjw149990	if [ "x$fp_bootpath" != "x" ]; then
41760fffc19Sjw149990		new_bootpath=`echo $fp_bootpath |sed -e"s,sd,disk,g"`
41860fffc19Sjw149990	fi
41960fffc19Sjw149990}
42060fffc19Sjw149990
42160fffc19Sjw149990#
42260fffc19Sjw149990# Emit a warning message to the user that by default we
42360fffc19Sjw149990# operate on all multipath-capable controllers that are
42460fffc19Sjw149990# attached to the system, and that if they want to operate
42560fffc19Sjw149990# on only a specific controller type (fp|mpt|....) then
42660fffc19Sjw149990# they need to re-invoke stmsboot with "-D $driver" in
42760fffc19Sjw149990# their argument list
42860fffc19Sjw149990#
42960fffc19Sjw149990
43060fffc19Sjw149990emit_driver_warning_msg() {
43160fffc19Sjw149990
43260fffc19Sjw149990	# for each driver that we support, grab the list
43360fffc19Sjw149990	# of controllers attached to the system.
43460fffc19Sjw149990
435*815dd917Sjmcp	echo ""
43660fffc19Sjw149990	echo "WARNING: stmsboot operates on each supported multipath-capable controller"
43760fffc19Sjw149990	echo "         detected in a host. In your system, these controllers are"
43860fffc19Sjw149990
439*815dd917Sjmcp	for WARNDRV in `echo $SUPPORTED_DRIVERS| $SED -e"s,|, ,g"`; do
440*815dd917Sjmcp		for i in `$STMSBOOTUTIL -D $WARNDRV -n | $SED -e"s,|, ,g"`; do
441*815dd917Sjmcp			$GREP "$i.*$WARNDRV.$" /etc/path_to_inst | $AWK -F"\"" '{print "/devices"$2}'
442*815dd917Sjmcp		done;
44360fffc19Sjw149990	done;
44460fffc19Sjw149990
44560fffc19Sjw149990	echo ""
44660fffc19Sjw149990	echo "If you do NOT wish to operate on these controllers, please quit stmsboot"
44760fffc19Sjw149990	echo "and re-invoke with -D { fp | mpt } to specify which controllers you wish"
44860fffc19Sjw149990	echo "to modify your multipathing configuration for."
44960fffc19Sjw149990
450*815dd917Sjmcp	echo ""
45160fffc19Sjw149990	gettext "Do you wish to continue? [y/n] (default: y) " 1>&2
45260fffc19Sjw149990	read response
45360fffc19Sjw149990
454*815dd917Sjmcp	if [ "x$response" != "xY" -a "x$response" != "xy" ]; then
45560fffc19Sjw149990		exit
45660fffc19Sjw149990	fi
45760fffc19Sjw149990
45860fffc19Sjw149990}
45960fffc19Sjw149990
4607c478bd9Sstevel@tonic-gatecmd=none
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate# process options
46360fffc19Sjw149990while getopts D:geduLl: c
4647c478bd9Sstevel@tonic-gatedo
4657c478bd9Sstevel@tonic-gate	case $c in
4667c478bd9Sstevel@tonic-gate	e)	setcmd enable;;
4677c478bd9Sstevel@tonic-gate	d)	setcmd disable;;
4687c478bd9Sstevel@tonic-gate	u)	setcmd update;;
4697c478bd9Sstevel@tonic-gate	L)	setcmd listall;;
4707c478bd9Sstevel@tonic-gate	l)	setcmd list
4717c478bd9Sstevel@tonic-gate		controller=$OPTARG;;
47260fffc19Sjw149990	D)	DRV=$OPTARG;;
47360fffc19Sjw149990	g)	GUID="-g";;
4747c478bd9Sstevel@tonic-gate	\?)	echo "$USAGE" 1>&2
4757c478bd9Sstevel@tonic-gate		exit 2;;
4767c478bd9Sstevel@tonic-gate	esac
4777c478bd9Sstevel@tonic-gatedone
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gateif [ "x$cmd" = xnone ]; then
4807c478bd9Sstevel@tonic-gate	echo "$USAGE" 1>&2
4817c478bd9Sstevel@tonic-gate	exit 2
4827c478bd9Sstevel@tonic-gatefi
4837c478bd9Sstevel@tonic-gate
48460fffc19Sjw149990if [ "x$DRV" = "x" ]; then
48560fffc19Sjw149990	DRVLIST="fp mpt"
48660fffc19Sjw149990else
48760fffc19Sjw149990	DRVLIST=$DRV
48860fffc19Sjw149990fi
48960fffc19Sjw149990
49060fffc19Sjw149990
49160fffc19Sjw149990STMSPRIVS=`/usr/bin/ppriv $$ | $EGREP "E:.*all|E:.*sys_devices"`
49260fffc19Sjw149990USERID=`id`
49360fffc19Sjw149990if [ "$USERID" != "uid=0(root) gid=0(root)" ] -o [ "x$STMSPRIVS" == "x" ]; then
4947c478bd9Sstevel@tonic-gate	gettext "You must be super-user to run this script.\n" 1>&2
4957c478bd9Sstevel@tonic-gate	exit 1
4967c478bd9Sstevel@tonic-gatefi
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate# just a sanity check
4997c478bd9Sstevel@tonic-gateif [ ! -f $STMSBOOTUTIL -o ! -f $STMSMETHODSCRIPT ]; then
5007c478bd9Sstevel@tonic-gate	fmt=`gettext "Can't find %s and/or %s"`
5017c478bd9Sstevel@tonic-gate	printf "$fmt\n" "$STMSBOOTUTIL" "$STMSMETHODSCRIPT" 1>&2
5027c478bd9Sstevel@tonic-gate	exit 1
5037c478bd9Sstevel@tonic-gatefi
5047c478bd9Sstevel@tonic-gate
50560fffc19Sjw149990# If the old sun4u-specific SMF method is found, remove it
506*815dd917Sjmcp$SVCCFG -s "platform/sun4u/mpxio-upgrade:default" < /dev/null > /dev/null 2>&1
507*815dd917Sjmcpif [ $? -eq 0 ]; then
508*815dd917Sjmcp	$SVCCFG delete "platform/sun4u/mpxio-upgrade:default" > /dev/null 2>&1
50960fffc19Sjw149990fi
51060fffc19Sjw149990
51160fffc19Sjw149990# now import the new service, if necessary
512*815dd917Sjmcp$SVCPROP -q $STMSINSTANCE < /dev/null > /dev/null 2>&1
51360fffc19Sjw149990if [ $? -ne 0 ]; then
51460fffc19Sjw149990	if [ -f /var/svc/manifest/system/device/mpxio-upgrade.xml ]; then
515*815dd917Sjmcp		$SVCCFG import /var/svc/manifest/system/device/mpxio-upgrade.xml
51660fffc19Sjw149990		if [ $? -ne 0 ]; then
51760fffc19Sjw149990			fmt=`gettext "Unable to import %s service"`
5187c478bd9Sstevel@tonic-gate			printf "$fmt\n" "$STMSINSTANCE" 1>&2
5197c478bd9Sstevel@tonic-gate			exit 1
52060fffc19Sjw149990		else
52160fffc19Sjw149990			fmt=`gettext "Service %s imported successfully, continuing"`
52260fffc19Sjw149990			printf "$fmt\n" "$STMSINSTANCE" 1>&2
52360fffc19Sjw149990		fi
52460fffc19Sjw149990	else
52560fffc19Sjw149990		fmt=`gettext "Service %s does not exist on this host"`
52660fffc19Sjw149990 		printf "$fmt\n" "$STMSINSTANCE" 1>&2
52760fffc19Sjw149990		exit 1
52860fffc19Sjw149990	fi
5297c478bd9Sstevel@tonic-gatefi
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable -o "x$cmd" = xupdate ]; then
5327c478bd9Sstevel@tonic-gate	#
5337c478bd9Sstevel@tonic-gate	# The bootup script doesn't work on cache-only-clients as the script
5346deb031bSsjelinek	# is executed before the plumbing for cachefs mounting of root is done.
5357c478bd9Sstevel@tonic-gate	#
53660fffc19Sjw149990	if $MOUNT -v | $EGREP -s " on / type (nfs|cachefs) "; then
5377c478bd9Sstevel@tonic-gate		gettext "This command option is not supported on systems with nfs or cachefs mounted root filesystem.\n" 1>&2
5387c478bd9Sstevel@tonic-gate		exit 1
5397c478bd9Sstevel@tonic-gate	fi
5407c478bd9Sstevel@tonic-gate
541*815dd917Sjmcp	# if the user has left the system with the mpxio-upgrade service
542*815dd917Sjmcp	# in a temporarily disabled state (ie, service is armed for the next
543*815dd917Sjmcp	# reboot), then let them know. We need to ensure that the system is
544*815dd917Sjmcp	# is in a sane state before allowing any further invocations, so
545*815dd917Sjmcp	# try to get the system admin to do so
546*815dd917Sjmcp
547*815dd917Sjmcp	ISARMED=`$SVCS -l $STMSINSTANCE |$GREP "enabled.*temporary"`
548*815dd917Sjmcp	if [ $? -eq 0 ]; then
549*815dd917Sjmcp		echo ""
550*815dd917Sjmcp		echo "You need the reboot the system in order to complete"
551*815dd917Sjmcp		echo "the previous invocation of stmsboot."
552*815dd917Sjmcp		echo ""
553*815dd917Sjmcp		echo "Do you wish to reboot the system now? (y/n, default y) \c"
554*815dd917Sjmcp		read response
555*815dd917Sjmcp
556*815dd917Sjmcp		if [ "x$response" = "xY" -o "x$response" = "xy" ]; then
557*815dd917Sjmcp			/usr/sbin/reboot
558*815dd917Sjmcp		else
559*815dd917Sjmcp			/bin/echo ""
560*815dd917Sjmcp			/bin/echo "Please reboot this system before continuing"
561*815dd917Sjmcp			/bin/echo ""
562*815dd917Sjmcp			exit 1
563*815dd917Sjmcp		fi
564*815dd917Sjmcp	fi
565*815dd917Sjmcp
5667c478bd9Sstevel@tonic-gate	if [ -d $SAVEDIR ]; then
5677c478bd9Sstevel@tonic-gate		#
5687c478bd9Sstevel@tonic-gate		# keep a copy of the last saved files, useful for manual
5697c478bd9Sstevel@tonic-gate		# recovery in case of a problem.
5707c478bd9Sstevel@tonic-gate		#
57160fffc19Sjw149990		for d in $DRVLIST; do
57260fffc19Sjw149990			DRVCONF=$d.conf
57360fffc19Sjw149990			KDRVCONF=/kernel/drv/$d.conf
57460fffc19Sjw149990			TMPDRVCONF=/var/run/tmp.$d.conf.$$
57560fffc19Sjw149990			TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$;
57660fffc19Sjw149990
5775a4c37c9Sqh201292			if [ "x$MACH" = "xsparc" ]; then
57860fffc19Sjw149990				backup_lastsaved $KDRVCONF $VFSTAB
5797c478bd9Sstevel@tonic-gate			else
58060fffc19Sjw149990				backup_lastsaved $KDRVCONF $VFSTAB $BOOTENV_FILE
5815a4c37c9Sqh201292			fi
58260fffc19Sjw149990		done
5835a4c37c9Sqh201292	else
5847c478bd9Sstevel@tonic-gate		mkdir $SAVEDIR
5857c478bd9Sstevel@tonic-gate	fi
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gatefi
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then
59060fffc19Sjw149990
59160fffc19Sjw149990	msgneeded=`echo "$DRVLIST" |grep " "`
59260fffc19Sjw149990	if [ -n "$msgneeded" ]; then
59360fffc19Sjw149990		emit_driver_warning_msg
59460fffc19Sjw149990	fi
59560fffc19Sjw149990	for d in $DRVLIST; do
59660fffc19Sjw149990		configure_mpxio $cmd $d
59760fffc19Sjw149990	done
59860fffc19Sjw149990
59960fffc19Sjw149990	if [ $reboot_needed -ne 0 ]; then
60060fffc19Sjw149990
60160fffc19Sjw149990		# Need to update bootpath on x86 if our boot device is
60260fffc19Sjw149990		# now accessed through mpxio.
60360fffc19Sjw149990		# Only update bootpath before reboot when mpxio is enabled
60460fffc19Sjw149990		# If mpxio is currently disabled, we will update bootpath
60560fffc19Sjw149990		# on reboot in the mpxio-upgrade service
60660fffc19Sjw149990
60760fffc19Sjw149990		if [ "x$MACH" = "xi386" -a "x$cmd" = "xdisable" ]; then
60860fffc19Sjw149990			get_newbootpath_for_stmsdev
60960fffc19Sjw149990			if [ $? -ne 0 ]; then
61060fffc19Sjw149990				rm -f $TMPDRVCONF > /dev/null 2>&1
61160fffc19Sjw149990				gettext "failed to update bootpath.\n" 1>&2
61260fffc19Sjw149990				gettext "No changes were made to your STMS configuration.\n" 1>&2
61360fffc19Sjw149990				return 1
61460fffc19Sjw149990			fi
61560fffc19Sjw149990		fi
61660fffc19Sjw149990		update_sysfiles
61760fffc19Sjw149990	else
61860fffc19Sjw149990		echo "STMS is already ${cmd}d. No changes or reboots needed"
61960fffc19Sjw149990	fi
62060fffc19Sjw149990
62160fffc19Sjw149990
6227c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xupdate ]; then
6235a4c37c9Sqh201292	if [ "x$MACH" = "xi386" ]; then
6245a4c37c9Sqh201292	# In this case we always change the bootpath to phci-based
6255a4c37c9Sqh201292	# path first. bootpath will later be modified in mpxio-upgrade
6265a4c37c9Sqh201292	# to the vhci-based path if mpxio is enabled on root.
6275a4c37c9Sqh201292		get_newbootpath_for_stmsdev
6285a4c37c9Sqh201292		if [ $? -ne 0 ]; then
6295a4c37c9Sqh201292			gettext "failed to update bootpath.\n" 1>&2
6305a4c37c9Sqh201292			return 1
6315a4c37c9Sqh201292		fi
6325a4c37c9Sqh201292	fi
6337c478bd9Sstevel@tonic-gate	update_sysfiles
63460fffc19Sjw149990
6357c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xlist ]; then
63660fffc19Sjw149990		$STMSBOOTUTIL $GUID -l $controller
6377c478bd9Sstevel@tonic-gateelse
63860fffc19Sjw149990		$STMSBOOTUTIL $GUID -L
6397c478bd9Sstevel@tonic-gatefi
6407c478bd9Sstevel@tonic-gate
6417c478bd9Sstevel@tonic-gateexit $?
642