1*7c478bd9Sstevel@tonic-gate#!/sbin/sh 2*7c478bd9Sstevel@tonic-gate# 3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START 4*7c478bd9Sstevel@tonic-gate# 5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only 7*7c478bd9Sstevel@tonic-gate# (the "License"). You may not use this file except in compliance 8*7c478bd9Sstevel@tonic-gate# with the License. 9*7c478bd9Sstevel@tonic-gate# 10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 13*7c478bd9Sstevel@tonic-gate# and limitations under the License. 14*7c478bd9Sstevel@tonic-gate# 15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 20*7c478bd9Sstevel@tonic-gate# 21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END 22*7c478bd9Sstevel@tonic-gate# 23*7c478bd9Sstevel@tonic-gate# 24*7c478bd9Sstevel@tonic-gate# Copyright 2004 Sun Microsystems, Inc. All rights reserved. 25*7c478bd9Sstevel@tonic-gate# Use is subject to license terms. 26*7c478bd9Sstevel@tonic-gate# 27*7c478bd9Sstevel@tonic-gate#ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gatePATH=/usr/bin:/usr/sbin:$PATH; export PATH 30*7c478bd9Sstevel@tonic-gateSTMSBOOTUTIL=/lib/mpxio/stmsboot_util 31*7c478bd9Sstevel@tonic-gateSTMSMETHODSCRIPT=/lib/svc/method/mpxio-upgrade 32*7c478bd9Sstevel@tonic-gateSTMSINSTANCE=platform/sun4u/mpxio-upgrade:default 33*7c478bd9Sstevel@tonic-gateFPCONF=/kernel/drv/fp.conf 34*7c478bd9Sstevel@tonic-gateTMPFPCONF=/var/run/tmp.fp.conf.$$ 35*7c478bd9Sstevel@tonic-gateVFSTAB=/etc/vfstab 36*7c478bd9Sstevel@tonic-gateSAVEDIR=/etc/mpxio 37*7c478bd9Sstevel@tonic-gateRECOVERFILE=$SAVEDIR/recover_instructions 38*7c478bd9Sstevel@tonic-gateSVCCFG_RECOVERY=$SAVEDIR/svccfg_recover 39*7c478bd9Sstevel@tonic-gateUSAGE=`gettext "Usage: stmsboot -e | -d | -u | -L | -l controller_number"` 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate# 42*7c478bd9Sstevel@tonic-gate# Copy all entries (including comments) from source driver.conf to destination 43*7c478bd9Sstevel@tonic-gate# driver.conf except those entries which contain mpxio-disable property. 44*7c478bd9Sstevel@tonic-gate# Take into consideration entries that spawn more than one line. 45*7c478bd9Sstevel@tonic-gate# 46*7c478bd9Sstevel@tonic-gate# $1 source driver.conf file 47*7c478bd9Sstevel@tonic-gate# $2 destination driver.conf file 48*7c478bd9Sstevel@tonic-gate# 49*7c478bd9Sstevel@tonic-gate# Returns 0 on success, non zero on failure. 50*7c478bd9Sstevel@tonic-gate# 51*7c478bd9Sstevel@tonic-gatedelete_mpxio_disable_entries() 52*7c478bd9Sstevel@tonic-gate{ 53*7c478bd9Sstevel@tonic-gate sed ' 54*7c478bd9Sstevel@tonic-gate /^[ ]*#/{ p 55*7c478bd9Sstevel@tonic-gate d 56*7c478bd9Sstevel@tonic-gate } 57*7c478bd9Sstevel@tonic-gate s/[ ]*$// 58*7c478bd9Sstevel@tonic-gate /^$/{ p 59*7c478bd9Sstevel@tonic-gate d 60*7c478bd9Sstevel@tonic-gate } 61*7c478bd9Sstevel@tonic-gate /mpxio-disable[ ]*=.*;$/d 62*7c478bd9Sstevel@tonic-gate /;$/{ p 63*7c478bd9Sstevel@tonic-gate d 64*7c478bd9Sstevel@tonic-gate } 65*7c478bd9Sstevel@tonic-gate :rdnext 66*7c478bd9Sstevel@tonic-gate N 67*7c478bd9Sstevel@tonic-gate s/[ ]*$// 68*7c478bd9Sstevel@tonic-gate /[^;]$/b rdnext 69*7c478bd9Sstevel@tonic-gate /mpxio-disable[ ]*=/d' $1 > $2 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate return $? 72*7c478bd9Sstevel@tonic-gate} 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate# 75*7c478bd9Sstevel@tonic-gate# backup the last saved copy of the specified files. 76*7c478bd9Sstevel@tonic-gate# $* files to backup 77*7c478bd9Sstevel@tonic-gate# 78*7c478bd9Sstevel@tonic-gatebackup_lastsaved() 79*7c478bd9Sstevel@tonic-gate{ 80*7c478bd9Sstevel@tonic-gate for file in $* 81*7c478bd9Sstevel@tonic-gate do 82*7c478bd9Sstevel@tonic-gate file=`basename $file` 83*7c478bd9Sstevel@tonic-gate if [ -f $SAVEDIR/$file ]; then 84*7c478bd9Sstevel@tonic-gate mv $SAVEDIR/$file $SAVEDIR/${file}.old 85*7c478bd9Sstevel@tonic-gate fi 86*7c478bd9Sstevel@tonic-gate done 87*7c478bd9Sstevel@tonic-gate} 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate# 90*7c478bd9Sstevel@tonic-gate# build recover instructions 91*7c478bd9Sstevel@tonic-gate# 92*7c478bd9Sstevel@tonic-gate# $1 1 to include boot script in the instructions 93*7c478bd9Sstevel@tonic-gate# 0 otherwise 94*7c478bd9Sstevel@tonic-gate# 95*7c478bd9Sstevel@tonic-gatebuild_recover() 96*7c478bd9Sstevel@tonic-gate{ 97*7c478bd9Sstevel@tonic-gate gettext "Instructions to recover your previous STMS configuration (if in case the system does not boot):\n\n" > $RECOVERFILE 98*7c478bd9Sstevel@tonic-gate echo "\tboot net \c" >> $RECOVERFILE 99*7c478bd9Sstevel@tonic-gate gettext "(or from a cd/dvd/another disk)\n" >> $RECOVERFILE 100*7c478bd9Sstevel@tonic-gate echo "\tfsck <your-root-device>" >> $RECOVERFILE 101*7c478bd9Sstevel@tonic-gate echo "\tmount <your-root-device> /mnt" >> $RECOVERFILE 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate if [ "x$cmd" = xupdate ]; then 104*7c478bd9Sstevel@tonic-gate gettext "\tUndo the modifications you made to STMS configuration.\n\tFor example undo any changes you made to " >> $RECOVERFILE 105*7c478bd9Sstevel@tonic-gate echo "/mnt$FPCONF." >> $RECOVERFILE 106*7c478bd9Sstevel@tonic-gate else 107*7c478bd9Sstevel@tonic-gate echo "\tcp /mnt${SAVEDIR}/fp.conf /mnt$FPCONF" >> $RECOVERFILE 108*7c478bd9Sstevel@tonic-gate fi 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate if [ $1 -eq 1 ]; then 111*7c478bd9Sstevel@tonic-gate echo "\tcp /mnt${SAVEDIR}/vfstab /mnt$VFSTAB" >> $RECOVERFILE 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate echo "repository /mnt/etc/svc/repository.db" > $SVCCFG_RECOVERY 114*7c478bd9Sstevel@tonic-gate echo "select $STMSINSTANCE" >> $SVCCFG_RECOVERY 115*7c478bd9Sstevel@tonic-gate echo "setprop general/enabled=false" >> $SVCCFG_RECOVERY 116*7c478bd9Sstevel@tonic-gate echo "exit" >> $SVCCFG_RECOVERY 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate echo "\t/usr/sbin/svccfg -f /mnt$SVCCFG_RECOVERY" >> $RECOVERFILE 119*7c478bd9Sstevel@tonic-gate fi 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate rootdisk=`mount | grep "/ on " | cut -f 3 -d " "` 122*7c478bd9Sstevel@tonic-gate echo "\tumount /mnt\n\treboot\n\n${rootdisk} \c" >> $RECOVERFILE 123*7c478bd9Sstevel@tonic-gate gettext "was your root device,\nbut it could be named differently after you boot net.\n" >> $RECOVERFILE 124*7c478bd9Sstevel@tonic-gate} 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate# 127*7c478bd9Sstevel@tonic-gate# Arrange for /etc/vfstab and dump configuration to be updated 128*7c478bd9Sstevel@tonic-gate# during the next reboot. If the cmd is "enable" or "disable", copy 129*7c478bd9Sstevel@tonic-gate# $TMPFPCONF to $FPCONF. 130*7c478bd9Sstevel@tonic-gate# 131*7c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure. 132*7c478bd9Sstevel@tonic-gate# 133*7c478bd9Sstevel@tonic-gateupdate_sysfiles() 134*7c478bd9Sstevel@tonic-gate{ 135*7c478bd9Sstevel@tonic-gate gettext "WARNING: This operation will require a reboot.\nDo you want to continue ? [y/n] (default: y) " 136*7c478bd9Sstevel@tonic-gate read response 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate if [ "x$response" != x -a "x$response" != xy -a \ 139*7c478bd9Sstevel@tonic-gate "x$response" != xY ]; then 140*7c478bd9Sstevel@tonic-gate rm -f $TMPFPCONF 141*7c478bd9Sstevel@tonic-gate return 0 142*7c478bd9Sstevel@tonic-gate fi 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate need_bootscript=1 145*7c478bd9Sstevel@tonic-gate if [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then 146*7c478bd9Sstevel@tonic-gate cp $FPCONF $SAVEDIR 147*7c478bd9Sstevel@tonic-gate cp $TMPFPCONF $FPCONF 148*7c478bd9Sstevel@tonic-gate rm -f $TMPFPCONF 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate # 151*7c478bd9Sstevel@tonic-gate # there is no need to update the system files in the following 152*7c478bd9Sstevel@tonic-gate # cases: 153*7c478bd9Sstevel@tonic-gate # - we are enabling mpxio and the system has no configured 154*7c478bd9Sstevel@tonic-gate # disks accessible by phci paths. 155*7c478bd9Sstevel@tonic-gate # - we are disabling mpxio and the system has no configured 156*7c478bd9Sstevel@tonic-gate # disks accessible by vhci paths. 157*7c478bd9Sstevel@tonic-gate # 158*7c478bd9Sstevel@tonic-gate if [ "x$cmd" = xenable ]; then 159*7c478bd9Sstevel@tonic-gate ls -l /dev/dsk/*s2 2> /dev/null | \ 160*7c478bd9Sstevel@tonic-gate egrep -s "/fp@.*/ssd@.*" 161*7c478bd9Sstevel@tonic-gate else 162*7c478bd9Sstevel@tonic-gate ls -l /dev/dsk/*s2 2> /dev/null | \ 163*7c478bd9Sstevel@tonic-gate egrep -s "/scsi_vhci.*/ssd@.*" 164*7c478bd9Sstevel@tonic-gate fi 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate if [ $? -ne 0 ]; then 167*7c478bd9Sstevel@tonic-gate need_bootscript=0 168*7c478bd9Sstevel@tonic-gate fi 169*7c478bd9Sstevel@tonic-gate fi 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate if [ $need_bootscript -eq 1 ]; then 172*7c478bd9Sstevel@tonic-gate # 173*7c478bd9Sstevel@tonic-gate # Enable the mpxio-upgrade service, but don't run it now. 174*7c478bd9Sstevel@tonic-gate # The service will run during the next reboot and will do 175*7c478bd9Sstevel@tonic-gate # the actual job of modifying the system files. 176*7c478bd9Sstevel@tonic-gate # 177*7c478bd9Sstevel@tonic-gate svcadm disable -t $STMSINSTANCE 178*7c478bd9Sstevel@tonic-gate svccfg -f - << EOF 179*7c478bd9Sstevel@tonic-gateselect $STMSINSTANCE 180*7c478bd9Sstevel@tonic-gatesetprop general/enabled = true 181*7c478bd9Sstevel@tonic-gateEOF 182*7c478bd9Sstevel@tonic-gate fi 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate build_recover $need_bootscript 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate gettext "The changes will come into effect after rebooting the system.\nReboot the system now ? [y/n] (default: y) " 187*7c478bd9Sstevel@tonic-gate read response 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate if [ "x$response" = x -o "x$response" = xy -o \ 190*7c478bd9Sstevel@tonic-gate "x$response" = xY ]; then 191*7c478bd9Sstevel@tonic-gate reboot 192*7c478bd9Sstevel@tonic-gate fi 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate return 0 195*7c478bd9Sstevel@tonic-gate} 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate# 198*7c478bd9Sstevel@tonic-gate# Enable or disable mpxio as specified by the cmd. 199*7c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure. 200*7c478bd9Sstevel@tonic-gate# 201*7c478bd9Sstevel@tonic-gateconfigure_mpxio() 202*7c478bd9Sstevel@tonic-gate{ 203*7c478bd9Sstevel@tonic-gate if [ "x$cmd" = xenable ]; then 204*7c478bd9Sstevel@tonic-gate propval=no 205*7c478bd9Sstevel@tonic-gate msg=`gettext "STMS already enabled."` 206*7c478bd9Sstevel@tonic-gate else 207*7c478bd9Sstevel@tonic-gate propval=yes 208*7c478bd9Sstevel@tonic-gate msg=`gettext "STMS already disabled."` 209*7c478bd9Sstevel@tonic-gate fi 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate if delete_mpxio_disable_entries $FPCONF $TMPFPCONF; then 212*7c478bd9Sstevel@tonic-gate echo "mpxio-disable=\"${propval}\";" >> $TMPFPCONF 213*7c478bd9Sstevel@tonic-gate if diff -b $FPCONF $TMPFPCONF > /dev/null; then 214*7c478bd9Sstevel@tonic-gate rm -f $TMPFPCONF 215*7c478bd9Sstevel@tonic-gate echo "$msg" 216*7c478bd9Sstevel@tonic-gate return 0 217*7c478bd9Sstevel@tonic-gate fi 218*7c478bd9Sstevel@tonic-gate update_sysfiles 219*7c478bd9Sstevel@tonic-gate return $? 220*7c478bd9Sstevel@tonic-gate else 221*7c478bd9Sstevel@tonic-gate rm -f $TMPFPCONF 222*7c478bd9Sstevel@tonic-gate gettext "failed to update " 1>&2 223*7c478bd9Sstevel@tonic-gate echo "$FPCONF." 1>&2 224*7c478bd9Sstevel@tonic-gate gettext "No changes were made to your STMS configuration.\n" 1>&2 225*7c478bd9Sstevel@tonic-gate return 1 226*7c478bd9Sstevel@tonic-gate fi 227*7c478bd9Sstevel@tonic-gate} 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gatesetcmd() 230*7c478bd9Sstevel@tonic-gate{ 231*7c478bd9Sstevel@tonic-gate if [ "x$cmd" = xnone ]; then 232*7c478bd9Sstevel@tonic-gate cmd=$1 233*7c478bd9Sstevel@tonic-gate else 234*7c478bd9Sstevel@tonic-gate echo "$USAGE" 1>&2 235*7c478bd9Sstevel@tonic-gate exit 2 236*7c478bd9Sstevel@tonic-gate fi 237*7c478bd9Sstevel@tonic-gate} 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gatecmd=none 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate# process options 242*7c478bd9Sstevel@tonic-gatewhile getopts eduLl: c 243*7c478bd9Sstevel@tonic-gatedo 244*7c478bd9Sstevel@tonic-gate case $c in 245*7c478bd9Sstevel@tonic-gate e) setcmd enable;; 246*7c478bd9Sstevel@tonic-gate d) setcmd disable;; 247*7c478bd9Sstevel@tonic-gate u) setcmd update;; 248*7c478bd9Sstevel@tonic-gate L) setcmd listall;; 249*7c478bd9Sstevel@tonic-gate l) setcmd list 250*7c478bd9Sstevel@tonic-gate controller=$OPTARG;; 251*7c478bd9Sstevel@tonic-gate \?) echo "$USAGE" 1>&2 252*7c478bd9Sstevel@tonic-gate exit 2;; 253*7c478bd9Sstevel@tonic-gate esac 254*7c478bd9Sstevel@tonic-gatedone 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gateif [ "x$cmd" = xnone ]; then 257*7c478bd9Sstevel@tonic-gate echo "$USAGE" 1>&2 258*7c478bd9Sstevel@tonic-gate exit 2 259*7c478bd9Sstevel@tonic-gatefi 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gateset `id` 262*7c478bd9Sstevel@tonic-gateif [ "$1" != "uid=0(root)" ]; then 263*7c478bd9Sstevel@tonic-gate gettext "You must be super-user to run this script.\n" 1>&2 264*7c478bd9Sstevel@tonic-gate exit 1 265*7c478bd9Sstevel@tonic-gatefi 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate# just a sanity check 268*7c478bd9Sstevel@tonic-gateif [ ! -f $STMSBOOTUTIL -o ! -f $STMSMETHODSCRIPT ]; then 269*7c478bd9Sstevel@tonic-gate fmt=`gettext "Can't find %s and/or %s"` 270*7c478bd9Sstevel@tonic-gate printf "$fmt\n" "$STMSBOOTUTIL" "$STMSMETHODSCRIPT" 1>&2 271*7c478bd9Sstevel@tonic-gate exit 1 272*7c478bd9Sstevel@tonic-gatefi 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gatesvcprop -q $STMSINSTANCE 275*7c478bd9Sstevel@tonic-gateif [ $? -ne 0 ]; then 276*7c478bd9Sstevel@tonic-gate fmt=`gettext "Can't find %s service"` 277*7c478bd9Sstevel@tonic-gate printf "$fmt\n" "$STMSINSTANCE" 1>&2 278*7c478bd9Sstevel@tonic-gate exit 1 279*7c478bd9Sstevel@tonic-gatefi 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable -o "x$cmd" = xupdate ]; then 282*7c478bd9Sstevel@tonic-gate # 283*7c478bd9Sstevel@tonic-gate # The bootup script doesn't work on cache-only-clients as the script 284*7c478bd9Sstevel@tonic-gate # is executed before the plumbing for cachfs mounting of root is done. 285*7c478bd9Sstevel@tonic-gate # 286*7c478bd9Sstevel@tonic-gate if mount -v | egrep -s " on / type (nfs|cachefs) "; then 287*7c478bd9Sstevel@tonic-gate gettext "This command option is not supported on systems with nfs or cachefs mounted root filesystem.\n" 1>&2 288*7c478bd9Sstevel@tonic-gate exit 1 289*7c478bd9Sstevel@tonic-gate fi 290*7c478bd9Sstevel@tonic-gate 291*7c478bd9Sstevel@tonic-gate if [ -d $SAVEDIR ]; then 292*7c478bd9Sstevel@tonic-gate # 293*7c478bd9Sstevel@tonic-gate # keep a copy of the last saved files, useful for manual 294*7c478bd9Sstevel@tonic-gate # recovery in case of a problem. 295*7c478bd9Sstevel@tonic-gate # 296*7c478bd9Sstevel@tonic-gate backup_lastsaved $FPCONF $VFSTAB 297*7c478bd9Sstevel@tonic-gate else 298*7c478bd9Sstevel@tonic-gate mkdir $SAVEDIR 299*7c478bd9Sstevel@tonic-gate fi 300*7c478bd9Sstevel@tonic-gate 301*7c478bd9Sstevel@tonic-gatefi 302*7c478bd9Sstevel@tonic-gate 303*7c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then 304*7c478bd9Sstevel@tonic-gate configure_mpxio $cmd 305*7c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xupdate ]; then 306*7c478bd9Sstevel@tonic-gate update_sysfiles 307*7c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xlist ]; then 308*7c478bd9Sstevel@tonic-gate $STMSBOOTUTIL -l $controller 309*7c478bd9Sstevel@tonic-gateelse 310*7c478bd9Sstevel@tonic-gate $STMSBOOTUTIL -L 311*7c478bd9Sstevel@tonic-gatefi 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gateexit $? 314