xref: /illumos-gate/usr/src/cmd/stmsboot/mpxio-upgrade (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28
29. /lib/svc/share/fs_include.sh
30. /lib/svc/share/net_include.sh
31
32# Make sure that the essential libraries can be found.
33LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
34STMSBOOTUTIL=/lib/mpxio/stmsboot_util
35FPCONF=/kernel/drv/fp.conf
36SAVEDIR=/etc/mpxio
37RECOVERFILE=$SAVEDIR/recover_instructions
38DEVFSADM=/usr/sbin/devfsadm
39METADEVADM=/usr/sbin/metadevadm
40usrmounted=0
41
42# map $special and $fsckdev
43mpxio_mapdev()
44{
45	new_special=`$STMSBOOTUTIL -m $special`
46	if [ $? -eq 0 ]; then
47		special=$new_special
48	fi
49
50	new_fsckdev=`$STMSBOOTUTIL -m $fsckdev`
51	if [ $? -eq 0 ]; then
52		fsckdev=$new_fsckdev
53	fi
54}
55
56mpxio_error()
57{
58	cecho "\nERROR: stmsboot: $1"
59	#
60	# display recovery instructions - the first call logs to the service
61	# log and the second call displays on the console.
62	#
63	shcat $RECOVERFILE
64	shcat $RECOVERFILE >/dev/msglog 2>&1
65	cecho "These instructions were also logged to the file $RECOVERFILE\n"
66}
67
68#
69# root ("/") is already mounted read only by the kernel.
70# Remount the root read-write.
71#
72mpxio_mount_root()
73{
74	exec < $vfstab; readvfstab /
75	mpxio_mapdev
76
77	checkopt "llock" $mntopts
78	mntopts='remount'
79	[ -n "$otherops" ] && mntopts="${mntopts},${otherops}"
80	/sbin/mount -m -F $fstype -o $mntopts $special $mountp \
81>/dev/msglog 2>&1
82}
83
84#
85# mount /usr read only
86#
87mpxio_mount_usr()
88{
89	exec < $vfstab; readvfstab "/usr"
90	ret_val=0
91	if [ -n "$mountp" ]; then
92		mpxio_mapdev
93		if [ "$fstype" = cachefs ]; then
94			# Mount read-only without the cache.
95			case "$mntopts" in
96			*backfstype=nfs*)
97				cfsbacktype=nfs
98				;;
99			*backfstype=hsfs*)
100				cfsbacktype=hsfs
101				;;
102			*)
103				cecho 'stmsboot: invalid vfstab entry for /usr'
104				cfsbacktype=nfs
105				;;
106			esac
107			# see the comment below for /dev/null
108			/sbin/mount -m -F $cfsbacktype -o ro $special $mountp \
109>/dev/null 2>&1
110			ret_val=$?
111		else
112			#
113			# Must use -o largefiles here to ensure the read-only
114			# mount does not fail as a result of having a large
115			# file present on /usr.
116			#
117			if [ "x$mntopts" = x- ]; then
118				mntopts='ro,largefiles'
119			else
120				checkopt largefiles $mntopts
121				if [ "x$option" != xlargefiles ]; then
122					mntopts="largefiles,$mntopts"
123				fi
124
125				checkopt ro $mntopts
126				if [ "x$option" != xro ]; then
127					mntopts="ro,$mntopts"
128				fi
129
130				#
131				# Requesting logging on a read-only mount
132				# causes errors to be displayed, so remove
133				# "logging" from the list of options.
134				#
135
136				checkopt logging $mntopts
137				if [ "x$option" = xlogging ]; then
138					mntopts="$otherops"
139				fi
140			fi
141
142			#
143			# In case of a manual restart of the service, mount
144			# will emit messages if /usr is already mounted.
145			# So redirect the output to /dev/null.
146			#
147			/sbin/mount -m -F $fstype -o $mntopts $special /usr \
148>/dev/null 2>&1
149			ret_val=$?
150		fi
151		if [ $ret_val -eq 0 ]; then
152			usrmounted=1
153		fi
154	fi
155
156	return $ret_val
157}
158
159# update system dump configuration
160update_dumpconf()
161{
162	set -- `dumpadm -u 2>&1 | egrep 'cannot use /dev.* as dump device'`
163	if [ "x$4" != x ]; then
164		newname=`$STMSBOOTUTIL -M $4`
165		if [ $? -eq 0 ]; then
166			if dumpadm -d $newname > /dev/null; then
167				cecho "stmsboot: dump configuration has been \
168updated."
169			else
170				mpxio_error "failed to configure $newname as \
171the dump device.\nold dump device name: $4"
172				return 1
173			fi
174		fi
175	fi
176	return 0
177}
178
179#
180# do the actual work
181#
182mpxio_main()
183{
184	#
185	# NOTE: If the first attempt to run the service has failed due to an
186	# expected error, users should be able to manually rerun the service.
187	#
188	# First mount /usr read only. This must be done to run
189	# utilities such as fsck and devfsadm.
190	# In the case of a manual rerun of the service, mounting of /usr here
191	# fails if /usr already happens to be mounted. It is better that we
192	# do not mount /usr if already mounted, but there seems to be no
193	# apparent way to check whether /usr is mounted or not as we mount
194	# /usr without making an entry into /etc/mnttab. So instead of
195	# explicitly checking for mount failures, we just do a sanity check
196	# by looking for some file (in this case devfsadm) in /usr.
197	#
198	mpxio_mount_usr
199	if [ ! -s $DEVFSADM ]; then
200		mpxio_error "failed to mount the /usr filesystem."
201		return
202	fi
203
204	if mpxio_mount_root; then
205		# create /dev links
206		cecho "stmsboot: configuring devices"
207		$DEVFSADM
208
209		# update /etc/vfstab to reflect device name changes
210		if $STMSBOOTUTIL -u >/dev/msglog 2>&1; then
211			if update_dumpconf; then
212				# update svm configuration to reflect new names
213				if [ -s /kernel/drv/md.conf ] && \
214				    [ -x $METADEVADM ]; then
215					$METADEVADM -r >/dev/msglog 2>&1
216				fi
217			fi
218		else
219			mpxio_error "failed to update /etc/vfstab."
220		fi
221
222		/usr/sbin/svcadm disable platform/sun4u/mpxio-upgrade
223
224		/usr/sbin/reboot
225	else
226		mpxio_error "failed to mount the root filesystem."
227		if [ $usrmounted -eq 1 ]; then
228			/sbin/umount /usr
229		fi
230	fi
231}
232
233mpxio_main
234