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