xref: /titanic_50/usr/src/cmd/stmsboot/stmsboot.sh (revision cfc4930c5319f14873d497982c6536d82c25c23a)
1a0261a43SJames C. McPherson#!/sbin/sh -p
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#
23a0261a43SJames C. McPherson# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
26815dd917Sjmcp#
277c478bd9Sstevel@tonic-gatePATH=/usr/bin:/usr/sbin:$PATH; export PATH
287c478bd9Sstevel@tonic-gateSTMSBOOTUTIL=/lib/mpxio/stmsboot_util
297c478bd9Sstevel@tonic-gateSTMSMETHODSCRIPT=/lib/svc/method/mpxio-upgrade
3060fffc19Sjw149990KDRVCONF=
3160fffc19Sjw149990DRVCONF=
3260fffc19Sjw149990TMPDRVCONF=
3360fffc19Sjw149990TMPDRVCONF_MPXIO_ENTRY=
34*cfc4930cSYong-Feng DuTMPDRVCONF_SATA_ENTRY=
3560fffc19Sjw149990DRVLIST=
3660fffc19Sjw149990GUID=
377c478bd9Sstevel@tonic-gateVFSTAB=/etc/vfstab
387c478bd9Sstevel@tonic-gateSAVEDIR=/etc/mpxio
397c478bd9Sstevel@tonic-gateRECOVERFILE=$SAVEDIR/recover_instructions
407c478bd9Sstevel@tonic-gateSVCCFG_RECOVERY=$SAVEDIR/svccfg_recover
4160fffc19Sjw149990SUPPORTED_DRIVERS="fp|mpt"
4260fffc19Sjw149990USAGE=`gettext "Usage: stmsboot [-D $SUPPORTED_DRIVERS] -e | -d | -u | -L | -l controller_number"`
43aca6e9ccSramatTEXTDOMAIN=SUNW_OST_OSCMD
44aca6e9ccSramatexport TEXTDOMAIN
45a0261a43SJames C. McPhersonSTMSINSTANCE=svc:system/device/mpxio-upgrade:default
4660fffc19Sjw149990STMSBOOT=/usr/sbin/stmsboot
4760fffc19Sjw149990BOOTADM=/sbin/bootadm
4860fffc19Sjw149990MOUNT=/usr/sbin/mount
49a0261a43SJames C. McPhersonEEPROM=/usr/sbin/eeprom
5060fffc19Sjw149990EGREP=/usr/bin/egrep
5160fffc19Sjw149990GREP=/usr/bin/grep
5260fffc19Sjw149990AWK=/usr/bin/awk
53a0261a43SJames C. McPhersonCP=/usr/bin/cp
54a0261a43SJames C. McPhersonLS=/usr/bin/ls
55a0261a43SJames C. McPhersonMV=/usr/bin/mv
56a0261a43SJames C. McPhersonRM=/usr/bin/rm
5760fffc19Sjw149990SORT=/usr/bin/sort
5860fffc19Sjw149990UNIQ=/usr/bin/uniq
5960fffc19Sjw149990EXPR=/usr/bin/expr
60a0261a43SJames C. McPhersonMKDIR=/usr/bin/mkdir
61a0261a43SJames C. McPhersonREBOOT=/usr/sbin/reboot
62815dd917SjmcpSED=/usr/bin/sed
63815dd917SjmcpSVCPROP=/usr/bin/svcprop
64815dd917SjmcpSVCCFG=/usr/sbin/svccfg
65815dd917SjmcpSVCS=/usr/bin/svcs
66815dd917SjmcpSVCADM=/usr/sbin/svcadm
677c478bd9Sstevel@tonic-gate
68a0261a43SJames C. McPhersonNOW=`/usr/bin/date +%G%m%d_%H%M`
695a4c37c9Sqh201292MACH=`/usr/bin/uname -p`
70a0261a43SJames C. McPhersonBOOTENV_FILE=bootenv.rc
7160fffc19Sjw149990reboot_needed=0
72a0261a43SJames C. McPhersonnew_bootpath=""
73a0261a43SJames C. McPhersonCLIENT_TYPE_PHCI=""
74a0261a43SJames C. McPhersonCLIENT_TYPE_VHCI="/scsi_vhci"
7560fffc19Sjw149990
767c478bd9Sstevel@tonic-gate#
7760fffc19Sjw149990# Copy all entries (including comments) from source driver.conf
7860fffc19Sjw149990# to destination driver.conf except those entries which contain
7960fffc19Sjw149990# the mpxio-disable property.
807c478bd9Sstevel@tonic-gate# Take into consideration entries that spawn more than one line.
817c478bd9Sstevel@tonic-gate#
827c478bd9Sstevel@tonic-gate# $1	source driver.conf file
837c478bd9Sstevel@tonic-gate# $2	destination driver.conf file
847c478bd9Sstevel@tonic-gate#
857c478bd9Sstevel@tonic-gate# Returns 0 on success, non zero on failure.
867c478bd9Sstevel@tonic-gate#
877c478bd9Sstevel@tonic-gatedelete_mpxio_disable_entries()
887c478bd9Sstevel@tonic-gate{
89a0261a43SJames C. McPherson	# be careful here, we've got embedded \t characters
90a0261a43SJames C. McPherson	# in sed's pattern space.
91a0261a43SJames C. McPherson	$SED '
927c478bd9Sstevel@tonic-gate		/^[ 	]*#/{ p
937c478bd9Sstevel@tonic-gate			      d
947c478bd9Sstevel@tonic-gate			    }
957c478bd9Sstevel@tonic-gate		s/[ 	]*$//
967c478bd9Sstevel@tonic-gate		/^$/{ p
977c478bd9Sstevel@tonic-gate		      d
987c478bd9Sstevel@tonic-gate		    }
995a4c37c9Sqh201292		/mpxio-disable[ 	]*=.*;$/{ w '$3'
1005a4c37c9Sqh201292						  d
1015a4c37c9Sqh201292						}
102*cfc4930cSYong-Feng Du		/disable-sata-mpxio[ 	]*=.*;$/{ w '$4'
103*cfc4930cSYong-Feng Du						  d
104*cfc4930cSYong-Feng Du						}
1057c478bd9Sstevel@tonic-gate		/;$/{ p
1067c478bd9Sstevel@tonic-gate		      d
1077c478bd9Sstevel@tonic-gate		    }
1087c478bd9Sstevel@tonic-gate		:rdnext
1097c478bd9Sstevel@tonic-gate		N
1107c478bd9Sstevel@tonic-gate		s/[ 	]*$//
1117c478bd9Sstevel@tonic-gate		/[^;]$/b rdnext
1125a4c37c9Sqh201292		/mpxio-disable[ 	]*=/{ s/\n/ /g
1135a4c37c9Sqh201292					      w '$3'
1145a4c37c9Sqh201292					      d
1155a4c37c9Sqh201292					    }
1165a4c37c9Sqh201292		' $1 > $2
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate	return $?
1197c478bd9Sstevel@tonic-gate}
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate#
1227c478bd9Sstevel@tonic-gate# backup the last saved copy of the specified files.
1237c478bd9Sstevel@tonic-gate# $*	files to backup
1247c478bd9Sstevel@tonic-gate#
1257c478bd9Sstevel@tonic-gatebackup_lastsaved()
1267c478bd9Sstevel@tonic-gate{
1277c478bd9Sstevel@tonic-gate	for file in $*
1287c478bd9Sstevel@tonic-gate	do
129a0261a43SJames C. McPherson		newfile=`basename $file`
130a0261a43SJames C. McPherson		$CP $file $SAVEDIR/$newfile.$cmd.$NOW
1317c478bd9Sstevel@tonic-gate	done
1327c478bd9Sstevel@tonic-gate}
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate#
1357c478bd9Sstevel@tonic-gate# build recover instructions
1367c478bd9Sstevel@tonic-gate#
1377c478bd9Sstevel@tonic-gate# $1	1 to include boot script in the instructions
1387c478bd9Sstevel@tonic-gate#	0 otherwise
1397c478bd9Sstevel@tonic-gate#
1407c478bd9Sstevel@tonic-gatebuild_recover()
1417c478bd9Sstevel@tonic-gate{
1427c478bd9Sstevel@tonic-gate	gettext "Instructions to recover your previous STMS configuration (if in case the system does not boot):\n\n" > $RECOVERFILE
1437c478bd9Sstevel@tonic-gate	echo "\tboot net \c"  >> $RECOVERFILE
1447c478bd9Sstevel@tonic-gate	gettext "(or from a cd/dvd/another disk)\n" >> $RECOVERFILE
1457c478bd9Sstevel@tonic-gate	echo "\tfsck <your-root-device>" >> $RECOVERFILE
1467c478bd9Sstevel@tonic-gate	echo "\tmount <your-root-device> /mnt" >> $RECOVERFILE
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate	if [ "x$cmd" = xupdate ]; then
1497c478bd9Sstevel@tonic-gate		gettext "\tUndo the modifications you made to STMS configuration.\n\tFor example undo any changes you made to " >> $RECOVERFILE
15060fffc19Sjw149990		echo "/mnt$KDRVCONF." >> $RECOVERFILE
1517c478bd9Sstevel@tonic-gate	else
152a0261a43SJames C. McPherson		echo "\tcp /mnt${SAVEDIR}/$DRVCONF.$cmd.$NOW /mnt$KDRVCONF" >> $RECOVERFILE
1537c478bd9Sstevel@tonic-gate	fi
1547c478bd9Sstevel@tonic-gate
155815dd917Sjmcp	if [ $1 -eq 1 ]; then
156a0261a43SJames C. McPherson		echo "\tcp /mnt${SAVEDIR}/vfstab.$cmd.$NOW /mnt$VFSTAB" >> $RECOVERFILE
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate		echo "repository /mnt/etc/svc/repository.db" > $SVCCFG_RECOVERY
1597c478bd9Sstevel@tonic-gate		echo "select $STMSINSTANCE" >> $SVCCFG_RECOVERY
1607c478bd9Sstevel@tonic-gate		echo "setprop general/enabled=false" >> $SVCCFG_RECOVERY
1617c478bd9Sstevel@tonic-gate		echo "exit" >> $SVCCFG_RECOVERY
1627c478bd9Sstevel@tonic-gate
163815dd917Sjmcp		echo "\t$SVCCFG -f /mnt$SVCCFG_RECOVERY" >> $RECOVERFILE
1645a4c37c9Sqh201292
1655a4c37c9Sqh201292		if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then
166a0261a43SJames C. McPherson			echo "\tcp /mnt${SAVEDIR}/bootenv.rc.$cmd.$NOW /mnt/boot/solaris/$BOOTENV_FILE" >> $RECOVERFILE
1675a4c37c9Sqh201292		fi
1687c478bd9Sstevel@tonic-gate	fi
1697c478bd9Sstevel@tonic-gate
17060fffc19Sjw149990	rootdisk=`$MOUNT | $GREP "/ on " | cut -f 3 -d " "`
1717c478bd9Sstevel@tonic-gate	echo "\tumount /mnt\n\treboot\n\n${rootdisk} \c" >> $RECOVERFILE
1727c478bd9Sstevel@tonic-gate	gettext "was your root device,\nbut it could be named differently after you boot net.\n" >> $RECOVERFILE
1737c478bd9Sstevel@tonic-gate}
1747c478bd9Sstevel@tonic-gate
175a0261a43SJames C. McPherson
1767c478bd9Sstevel@tonic-gate#
1777c478bd9Sstevel@tonic-gate# Arrange for /etc/vfstab and dump configuration to be updated
1787c478bd9Sstevel@tonic-gate# during the next reboot. If the cmd is "enable" or "disable", copy
17960fffc19Sjw149990# $TMPDRVCONF to $KDRVCONF.
1807c478bd9Sstevel@tonic-gate#
1817c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure.
1827c478bd9Sstevel@tonic-gate#
1837c478bd9Sstevel@tonic-gateupdate_sysfiles()
1847c478bd9Sstevel@tonic-gate{
18560fffc19Sjw149990
186a0261a43SJames C. McPherson	gettext "WARNING: This operation will require a reboot.\n"
187a0261a43SJames C. McPherson	gettext "Do you want to continue ? [y/n] (default: y) "
1887c478bd9Sstevel@tonic-gate	read response
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate	if [ "x$response" != x -a "x$response" != xy -a \
1917c478bd9Sstevel@tonic-gate	    "x$response" != xY ]; then
19260fffc19Sjw149990		for d in $DRVLIST; do
19360fffc19Sjw149990			TMPDRVCONF=/var/run/tmp.$d.conf.$$
194a0261a43SJames C. McPherson			$RM -f $TMPDRVCONF > /dev/null 2>&1
19560fffc19Sjw149990		done;
19660fffc19Sjw149990		return 0;
1977c478bd9Sstevel@tonic-gate	fi
1987c478bd9Sstevel@tonic-gate
199815dd917Sjmcp	# set need_bootscript to the number of drivers that
200815dd917Sjmcp	# we support.
201815dd917Sjmcp	need_bootscript=`echo $SUPPORTED_DRIVERS|$AWK -F"|" '{print NF}'`
20260fffc19Sjw149990
2037c478bd9Sstevel@tonic-gate	if [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then
20460fffc19Sjw149990
20560fffc19Sjw149990		for d in $DRVLIST; do
20660fffc19Sjw149990			DRVCONF=$d.conf
20760fffc19Sjw149990			KDRVCONF=/kernel/drv/$d.conf
20860fffc19Sjw149990			TMPDRVCONF=/var/run/tmp.$d.conf.$$
20960fffc19Sjw149990
210a0261a43SJames C. McPherson			$CP $KDRVCONF $SAVEDIR/`basename $KDRVCONF`.$cmd.$NOW
211815dd917Sjmcp			if [ -f $TMPDRVCONF ]; then
212a0261a43SJames C. McPherson				$CP $TMPDRVCONF $KDRVCONF
213a0261a43SJames C. McPherson				$RM -f $TMPDRVCONF
214815dd917Sjmcp			else
215815dd917Sjmcp				# if $TMPDRVCONF doesn't exist, then we
216815dd917Sjmcp				# haven't made any changes to it
217815dd917Sjmcp				continue;
218815dd917Sjmcp			fi
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate			#
2217c478bd9Sstevel@tonic-gate			# there is no need to update the system files in the following
2227c478bd9Sstevel@tonic-gate			# cases:
2237c478bd9Sstevel@tonic-gate			# - we are enabling mpxio and the system has no configured
2247c478bd9Sstevel@tonic-gate			#   disks accessible by phci paths.
2257c478bd9Sstevel@tonic-gate			# - we are disabling mpxio and the system has no configured
2267c478bd9Sstevel@tonic-gate			#   disks accessible by vhci paths.
2277c478bd9Sstevel@tonic-gate			#
22860fffc19Sjw149990
229815dd917Sjmcp			# Function to setup the CLIENT_TYPE_PHCI string based on
230815dd917Sjmcp			# the list of drivers that we're operating on. The variable
231815dd917Sjmcp			# depends upon the pathname of the parent node in the
232815dd917Sjmcp			# device tree, which can be different on x86/x64 and sparc.
233815dd917Sjmcp
234a0261a43SJames C. McPherson			CLIENT_TYPE_PHCI=`$STMSBOOTUTIL -D $d -N`;
235815dd917Sjmcp
23660fffc19Sjw149990			if [ "x$CLIENT_TYPE_PHCI" = "x" ]; then
23760fffc19Sjw149990				continue;
23860fffc19Sjw149990			fi
23960fffc19Sjw149990
24060fffc19Sjw149990			if [ "x$cmd" = "xenable" ]; then
241a0261a43SJames C. McPherson				$LS -l /dev/dsk/*s2 2> /dev/null | \
24260fffc19Sjw149990				    $EGREP -s "$CLIENT_TYPE_PHCI"
2437c478bd9Sstevel@tonic-gate			else
244a0261a43SJames C. McPherson				$LS -l /dev/dsk/*s2 2> /dev/null | \
24560fffc19Sjw149990				    $EGREP -s "$CLIENT_TYPE_VHCI"
2467c478bd9Sstevel@tonic-gate			fi
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate			if [ $? -ne 0 ]; then
249815dd917Sjmcp				need_bootscript=`$EXPR $need_bootscript - 1`
25060fffc19Sjw149990			fi
25160fffc19Sjw149990		done
25260fffc19Sjw149990	fi
25360fffc19Sjw149990
254815dd917Sjmcp	if [ $need_bootscript -gt 0 ]; then
255815dd917Sjmcp		need_bootscript=1
2565a4c37c9Sqh201292		if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then
2575a4c37c9Sqh201292			#only update bootpath for x86.
258a0261a43SJames C. McPherson			$CP /boot/solaris/$BOOTENV_FILE $SAVEDIR/$BOOTENV_FILE.$cmd.$NOW
259a0261a43SJames C. McPherson			$EEPROM bootpath="$new_bootpath"
2605a4c37c9Sqh201292		fi
261a0261a43SJames C. McPherson		# Enable the mpxio-upgrade service for the reboot
262815dd917Sjmcp		$SVCADM disable -t $STMSINSTANCE
263a0261a43SJames C. McPherson		$SVCCFG -s $STMSINSTANCE "setprop general/enabled=true"
264815dd917Sjmcp	else
265815dd917Sjmcp		need_bootscript=0
2667c478bd9Sstevel@tonic-gate	fi
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate	build_recover $need_bootscript
2697c478bd9Sstevel@tonic-gate
27060fffc19Sjw149990	if [ "x$MACH" = "xi386" ]; then
27160fffc19Sjw149990		$BOOTADM update-archive
27260fffc19Sjw149990	fi
27360fffc19Sjw149990
2747c478bd9Sstevel@tonic-gate	gettext "The changes will come into effect after rebooting the system.\nReboot the system now ? [y/n] (default: y) "
2757c478bd9Sstevel@tonic-gate	read response
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate	if [ "x$response" = x -o "x$response" = xy -o \
2787c478bd9Sstevel@tonic-gate	    "x$response" = xY ]; then
279a0261a43SJames C. McPherson		$REBOOT
2807c478bd9Sstevel@tonic-gate	fi
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate	return 0
2837c478bd9Sstevel@tonic-gate}
2847c478bd9Sstevel@tonic-gate
285a0261a43SJames C. McPherson
2867c478bd9Sstevel@tonic-gate#
2877c478bd9Sstevel@tonic-gate# Enable or disable mpxio as specified by the cmd.
2887c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure.
2897c478bd9Sstevel@tonic-gate#
29060fffc19Sjw149990# Args: $cmd = {enable | disable}
29160fffc19Sjw149990#	$d = {fp | mpt}
29260fffc19Sjw149990#
29360fffc19Sjw149990# the global variable $DRVLIST is used
29460fffc19Sjw149990#
2957c478bd9Sstevel@tonic-gateconfigure_mpxio()
2967c478bd9Sstevel@tonic-gate{
297a0261a43SJames C. McPherson	# be careful here, we've got embedded \t characters
298a0261a43SJames C. McPherson	# in sed's pattern space.
2995a4c37c9Sqh201292	mpxiodisableno='mpxio-disable[ 	]*=[ 	]*"no"[ 	]*;'
3005a4c37c9Sqh201292	mpxiodisableyes='mpxio-disable[ 	]*=[ 	]*"yes"[ 	]*;'
301*cfc4930cSYong-Feng Du	satadisableno='disable-sata-mpxio[ 	]*=[ 	]*"no"[ 	]*;'
302*cfc4930cSYong-Feng Du	satadisableyes='disable-sata-mpxio[ 	]*=[ 	]*"yes"[ 	]*;'
3035a4c37c9Sqh201292
3047c478bd9Sstevel@tonic-gate	if [ "x$cmd" = xenable ]; then
3055a4c37c9Sqh201292		mpxiodisable_cur_entry=$mpxiodisableyes
306*cfc4930cSYong-Feng Du		satadisable_cur_entry=$satadisableyes
3077c478bd9Sstevel@tonic-gate		propval=no
30860fffc19Sjw149990		msg=`gettext "STMS already enabled"`
3097c478bd9Sstevel@tonic-gate	else
3105a4c37c9Sqh201292		mpxiodisable_cur_entry=$mpxiodisableno
311*cfc4930cSYong-Feng Du		satadisable_cur_entry=$satadisableno
3127c478bd9Sstevel@tonic-gate		propval=yes
31360fffc19Sjw149990		msg=`gettext "STMS already disabled"`
3147c478bd9Sstevel@tonic-gate	fi
3157c478bd9Sstevel@tonic-gate
31660fffc19Sjw149990	DRVCONF=$d.conf
31760fffc19Sjw149990	KDRVCONF=/kernel/drv/$d.conf
31860fffc19Sjw149990	TMPDRVCONF=/var/run/tmp.$d.conf.$$
31960fffc19Sjw149990	TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$;
320*cfc4930cSYong-Feng Du	TMPDRVCONF_SATA_ENTRY=/var/run/tmp.$d.conf.sataentry.$$;
32160fffc19Sjw149990
322*cfc4930cSYong-Feng Du	if delete_mpxio_disable_entries $KDRVCONF $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY $TMPDRVCONF_SATA_ENTRY; then
32360fffc19Sjw149990
32460fffc19Sjw149990		if [ -s $TMPDRVCONF_MPXIO_ENTRY ]; then
32560fffc19Sjw149990			# $DRVCONF does have mpxiodisable entries
32660fffc19Sjw149990			$EGREP -s "$mpxiodisable_cur_entry" $TMPDRVCONF_MPXIO_ENTRY
327*cfc4930cSYong-Feng Du			if [ $? -eq 0 ]; then
328*cfc4930cSYong-Feng Du				reboot_needed=`$EXPR $reboot_needed + 1`
329*cfc4930cSYong-Feng Du			else
3305a4c37c9Sqh201292				# if all mpxiodisable entries are no/yes for
3315a4c37c9Sqh201292				# enable/disable mpxio, notify the user
332*cfc4930cSYong-Feng Du				$EGREP -s "$satadisable_cur_entry" $TMPDRVCONF_SATA_ENTRY
333*cfc4930cSYong-Feng Du				if [ $? -eq 0 ]; then
33460fffc19Sjw149990					reboot_needed=`$EXPR $reboot_needed + 1`
335*cfc4930cSYong-Feng Du				else
336*cfc4930cSYong-Feng Du					$RM -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY $TMPDRVCONF_SATA_ENTRY > /dev/null 2>&1
337*cfc4930cSYong-Feng Du				fi
3387c478bd9Sstevel@tonic-gate			fi
33960fffc19Sjw149990
34060fffc19Sjw149990			# If mpxiodisable entries do not exist, always continue update
3415a4c37c9Sqh201292		fi
3427c478bd9Sstevel@tonic-gate	else
343*cfc4930cSYong-Feng Du		$RM -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY $TMPDRVCONF_SATA_ENTRY > /dev/null 2>&1
3447c478bd9Sstevel@tonic-gate		gettext "failed to update " 1>&2
34560fffc19Sjw149990		echo "$KDRVCONF." 1>&2
3467c478bd9Sstevel@tonic-gate		gettext "No changes were made to your STMS configuration.\n" 1>&2
3477c478bd9Sstevel@tonic-gate		return 1
3487c478bd9Sstevel@tonic-gate	fi
3495a4c37c9Sqh201292
35060fffc19Sjw149990	rm $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1
35160fffc19Sjw149990	echo "mpxio-disable=\"${propval}\";" >> $TMPDRVCONF
352*cfc4930cSYong-Feng Du	echo "disable-sata-mpxio=\"${propval}\";" >> $TMPDRVCONF
3535a4c37c9Sqh201292
3547c478bd9Sstevel@tonic-gate}
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gatesetcmd()
3577c478bd9Sstevel@tonic-gate{
3587c478bd9Sstevel@tonic-gate	if [ "x$cmd" = xnone ]; then
3597c478bd9Sstevel@tonic-gate		cmd=$1
3607c478bd9Sstevel@tonic-gate	else
3617c478bd9Sstevel@tonic-gate		echo "$USAGE" 1>&2
3627c478bd9Sstevel@tonic-gate		exit 2
3637c478bd9Sstevel@tonic-gate	fi
3647c478bd9Sstevel@tonic-gate}
3657c478bd9Sstevel@tonic-gate
36660fffc19Sjw149990#
3675a4c37c9Sqh201292# Need to update bootpath on x86 if boot system from FC disk
3685a4c37c9Sqh201292# Only update bootpath here when mpxio is enabled
369a0261a43SJames C. McPherson# If mpxio is currently disabled, then we'll update bootpath in the
370a0261a43SJames C. McPherson# mpxio-upgrade service method on reboot.
37160fffc19Sjw149990#
37260fffc19Sjw149990
3735a4c37c9Sqh201292get_newbootpath_for_stmsdev() {
3745a4c37c9Sqh201292	if [ "x$cmd" = "xenable" ]; then
3755a4c37c9Sqh201292		return 0
3765a4c37c9Sqh201292	fi
3775a4c37c9Sqh201292
378a0261a43SJames C. McPherson	cur_bootpath=`$STMSBOOTUTIL -b`
379a0261a43SJames C. McPherson	if [ $? != 0 ]; then
3805a4c37c9Sqh201292		return 1
3815a4c37c9Sqh201292	fi
3825a4c37c9Sqh201292
383a0261a43SJames C. McPherson	# Since on x64 platforms the eeprom command doesn't update the
384a0261a43SJames C. McPherson	# kernel, the file /boot/solaris/bootenv.rc and the kernel's
385a0261a43SJames C. McPherson	# bootpath variable have a good chance of differing. We do some
386a0261a43SJames C. McPherson	# extra handwaving to get the correct bootpath variable setting.
387a0261a43SJames C. McPherson
388a0261a43SJames C. McPherson	ONDISKVER=`$AWK '/bootpath/ {print $3}' /boot/solaris/bootenv.rc|\
389a0261a43SJames C. McPherson		$SED -e"s,',,g"`
390a0261a43SJames C. McPherson	if [ "x$ONDISKVER" != "x$cur_bootpath" ]; then
391a0261a43SJames C. McPherson		cur_bootpath="$ONDISKVER"
392a0261a43SJames C. McPherson	fi
393a0261a43SJames C. McPherson
394a0261a43SJames C. McPherson	NEWBOOTPATH=""
395a0261a43SJames C. McPherson	for path in $cur_bootpath; do
396a0261a43SJames C. McPherson		mapped=`$STMSBOOTUTIL -p $path`
397a0261a43SJames C. McPherson		if [ "$mapped" != "NOT_MAPPED" ]; then
398a0261a43SJames C. McPherson			if [ "$mapped" != "$path" ]; then
399a0261a43SJames C. McPherson				NEWBOOTPATH=`echo "$path " | \
400a0261a43SJames C. McPherson				   $SED -e"s|$path|$mapped|"`" $NEWBOOTPATH"
401a0261a43SJames C. McPherson			else
402a0261a43SJames C. McPherson				NEWBOOTPATH="$NEWBOOTPATH $path"
403a0261a43SJames C. McPherson			fi
404a0261a43SJames C. McPherson		fi
405a0261a43SJames C. McPherson	done
406a0261a43SJames C. McPherson	# now strip off leading and trailing space chars
407a0261a43SJames C. McPherson	new_bootpath=`echo $NEWBOOTPATH`
4085a4c37c9Sqh201292	return 0
40960fffc19Sjw149990}
41060fffc19Sjw149990
41160fffc19Sjw149990#
41260fffc19Sjw149990# Emit a warning message to the user that by default we
41360fffc19Sjw149990# operate on all multipath-capable controllers that are
41460fffc19Sjw149990# attached to the system, and that if they want to operate
41560fffc19Sjw149990# on only a specific controller type (fp|mpt|....) then
41660fffc19Sjw149990# they need to re-invoke stmsboot with "-D $driver" in
41760fffc19Sjw149990# their argument list
41860fffc19Sjw149990#
41960fffc19Sjw149990
42060fffc19Sjw149990emit_driver_warning_msg() {
42160fffc19Sjw149990
42260fffc19Sjw149990	# for each driver that we support, grab the list
42360fffc19Sjw149990	# of controllers attached to the system.
42460fffc19Sjw149990
425815dd917Sjmcp	echo ""
42653ed03b5Sjmcp	gettext "WARNING: stmsboot operates on each supported multipath-capable controller\n"
42753ed03b5Sjmcp	gettext "         detected in a host. In your system, these controllers are\n\n"
42860fffc19Sjw149990
429815dd917Sjmcp	for WARNDRV in `echo $SUPPORTED_DRIVERS| $SED -e"s,|, ,g"`; do
430a0261a43SJames C. McPherson		$STMSBOOTUTIL -D $WARNDRV -n
43160fffc19Sjw149990	done;
43260fffc19Sjw149990
43360fffc19Sjw149990	echo ""
43453ed03b5Sjmcp	gettext "If you do NOT wish to operate on these controllers, please quit stmsboot\n"
43553ed03b5Sjmcp	gettext "and re-invoke with -D { fp | mpt } to specify which controllers you wish\n"
43653ed03b5Sjmcp	gettext "to modify your multipathing configuration for.\n"
43760fffc19Sjw149990
438815dd917Sjmcp	echo ""
43953ed03b5Sjmcp	gettext "Do you wish to continue? [y/n] (default: y) "
44060fffc19Sjw149990	read response
44160fffc19Sjw149990
4428cecff49Sgp87344	if [ "x$response" != "x" -a "x$response" != "xY" -a \
4438cecff49Sgp87344	    "x$response" != "xy" ]; then
44460fffc19Sjw149990		exit
44560fffc19Sjw149990	fi
44660fffc19Sjw149990}
44760fffc19Sjw149990
4487c478bd9Sstevel@tonic-gate
449a0261a43SJames C. McPherson#
450a0261a43SJames C. McPherson#
451a0261a43SJames C. McPherson# main starts here
452a0261a43SJames C. McPherson#
453a0261a43SJames C. McPherson
454a0261a43SJames C. McPhersoncmd=none
4557c478bd9Sstevel@tonic-gate# process options
45660fffc19Sjw149990while getopts D:geduLl: c
4577c478bd9Sstevel@tonic-gatedo
4587c478bd9Sstevel@tonic-gate	case $c in
4597c478bd9Sstevel@tonic-gate	e)	setcmd enable;;
4607c478bd9Sstevel@tonic-gate	d)	setcmd disable;;
4617c478bd9Sstevel@tonic-gate	u)	setcmd update;;
4627c478bd9Sstevel@tonic-gate	L)	setcmd listall;;
4637c478bd9Sstevel@tonic-gate	l)	setcmd list
4647c478bd9Sstevel@tonic-gate		controller=$OPTARG;;
46560fffc19Sjw149990	D)	DRV=$OPTARG;;
46660fffc19Sjw149990	g)	GUID="-g";;
4677c478bd9Sstevel@tonic-gate	\?)	echo "$USAGE" 1>&2
4687c478bd9Sstevel@tonic-gate		exit 2;;
4697c478bd9Sstevel@tonic-gate	esac
4707c478bd9Sstevel@tonic-gatedone
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gateif [ "x$cmd" = xnone ]; then
4737c478bd9Sstevel@tonic-gate	echo "$USAGE" 1>&2
4747c478bd9Sstevel@tonic-gate	exit 2
4757c478bd9Sstevel@tonic-gatefi
4767c478bd9Sstevel@tonic-gate
47760fffc19Sjw149990if [ "x$DRV" = "x" ]; then
47860fffc19Sjw149990	DRVLIST="fp mpt"
47960fffc19Sjw149990else
48060fffc19Sjw149990	DRVLIST=$DRV
48160fffc19Sjw149990fi
48260fffc19Sjw149990
48334c94816SjmcpUSERID=`id | $EGREP "uid=0"`
48434c94816Sjmcpif [ -z "$USERID" ]; then
4857c478bd9Sstevel@tonic-gate	gettext "You must be super-user to run this script.\n" 1>&2
4867c478bd9Sstevel@tonic-gate	exit 1
4877c478bd9Sstevel@tonic-gatefi
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate# just a sanity check
4907c478bd9Sstevel@tonic-gateif [ ! -f $STMSBOOTUTIL -o ! -f $STMSMETHODSCRIPT ]; then
4917c478bd9Sstevel@tonic-gate	fmt=`gettext "Can't find %s and/or %s"`
4927c478bd9Sstevel@tonic-gate	printf "$fmt\n" "$STMSBOOTUTIL" "$STMSMETHODSCRIPT" 1>&2
4937c478bd9Sstevel@tonic-gate	exit 1
4947c478bd9Sstevel@tonic-gatefi
4957c478bd9Sstevel@tonic-gate
49660fffc19Sjw149990# If the old sun4u-specific SMF method is found, remove it
497815dd917Sjmcp$SVCCFG -s "platform/sun4u/mpxio-upgrade:default" < /dev/null > /dev/null 2>&1
498815dd917Sjmcpif [ $? -eq 0 ]; then
499815dd917Sjmcp	$SVCCFG delete "platform/sun4u/mpxio-upgrade:default" > /dev/null 2>&1
50060fffc19Sjw149990fi
50160fffc19Sjw149990
50260fffc19Sjw149990# now import the new service, if necessary
503815dd917Sjmcp$SVCPROP -q $STMSINSTANCE < /dev/null > /dev/null 2>&1
50460fffc19Sjw149990if [ $? -ne 0 ]; then
50560fffc19Sjw149990	if [ -f /var/svc/manifest/system/device/mpxio-upgrade.xml ]; then
506815dd917Sjmcp		$SVCCFG import /var/svc/manifest/system/device/mpxio-upgrade.xml
50760fffc19Sjw149990		if [ $? -ne 0 ]; then
50853ed03b5Sjmcp			fmt=`gettext "Unable to import the %s service"`
5097c478bd9Sstevel@tonic-gate			printf "$fmt\n" "$STMSINSTANCE" 1>&2
5107c478bd9Sstevel@tonic-gate			exit 1
51160fffc19Sjw149990		else
51260fffc19Sjw149990			fmt=`gettext "Service %s imported successfully, continuing"`
51360fffc19Sjw149990			printf "$fmt\n" "$STMSINSTANCE" 1>&2
51460fffc19Sjw149990		fi
51560fffc19Sjw149990	else
51660fffc19Sjw149990		fmt=`gettext "Service %s does not exist on this host"`
51760fffc19Sjw149990 		printf "$fmt\n" "$STMSINSTANCE" 1>&2
51860fffc19Sjw149990		exit 1
51960fffc19Sjw149990	fi
5207c478bd9Sstevel@tonic-gatefi
5217c478bd9Sstevel@tonic-gate
522a0261a43SJames C. McPherson
523a0261a43SJames C. McPherson# make sure we can stash our data somewhere private
524a0261a43SJames C. McPhersonif [ ! -d $SAVEDIR ]; then
525a0261a43SJames C. McPherson	$MKDIR -p $SAVEDIR
526a0261a43SJames C. McPhersonfi
527a0261a43SJames C. McPherson# prime the cache
528a0261a43SJames C. McPherson$STMSBOOTUTIL -i
529a0261a43SJames C. McPherson
530a0261a43SJames C. McPherson
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
537a0261a43SJames C. McPherson		gettext "This command option is not supported on systems with an nfs or cachefs mounted root filesystem.\n" 1>&2
5387c478bd9Sstevel@tonic-gate		exit 1
5397c478bd9Sstevel@tonic-gate	fi
5407c478bd9Sstevel@tonic-gate
541815dd917Sjmcp	# if the user has left the system with the mpxio-upgrade service
542815dd917Sjmcp	# in a temporarily disabled state (ie, service is armed for the next
543815dd917Sjmcp	# reboot), then let them know. We need to ensure that the system is
544815dd917Sjmcp	# is in a sane state before allowing any further invocations, so
545815dd917Sjmcp	# try to get the system admin to do so
546815dd917Sjmcp
547a0261a43SJames C. McPherson	ISARMED=`$SVCS -l $STMSINSTANCE|$GREP "enabled.*false.*temporary"`
548a0261a43SJames C. McPherson	if [ ! $? ]; then
549815dd917Sjmcp		echo ""
55053ed03b5Sjmcp		gettext "You need to reboot the system in order to complete\n"
55153ed03b5Sjmcp		gettext "the previous invocation of stmsboot.\n"
552815dd917Sjmcp		echo ""
55353ed03b5Sjmcp		gettext "Do you wish to reboot the system now? (y/n, default y) "
554815dd917Sjmcp		read response
555815dd917Sjmcp
5568cecff49Sgp87344		if [ "x$response" = "x" -o "x$response" = "xY" -o \
5578cecff49Sgp87344		    "x$response" = "xy" ]; then
558a0261a43SJames C. McPherson			$REBOOT
559815dd917Sjmcp		else
56053ed03b5Sjmcp			echo ""
56153ed03b5Sjmcp			gettext "Please reboot this system before continuing\n"
56253ed03b5Sjmcp			echo ""
563815dd917Sjmcp			exit 1
564815dd917Sjmcp		fi
565815dd917Sjmcp	fi
566815dd917Sjmcp
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.$$;
5765a4c37c9Sqh201292		if [ "x$MACH" = "xsparc" ]; then
57760fffc19Sjw149990			backup_lastsaved $KDRVCONF $VFSTAB
5787c478bd9Sstevel@tonic-gate		else
579a0261a43SJames C. McPherson			backup_lastsaved $KDRVCONF $VFSTAB /boot/solaris/$BOOTENV_FILE
5805a4c37c9Sqh201292		fi
58160fffc19Sjw149990	done
5827c478bd9Sstevel@tonic-gatefi
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then
58560fffc19Sjw149990
58660fffc19Sjw149990	msgneeded=`echo "$DRVLIST" |grep " "`
58760fffc19Sjw149990	if [ -n "$msgneeded" ]; then
58860fffc19Sjw149990		emit_driver_warning_msg
58960fffc19Sjw149990	fi
59060fffc19Sjw149990	for d in $DRVLIST; do
59160fffc19Sjw149990		configure_mpxio $cmd $d
59260fffc19Sjw149990	done
59360fffc19Sjw149990
59460fffc19Sjw149990	if [ $reboot_needed -ne 0 ]; then
59560fffc19Sjw149990		# Need to update bootpath on x86 if our boot device is
59660fffc19Sjw149990		# now accessed through mpxio.
59760fffc19Sjw149990		# Only update bootpath before reboot when mpxio is enabled
59860fffc19Sjw149990		# If mpxio is currently disabled, we will update bootpath
59960fffc19Sjw149990		# on reboot in the mpxio-upgrade service
60060fffc19Sjw149990
60160fffc19Sjw149990		if [ "x$MACH" = "xi386" -a "x$cmd" = "xdisable" ]; then
60260fffc19Sjw149990			get_newbootpath_for_stmsdev
60360fffc19Sjw149990			if [ $? -ne 0 ]; then
604a0261a43SJames C. McPherson				$RM -f $TMPDRVCONF > /dev/null 2>&1
60560fffc19Sjw149990				gettext "failed to update bootpath.\n" 1>&2
60660fffc19Sjw149990				gettext "No changes were made to your STMS configuration.\n" 1>&2
60760fffc19Sjw149990				return 1
60860fffc19Sjw149990			fi
60960fffc19Sjw149990		fi
61060fffc19Sjw149990		update_sysfiles
61160fffc19Sjw149990	else
61260fffc19Sjw149990		echo "STMS is already ${cmd}d. No changes or reboots needed"
61360fffc19Sjw149990	fi
61460fffc19Sjw149990
61560fffc19Sjw149990
6167c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xupdate ]; then
6175a4c37c9Sqh201292	if [ "x$MACH" = "xi386" ]; then
6185a4c37c9Sqh201292	# In this case we always change the bootpath to phci-based
6195a4c37c9Sqh201292	# path first. bootpath will later be modified in mpxio-upgrade
6205a4c37c9Sqh201292	# to the vhci-based path if mpxio is enabled on root.
6215a4c37c9Sqh201292		get_newbootpath_for_stmsdev
6225a4c37c9Sqh201292		if [ $? -ne 0 ]; then
6235a4c37c9Sqh201292			gettext "failed to update bootpath.\n" 1>&2
6245a4c37c9Sqh201292			return 1
6255a4c37c9Sqh201292		fi
6265a4c37c9Sqh201292	fi
6277c478bd9Sstevel@tonic-gate	update_sysfiles
62860fffc19Sjw149990
6297c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xlist ]; then
63060fffc19Sjw149990		$STMSBOOTUTIL $GUID -l $controller
6317c478bd9Sstevel@tonic-gateelse
63260fffc19Sjw149990		$STMSBOOTUTIL $GUID -L
6337c478bd9Sstevel@tonic-gatefi
6347c478bd9Sstevel@tonic-gate
6357c478bd9Sstevel@tonic-gateexit $?
636