1#!/sbin/sh 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22# 23# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26#ident "%Z%%M% %I% %E% SMI" 27 28PATH=/usr/bin:/usr/sbin:$PATH; export PATH 29STMSBOOTUTIL=/lib/mpxio/stmsboot_util 30STMSMETHODSCRIPT=/lib/svc/method/mpxio-upgrade 31FPCONF=/kernel/drv/fp.conf 32TMPFPCONF=/var/run/tmp.fp.conf.$$ 33TMPFPCONF_MPXIO_ENTRY=/var/run/tmp.fp.conf.mpxioentry.$$ 34VFSTAB=/etc/vfstab 35SAVEDIR=/etc/mpxio 36RECOVERFILE=$SAVEDIR/recover_instructions 37SVCCFG_RECOVERY=$SAVEDIR/svccfg_recover 38USAGE=`gettext "Usage: stmsboot -e | -d | -u | -L | -l controller_number"` 39TEXTDOMAIN=SUNW_OST_OSCMD 40export TEXTDOMAIN 41STMSINSTANCE=system/device/mpxio-upgrade:default 42 43MACH=`/usr/bin/uname -p` 44if [ "x$MACH" = "xsparc" ]; then 45 CLIENT_TYPE_VHCI="/scsi_vhci.*/ssd@.*" 46 CLIENT_TYPE_PHCI="/fp@.*/ssd@.*" 47else 48 CLIENT_TYPE_VHCI="/scsi_vhci.*/disk@.*" 49 CLIENT_TYPE_PHCI="/fp@.*/disk@.*" 50 BOOTENV_FILE=/boot/solaris/bootenv.rc 51fi 52# 53# Copy all entries (including comments) from source driver.conf to destination 54# driver.conf except those entries which contain mpxio-disable property. 55# Take into consideration entries that spawn more than one line. 56# 57# $1 source driver.conf file 58# $2 destination driver.conf file 59# 60# Returns 0 on success, non zero on failure. 61# 62delete_mpxio_disable_entries() 63{ 64 sed ' 65 /^[ ]*#/{ p 66 d 67 } 68 s/[ ]*$// 69 /^$/{ p 70 d 71 } 72 /mpxio-disable[ ]*=.*;$/{ w '$3' 73 d 74 } 75 /;$/{ p 76 d 77 } 78 :rdnext 79 N 80 s/[ ]*$// 81 /[^;]$/b rdnext 82 /mpxio-disable[ ]*=/{ s/\n/ /g 83 w '$3' 84 d 85 } 86 ' $1 > $2 87 88 return $? 89} 90 91# 92# backup the last saved copy of the specified files. 93# $* files to backup 94# 95backup_lastsaved() 96{ 97 for file in $* 98 do 99 file=`basename $file` 100 if [ -f $SAVEDIR/$file ]; then 101 mv $SAVEDIR/$file $SAVEDIR/${file}.old 102 fi 103 done 104} 105 106# 107# build recover instructions 108# 109# $1 1 to include boot script in the instructions 110# 0 otherwise 111# 112build_recover() 113{ 114 gettext "Instructions to recover your previous STMS configuration (if in case the system does not boot):\n\n" > $RECOVERFILE 115 echo "\tboot net \c" >> $RECOVERFILE 116 gettext "(or from a cd/dvd/another disk)\n" >> $RECOVERFILE 117 echo "\tfsck <your-root-device>" >> $RECOVERFILE 118 echo "\tmount <your-root-device> /mnt" >> $RECOVERFILE 119 120 if [ "x$cmd" = xupdate ]; then 121 gettext "\tUndo the modifications you made to STMS configuration.\n\tFor example undo any changes you made to " >> $RECOVERFILE 122 echo "/mnt$FPCONF." >> $RECOVERFILE 123 else 124 echo "\tcp /mnt${SAVEDIR}/fp.conf /mnt$FPCONF" >> $RECOVERFILE 125 fi 126 127 if [ $1 -eq 1 ]; then 128 echo "\tcp /mnt${SAVEDIR}/vfstab /mnt$VFSTAB" >> $RECOVERFILE 129 130 echo "repository /mnt/etc/svc/repository.db" > $SVCCFG_RECOVERY 131 echo "select $STMSINSTANCE" >> $SVCCFG_RECOVERY 132 echo "setprop general/enabled=false" >> $SVCCFG_RECOVERY 133 echo "exit" >> $SVCCFG_RECOVERY 134 135 echo "\t/usr/sbin/svccfg -f /mnt$SVCCFG_RECOVERY" >> $RECOVERFILE 136 137 if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then 138 echo "\tcp /mnt${SAVEDIR}/bootenv.rc /mnt$BOOTENV_FILE" >> $RECOVERFILE 139 fi 140 fi 141 142 rootdisk=`mount | grep "/ on " | cut -f 3 -d " "` 143 echo "\tumount /mnt\n\treboot\n\n${rootdisk} \c" >> $RECOVERFILE 144 gettext "was your root device,\nbut it could be named differently after you boot net.\n" >> $RECOVERFILE 145} 146 147# 148# Arrange for /etc/vfstab and dump configuration to be updated 149# during the next reboot. If the cmd is "enable" or "disable", copy 150# $TMPFPCONF to $FPCONF. 151# 152# Returns 0 on success, 1 on failure. 153# 154update_sysfiles() 155{ 156 gettext "WARNING: This operation will require a reboot.\nDo you want to continue ? [y/n] (default: y) " 157 read response 158 159 if [ "x$response" != x -a "x$response" != xy -a \ 160 "x$response" != xY ]; then 161 rm -f $TMPFPCONF 162 return 0 163 fi 164 165 need_bootscript=1 166 if [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then 167 cp $FPCONF $SAVEDIR 168 cp $TMPFPCONF $FPCONF 169 rm -f $TMPFPCONF 170 171 # 172 # there is no need to update the system files in the following 173 # cases: 174 # - we are enabling mpxio and the system has no configured 175 # disks accessible by phci paths. 176 # - we are disabling mpxio and the system has no configured 177 # disks accessible by vhci paths. 178 # 179 if [ "x$cmd" = xenable ]; then 180 ls -l /dev/dsk/*s2 2> /dev/null | \ 181 egrep -s $CLIENT_TYPE_PHCI 182 else 183 ls -l /dev/dsk/*s2 2> /dev/null | \ 184 egrep -s $CLIENT_TYPE_VHCI 185 fi 186 187 if [ $? -ne 0 ]; then 188 need_bootscript=0 189 fi 190 fi 191 192 if [ $need_bootscript -eq 1 ]; then 193 if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then 194 #only update bootpath for x86. 195 cp $BOOTENV_FILE $SAVEDIR 196 eeprom bootpath=$new_bootpath 197 fi 198 # 199 # Enable the mpxio-upgrade service, but don't run it now. 200 # The service will run during the next reboot and will do 201 # the actual job of modifying the system files. 202 # 203 svcadm disable -t $STMSINSTANCE 204 svccfg -f - << EOF 205select $STMSINSTANCE 206setprop general/enabled = true 207EOF 208 fi 209 210 build_recover $need_bootscript 211 212 gettext "The changes will come into effect after rebooting the system.\nReboot the system now ? [y/n] (default: y) " 213 read response 214 215 if [ "x$response" = x -o "x$response" = xy -o \ 216 "x$response" = xY ]; then 217 reboot 218 fi 219 220 return 0 221} 222 223# 224# Enable or disable mpxio as specified by the cmd. 225# Returns 0 on success, 1 on failure. 226# 227configure_mpxio() 228{ 229 mpxiodisableno='mpxio-disable[ ]*=[ ]*"no"[ ]*;' 230 mpxiodisableyes='mpxio-disable[ ]*=[ ]*"yes"[ ]*;' 231 232 if [ "x$cmd" = xenable ]; then 233 mpxiodisable_cur_entry=$mpxiodisableyes 234 propval=no 235 msg=`gettext "STMS already enabled."` 236 else 237 mpxiodisable_cur_entry=$mpxiodisableno 238 propval=yes 239 msg=`gettext "STMS already disabled."` 240 fi 241 242 if delete_mpxio_disable_entries $FPCONF $TMPFPCONF $TMPFPCONF_MPXIO_ENTRY; then 243 if [ -s $TMPFPCONF_MPXIO_ENTRY ]; then 244 # fp.conf does have mpxiodisable entries 245 egrep -s "$mpxiodisable_cur_entry" $TMPFPCONF_MPXIO_ENTRY 246 if [ $? -ne 0 ]; then 247 # if all mpxiodisable entries are no/yes for 248 # enable/disable mpxio, notify the user 249 rm -f $TMPFPCONF $TMPFPCONF_MPXIO_ENTRY 250 echo "$msg" 251 return 0 252 fi 253 # If mpxiodisable entries does not exist, always continue update 254 fi 255 else 256 rm -f $TMPFPCONF $TMPFPCONF_MPXIO_ENTRY 257 gettext "failed to update " 1>&2 258 echo "$FPCONF." 1>&2 259 gettext "No changes were made to your STMS configuration.\n" 1>&2 260 return 1 261 fi 262 263 rm $TMPFPCONF_MPXIO_ENTRY 264 echo "mpxio-disable=\"${propval}\";" >> $TMPFPCONF 265 266 #Need to update bootpath on x86 if boot system from FC disk 267 #Only update bootpath before reboot when mpxio is enabled 268 #If mpxio is disabled currently, will update bootpath in mpxio-upgrade 269 if [ "x$MACH" = "xi386" -a "x$cmd" = "xdisable" ]; then 270 get_newbootpath_for_stmsdev 271 if [ $? -ne 0 ]; then 272 rm -f $TMPFPCONF 273 gettext "failed to update bootpath.\n" 1>&2 274 gettext "No changes were made to your STMS configuration.\n" 1>&2 275 return 1 276 fi 277 fi 278 update_sysfiles 279 return $? 280} 281 282setcmd() 283{ 284 if [ "x$cmd" = xnone ]; then 285 cmd=$1 286 else 287 echo "$USAGE" 1>&2 288 exit 2 289 fi 290} 291 292 293#Need to update bootpath on x86 if boot system from FC disk 294#Only update bootpath here when mpxio is enabled 295#If mpxio is disabled currently, will update bootpath in mpxio-upgrade 296get_newbootpath_for_stmsdev() { 297 if [ "x$cmd" = "xenable" ]; then 298 return 0 299 fi 300 301 cur_bootpath=`eeprom bootpath | sed 's/bootpath=[ ]*//g' | sed 's/[ ]*$//'` 302 if [ "x$cur_bootpath" = "x" ]; then 303 gettext "failed to get bootpath by eeprom\n" 1>&2 304 return 1 305 fi 306 307 #only update bootpath for STMS path 308 echo $cur_bootpath|grep $CLIENT_TYPE_VHCI > /dev/null 2>&1 309 if [ $? -eq 1 ]; then 310 return 0 311 fi 312 313 new_bootpath=`$STMSBOOTUTIL -p /devices$cur_bootpath` 314 if [ $? -ne 0 ]; then 315 new_bootpath="" 316 return 1 317 fi 318} 319 320 321cmd=none 322 323# process options 324while getopts eduLl: c 325do 326 case $c in 327 e) setcmd enable;; 328 d) setcmd disable;; 329 u) setcmd update;; 330 L) setcmd listall;; 331 l) setcmd list 332 controller=$OPTARG;; 333 \?) echo "$USAGE" 1>&2 334 exit 2;; 335 esac 336done 337 338if [ "x$cmd" = xnone ]; then 339 echo "$USAGE" 1>&2 340 exit 2 341fi 342 343set `id` 344if [ "$1" != "uid=0(root)" ]; then 345 gettext "You must be super-user to run this script.\n" 1>&2 346 exit 1 347fi 348 349# just a sanity check 350if [ ! -f $STMSBOOTUTIL -o ! -f $STMSMETHODSCRIPT ]; then 351 fmt=`gettext "Can't find %s and/or %s"` 352 printf "$fmt\n" "$STMSBOOTUTIL" "$STMSMETHODSCRIPT" 1>&2 353 exit 1 354fi 355 356svcprop -q $STMSINSTANCE 357if [ $? -ne 0 ]; then 358 fmt=`gettext "Can't find %s service"` 359 printf "$fmt\n" "$STMSINSTANCE" 1>&2 360 exit 1 361fi 362 363if [ "x$cmd" = xenable -o "x$cmd" = xdisable -o "x$cmd" = xupdate ]; then 364 # 365 # The bootup script doesn't work on cache-only-clients as the script 366 # is executed before the plumbing for cachefs mounting of root is done. 367 # 368 if mount -v | egrep -s " on / type (nfs|cachefs) "; then 369 gettext "This command option is not supported on systems with nfs or cachefs mounted root filesystem.\n" 1>&2 370 exit 1 371 fi 372 373 if [ -d $SAVEDIR ]; then 374 # 375 # keep a copy of the last saved files, useful for manual 376 # recovery in case of a problem. 377 # 378 if [ "x$MACH" = "xsparc" ]; then 379 backup_lastsaved $FPCONF $VFSTAB 380 else 381 backup_lastsaved $FPCONF $VFSTAB $BOOTENV_FILE 382 fi 383 else 384 mkdir $SAVEDIR 385 fi 386 387fi 388 389if [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then 390 configure_mpxio $cmd 391elif [ "x$cmd" = xupdate ]; then 392 if [ "x$MACH" = "xi386" ]; then 393 # In this case we always change the bootpath to phci-based 394 # path first. bootpath will later be modified in mpxio-upgrade 395 # to the vhci-based path if mpxio is enabled on root. 396 get_newbootpath_for_stmsdev 397 if [ $? -ne 0 ]; then 398 gettext "failed to update bootpath.\n" 1>&2 399 return 1 400 fi 401 fi 402 update_sysfiles 403elif [ "x$cmd" = xlist ]; then 404 $STMSBOOTUTIL -l $controller 405else 406 $STMSBOOTUTIL -L 407fi 408 409exit $? 410