: /bin/sh include - sourced from $SI_CONFIG_DIR/Scripts/Finish/Std
#
# aryzhov@spasu.net
#
# In the beginning of a finish scripts, we must detach the unused
# root submirror, in order to avoid the inconsistencies
# resulting from writing to one submirror only
# (See my Usenet post aryzhov@spasu net "submirror dirty at Jumpstart")
#

RS_detach() {

  #
  # First, make sure we indeed have /a mounted on a "dirty" mirror
  #
  cat $SI_PROFILE | expand | egrep '^filesys .*mirror' | egrep -s ' /$| / ' || return 0

  echo === SVM is set in Profile, now check for dirty mirrorrs ===

  ROOTDEV=`mount   | awk '$1=="/a" {print $3}'`
  OTHER_DEVS=`mount | awk '$1!="/a" && $1~/^\/a\// {print $3}'`
  { echo $OTHER_DEVS | egrep -s /dev/md/dsk && echo $ROOTDEV | egrep -s /dev/dsk; } || return 0

  ROOTDEV=`echo $ROOTDEV | cut -d/ -f4`
  echo $ROOTDEV | egrep -s '^c[0-9]' || StartShell "/a mounted on suspicious device"

  for MIRR in `/sbin/metastat | grep ': Mirror' | cut -d: -f1`; do
    metastat $MIRR | awk '$1=="'$ROOTDEV'"' | egrep -s $ROOTDEV && break
  done

  SUBMIRRORS=`/sbin/metastat $MIRR | grep ': Submirror of' | cut -d: -f1`
  for SUBM in `echo $SUBMIRRORS`; do
    metastat $SUBM | awk '$1=="'$ROOTDEV'"' | egrep -s $ROOTDEV && break
  done
  echo $SUBM | egrep -s '^d[0-9]' || StartShell "Failed to detect the submirrors of $MIRR"
  ACTIVE_SUBM=$SUBM
  PASSIVE_SUBS=`echo "$SUBMIRRORS" | grep -v $SUBM$`

  echo === detaching the unreliable root submirrors ===
  #
  # Can not detach the unsynched submirror
  #
  while metastat $MIRR | grep %; do sleep 60; done
  echo === - ignore the "read only" error messages ===
  for S in `echo $PASSIVE_SUBS`; do echo $S; metadetach $MIRR $S; done
  echo
}


RS_attach() {
  [ `echo $PASSIVE_SUBS | wc -w` -eq 0 ] && return 0
  echo === attaching the previously disabled root submirrors ===
  for S in `echo $PASSIVE_SUBS`; do echo $S; metattach  $MIRR $S; done
  echo
  #
  # Something is wrong when booting from a non-complete mirror
  # Wait till it syncs
  #
  metastat | grep %
  echo
  while metastat $MIRR | grep %; do sleep 60; done
}


#
# RS_detach will be included in the beginning of finish script,
# RS_attach will - in the end (or after Recommended patch cluster is applied)
#
