xref: /titanic_41/usr/src/cmd/stmsboot/mpxio-upgrade (revision 22a914219d15da040a4bf15ae1df9941858a46aa)
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
28. /lib/svc/share/fs_include.sh
29. /lib/svc/share/net_include.sh
30
31# Make sure that the essential libraries can be found.
32LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
33STMSBOOTUTIL=/lib/mpxio/stmsboot_util
34FPCONF=/kernel/drv/fp.conf
35SAVEDIR=/etc/mpxio
36RECOVERFILE=$SAVEDIR/recover_instructions
37DEVFSADM=/usr/sbin/devfsadm
38METADEVADM=/usr/sbin/metadevadm
39usrmounted=0
40MACH=`/usr/bin/uname -p`
41EGREP=/usr/bin/egrep
42SED=/usr$SED
43
44# map $special and $fsckdev
45mpxio_mapdev()
46{
47	new_special=`$STMSBOOTUTIL -m $special`
48	if [ $? -eq 0 ]; then
49		special=$new_special
50	fi
51
52	new_fsckdev=`$STMSBOOTUTIL -m $fsckdev`
53	if [ $? -eq 0 ]; then
54		fsckdev=$new_fsckdev
55	fi
56}
57
58mpxio_error()
59{
60	cecho "\nERROR: stmsboot: $1"
61	#
62	# display recovery instructions - the first call logs to the service
63	# log and the second call displays on the console.
64	#
65	shcat $RECOVERFILE
66	shcat $RECOVERFILE >/dev/msglog 2>&1
67	cecho "These instructions were also logged to the file $RECOVERFILE\n"
68}
69
70#
71# root ("/") is already mounted read only by the kernel.
72# Remount the root read-write.
73#
74mpxio_mount_root()
75{
76	exec < $vfstab; readvfstab /
77	mpxio_mapdev
78
79	checkopt "llock" $mntopts
80	mntopts='remount'
81	[ -n "$otherops" ] && mntopts="${mntopts},${otherops}"
82	/sbin/mount -m -F $fstype -o $mntopts $special $mountp \
83>/dev/msglog 2>&1
84}
85
86#
87# mount /usr read only
88#
89mpxio_mount_usr()
90{
91	exec < $vfstab; readvfstab "/usr"
92	ret_val=0
93	if [ -n "$mountp" ]; then
94		mpxio_mapdev
95		if [ "$fstype" = cachefs ]; then
96			# Mount read-only without the cache.
97			case "$mntopts" in
98			*backfstype=nfs*)
99				cfsbacktype=nfs
100				;;
101			*backfstype=hsfs*)
102				cfsbacktype=hsfs
103				;;
104			*)
105				cecho 'stmsboot: invalid vfstab entry for /usr'
106				cfsbacktype=nfs
107				;;
108			esac
109			# see the comment below for /dev/null
110			/sbin/mount -m -F $cfsbacktype -o ro $special $mountp \
111>/dev/null 2>&1
112			ret_val=$?
113		else
114			#
115			# Must use -o largefiles here to ensure the read-only
116			# mount does not fail as a result of having a large
117			# file present on /usr.
118			#
119			if [ "x$mntopts" = x- ]; then
120				mntopts='ro,largefiles'
121			else
122				checkopt largefiles $mntopts
123				if [ "x$option" != xlargefiles ]; then
124					mntopts="largefiles,$mntopts"
125				fi
126
127				checkopt ro $mntopts
128				if [ "x$option" != xro ]; then
129					mntopts="ro,$mntopts"
130				fi
131
132				#
133				# Requesting logging on a read-only mount
134				# causes errors to be displayed, so remove
135				# "logging" from the list of options.
136				#
137
138				checkopt logging $mntopts
139				if [ "x$option" = xlogging ]; then
140					mntopts="$otherops"
141				fi
142			fi
143
144			#
145			# In case of a manual restart of the service, mount
146			# will emit messages if /usr is already mounted.
147			# So redirect the output to /dev/null.
148			#
149			/sbin/mount -m -F $fstype -o $mntopts $special /usr \
150>/dev/null 2>&1
151			ret_val=$?
152		fi
153		if [ $ret_val -eq 0 ]; then
154			usrmounted=1
155		fi
156	fi
157
158	return $ret_val
159}
160
161# update system dump configuration
162update_dumpconf()
163{
164	#
165	# Disable device-in-use checking (done in libdiskmgt).
166	# Without disabling this check, the configuration of dump device
167	# would fail as the device-in-use code incorrectly concludes that
168	# the device is in use and hence prevents configuration of the dump
169	# device.
170	#
171	NOINUSE_CHECK=1
172	export NOINUSE_CHECK
173
174	set -- `dumpadm -u 2>&1 | $EGREP 'cannot use /dev.* as dump device'`
175	if [ "x$4" != x ]; then
176		newname=`$STMSBOOTUTIL -M $4`
177		if [ $? -eq 0 ]; then
178			if /usr/sbin/dumpadm -d $newname > /dev/msglog 2> /dev/console; then
179				cecho "stmsboot: dump configuration has been \
180updated."
181			else
182				mpxio_error "failed to configure $newname as \
183the dump device.\nold dump device name: $4"
184				return 1
185			fi
186		fi
187	fi
188	return 0
189}
190
191# Update bootpath for x86 here when we are enabling mpxio on root
192update_bootpath()
193{
194	cur_bootpath=`/usr/sbin/eeprom bootpath | $SED 's/bootpath=[ 	]*//g' | $SED 's/[ 	].*//'`
195	# only take care of phci-based path here
196	PHCIOPT=`$STMSBOOTUTIL -D mpt -n`
197	echo $cur_bootpath | $EGREP -s "/fp@.*/disk|$PHCIOPT"
198
199	if [ $? -eq 0 ]; then
200		new_bootpath=`$STMSBOOTUTIL -m /devices$cur_bootpath`
201		if [ $? -eq 0 -a "x$new_bootpath" != "x" ]; then
202			# stmsboot_util -m phci-based path got mapped path back means
203			# mpxio is enabled on bootpath
204			new_bootpath=`echo $new_bootpath|$SED "s/.*\/devices//"`
205			/usr/sbin/eeprom bootpath=$new_bootpath
206			cecho "stmsboot: bootpath has been updated"
207
208			/sbin/bootadm update-archive
209		fi
210	fi
211}
212
213#
214# do the actual work
215#
216mpxio_main()
217{
218	#
219	# NOTE: If the first attempt to run the service has failed due to an
220	# expected error, users should be able to manually rerun the service.
221	#
222	# First mount /usr read only. This must be done to run
223	# utilities such as fsck and devfsadm.
224	# In the case of a manual rerun of the service, mounting of /usr here
225	# fails if /usr already happens to be mounted. It is better that we
226	# do not mount /usr if already mounted, but there seems to be no
227	# apparent way to check whether /usr is mounted or not as we mount
228	# /usr without making an entry into /etc/mnttab. So instead of
229	# explicitly checking for mount failures, we just do a sanity check
230	# by looking for some file (in this case devfsadm) in /usr.
231	#
232	mpxio_mount_usr
233	if [ ! -s $DEVFSADM ]; then
234		mpxio_error "failed to mount the /usr filesystem."
235		return
236	fi
237
238	if mpxio_mount_root; then
239		# create /dev links
240		cecho "stmsboot: configuring devices"
241		$DEVFSADM
242
243		# update /etc/vfstab to reflect device name changes
244		if $STMSBOOTUTIL -u >/dev/msglog 2>&1; then
245			if update_dumpconf; then
246				# update svm configuration to reflect new names
247				if [ -s /kernel/drv/md.conf ] && \
248				    [ -x $METADEVADM ]; then
249					$METADEVADM -r >/dev/msglog 2>&1
250				fi
251			fi
252			if [ "x$MACH" = "xi386" ]; then
253				# only update bootpath here for x86
254				update_bootpath
255			fi
256		else
257			mpxio_error "failed to update /etc/vfstab."
258		fi
259
260		/usr/sbin/svcadm disable system/device/mpxio-upgrade
261
262		/usr/sbin/reboot
263	else
264		mpxio_error "failed to mount the root filesystem."
265		if [ $usrmounted -eq 1 ]; then
266			/sbin/umount /usr
267		fi
268	fi
269}
270
271mpxio_main
272