xref: /titanic_41/usr/src/cmd/lvm/util/svc-metasync (revision 1402f64f9efa57c2c2cba776f3f45c67e6055deb)
1#!/bin/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# Start mirror resync threads.
29
30DEVFSADM=/usr/sbin/devfsadm
31METADEVADM=/usr/sbin/metadevadm
32METASYNC=/usr/sbin/metasync
33METADEV=/dev/md/admin
34METASET=/usr/sbin/metaset
35TMPFILE=/var/run/metaset.$$
36
37. /lib/svc/share/smf_include.sh
38
39print_verbose()
40{
41	echo "Unable to resolve unnamed devices for volume management."
42	echo "Please refer to the Solaris Volume Manager documentation,"
43	echo "Troubleshooting section, at http://docs.sun.com or from"
44	echo "your local copy."
45}
46
47resolve_auto_take_sets()
48{
49	if [ -x $METASET ]; then
50		# Fixing up of the ctd names for devices in auto take
51		# sets relies heavily on the output of the metaset
52		# command. Any change to the output of the metaset command
53		# should modify this script as well in order ensure nothing
54		# breaks
55		#
56		# The following command saves all of the auto-take set names
57		# into the TMPFILE
58		name_str=`gettext "Set name"`
59		mn_str=`gettext "Multi-owner"`
60		$METASET | /bin/nawk -F ' |\t|,' -v snm="$name_str" \
61		    -v mstr="$mn_str" '$0 ~ snm { \
62		    if (index($0, mstr) == 0) print $4 \
63		}' > $TMPFILE 2>&1
64
65		if [ -s "$TMPFILE" ]; then
66			localised_string=`gettext "Yes (auto)"`
67			for i in `cat $TMPFILE`; do
68				$METASET -s $i | grep "$localised_string" \
69				    > /dev/null 2>&1
70				if [ $? -eq 0 ]; then
71					$METADEVADM -l -r -s $i
72					error=$?
73					case $error in
74					0|2)	;;
75					3) 	print_verbose
76				    		;;
77					*)	echo "$METADEVADM \
78						-r failure $error."
79						;;
80					esac
81				fi
82			done
83		fi
84		if [ -f "$TMPFILE" ]; then
85			/usr/bin/rm -f $TMPFILE
86		fi
87	fi
88}
89
90if [ ! -s /kernel/drv/md.conf ]; then
91	echo "/kernel/drv/md.conf is missing."
92	exit 0
93fi
94
95if grep '^mddb_bootlist' /kernel/drv/md.conf >/dev/null 2>&1; then :; else
96	echo "No 'mddb_bootlist' entry in /kernel/drv/md.conf."
97	exit 0
98fi
99
100if [ ! -x $METADEVADM ]; then
101	echo "$METADEVADM is missing or not executable."
102	exit $SMF_EXIT_ERR_CONFIG
103fi
104
105if [ ! -x $METASYNC ]; then
106	echo "$METASYNC is missing or not executable."
107	exit $SMF_EXIT_ERR_CONFIG
108fi
109
110if [ ! -c $METADEV ]; then
111	echo "$METADEV is missing or not a character device."
112	exit 0
113fi
114
115$METADEVADM -l -r
116error=$?
117case $error in
1180|2)	;;
119
1203)	echo "Executing devfsadm"
121	$DEVFSADM
122	devfsadmerror=$?
123	if [ $devfsadmerror = 0 ]; then
124		echo "Executing metadevadm -r"
125		$METADEVADM -l -r
126		error=$?
127	fi
128	if [ $devfsadmerror != 0 -o $error = 3 ]; then
129		print_verbose
130	elif [ $error != 0 -a $error != 2 ]; then
131		echo "$METADEVADM -r failure $error."
132	fi
133	;;
134
135*)	echo "$METADEVADM -r failure $error."
136	exit 1
137	;;
138esac
139
140resolve_auto_take_sets
141
142$METASYNC -r
143error=$?
144case $error in
1450)	;;
146
147*)	echo "Unknown $METASYNC -r failure $error."
148	exit 1
149	;;
150esac
151
152