#!/bin/ksh

#pragma ident "@(#)nfs.stop	1.7	99/08/16 SMI"
#
#       Copyright (C) 1997 Sun Microsystems, Inc.
#

# This used to be HA-NFS stop method
# Now the stop and stop_net methods have been switched, that improves failover
# time for Solaris2.5.1 NFS clients a little bit.
#
# This script is passed 3 arguments - a comma separated list of logical hosts
# mastered on this node, a comma separated list of logical hosts not mastered
# on this node, and the timeout registered with this method.
m_list=$(print $1 | tr ',' ' ')
nm_list=$(print $2 | tr ',' ' ')
timeout=$3

CLUSTERBIN=/opt/SUNWcluster/bin
CLUSTERVAR=/var/opt/SUNWcluster
CLUSTERETC=/etc/opt/SUNWcluster/conf
CLUSTNAME=$(/bin/cat ${CLUSTERETC}/default_clustername)

cdbfile=${CLUSTERETC}/${CLUSTNAME}.cdb
ccdfile=$(${CLUSTERBIN}/ccdadm ${CLUSTNAME} -w)
hanfsdir=$(${CLUSTERBIN}/cdbmatch cluster.hanfsdir ${cdbfile})

# get information about current membership, localnodeid, etc

node_status=$(${CLUSTERBIN}/get_node_status)
node_status=$(print ${node_status})

localnodeid=${node_status%% membership:*}
localnodeid=${localnodeid##*node id: }
localhostname=$(${CLUSTERBIN}/cdbmatch cluster.node.${localnodeid}.hostname \
			${cdbfile})

currnodes=${node_status##*membership: }
currnodes=${currnodes%% interconnect*}

to_unmaster_list=""
for l in ${nm_list}; do
  cm=$(${CLUSTERBIN}/haget -f master -h ${l})
  if [[ "${cm}" != "${localhostname}" ]]; then
    continue
  else
    to_unmaster_list="${l} ${to_unmaster_list}"
  fi
done

if [[ -n "${to_unmaster_list}" ]]; then
  ${CLUSTERBIN}/scnfs ${CLUSTNAME} killd
  for l in ${to_unmaster_list}; do
    ${CLUSTERBIN}/scnfs ${CLUSTNAME} unshare ${l}
  done

  # restart daemons if there are logical hosts to master
  
  if [[ -n "${m_list}" ]]; then
    ${CLUSTERBIN}/scnfs ${CLUSTNAME} startd "${currnodes}" ${localnodeid} \
		${ccdfile} "${m_list}"
  fi
fi

exit 0
