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