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