Print this page
6805730 some simple changes would make 'init 5' much faster
6809492 startd shouldn't let hung subprocesses impede shutdown
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/initpkg/umountall.sh
+++ new/usr/src/cmd/initpkg/umountall.sh
1 1 #!/sbin/sh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 #
23 -# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 +# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 25 #
26 26 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
27 27 # All Rights Reserved
28 28 #
29 29 #
30 30
31 31 usage () {
32 32 if [ -n "$1" ]; then
33 33 echo "umountall: $1" 1>&2
34 34 fi
35 35 echo "Usage:\n\tumountall [-k] [-s] [-F FSType] [-l|-r] [-Z] [-n]" 1>&2
36 36 echo "\tumountall [-k] [-s] [-h host] [-Z] [-n]" 1>&2
37 37 exit 2
38 38 }
39 39
40 40 MNTTAB=/etc/mnttab
41 41
42 42 # This script is installed as both /sbin/umountall (as used in some
43 43 # /sbin/rc? and /etc/init.d scripts) _and_ as /usr/sbin/umountall (typically
44 44 # PATHed from the command line). As such it should not depend on /usr
45 45 # being mounted (if /usr is a separate filesystem).
46 46 #
47 47 # /sbin/sh Bourne shell builtins we use:
48 48 # echo
49 49 # exit
50 50 # getopts
51 51 # test, [ ]
52 52 # exec
53 53 # read
54 54 #
55 55 # /sbin commands we use:
56 56 # /sbin/uname
57 57 # /sbin/umount
58 58 #
59 59 # The following /usr based commands may be used by this script (depending on
60 60 # command line options). We will set our PATH to find them, but where they
61 61 # are not present (eg, if /usr is not mounted) we will catch references to
62 62 # them via shell functions conditionally defined after option processing
63 63 # (don't use any of these commands before then).
64 64 #
65 65 # Command Command line option and use
66 66 # /usr/bin/sleep -k, to sleep after an fuser -c -k on the mountpoint
67 67 # /usr/sbin/fuser -k, to kill processes keeping a mount point busy
68 68 #
69 69 # In addition, we use /usr/bin/tail if it is available; if not we use
70 70 # slower shell constructs to reverse a file.
71 71
72 72 PATH=/sbin:/usr/sbin:/usr/bin
73 73
74 74 DEFERRED_ACTIVATION_PATCH_FLAG="/var/run/.patch_loopback_mode"
75 75 SVC_STARTD="/lib/svc/bin/svc.startd"
76 76
77 77 # Clear these in case they were already set in our inherited environment.
78 78 FSType=
79 79 FFLAG=
80 80 HOST=
81 81 HFLAG=
82 82 RFLAG=
83 83 LFLAG=
84 84 SFLAG=
85 85 KFLAG=
86 86 ZFLAG=
87 87 NFLAG=
88 88 LOCALNAME=
89 89 UMOUNTFLAG=
90 90
91 91
92 92 while getopts ?rslkF:h:Zn c
93 93 do
94 94 case $c in
95 95 r) RFLAG="r";;
96 96 l) LFLAG="l";;
97 97 s) SFLAG="s";;
98 98 k) KFLAG="k";;
99 99 h) if [ -n "$HFLAG" ]; then
100 100 usage "more than one host specified"
101 101 fi
102 102 HOST=$OPTARG
103 103 HFLAG="h"
104 104 LOCALNAME=`uname -n`
105 105 ;;
106 106 F) if [ -n "$FFLAG" ]; then
107 107 usage "more than one FStype specified"
108 108 fi
109 109 FSType=$OPTARG
110 110 FFLAG="f"
111 111 case $FSType in
112 112 ?????????*)
113 113 usage "FSType ${FSType} exceeds 8 characters"
114 114 esac;
115 115 ;;
116 116 Z) ZFLAG="z";;
117 117 n) NFLAG="n"
118 118 # Alias any commands that would perform real actions to
119 119 # something that tells what action would have been performed
120 120 UMOUNTFLAG="-V"
121 121 fuser () {
122 122 echo "fuser $*" 1>&2
123 123 }
124 124 sleep () {
125 125 : # No need to show where we'd sleep
126 126 }
127 127 ;;
128 128 \?) usage ""
129 129 ;;
130 130 esac
131 131 done
132 132
133 133 # Sanity checking:
134 134 # 1) arguments beyond those supported
135 135 # 2) can't specify both remote and local
136 136 # 3) can't specify a host with -r or -l
137 137 # 4) can't specify a fstype with -h
138 138 # 5) can't specify this host with -h (checks only uname -n)
139 139 # 6) can't be fstype nfs and local
140 140 # 7) only fstype nfs is remote
141 141
142 142 if [ $# -ge $OPTIND ]; then # 1
143 143 usage "additional arguments not supported"
144 144 fi
145 145
146 146 if [ -n "$RFLAG" -a -n "$LFLAG" ]; then # 2
147 147 usage "options -r and -l are incompatible"
148 148 fi
149 149
150 150 if [ \( -n "$RFLAG" -o -n "$LFLAG" \) -a "$HFLAG" = "h" ]; then # 3
151 151 usage "option -${RFLAG}${LFLAG} incompatible with -h option"
152 152 fi
153 153
154 154 if [ -n "$FFLAG" -a "$HFLAG" = "h" ]; then # 4
155 155 usage "Specifying FStype incompatible with -h option"
156 156 fi
157 157
158 158 if [ -n "$HFLAG" -a "$HOST" = "$LOCALNAME" ]; then # 5
159 159 usage "Specifying local host illegal for -h option"
160 160 fi
161 161
|
↓ open down ↓ |
128 lines elided |
↑ open up ↑ |
162 162 if [ "$FSType" = "nfs" -a "$LFLAG" = "l" ]; then # 6
163 163 usage "option -l and FSType nfs are incompatible"
164 164 fi
165 165
166 166 if [ -n "$FFLAG" -a "$FSType" != "nfs" -a -n "$RFLAG" ]; then # 7
167 167 usage "option -r and FSType ${FSType} are incompatible"
168 168 fi
169 169
170 170 ZONENAME=`zonename`
171 171
172 -# Check and if needed sync the boot archive before unmounting everything.
173 172 #
174 -if [ -z "${RFLAG}${NFLAG}${HFLAG}${FSType}" -a "$ZONENAME" = "global" \
175 - -a -x /sbin/bootadm ] ; then
176 - /sbin/bootadm -a update_all
177 -fi
178 -
179 -
180 -#
181 173 # If we are in deferred activation patching, and the caller is
182 174 # svc.startd, then exit without unmounting any of the remaining
183 175 # file systems since the call path is from shutdown. Note that
184 176 # by the time we get here, smf stop methods for nfs, cachefs
185 177 # etc, will have run.
186 178 #
187 179 if [ -f $DEFERRED_ACTIVATION_PATCH_FLAG ] ; then
188 180 ppid=`ps -o ppid= -p $$` # parent of umountall will be sh
189 181 # from system()
190 182
191 183 ppid=`ps -o ppid= -p $ppid` # parent of sh will be svc.startd
192 184 COMM=`ps -o comm= -p $ppid`
193 185 if [ "$COMM" = "$SVC_STARTD" ] ; then
194 186 exit
195 187 fi
196 188 fi
197 189
198 190 #
199 191 # Take advantage of parallel unmounting at this point if we have no
200 192 # criteria to match and we are in the global zone
201 193 #
202 194 if [ -z "${SFLAG}${LFLAG}${RFLAG}${HFLAG}${KFLAG}${FFLAG}${ZFLAG}" -a \
203 195 "$ZONENAME" = "global" ]; then
204 196 umount -a ${UMOUNTFLAG}
205 197 exit # with return code of the umount -a
206 198 fi
207 199
208 200 #
209 201 # Catch uses of /usr commands when /usr is not mounted
210 202 if [ -n "$KFLAG" -a -z "$NFLAG" ]; then
211 203 if [ ! -x /usr/sbin/fuser ]; then
212 204 fuser () {
213 205 echo "umountall: fuser -k skipped (no /usr)" 1>&2
214 206 # continue - not fatal
215 207 }
216 208 sleep () {
217 209 : # no point in sleeping if fuser is doing nothing
218 210 }
219 211 else
220 212 if [ ! -x /usr/bin/sleep ]; then
221 213 sleep () {
222 214 echo "umountall: sleep after fuser -k skipped (no /usr)" 1>&2
223 215 # continue - not fatal
224 216 }
225 217 fi
226 218 fi
227 219 fi
228 220
229 221 #
230 222 # Shell function to avoid using /usr/bin/cut. Given a dev from a
231 223 # fstype=nfs line in mnttab (eg, "host:/export) extract the host
232 224 # component.
233 225 print_host () {
234 226 OIFS=$IFS
235 227 IFS=":"
236 228 set -- $*
237 229 echo $1
238 230 IFS=$OIFS
239 231 }
240 232
241 233 #
242 234 # doumounts echos its return code to stdout, so commands used within
243 235 # this function should take care to produce no other output to stdout.
244 236 doumounts () {
245 237 (
246 238 rc=0
247 239 fslist=""
248 240 nfslist=""
249 241 while read dev mountp fstype mode dummy
250 242 do
251 243 case "${mountp}" in
252 244 / | \
253 245 /dev | \
254 246 /dev/fd | \
255 247 /devices | \
256 248 /etc/mnttab | \
257 249 /etc/svc/volatile | \
258 250 /lib | \
259 251 /proc | \
260 252 /sbin | \
261 253 /system/contract | \
262 254 /system/object | \
263 255 /tmp | \
264 256 /usr | \
265 257 /var | \
266 258 /var/adm | \
267 259 /var/run | \
268 260 '' )
269 261 #
270 262 # file systems possibly mounted in the kernel or
271 263 # in the methods of some of the file system
272 264 # services
273 265 #
274 266 continue
275 267 ;;
276 268 * )
277 269 if [ -n "$HFLAG" ]; then
278 270 if [ "$fstype" = "nfs" ]; then
279 271 thishost=`print_host $dev`
280 272 if [ "$HOST" != "$thishost" ]; then
281 273 continue
282 274 fi
283 275 else
284 276 continue
285 277 fi
286 278 fi
287 279 if [ -n "$FFLAG" -a "$FSType" != "$fstype" ]; then
288 280 continue
289 281 fi
290 282 if [ -n "$LFLAG" -a "$fstype" = "nfs" ]; then
291 283 nfslist="$nfslist $mountp"
292 284 continue
293 285 fi
294 286 #
295 287 # This will filter out autofs mounts with nfs file
296 288 # system mounted on the top of it.
297 289 #
298 290 # WARNING: use of any syscall on a NFS file system has
299 291 # the danger to go over-the-wire and could cause nfs
300 292 # clients to hang on shutdown, if the nfs server is
301 293 # down beforehand.
302 294 # For the reason described above, a simple test like
303 295 # "df -F nfs $mountp" can't be used to filter out
304 296 # nfs-over-autofs mounts. We loop over a list instead:
305 297 #
306 298 if [ -n "$LFLAG" -a -n "$nfslist" -a "$fstype" = "autofs" ]
307 299 then
308 300 for m in $nfslist; do
309 301 if [ "$mountp" = "$m" ]; then
310 302 # Resume the outer while loop
311 303 continue 2
312 304 fi
313 305 done
314 306 fi
315 307 if [ -n "$RFLAG" -a "$fstype" != "nfs" ]; then
316 308 continue
317 309 fi
318 310 if [ "$ZONENAME" != "global" ]; then
319 311 for option in `echo $mode | tr , '\012'`; do
320 312 #
321 313 # should not see any zone options
322 314 # but our own
323 315 #
324 316 if [ "$option" = "zone=$ZONENAME" ]; then
325 317 break
326 318 fi
327 319 done
328 320 if [ "$option" != "zone=$ZONENAME" ]; then
329 321 continue
330 322 fi
331 323 # we are called from the global zone
332 324 else
333 325 for option in `echo $mode | tr , '\012'`; do
334 326 case "$option" in
335 327 zone=*)
336 328 option="zone="
337 329 break
338 330 ;;
339 331 esac
340 332 done
341 333 # skip mounts from non-global zones if ZFLAG is not set
342 334 if [ "$option" = "zone=" -a -z "$ZFLAG" ]; then
343 335 continue
344 336 fi
345 337 # skip mounts from the global zone if ZFLAG is set
346 338 if [ "$option" != "zone=" -a -n "$ZFLAG" ]; then
347 339 continue
348 340 fi
349 341 fi
350 342 if [ -n "${KFLAG}" ]; then
351 343 fuser -c -k $mountp 1>&2
352 344 sleep 2
353 345 fi
354 346 if [ -n "$SFLAG" ]; then
355 347 umount ${UMOUNTFLAG} ${mountp} 1>&2
356 348 trc=$?
357 349 if [ $trc -ne 0 ]; then
358 350 rc=$trc
359 351 fi
360 352 else
361 353 # We want to umount in parallel
362 354 fslist="$fslist $mountp"
363 355 fi
364 356 esac
365 357 done
366 358
367 359 if [ -n "$fslist" ]; then
368 360 umount -a ${UMOUNTFLAG} $fslist 1>&2
369 361 trc=$?
370 362 if [ $trc -ne 0 ]; then
371 363 rc=$trc
372 364 fi
373 365 fi
374 366
375 367 echo $rc
376 368 )
377 369 }
378 370
379 371 #
380 372 # /etc/mnttab has the most recent mounts last. Reverse it so that we
381 373 # may umount in opposite order to the original mounts.
382 374 #
383 375
384 376 if [ ! -x /usr/bin/tail ]; then
385 377 exec < $MNTTAB
386 378 REVERSED=
387 379 while read line; do
388 380 if [ -n "$REVERSED" ]; then
389 381 REVERSED="$line\n$REVERSED"
390 382 else
391 383 REVERSED="$line"
392 384 fi
393 385 done
394 386
395 387 error=`echo $REVERSED | doumounts`
396 388 else
397 389 error=`tail -r $MNTTAB | doumounts`
398 390 fi
399 391
400 392 exit $error
|
↓ open down ↓ |
210 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX