2007-05-31 05:09:45 +04:00
#!/bin/sh
2007-06-01 14:54:26 +04:00
# this script needs to be installed so that statd points to it with the -H
2007-06-02 13:45:06 +04:00
# command line argument. The easiest way to do that is to put something like this in
# /etc/sysconfig/nfs:
# STATD_HOSTNAME="myhostname -H /etc/ctdb/statd-callout"
2007-09-14 08:14:03 +04:00
[ -z "$CTDB_BASE" ] && {
export CTDB_BASE="/etc/ctdb"
}
. $CTDB_BASE/functions
2009-11-09 17:06:59 +03:00
loadconfig ctdb
2007-06-03 16:07:07 +04:00
loadconfig nfs
2007-05-31 05:09:45 +04:00
2007-09-07 02:52:56 +04:00
[ -z $NFS_HOSTNAME ] && {
echo NFS_HOSTNAME is not configured. statd-callout failed.
exit 0
}
2007-05-31 05:09:45 +04:00
case "$1" in
add-client)
2007-09-06 05:30:49 +04:00
# the callout does not tell us to which ip the client connected
# so we must add it to all the ips that we serve
2010-08-30 12:13:28 +04:00
PNN=`ctdb xpnn | sed -e "s/.*://"`
ctdb ip -Y | while read LINE; do
NODE=`echo $LINE | cut -f3 -d:`
[ "$NODE" = "$PNN" ] || {
# not us
continue
}
IP=`echo $LINE | cut -f2 -d:`
2011-04-13 06:08:09 +04:00
mkdir -p $CTDB_VARDIR/state/statd/ip/$IP
2010-09-03 06:35:25 +04:00
touch $CTDB_VARDIR/state/statd/ip/$IP/$2
2007-05-31 05:09:45 +04:00
done
;;
del-client)
2010-08-30 12:13:28 +04:00
# the callout does not tell us to which ip the client disconnected
# so we must remove it from all the ips that we serve
PNN=`ctdb xpnn | sed -e "s/.*://"`
ctdb ip -Y | while read LINE; do
NODE=`echo $LINE | cut -f3 -d:`
[ "$NODE" = "$PNN" ] || {
# not us
continue
}
IP=`echo $LINE | cut -f2 -d:`
2010-09-03 06:35:25 +04:00
mkdir -p $CTDB_VARDIR/state/statd/ip/$IP
2011-04-13 06:08:09 +04:00
rm -f $CTDB_VARDIR/state/statd/ip/$IP/$2
2010-08-30 12:13:28 +04:00
done
;;
updatelocal)
# For all IPs we serve, collect info and push to the config database
PNN=`ctdb xpnn | sed -e "s/.*://"`
ctdb ip -Y | tail -n +2 | while read LINE; do
NODE=`echo $LINE | cut -f3 -d:`
[ "$NODE" = "$PNN" ] || {
continue
}
IP=`echo $LINE | cut -f2 -d:`
2010-09-03 06:35:25 +04:00
mkdir -p $CTDB_VARDIR/state/statd/ip/$IP
2010-09-01 09:48:55 +04:00
2010-09-03 06:35:25 +04:00
rm -f $CTDB_VARDIR/state/statd/ip/$IP.tar
tar cfP $CTDB_VARDIR/state/statd/ip/$IP.tar $CTDB_VARDIR/state/statd/ip/$IP
2010-08-30 12:13:28 +04:00
2010-09-03 06:35:25 +04:00
rm -f $CTDB_VARDIR/state/statd/ip/$IP.rec
ctdb pfetch ctdb.tdb statd-state:$IP $CTDB_VARDIR/state/statd/ip/$IP.rec 2>/dev/null
2010-08-30 12:13:28 +04:00
[ "$?" = "0" ] || {
# something went wrong, try storing this data
echo No record. Store STATD state data for $IP
2010-09-03 06:35:25 +04:00
ctdb pstore ctdb.tdb statd-state:$IP $CTDB_VARDIR/state/statd/ip/$IP.tar 2>/dev/null
2010-08-30 12:13:28 +04:00
continue
}
2010-09-03 06:35:25 +04:00
cmp $CTDB_VARDIR/state/statd/ip/$IP.tar $CTDB_VARDIR/state/statd/ip/$IP.rec >/dev/null 2>/dev/null
2010-08-30 12:13:28 +04:00
[ "$?" = "0" ] || {
# something went wrong, try storing this data
echo Updated record. Store STATD state data for $IP
2010-09-03 06:35:25 +04:00
ctdb pstore ctdb.tdb statd-state:$IP $CTDB_VARDIR/state/statd/ip/$IP.tar 2>/dev/null
2010-08-30 12:13:28 +04:00
continue
}
2007-05-31 05:09:45 +04:00
done
;;
2010-08-30 12:13:28 +04:00
updateremote)
# For all IPs we dont serve, pull the state from the database
PNN=`ctdb xpnn | sed -e "s/.*://"`
ctdb ip -Y | tail -n +2 | while read LINE; do
NODE=`echo $LINE | cut -f3 -d:`
[ "$NODE" = "$PNN" ] && {
continue
}
IP=`echo $LINE | cut -f2 -d:`
2010-09-03 06:35:25 +04:00
mkdir -p $CTDB_VARDIR/state/statd/ip/$IP
2010-09-01 09:48:55 +04:00
2010-09-03 06:35:25 +04:00
rm -f $CTDB_VARDIR/state/statd/ip/$IP.rec
ctdb pfetch ctdb.tdb statd-state:$IP $CTDB_VARDIR/state/statd/ip/$IP.rec 2>/dev/null
2010-08-30 12:13:28 +04:00
[ "$?" = "0" ] || {
continue
}
2010-09-03 06:35:25 +04:00
rm -f $CTDB_VARDIR/state/statd/ip/$IP/*
tar xfP $CTDB_VARDIR/state/statd/ip/$IP.rec
2010-08-30 12:13:28 +04:00
done
;;
2007-06-01 07:14:05 +04:00
notify)
2007-09-07 02:52:56 +04:00
# we must restart the lockmanager (on all nodes) so that we get
# a clusterwide grace period (so other clients dont take out
# conflicting locks through other nodes before all locks have been
# reclaimed)
# we need these settings to make sure that no tcp connections survive
# across a very fast failover/failback
2007-10-22 04:18:38 +04:00
#echo 10 > /proc/sys/net/ipv4/tcp_fin_timeout
2007-10-21 00:42:33 +04:00
#echo 0 > /proc/sys/net/ipv4/tcp_max_tw_buckets
#echo 0 > /proc/sys/net/ipv4/tcp_max_orphans
2007-09-07 02:52:56 +04:00
2010-08-30 12:13:28 +04:00
# Delete the notification list for statd, we dont want it to
# ping any clients
2007-09-07 02:52:56 +04:00
rm -f /var/lib/nfs/statd/sm/*
rm -f /var/lib/nfs/statd/sm.bak/*
2007-09-07 06:14:53 +04:00
2007-09-07 02:52:56 +04:00
# we must keep a monotonically increasing state variable for the entire
# cluster so state always increases when ip addresses fail from one
# node to another
2010-08-30 12:13:28 +04:00
# We use epoch and hope the nodes are close enough in clock.
# Even numbers mean service is shut down, odd numbers mean
# service is started.
STATE=`date +"%s"`
STATE=`expr "$STATE" "/" "2"`
2007-09-07 02:52:56 +04:00
2007-09-07 06:14:53 +04:00
# we must also let some time pass between stopping and restarting the
# lockmanager since othervise there is a window where the lockmanager
# will respond "strangely" immediately after restarting it, which
# causes clients to fail to reclaim the locks.
#
2008-02-11 01:52:09 +03:00
startstop_nfslock stop > /dev/null 2>&1
2007-09-07 06:14:53 +04:00
sleep 2
2007-09-07 02:52:56 +04:00
# now start lockmanager again with the new state directory.
2008-02-11 01:52:09 +03:00
startstop_nfslock start > /dev/null 2>&1
2007-09-07 02:52:56 +04:00
# we now need to send out additional statd notifications to ensure
# that clients understand that the lockmanager has restarted.
# we have three cases:
# 1, clients that ignore the ip address the stat notification came from
# and ONLY care about the 'name' in the notify packet.
# these clients ONLY work with lock failover IFF that name
# can be resolved into an ipaddress that matches the one used
# to mount the share. (==linux clients)
# This is handled when starting lockmanager above, but those
# packets are sent from the "wrong" ip address, something linux
# clients are ok with, buth other clients will barf at.
# 2, Some clients only accept statd packets IFF they come from the
# 'correct' ip address.
# 2a,Send out the notification using the 'correct' ip address and also
# specify the 'correct' hostname in the statd packet.
# Some clients require both the correct source address and also the
# correct name. (these clients also ONLY work if the ip addresses
# used to map the share can be resolved into the name returned in
# the notify packet.)
# 2b,Other clients require that the source ip address of the notify
# packet matches the ip address used to take out the lock.
# I.e. that the correct source address is used.
# These clients also require that the statd notify packet contains
# the name as the ip address used when the lock was taken out.
#
# Both 2a and 2b are commonly used in lockmanagers since they maximize
# probability that the client will accept the statd notify packet and
# not just ignore it.
2010-08-30 12:13:28 +04:00
# For all IPs we serve, collect info and push to the config database
PNN=`ctdb xpnn | sed -e "s/.*://"`
ctdb ip -Y | tail -n +2 | while read LINE; do
NODE=`echo $LINE | cut -f3 -d:`
[ "$NODE" = "$PNN" ] || {
continue
}
IP=`echo $LINE | cut -f2 -d:`
2010-09-03 06:35:25 +04:00
ls $CTDB_VARDIR/state/statd/ip/$IP | while read CLIENT; do
rm $CTDB_VARDIR/state/statd/ip/$IP/$CLIENT
2011-04-13 06:08:09 +04:00
smnotify --client=$CLIENT --ip=$IP --server=$ip --stateval=$STATE
smnotify --client=$CLIENT --ip=$IP --server=$NFS_HOSTNAME --stateval=$STATE
2010-08-30 12:13:28 +04:00
STATE=`expr "$STATE" "+" "1"`
2011-04-13 06:08:09 +04:00
smnotify --client=$CLIENT --ip=$IP --server=$ip --stateval=$STATE
smnotify --client=$CLIENT --ip=$IP --server=$NFS_HOSTNAME --stateval=$STATE
2007-08-04 05:23:04 +04:00
done
2007-05-31 05:09:45 +04:00
done
;;
esac