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" 27815dd917Sjmcp# 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 56815dd917SjmcpSED=/usr/bin/sed 57815dd917SjmcpSVCPROP=/usr/bin/svcprop 58815dd917SjmcpSVCCFG=/usr/sbin/svccfg 59815dd917SjmcpSVCS=/usr/bin/svcs 60815dd917SjmcpSVCADM=/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 148815dd917Sjmcp 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 156815dd917Sjmcp 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 190815dd917Sjmcp # set need_bootscript to the number of drivers that 191815dd917Sjmcp # we support. 192815dd917Sjmcp 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 202815dd917Sjmcp if [ -f $TMPDRVCONF ]; then 20360fffc19Sjw149990 cp $TMPDRVCONF $KDRVCONF 204815dd917Sjmcp rm -f $TMPDRVCONF 205815dd917Sjmcp else 206815dd917Sjmcp # if $TMPDRVCONF doesn't exist, then we 207815dd917Sjmcp # haven't made any changes to it 208815dd917Sjmcp continue; 209815dd917Sjmcp 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 220815dd917Sjmcp # Function to setup the CLIENT_TYPE_PHCI string based on 221815dd917Sjmcp # the list of drivers that we're operating on. The variable 222815dd917Sjmcp # depends upon the pathname of the parent node in the 223815dd917Sjmcp # device tree, which can be different on x86/x64 and sparc. 224815dd917Sjmcp 225815dd917Sjmcp CLIENT_TYPE_PHCI=`$STMSBOOTUTIL -D $d -n`; 226815dd917Sjmcp 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 240815dd917Sjmcp need_bootscript=`$EXPR $need_bootscript - 1` 24160fffc19Sjw149990 fi 24260fffc19Sjw149990 done 24360fffc19Sjw149990 fi 24460fffc19Sjw149990 245815dd917Sjmcp if [ $need_bootscript -gt 0 ]; then 246815dd917Sjmcp need_bootscript=1 2475a4c37c9Sqh201292 if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then 2485a4c37c9Sqh201292 #only update bootpath for x86. 2495a4c37c9Sqh201292 cp $BOOTENV_FILE $SAVEDIR 25060fffc19Sjw149990 /usr/sbin/eeprom bootpath=$new_bootpath 2515a4c37c9Sqh201292 fi 2527c478bd9Sstevel@tonic-gate # 2537c478bd9Sstevel@tonic-gate # Enable the mpxio-upgrade service, but don't run it now. 2547c478bd9Sstevel@tonic-gate # The service will run during the next reboot and will do 2557c478bd9Sstevel@tonic-gate # the actual job of modifying the system files. 2567c478bd9Sstevel@tonic-gate # 257815dd917Sjmcp $SVCADM disable -t $STMSINSTANCE 258815dd917Sjmcp $SVCCFG -f - << EOF 2597c478bd9Sstevel@tonic-gateselect $STMSINSTANCE 2607c478bd9Sstevel@tonic-gatesetprop general/enabled = true 2617c478bd9Sstevel@tonic-gateEOF 262815dd917Sjmcp else 263815dd917Sjmcp need_bootscript=0 2647c478bd9Sstevel@tonic-gate fi 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate build_recover $need_bootscript 2677c478bd9Sstevel@tonic-gate 26860fffc19Sjw149990 if [ "x$MACH" = "xi386" ]; then 26960fffc19Sjw149990 $BOOTADM update-archive 27060fffc19Sjw149990 fi 27160fffc19Sjw149990 2727c478bd9Sstevel@tonic-gate gettext "The changes will come into effect after rebooting the system.\nReboot the system now ? [y/n] (default: y) " 2737c478bd9Sstevel@tonic-gate read response 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate if [ "x$response" = x -o "x$response" = xy -o \ 2767c478bd9Sstevel@tonic-gate "x$response" = xY ]; then 27760fffc19Sjw149990 /usr/sbin/reboot 2787c478bd9Sstevel@tonic-gate fi 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate return 0 2817c478bd9Sstevel@tonic-gate} 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate# 2847c478bd9Sstevel@tonic-gate# Enable or disable mpxio as specified by the cmd. 2857c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure. 2867c478bd9Sstevel@tonic-gate# 28760fffc19Sjw149990# Args: $cmd = {enable | disable} 28860fffc19Sjw149990# $d = {fp | mpt} 28960fffc19Sjw149990# 29060fffc19Sjw149990# the global variable $DRVLIST is used 29160fffc19Sjw149990# 2927c478bd9Sstevel@tonic-gateconfigure_mpxio() 2937c478bd9Sstevel@tonic-gate{ 2945a4c37c9Sqh201292 mpxiodisableno='mpxio-disable[ ]*=[ ]*"no"[ ]*;' 2955a4c37c9Sqh201292 mpxiodisableyes='mpxio-disable[ ]*=[ ]*"yes"[ ]*;' 2965a4c37c9Sqh201292 2977c478bd9Sstevel@tonic-gate if [ "x$cmd" = xenable ]; then 2985a4c37c9Sqh201292 mpxiodisable_cur_entry=$mpxiodisableyes 2997c478bd9Sstevel@tonic-gate propval=no 30060fffc19Sjw149990 msg=`gettext "STMS already enabled"` 3017c478bd9Sstevel@tonic-gate else 3025a4c37c9Sqh201292 mpxiodisable_cur_entry=$mpxiodisableno 3037c478bd9Sstevel@tonic-gate propval=yes 30460fffc19Sjw149990 msg=`gettext "STMS already disabled"` 3057c478bd9Sstevel@tonic-gate fi 3067c478bd9Sstevel@tonic-gate 30760fffc19Sjw149990 DRVCONF=$d.conf 30860fffc19Sjw149990 KDRVCONF=/kernel/drv/$d.conf 30960fffc19Sjw149990 TMPDRVCONF=/var/run/tmp.$d.conf.$$ 31060fffc19Sjw149990 TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$; 31160fffc19Sjw149990 31260fffc19Sjw149990 if delete_mpxio_disable_entries $KDRVCONF $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY; then 31360fffc19Sjw149990 31460fffc19Sjw149990 if [ -s $TMPDRVCONF_MPXIO_ENTRY ]; then 31560fffc19Sjw149990 # $DRVCONF does have mpxiodisable entries 31660fffc19Sjw149990 $EGREP -s "$mpxiodisable_cur_entry" $TMPDRVCONF_MPXIO_ENTRY 3175a4c37c9Sqh201292 if [ $? -ne 0 ]; then 3185a4c37c9Sqh201292 # if all mpxiodisable entries are no/yes for 3195a4c37c9Sqh201292 # enable/disable mpxio, notify the user 32060fffc19Sjw149990 rm -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1 32160fffc19Sjw149990 continue; 32260fffc19Sjw149990 else 32360fffc19Sjw149990 reboot_needed=`$EXPR $reboot_needed + 1` 3247c478bd9Sstevel@tonic-gate fi 32560fffc19Sjw149990 32660fffc19Sjw149990 # If mpxiodisable entries do not exist, always continue update 3275a4c37c9Sqh201292 fi 3287c478bd9Sstevel@tonic-gate else 32960fffc19Sjw149990 rm -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1 3307c478bd9Sstevel@tonic-gate gettext "failed to update " 1>&2 33160fffc19Sjw149990 echo "$KDRVCONF." 1>&2 3327c478bd9Sstevel@tonic-gate gettext "No changes were made to your STMS configuration.\n" 1>&2 3337c478bd9Sstevel@tonic-gate return 1 3347c478bd9Sstevel@tonic-gate fi 3355a4c37c9Sqh201292 33660fffc19Sjw149990 rm $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1 33760fffc19Sjw149990 echo "mpxio-disable=\"${propval}\";" >> $TMPDRVCONF 3385a4c37c9Sqh201292 3397c478bd9Sstevel@tonic-gate} 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gatesetcmd() 3427c478bd9Sstevel@tonic-gate{ 3437c478bd9Sstevel@tonic-gate if [ "x$cmd" = xnone ]; then 3447c478bd9Sstevel@tonic-gate cmd=$1 3457c478bd9Sstevel@tonic-gate else 3467c478bd9Sstevel@tonic-gate echo "$USAGE" 1>&2 3477c478bd9Sstevel@tonic-gate exit 2 3487c478bd9Sstevel@tonic-gate fi 3497c478bd9Sstevel@tonic-gate} 3507c478bd9Sstevel@tonic-gate 35160fffc19Sjw149990# 3525a4c37c9Sqh201292#Need to update bootpath on x86 if boot system from FC disk 3535a4c37c9Sqh201292#Only update bootpath here when mpxio is enabled 3545a4c37c9Sqh201292#If mpxio is disabled currently, will update bootpath in mpxio-upgrade 35560fffc19Sjw149990# 35660fffc19Sjw149990 3575a4c37c9Sqh201292get_newbootpath_for_stmsdev() { 3585a4c37c9Sqh201292 if [ "x$cmd" = "xenable" ]; then 3595a4c37c9Sqh201292 return 0 3605a4c37c9Sqh201292 fi 3615a4c37c9Sqh201292 362*53ed03b5Sjmcp cur_bootpath=`/usr/sbin/eeprom bootpath | \ 363*53ed03b5Sjmcp $SED 's/bootpath=[ ]*//g' | $SED 's/[ ]*$//'` 3645a4c37c9Sqh201292 if [ "x$cur_bootpath" = "x" ]; then 3655a4c37c9Sqh201292 gettext "failed to get bootpath by eeprom\n" 1>&2 3665a4c37c9Sqh201292 return 1 3675a4c37c9Sqh201292 fi 3685a4c37c9Sqh201292 3695a4c37c9Sqh201292 #only update bootpath for STMS path 37060fffc19Sjw149990 echo $cur_bootpath|$EGREP $CLIENT_TYPE_VHCI > /dev/null 2>&1 3715a4c37c9Sqh201292 if [ $? -eq 1 ]; then 3725a4c37c9Sqh201292 return 0 3735a4c37c9Sqh201292 fi 3745a4c37c9Sqh201292 3755a4c37c9Sqh201292 new_bootpath=`$STMSBOOTUTIL -p /devices$cur_bootpath` 3765a4c37c9Sqh201292 if [ $? -ne 0 ]; then 3775a4c37c9Sqh201292 new_bootpath="" 3785a4c37c9Sqh201292 return 1 3795a4c37c9Sqh201292 fi 38060fffc19Sjw149990 38160fffc19Sjw149990 # we replace "sd" with "disk" if we need to work on the eeprom 38260fffc19Sjw149990 # bootpath setting, since fibre-channel devices will report as 38360fffc19Sjw149990 # being attached via "disk" and not "sd". One day we'll have a 38460fffc19Sjw149990 # truly unified and architecture-independent view of the device 38560fffc19Sjw149990 # tree, and this block will be redundant 38660fffc19Sjw149990 fp_bootpath=`echo $new_bootpath|grep fp.*sd` 38760fffc19Sjw149990 if [ "x$fp_bootpath" != "x" ]; then 38860fffc19Sjw149990 new_bootpath=`echo $fp_bootpath |sed -e"s,sd,disk,g"` 38960fffc19Sjw149990 fi 39060fffc19Sjw149990} 39160fffc19Sjw149990 39260fffc19Sjw149990# 39360fffc19Sjw149990# Emit a warning message to the user that by default we 39460fffc19Sjw149990# operate on all multipath-capable controllers that are 39560fffc19Sjw149990# attached to the system, and that if they want to operate 39660fffc19Sjw149990# on only a specific controller type (fp|mpt|....) then 39760fffc19Sjw149990# they need to re-invoke stmsboot with "-D $driver" in 39860fffc19Sjw149990# their argument list 39960fffc19Sjw149990# 40060fffc19Sjw149990 40160fffc19Sjw149990emit_driver_warning_msg() { 40260fffc19Sjw149990 40360fffc19Sjw149990 # for each driver that we support, grab the list 40460fffc19Sjw149990 # of controllers attached to the system. 40560fffc19Sjw149990 406815dd917Sjmcp echo "" 407*53ed03b5Sjmcp gettext "WARNING: stmsboot operates on each supported multipath-capable controller\n" 408*53ed03b5Sjmcp gettext " detected in a host. In your system, these controllers are\n\n" 40960fffc19Sjw149990 410815dd917Sjmcp for WARNDRV in `echo $SUPPORTED_DRIVERS| $SED -e"s,|, ,g"`; do 411815dd917Sjmcp for i in `$STMSBOOTUTIL -D $WARNDRV -n | $SED -e"s,|, ,g"`; do 412815dd917Sjmcp $GREP "$i.*$WARNDRV.$" /etc/path_to_inst | $AWK -F"\"" '{print "/devices"$2}' 413815dd917Sjmcp done; 41460fffc19Sjw149990 done; 41560fffc19Sjw149990 41660fffc19Sjw149990 echo "" 417*53ed03b5Sjmcp gettext "If you do NOT wish to operate on these controllers, please quit stmsboot\n" 418*53ed03b5Sjmcp gettext "and re-invoke with -D { fp | mpt } to specify which controllers you wish\n" 419*53ed03b5Sjmcp gettext "to modify your multipathing configuration for.\n" 42060fffc19Sjw149990 421815dd917Sjmcp echo "" 422*53ed03b5Sjmcp gettext "Do you wish to continue? [y/n] (default: y) " 42360fffc19Sjw149990 read response 42460fffc19Sjw149990 4258cecff49Sgp87344 if [ "x$response" != "x" -a "x$response" != "xY" -a \ 4268cecff49Sgp87344 "x$response" != "xy" ]; then 42760fffc19Sjw149990 exit 42860fffc19Sjw149990 fi 42960fffc19Sjw149990 43060fffc19Sjw149990} 43160fffc19Sjw149990 4327c478bd9Sstevel@tonic-gatecmd=none 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate# process options 43560fffc19Sjw149990while getopts D:geduLl: c 4367c478bd9Sstevel@tonic-gatedo 4377c478bd9Sstevel@tonic-gate case $c in 4387c478bd9Sstevel@tonic-gate e) setcmd enable;; 4397c478bd9Sstevel@tonic-gate d) setcmd disable;; 4407c478bd9Sstevel@tonic-gate u) setcmd update;; 4417c478bd9Sstevel@tonic-gate L) setcmd listall;; 4427c478bd9Sstevel@tonic-gate l) setcmd list 4437c478bd9Sstevel@tonic-gate controller=$OPTARG;; 44460fffc19Sjw149990 D) DRV=$OPTARG;; 44560fffc19Sjw149990 g) GUID="-g";; 4467c478bd9Sstevel@tonic-gate \?) echo "$USAGE" 1>&2 4477c478bd9Sstevel@tonic-gate exit 2;; 4487c478bd9Sstevel@tonic-gate esac 4497c478bd9Sstevel@tonic-gatedone 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gateif [ "x$cmd" = xnone ]; then 4527c478bd9Sstevel@tonic-gate echo "$USAGE" 1>&2 4537c478bd9Sstevel@tonic-gate exit 2 4547c478bd9Sstevel@tonic-gatefi 4557c478bd9Sstevel@tonic-gate 45660fffc19Sjw149990if [ "x$DRV" = "x" ]; then 45760fffc19Sjw149990 DRVLIST="fp mpt" 45860fffc19Sjw149990else 45960fffc19Sjw149990 DRVLIST=$DRV 46060fffc19Sjw149990fi 46160fffc19Sjw149990 46234c94816SjmcpUSERID=`id | $EGREP "uid=0"` 46334c94816Sjmcpif [ -z "$USERID" ]; then 4647c478bd9Sstevel@tonic-gate gettext "You must be super-user to run this script.\n" 1>&2 4657c478bd9Sstevel@tonic-gate exit 1 4667c478bd9Sstevel@tonic-gatefi 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate# just a sanity check 4697c478bd9Sstevel@tonic-gateif [ ! -f $STMSBOOTUTIL -o ! -f $STMSMETHODSCRIPT ]; then 4707c478bd9Sstevel@tonic-gate fmt=`gettext "Can't find %s and/or %s"` 4717c478bd9Sstevel@tonic-gate printf "$fmt\n" "$STMSBOOTUTIL" "$STMSMETHODSCRIPT" 1>&2 4727c478bd9Sstevel@tonic-gate exit 1 4737c478bd9Sstevel@tonic-gatefi 4747c478bd9Sstevel@tonic-gate 47560fffc19Sjw149990# If the old sun4u-specific SMF method is found, remove it 476815dd917Sjmcp$SVCCFG -s "platform/sun4u/mpxio-upgrade:default" < /dev/null > /dev/null 2>&1 477815dd917Sjmcpif [ $? -eq 0 ]; then 478815dd917Sjmcp $SVCCFG delete "platform/sun4u/mpxio-upgrade:default" > /dev/null 2>&1 47960fffc19Sjw149990fi 48060fffc19Sjw149990 48160fffc19Sjw149990# now import the new service, if necessary 482815dd917Sjmcp$SVCPROP -q $STMSINSTANCE < /dev/null > /dev/null 2>&1 48360fffc19Sjw149990if [ $? -ne 0 ]; then 48460fffc19Sjw149990 if [ -f /var/svc/manifest/system/device/mpxio-upgrade.xml ]; then 485815dd917Sjmcp $SVCCFG import /var/svc/manifest/system/device/mpxio-upgrade.xml 48660fffc19Sjw149990 if [ $? -ne 0 ]; then 487*53ed03b5Sjmcp fmt=`gettext "Unable to import the %s service"` 4887c478bd9Sstevel@tonic-gate printf "$fmt\n" "$STMSINSTANCE" 1>&2 4897c478bd9Sstevel@tonic-gate exit 1 49060fffc19Sjw149990 else 49160fffc19Sjw149990 fmt=`gettext "Service %s imported successfully, continuing"` 49260fffc19Sjw149990 printf "$fmt\n" "$STMSINSTANCE" 1>&2 49360fffc19Sjw149990 fi 49460fffc19Sjw149990 else 49560fffc19Sjw149990 fmt=`gettext "Service %s does not exist on this host"` 49660fffc19Sjw149990 printf "$fmt\n" "$STMSINSTANCE" 1>&2 49760fffc19Sjw149990 exit 1 49860fffc19Sjw149990 fi 4997c478bd9Sstevel@tonic-gatefi 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable -o "x$cmd" = xupdate ]; then 5027c478bd9Sstevel@tonic-gate # 5037c478bd9Sstevel@tonic-gate # The bootup script doesn't work on cache-only-clients as the script 5046deb031bSsjelinek # is executed before the plumbing for cachefs mounting of root is done. 5057c478bd9Sstevel@tonic-gate # 50660fffc19Sjw149990 if $MOUNT -v | $EGREP -s " on / type (nfs|cachefs) "; then 5077c478bd9Sstevel@tonic-gate gettext "This command option is not supported on systems with nfs or cachefs mounted root filesystem.\n" 1>&2 5087c478bd9Sstevel@tonic-gate exit 1 5097c478bd9Sstevel@tonic-gate fi 5107c478bd9Sstevel@tonic-gate 511815dd917Sjmcp # if the user has left the system with the mpxio-upgrade service 512815dd917Sjmcp # in a temporarily disabled state (ie, service is armed for the next 513815dd917Sjmcp # reboot), then let them know. We need to ensure that the system is 514815dd917Sjmcp # is in a sane state before allowing any further invocations, so 515815dd917Sjmcp # try to get the system admin to do so 516815dd917Sjmcp 517815dd917Sjmcp ISARMED=`$SVCS -l $STMSINSTANCE |$GREP "enabled.*temporary"` 518815dd917Sjmcp if [ $? -eq 0 ]; then 519815dd917Sjmcp echo "" 520*53ed03b5Sjmcp gettext "You need to reboot the system in order to complete\n" 521*53ed03b5Sjmcp gettext "the previous invocation of stmsboot.\n" 522815dd917Sjmcp echo "" 523*53ed03b5Sjmcp gettext "Do you wish to reboot the system now? (y/n, default y) " 524815dd917Sjmcp read response 525815dd917Sjmcp 5268cecff49Sgp87344 if [ "x$response" = "x" -o "x$response" = "xY" -o \ 5278cecff49Sgp87344 "x$response" = "xy" ]; then 528815dd917Sjmcp /usr/sbin/reboot 529815dd917Sjmcp else 530*53ed03b5Sjmcp echo "" 531*53ed03b5Sjmcp gettext "Please reboot this system before continuing\n" 532*53ed03b5Sjmcp echo "" 533815dd917Sjmcp exit 1 534815dd917Sjmcp fi 535815dd917Sjmcp fi 536815dd917Sjmcp 5377c478bd9Sstevel@tonic-gate if [ -d $SAVEDIR ]; then 5387c478bd9Sstevel@tonic-gate # 5397c478bd9Sstevel@tonic-gate # keep a copy of the last saved files, useful for manual 5407c478bd9Sstevel@tonic-gate # recovery in case of a problem. 5417c478bd9Sstevel@tonic-gate # 54260fffc19Sjw149990 for d in $DRVLIST; do 54360fffc19Sjw149990 DRVCONF=$d.conf 54460fffc19Sjw149990 KDRVCONF=/kernel/drv/$d.conf 54560fffc19Sjw149990 TMPDRVCONF=/var/run/tmp.$d.conf.$$ 54660fffc19Sjw149990 TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$; 54760fffc19Sjw149990 5485a4c37c9Sqh201292 if [ "x$MACH" = "xsparc" ]; then 54960fffc19Sjw149990 backup_lastsaved $KDRVCONF $VFSTAB 5507c478bd9Sstevel@tonic-gate else 55160fffc19Sjw149990 backup_lastsaved $KDRVCONF $VFSTAB $BOOTENV_FILE 5525a4c37c9Sqh201292 fi 55360fffc19Sjw149990 done 5545a4c37c9Sqh201292 else 5557c478bd9Sstevel@tonic-gate mkdir $SAVEDIR 5567c478bd9Sstevel@tonic-gate fi 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gatefi 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then 56160fffc19Sjw149990 56260fffc19Sjw149990 msgneeded=`echo "$DRVLIST" |grep " "` 56360fffc19Sjw149990 if [ -n "$msgneeded" ]; then 56460fffc19Sjw149990 emit_driver_warning_msg 56560fffc19Sjw149990 fi 56660fffc19Sjw149990 for d in $DRVLIST; do 56760fffc19Sjw149990 configure_mpxio $cmd $d 56860fffc19Sjw149990 done 56960fffc19Sjw149990 57060fffc19Sjw149990 if [ $reboot_needed -ne 0 ]; then 57160fffc19Sjw149990 57260fffc19Sjw149990 # Need to update bootpath on x86 if our boot device is 57360fffc19Sjw149990 # now accessed through mpxio. 57460fffc19Sjw149990 # Only update bootpath before reboot when mpxio is enabled 57560fffc19Sjw149990 # If mpxio is currently disabled, we will update bootpath 57660fffc19Sjw149990 # on reboot in the mpxio-upgrade service 57760fffc19Sjw149990 57860fffc19Sjw149990 if [ "x$MACH" = "xi386" -a "x$cmd" = "xdisable" ]; then 57960fffc19Sjw149990 get_newbootpath_for_stmsdev 58060fffc19Sjw149990 if [ $? -ne 0 ]; then 58160fffc19Sjw149990 rm -f $TMPDRVCONF > /dev/null 2>&1 58260fffc19Sjw149990 gettext "failed to update bootpath.\n" 1>&2 58360fffc19Sjw149990 gettext "No changes were made to your STMS configuration.\n" 1>&2 58460fffc19Sjw149990 return 1 58560fffc19Sjw149990 fi 58660fffc19Sjw149990 fi 58760fffc19Sjw149990 update_sysfiles 58860fffc19Sjw149990 else 58960fffc19Sjw149990 echo "STMS is already ${cmd}d. No changes or reboots needed" 59060fffc19Sjw149990 fi 59160fffc19Sjw149990 59260fffc19Sjw149990 5937c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xupdate ]; then 5945a4c37c9Sqh201292 if [ "x$MACH" = "xi386" ]; then 5955a4c37c9Sqh201292 # In this case we always change the bootpath to phci-based 5965a4c37c9Sqh201292 # path first. bootpath will later be modified in mpxio-upgrade 5975a4c37c9Sqh201292 # to the vhci-based path if mpxio is enabled on root. 5985a4c37c9Sqh201292 get_newbootpath_for_stmsdev 5995a4c37c9Sqh201292 if [ $? -ne 0 ]; then 6005a4c37c9Sqh201292 gettext "failed to update bootpath.\n" 1>&2 6015a4c37c9Sqh201292 return 1 6025a4c37c9Sqh201292 fi 6035a4c37c9Sqh201292 fi 6047c478bd9Sstevel@tonic-gate update_sysfiles 60560fffc19Sjw149990 6067c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xlist ]; then 60760fffc19Sjw149990 $STMSBOOTUTIL $GUID -l $controller 6087c478bd9Sstevel@tonic-gateelse 60960fffc19Sjw149990 $STMSBOOTUTIL $GUID -L 6107c478bd9Sstevel@tonic-gatefi 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gateexit $? 613