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 6*6deb031bSsjelinek# Common Development and Distribution License (the "License"). 7*6deb031bSsjelinek# 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# 23*6deb031bSsjelinek# Copyright 2006 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" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gatePATH=/usr/bin:/usr/sbin:$PATH; export PATH 297c478bd9Sstevel@tonic-gateSTMSBOOTUTIL=/lib/mpxio/stmsboot_util 307c478bd9Sstevel@tonic-gateSTMSMETHODSCRIPT=/lib/svc/method/mpxio-upgrade 317c478bd9Sstevel@tonic-gateSTMSINSTANCE=platform/sun4u/mpxio-upgrade:default 327c478bd9Sstevel@tonic-gateFPCONF=/kernel/drv/fp.conf 337c478bd9Sstevel@tonic-gateTMPFPCONF=/var/run/tmp.fp.conf.$$ 347c478bd9Sstevel@tonic-gateVFSTAB=/etc/vfstab 357c478bd9Sstevel@tonic-gateSAVEDIR=/etc/mpxio 367c478bd9Sstevel@tonic-gateRECOVERFILE=$SAVEDIR/recover_instructions 377c478bd9Sstevel@tonic-gateSVCCFG_RECOVERY=$SAVEDIR/svccfg_recover 387c478bd9Sstevel@tonic-gateUSAGE=`gettext "Usage: stmsboot -e | -d | -u | -L | -l controller_number"` 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate# 417c478bd9Sstevel@tonic-gate# Copy all entries (including comments) from source driver.conf to destination 427c478bd9Sstevel@tonic-gate# driver.conf except those entries which contain mpxio-disable property. 437c478bd9Sstevel@tonic-gate# Take into consideration entries that spawn more than one line. 447c478bd9Sstevel@tonic-gate# 457c478bd9Sstevel@tonic-gate# $1 source driver.conf file 467c478bd9Sstevel@tonic-gate# $2 destination driver.conf file 477c478bd9Sstevel@tonic-gate# 487c478bd9Sstevel@tonic-gate# Returns 0 on success, non zero on failure. 497c478bd9Sstevel@tonic-gate# 507c478bd9Sstevel@tonic-gatedelete_mpxio_disable_entries() 517c478bd9Sstevel@tonic-gate{ 527c478bd9Sstevel@tonic-gate sed ' 537c478bd9Sstevel@tonic-gate /^[ ]*#/{ p 547c478bd9Sstevel@tonic-gate d 557c478bd9Sstevel@tonic-gate } 567c478bd9Sstevel@tonic-gate s/[ ]*$// 577c478bd9Sstevel@tonic-gate /^$/{ p 587c478bd9Sstevel@tonic-gate d 597c478bd9Sstevel@tonic-gate } 607c478bd9Sstevel@tonic-gate /mpxio-disable[ ]*=.*;$/d 617c478bd9Sstevel@tonic-gate /;$/{ p 627c478bd9Sstevel@tonic-gate d 637c478bd9Sstevel@tonic-gate } 647c478bd9Sstevel@tonic-gate :rdnext 657c478bd9Sstevel@tonic-gate N 667c478bd9Sstevel@tonic-gate s/[ ]*$// 677c478bd9Sstevel@tonic-gate /[^;]$/b rdnext 687c478bd9Sstevel@tonic-gate /mpxio-disable[ ]*=/d' $1 > $2 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate return $? 717c478bd9Sstevel@tonic-gate} 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate# 747c478bd9Sstevel@tonic-gate# backup the last saved copy of the specified files. 757c478bd9Sstevel@tonic-gate# $* files to backup 767c478bd9Sstevel@tonic-gate# 777c478bd9Sstevel@tonic-gatebackup_lastsaved() 787c478bd9Sstevel@tonic-gate{ 797c478bd9Sstevel@tonic-gate for file in $* 807c478bd9Sstevel@tonic-gate do 817c478bd9Sstevel@tonic-gate file=`basename $file` 827c478bd9Sstevel@tonic-gate if [ -f $SAVEDIR/$file ]; then 837c478bd9Sstevel@tonic-gate mv $SAVEDIR/$file $SAVEDIR/${file}.old 847c478bd9Sstevel@tonic-gate fi 857c478bd9Sstevel@tonic-gate done 867c478bd9Sstevel@tonic-gate} 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate# 897c478bd9Sstevel@tonic-gate# build recover instructions 907c478bd9Sstevel@tonic-gate# 917c478bd9Sstevel@tonic-gate# $1 1 to include boot script in the instructions 927c478bd9Sstevel@tonic-gate# 0 otherwise 937c478bd9Sstevel@tonic-gate# 947c478bd9Sstevel@tonic-gatebuild_recover() 957c478bd9Sstevel@tonic-gate{ 967c478bd9Sstevel@tonic-gate gettext "Instructions to recover your previous STMS configuration (if in case the system does not boot):\n\n" > $RECOVERFILE 977c478bd9Sstevel@tonic-gate echo "\tboot net \c" >> $RECOVERFILE 987c478bd9Sstevel@tonic-gate gettext "(or from a cd/dvd/another disk)\n" >> $RECOVERFILE 997c478bd9Sstevel@tonic-gate echo "\tfsck <your-root-device>" >> $RECOVERFILE 1007c478bd9Sstevel@tonic-gate echo "\tmount <your-root-device> /mnt" >> $RECOVERFILE 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate if [ "x$cmd" = xupdate ]; then 1037c478bd9Sstevel@tonic-gate gettext "\tUndo the modifications you made to STMS configuration.\n\tFor example undo any changes you made to " >> $RECOVERFILE 1047c478bd9Sstevel@tonic-gate echo "/mnt$FPCONF." >> $RECOVERFILE 1057c478bd9Sstevel@tonic-gate else 1067c478bd9Sstevel@tonic-gate echo "\tcp /mnt${SAVEDIR}/fp.conf /mnt$FPCONF" >> $RECOVERFILE 1077c478bd9Sstevel@tonic-gate fi 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate if [ $1 -eq 1 ]; then 1107c478bd9Sstevel@tonic-gate echo "\tcp /mnt${SAVEDIR}/vfstab /mnt$VFSTAB" >> $RECOVERFILE 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate echo "repository /mnt/etc/svc/repository.db" > $SVCCFG_RECOVERY 1137c478bd9Sstevel@tonic-gate echo "select $STMSINSTANCE" >> $SVCCFG_RECOVERY 1147c478bd9Sstevel@tonic-gate echo "setprop general/enabled=false" >> $SVCCFG_RECOVERY 1157c478bd9Sstevel@tonic-gate echo "exit" >> $SVCCFG_RECOVERY 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate echo "\t/usr/sbin/svccfg -f /mnt$SVCCFG_RECOVERY" >> $RECOVERFILE 1187c478bd9Sstevel@tonic-gate fi 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate rootdisk=`mount | grep "/ on " | cut -f 3 -d " "` 1217c478bd9Sstevel@tonic-gate echo "\tumount /mnt\n\treboot\n\n${rootdisk} \c" >> $RECOVERFILE 1227c478bd9Sstevel@tonic-gate gettext "was your root device,\nbut it could be named differently after you boot net.\n" >> $RECOVERFILE 1237c478bd9Sstevel@tonic-gate} 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate# 1267c478bd9Sstevel@tonic-gate# Arrange for /etc/vfstab and dump configuration to be updated 1277c478bd9Sstevel@tonic-gate# during the next reboot. If the cmd is "enable" or "disable", copy 1287c478bd9Sstevel@tonic-gate# $TMPFPCONF to $FPCONF. 1297c478bd9Sstevel@tonic-gate# 1307c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure. 1317c478bd9Sstevel@tonic-gate# 1327c478bd9Sstevel@tonic-gateupdate_sysfiles() 1337c478bd9Sstevel@tonic-gate{ 1347c478bd9Sstevel@tonic-gate gettext "WARNING: This operation will require a reboot.\nDo you want to continue ? [y/n] (default: y) " 1357c478bd9Sstevel@tonic-gate read response 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate if [ "x$response" != x -a "x$response" != xy -a \ 1387c478bd9Sstevel@tonic-gate "x$response" != xY ]; then 1397c478bd9Sstevel@tonic-gate rm -f $TMPFPCONF 1407c478bd9Sstevel@tonic-gate return 0 1417c478bd9Sstevel@tonic-gate fi 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate need_bootscript=1 1447c478bd9Sstevel@tonic-gate if [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then 1457c478bd9Sstevel@tonic-gate cp $FPCONF $SAVEDIR 1467c478bd9Sstevel@tonic-gate cp $TMPFPCONF $FPCONF 1477c478bd9Sstevel@tonic-gate rm -f $TMPFPCONF 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate # 1507c478bd9Sstevel@tonic-gate # there is no need to update the system files in the following 1517c478bd9Sstevel@tonic-gate # cases: 1527c478bd9Sstevel@tonic-gate # - we are enabling mpxio and the system has no configured 1537c478bd9Sstevel@tonic-gate # disks accessible by phci paths. 1547c478bd9Sstevel@tonic-gate # - we are disabling mpxio and the system has no configured 1557c478bd9Sstevel@tonic-gate # disks accessible by vhci paths. 1567c478bd9Sstevel@tonic-gate # 1577c478bd9Sstevel@tonic-gate if [ "x$cmd" = xenable ]; then 1587c478bd9Sstevel@tonic-gate ls -l /dev/dsk/*s2 2> /dev/null | \ 1597c478bd9Sstevel@tonic-gate egrep -s "/fp@.*/ssd@.*" 1607c478bd9Sstevel@tonic-gate else 1617c478bd9Sstevel@tonic-gate ls -l /dev/dsk/*s2 2> /dev/null | \ 1627c478bd9Sstevel@tonic-gate egrep -s "/scsi_vhci.*/ssd@.*" 1637c478bd9Sstevel@tonic-gate fi 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate if [ $? -ne 0 ]; then 1667c478bd9Sstevel@tonic-gate need_bootscript=0 1677c478bd9Sstevel@tonic-gate fi 1687c478bd9Sstevel@tonic-gate fi 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate if [ $need_bootscript -eq 1 ]; then 1717c478bd9Sstevel@tonic-gate # 1727c478bd9Sstevel@tonic-gate # Enable the mpxio-upgrade service, but don't run it now. 1737c478bd9Sstevel@tonic-gate # The service will run during the next reboot and will do 1747c478bd9Sstevel@tonic-gate # the actual job of modifying the system files. 1757c478bd9Sstevel@tonic-gate # 1767c478bd9Sstevel@tonic-gate svcadm disable -t $STMSINSTANCE 1777c478bd9Sstevel@tonic-gate svccfg -f - << EOF 1787c478bd9Sstevel@tonic-gateselect $STMSINSTANCE 1797c478bd9Sstevel@tonic-gatesetprop general/enabled = true 1807c478bd9Sstevel@tonic-gateEOF 1817c478bd9Sstevel@tonic-gate fi 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate build_recover $need_bootscript 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate gettext "The changes will come into effect after rebooting the system.\nReboot the system now ? [y/n] (default: y) " 1867c478bd9Sstevel@tonic-gate read response 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate if [ "x$response" = x -o "x$response" = xy -o \ 1897c478bd9Sstevel@tonic-gate "x$response" = xY ]; then 1907c478bd9Sstevel@tonic-gate reboot 1917c478bd9Sstevel@tonic-gate fi 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate return 0 1947c478bd9Sstevel@tonic-gate} 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate# 1977c478bd9Sstevel@tonic-gate# Enable or disable mpxio as specified by the cmd. 1987c478bd9Sstevel@tonic-gate# Returns 0 on success, 1 on failure. 1997c478bd9Sstevel@tonic-gate# 2007c478bd9Sstevel@tonic-gateconfigure_mpxio() 2017c478bd9Sstevel@tonic-gate{ 2027c478bd9Sstevel@tonic-gate if [ "x$cmd" = xenable ]; then 2037c478bd9Sstevel@tonic-gate propval=no 2047c478bd9Sstevel@tonic-gate msg=`gettext "STMS already enabled."` 2057c478bd9Sstevel@tonic-gate else 2067c478bd9Sstevel@tonic-gate propval=yes 2077c478bd9Sstevel@tonic-gate msg=`gettext "STMS already disabled."` 2087c478bd9Sstevel@tonic-gate fi 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate if delete_mpxio_disable_entries $FPCONF $TMPFPCONF; then 2117c478bd9Sstevel@tonic-gate echo "mpxio-disable=\"${propval}\";" >> $TMPFPCONF 2127c478bd9Sstevel@tonic-gate if diff -b $FPCONF $TMPFPCONF > /dev/null; then 2137c478bd9Sstevel@tonic-gate rm -f $TMPFPCONF 2147c478bd9Sstevel@tonic-gate echo "$msg" 2157c478bd9Sstevel@tonic-gate return 0 2167c478bd9Sstevel@tonic-gate fi 2177c478bd9Sstevel@tonic-gate update_sysfiles 2187c478bd9Sstevel@tonic-gate return $? 2197c478bd9Sstevel@tonic-gate else 2207c478bd9Sstevel@tonic-gate rm -f $TMPFPCONF 2217c478bd9Sstevel@tonic-gate gettext "failed to update " 1>&2 2227c478bd9Sstevel@tonic-gate echo "$FPCONF." 1>&2 2237c478bd9Sstevel@tonic-gate gettext "No changes were made to your STMS configuration.\n" 1>&2 2247c478bd9Sstevel@tonic-gate return 1 2257c478bd9Sstevel@tonic-gate fi 2267c478bd9Sstevel@tonic-gate} 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gatesetcmd() 2297c478bd9Sstevel@tonic-gate{ 2307c478bd9Sstevel@tonic-gate if [ "x$cmd" = xnone ]; then 2317c478bd9Sstevel@tonic-gate cmd=$1 2327c478bd9Sstevel@tonic-gate else 2337c478bd9Sstevel@tonic-gate echo "$USAGE" 1>&2 2347c478bd9Sstevel@tonic-gate exit 2 2357c478bd9Sstevel@tonic-gate fi 2367c478bd9Sstevel@tonic-gate} 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gatecmd=none 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate# process options 2417c478bd9Sstevel@tonic-gatewhile getopts eduLl: c 2427c478bd9Sstevel@tonic-gatedo 2437c478bd9Sstevel@tonic-gate case $c in 2447c478bd9Sstevel@tonic-gate e) setcmd enable;; 2457c478bd9Sstevel@tonic-gate d) setcmd disable;; 2467c478bd9Sstevel@tonic-gate u) setcmd update;; 2477c478bd9Sstevel@tonic-gate L) setcmd listall;; 2487c478bd9Sstevel@tonic-gate l) setcmd list 2497c478bd9Sstevel@tonic-gate controller=$OPTARG;; 2507c478bd9Sstevel@tonic-gate \?) echo "$USAGE" 1>&2 2517c478bd9Sstevel@tonic-gate exit 2;; 2527c478bd9Sstevel@tonic-gate esac 2537c478bd9Sstevel@tonic-gatedone 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gateif [ "x$cmd" = xnone ]; then 2567c478bd9Sstevel@tonic-gate echo "$USAGE" 1>&2 2577c478bd9Sstevel@tonic-gate exit 2 2587c478bd9Sstevel@tonic-gatefi 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gateset `id` 2617c478bd9Sstevel@tonic-gateif [ "$1" != "uid=0(root)" ]; then 2627c478bd9Sstevel@tonic-gate gettext "You must be super-user to run this script.\n" 1>&2 2637c478bd9Sstevel@tonic-gate exit 1 2647c478bd9Sstevel@tonic-gatefi 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate# just a sanity check 2677c478bd9Sstevel@tonic-gateif [ ! -f $STMSBOOTUTIL -o ! -f $STMSMETHODSCRIPT ]; then 2687c478bd9Sstevel@tonic-gate fmt=`gettext "Can't find %s and/or %s"` 2697c478bd9Sstevel@tonic-gate printf "$fmt\n" "$STMSBOOTUTIL" "$STMSMETHODSCRIPT" 1>&2 2707c478bd9Sstevel@tonic-gate exit 1 2717c478bd9Sstevel@tonic-gatefi 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gatesvcprop -q $STMSINSTANCE 2747c478bd9Sstevel@tonic-gateif [ $? -ne 0 ]; then 2757c478bd9Sstevel@tonic-gate fmt=`gettext "Can't find %s service"` 2767c478bd9Sstevel@tonic-gate printf "$fmt\n" "$STMSINSTANCE" 1>&2 2777c478bd9Sstevel@tonic-gate exit 1 2787c478bd9Sstevel@tonic-gatefi 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable -o "x$cmd" = xupdate ]; then 2817c478bd9Sstevel@tonic-gate # 2827c478bd9Sstevel@tonic-gate # The bootup script doesn't work on cache-only-clients as the script 283*6deb031bSsjelinek # is executed before the plumbing for cachefs mounting of root is done. 2847c478bd9Sstevel@tonic-gate # 2857c478bd9Sstevel@tonic-gate if mount -v | egrep -s " on / type (nfs|cachefs) "; then 2867c478bd9Sstevel@tonic-gate gettext "This command option is not supported on systems with nfs or cachefs mounted root filesystem.\n" 1>&2 2877c478bd9Sstevel@tonic-gate exit 1 2887c478bd9Sstevel@tonic-gate fi 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate if [ -d $SAVEDIR ]; then 2917c478bd9Sstevel@tonic-gate # 2927c478bd9Sstevel@tonic-gate # keep a copy of the last saved files, useful for manual 2937c478bd9Sstevel@tonic-gate # recovery in case of a problem. 2947c478bd9Sstevel@tonic-gate # 2957c478bd9Sstevel@tonic-gate backup_lastsaved $FPCONF $VFSTAB 2967c478bd9Sstevel@tonic-gate else 2977c478bd9Sstevel@tonic-gate mkdir $SAVEDIR 2987c478bd9Sstevel@tonic-gate fi 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gatefi 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gateif [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then 3037c478bd9Sstevel@tonic-gate configure_mpxio $cmd 3047c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xupdate ]; then 3057c478bd9Sstevel@tonic-gate update_sysfiles 3067c478bd9Sstevel@tonic-gateelif [ "x$cmd" = xlist ]; then 3077c478bd9Sstevel@tonic-gate $STMSBOOTUTIL -l $controller 3087c478bd9Sstevel@tonic-gateelse 3097c478bd9Sstevel@tonic-gate $STMSBOOTUTIL -L 3107c478bd9Sstevel@tonic-gatefi 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gateexit $? 313