xref: /titanic_41/usr/src/cmd/lvm/util/svc-metasync (revision a1e4d62bc1ea0bd683c63f185da43cda7aec8f20)
12fb876aeSjeanm#!/bin/sh
22fb876aeSjeanm#
32fb876aeSjeanm# CDDL HEADER START
42fb876aeSjeanm#
52fb876aeSjeanm# The contents of this file are subject to the terms of the
62fb876aeSjeanm# Common Development and Distribution License (the "License").
72fb876aeSjeanm# You may not use this file except in compliance with the License.
82fb876aeSjeanm#
92fb876aeSjeanm# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
102fb876aeSjeanm# or http://www.opensolaris.org/os/licensing.
112fb876aeSjeanm# See the License for the specific language governing permissions
122fb876aeSjeanm# and limitations under the License.
132fb876aeSjeanm#
142fb876aeSjeanm# When distributing Covered Code, include this CDDL HEADER in each
152fb876aeSjeanm# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
162fb876aeSjeanm# If applicable, add the following below this CDDL HEADER, with the
172fb876aeSjeanm# fields enclosed by brackets "[]" replaced with your own identifying
182fb876aeSjeanm# information: Portions Copyright [yyyy] [name of copyright owner]
192fb876aeSjeanm#
202fb876aeSjeanm# CDDL HEADER END
212fb876aeSjeanm#
222fb876aeSjeanm#
232fb876aeSjeanm# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
242fb876aeSjeanm# Use is subject to license terms.
252fb876aeSjeanm#
262fb876aeSjeanm# ident	"%Z%%M%	%I%	%E% SMI"
272fb876aeSjeanm#
282fb876aeSjeanm# Start mirror resync threads.
292fb876aeSjeanm
302fb876aeSjeanmDEVFSADM=/usr/sbin/devfsadm
312fb876aeSjeanmMETADEVADM=/usr/sbin/metadevadm
322fb876aeSjeanmMETASYNC=/usr/sbin/metasync
332fb876aeSjeanmMETADEV=/dev/md/admin
342fb876aeSjeanmMETASET=/usr/sbin/metaset
352fb876aeSjeanmTMPFILE=/var/run/metaset.$$
362fb876aeSjeanm
372fb876aeSjeanm. /lib/svc/share/smf_include.sh
382fb876aeSjeanm
392fb876aeSjeanmprint_verbose()
402fb876aeSjeanm{
412fb876aeSjeanm	echo "Unable to resolve unnamed devices for volume management."
422fb876aeSjeanm	echo "Please refer to the Solaris Volume Manager documentation,"
432fb876aeSjeanm	echo "Troubleshooting section, at http://docs.sun.com or from"
442fb876aeSjeanm	echo "your local copy."
452fb876aeSjeanm}
462fb876aeSjeanm
472fb876aeSjeanmresolve_auto_take_sets()
482fb876aeSjeanm{
492fb876aeSjeanm	if [ -x $METASET ]; then
502fb876aeSjeanm		# Fixing up of the ctd names for devices in auto take
512fb876aeSjeanm		# sets relies heavily on the output of the metaset
522fb876aeSjeanm		# command. Any change to the output of the metaset command
532fb876aeSjeanm		# should modify this script as well in order ensure nothing
542fb876aeSjeanm		# breaks
552fb876aeSjeanm		#
562fb876aeSjeanm		# The following command saves all of the auto-take set names
572fb876aeSjeanm		# into the TMPFILE
582fb876aeSjeanm		name_str=`gettext "Set name"`
592fb876aeSjeanm		mn_str=`gettext "Multi-owner"`
602fb876aeSjeanm		$METASET | /bin/nawk -F ' |\t|,' -v snm="$name_str" \
612fb876aeSjeanm		    -v mstr="$mn_str" '$0 ~ snm { \
622fb876aeSjeanm		    if (index($0, mstr) == 0) print $4 \
632fb876aeSjeanm		}' > $TMPFILE 2>&1
642fb876aeSjeanm
652fb876aeSjeanm		if [ -s "$TMPFILE" ]; then
662fb876aeSjeanm			localised_string=`gettext "Yes (auto)"`
672fb876aeSjeanm			for i in `cat $TMPFILE`; do
682fb876aeSjeanm				$METASET -s $i | grep "$localised_string" \
692fb876aeSjeanm				    > /dev/null 2>&1
702fb876aeSjeanm				if [ $? -eq 0 ]; then
712fb876aeSjeanm					$METADEVADM -l -r -s $i
722fb876aeSjeanm					error=$?
732fb876aeSjeanm					case $error in
742fb876aeSjeanm					0|2)	;;
752fb876aeSjeanm					3) 	print_verbose
762fb876aeSjeanm				    		;;
772fb876aeSjeanm					*)	echo "$METADEVADM \
782fb876aeSjeanm						-r failure $error."
792fb876aeSjeanm						;;
802fb876aeSjeanm					esac
812fb876aeSjeanm				fi
822fb876aeSjeanm			done
83*a1e4d62bShshaw		fi
84*a1e4d62bShshaw		if [ -f "$TMPFILE" ]; then
852fb876aeSjeanm			/usr/bin/rm -f $TMPFILE
862fb876aeSjeanm		fi
872fb876aeSjeanm	fi
882fb876aeSjeanm}
892fb876aeSjeanm
902fb876aeSjeanmif [ ! -s /kernel/drv/md.conf ]; then
912fb876aeSjeanm	echo "/kernel/drv/md.conf is missing."
922fb876aeSjeanm	exit 0
932fb876aeSjeanmfi
942fb876aeSjeanm
952fb876aeSjeanmif grep '^mddb_bootlist' /kernel/drv/md.conf >/dev/null 2>&1; then :; else
962fb876aeSjeanm	echo "No 'mddb_bootlist' entry in /kernel/drv/md.conf."
972fb876aeSjeanm	exit 0
982fb876aeSjeanmfi
992fb876aeSjeanm
1002fb876aeSjeanmif [ ! -x $METADEVADM ]; then
1012fb876aeSjeanm	echo "$METADEVADM is missing or not executable."
1022fb876aeSjeanm	exit $SMF_EXIT_ERR_CONFIG
1032fb876aeSjeanmfi
1042fb876aeSjeanm
1052fb876aeSjeanmif [ ! -x $METASYNC ]; then
1062fb876aeSjeanm	echo "$METASYNC is missing or not executable."
1072fb876aeSjeanm	exit $SMF_EXIT_ERR_CONFIG
1082fb876aeSjeanmfi
1092fb876aeSjeanm
1102fb876aeSjeanmif [ ! -c $METADEV ]; then
1112fb876aeSjeanm	echo "$METADEV is missing or not a character device."
1122fb876aeSjeanm	exit 0
1132fb876aeSjeanmfi
1142fb876aeSjeanm
1152fb876aeSjeanm$METADEVADM -l -r
1162fb876aeSjeanmerror=$?
1172fb876aeSjeanmcase $error in
1182fb876aeSjeanm0|2)	;;
1192fb876aeSjeanm
1202fb876aeSjeanm3)	echo "Executing devfsadm"
1212fb876aeSjeanm	$DEVFSADM
1222fb876aeSjeanm	devfsadmerror=$?
1232fb876aeSjeanm	if [ $devfsadmerror = 0 ]; then
1242fb876aeSjeanm		echo "Executing metadevadm -r"
1252fb876aeSjeanm		$METADEVADM -l -r
1262fb876aeSjeanm		error=$?
1272fb876aeSjeanm	fi
1282fb876aeSjeanm	if [ $devfsadmerror != 0 -o $error = 3 ]; then
1292fb876aeSjeanm		print_verbose
1302fb876aeSjeanm	elif [ $error != 0 -a $error != 2 ]; then
1312fb876aeSjeanm		echo "$METADEVADM -r failure $error."
1322fb876aeSjeanm	fi
1332fb876aeSjeanm	;;
1342fb876aeSjeanm
1352fb876aeSjeanm*)	echo "$METADEVADM -r failure $error."
1362fb876aeSjeanm	exit 1
1372fb876aeSjeanm	;;
1382fb876aeSjeanmesac
1392fb876aeSjeanm
1402fb876aeSjeanmresolve_auto_take_sets
1412fb876aeSjeanm
1422fb876aeSjeanm$METASYNC -r
1432fb876aeSjeanmerror=$?
1442fb876aeSjeanmcase $error in
1452fb876aeSjeanm0)	;;
1462fb876aeSjeanm
1472fb876aeSjeanm*)	echo "Unknown $METASYNC -r failure $error."
1482fb876aeSjeanm	exit 1
1492fb876aeSjeanm	;;
1502fb876aeSjeanmesac
1512fb876aeSjeanm
152