1*2150Sjeanm#!/bin/sh
2*2150Sjeanm#
3*2150Sjeanm# CDDL HEADER START
4*2150Sjeanm#
5*2150Sjeanm# The contents of this file are subject to the terms of the
6*2150Sjeanm# Common Development and Distribution License (the "License").
7*2150Sjeanm# You may not use this file except in compliance with the License.
8*2150Sjeanm#
9*2150Sjeanm# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*2150Sjeanm# or http://www.opensolaris.org/os/licensing.
11*2150Sjeanm# See the License for the specific language governing permissions
12*2150Sjeanm# and limitations under the License.
13*2150Sjeanm#
14*2150Sjeanm# When distributing Covered Code, include this CDDL HEADER in each
15*2150Sjeanm# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*2150Sjeanm# If applicable, add the following below this CDDL HEADER, with the
17*2150Sjeanm# fields enclosed by brackets "[]" replaced with your own identifying
18*2150Sjeanm# information: Portions Copyright [yyyy] [name of copyright owner]
19*2150Sjeanm#
20*2150Sjeanm# CDDL HEADER END
21*2150Sjeanm#
22*2150Sjeanm#
23*2150Sjeanm# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*2150Sjeanm# Use is subject to license terms.
25*2150Sjeanm#
26*2150Sjeanm# ident	"%Z%%M%	%I%	%E% SMI"
27*2150Sjeanm#
28*2150Sjeanm# Start mirror resync threads.
29*2150Sjeanm
30*2150SjeanmDEVFSADM=/usr/sbin/devfsadm
31*2150SjeanmMETADEVADM=/usr/sbin/metadevadm
32*2150SjeanmMETASYNC=/usr/sbin/metasync
33*2150SjeanmMETADEV=/dev/md/admin
34*2150SjeanmMETASET=/usr/sbin/metaset
35*2150SjeanmTMPFILE=/var/run/metaset.$$
36*2150Sjeanm
37*2150Sjeanm. /lib/svc/share/smf_include.sh
38*2150Sjeanm
39*2150Sjeanmprint_verbose()
40*2150Sjeanm{
41*2150Sjeanm	echo "Unable to resolve unnamed devices for volume management."
42*2150Sjeanm	echo "Please refer to the Solaris Volume Manager documentation,"
43*2150Sjeanm	echo "Troubleshooting section, at http://docs.sun.com or from"
44*2150Sjeanm	echo "your local copy."
45*2150Sjeanm}
46*2150Sjeanm
47*2150Sjeanmresolve_auto_take_sets()
48*2150Sjeanm{
49*2150Sjeanm	if [ -x $METASET ]; then
50*2150Sjeanm		# Fixing up of the ctd names for devices in auto take
51*2150Sjeanm		# sets relies heavily on the output of the metaset
52*2150Sjeanm		# command. Any change to the output of the metaset command
53*2150Sjeanm		# should modify this script as well in order ensure nothing
54*2150Sjeanm		# breaks
55*2150Sjeanm		#
56*2150Sjeanm		# The following command saves all of the auto-take set names
57*2150Sjeanm		# into the TMPFILE
58*2150Sjeanm		name_str=`gettext "Set name"`
59*2150Sjeanm		mn_str=`gettext "Multi-owner"`
60*2150Sjeanm		$METASET | /bin/nawk -F ' |\t|,' -v snm="$name_str" \
61*2150Sjeanm		    -v mstr="$mn_str" '$0 ~ snm { \
62*2150Sjeanm		    if (index($0, mstr) == 0) print $4 \
63*2150Sjeanm		}' > $TMPFILE 2>&1
64*2150Sjeanm
65*2150Sjeanm		if [ -s "$TMPFILE" ]; then
66*2150Sjeanm			localised_string=`gettext "Yes (auto)"`
67*2150Sjeanm			for i in `cat $TMPFILE`; do
68*2150Sjeanm				$METASET -s $i | grep "$localised_string" \
69*2150Sjeanm				    > /dev/null 2>&1
70*2150Sjeanm				if [ $? -eq 0 ]; then
71*2150Sjeanm					$METADEVADM -l -r -s $i
72*2150Sjeanm					error=$?
73*2150Sjeanm					case $error in
74*2150Sjeanm					0|2)	;;
75*2150Sjeanm					3) 	print_verbose
76*2150Sjeanm				    		;;
77*2150Sjeanm					*)	echo "$METADEVADM \
78*2150Sjeanm						-r failure $error."
79*2150Sjeanm						;;
80*2150Sjeanm					esac
81*2150Sjeanm				fi
82*2150Sjeanm			done
83*2150Sjeanm			/usr/bin/rm -f $TMPFILE
84*2150Sjeanm		fi
85*2150Sjeanm	fi
86*2150Sjeanm}
87*2150Sjeanm
88*2150Sjeanmif [ ! -s /kernel/drv/md.conf ]; then
89*2150Sjeanm	echo "/kernel/drv/md.conf is missing."
90*2150Sjeanm	exit 0
91*2150Sjeanmfi
92*2150Sjeanm
93*2150Sjeanmif grep '^mddb_bootlist' /kernel/drv/md.conf >/dev/null 2>&1; then :; else
94*2150Sjeanm	echo "No 'mddb_bootlist' entry in /kernel/drv/md.conf."
95*2150Sjeanm	exit 0
96*2150Sjeanmfi
97*2150Sjeanm
98*2150Sjeanmif [ ! -x $METADEVADM ]; then
99*2150Sjeanm	echo "$METADEVADM is missing or not executable."
100*2150Sjeanm	exit $SMF_EXIT_ERR_CONFIG
101*2150Sjeanmfi
102*2150Sjeanm
103*2150Sjeanmif [ ! -x $METASYNC ]; then
104*2150Sjeanm	echo "$METASYNC is missing or not executable."
105*2150Sjeanm	exit $SMF_EXIT_ERR_CONFIG
106*2150Sjeanmfi
107*2150Sjeanm
108*2150Sjeanmif [ ! -c $METADEV ]; then
109*2150Sjeanm	echo "$METADEV is missing or not a character device."
110*2150Sjeanm	exit 0
111*2150Sjeanmfi
112*2150Sjeanm
113*2150Sjeanm$METADEVADM -l -r
114*2150Sjeanmerror=$?
115*2150Sjeanmcase $error in
116*2150Sjeanm0|2)	;;
117*2150Sjeanm
118*2150Sjeanm3)	echo "Executing devfsadm"
119*2150Sjeanm	$DEVFSADM
120*2150Sjeanm	devfsadmerror=$?
121*2150Sjeanm	if [ $devfsadmerror = 0 ]; then
122*2150Sjeanm		echo "Executing metadevadm -r"
123*2150Sjeanm		$METADEVADM -l -r
124*2150Sjeanm		error=$?
125*2150Sjeanm	fi
126*2150Sjeanm	if [ $devfsadmerror != 0 -o $error = 3 ]; then
127*2150Sjeanm		print_verbose
128*2150Sjeanm	elif [ $error != 0 -a $error != 2 ]; then
129*2150Sjeanm		echo "$METADEVADM -r failure $error."
130*2150Sjeanm	fi
131*2150Sjeanm	;;
132*2150Sjeanm
133*2150Sjeanm*)	echo "$METADEVADM -r failure $error."
134*2150Sjeanm	exit 1
135*2150Sjeanm	;;
136*2150Sjeanmesac
137*2150Sjeanm
138*2150Sjeanmresolve_auto_take_sets
139*2150Sjeanm
140*2150Sjeanm$METASYNC -r
141*2150Sjeanmerror=$?
142*2150Sjeanmcase $error in
143*2150Sjeanm0)	;;
144*2150Sjeanm
145*2150Sjeanm*)	echo "Unknown $METASYNC -r failure $error."
146*2150Sjeanm	exit 1
147*2150Sjeanm	;;
148*2150Sjeanmesac
149*2150Sjeanm
150