eventscripts: Fix statd-callout update handling
authorMartin Schwenke <martin@meltin.net>
Tue, 28 May 2013 02:01:57 +0000 (12:01 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 28 May 2013 06:11:47 +0000 (16:11 +1000)
60.nfs and 60.ganesha touch $statd_update_trigger every time they're
run.  This stops the statd-callout updates from ever being called.

Make this logic self-contained and move it to new function
nfs_statd_update() in the functions file.  Call this in 60.nfs and
60.ganesha with the appropriate update period as the only argument.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reported-by: Poornima Gupte <poornima.gupte@in.ibm.com>
(This used to be ctdb commit 1b5968f6be084590667f4f15ff3bef13ed9a2973)

ctdb/config/events.d/60.ganesha
ctdb/config/events.d/60.nfs
ctdb/config/functions

index 80e5ae7ac300c28fae192a6fed73cae69cc6d3e6..0066c540270b484c1c43e3f8624eddef7e379bf1 100755 (executable)
@@ -44,14 +44,6 @@ service_name="nfs-ganesha-$CTDB_CLUSTER_FILESYSTEM_TYPE"
 
 ctdb_setup_service_state_dir
 
-statd_update_trigger="$service_state_dir/update-trigger"
-# We want this file to always exist.  The corner case is when
-# auto-start/stop is switched off, NFS is added as a managed service
-# some time after ctdbd is started and someone else starts the NFS
-# service for us.  In this case this file might not otherwise exist
-# when we get to a monitor event.
-touch "$statd_update_trigger"
-
 ctdb_start_stop_service
 
 is_ctdb_managed_service || exit 0
@@ -216,13 +208,7 @@ case "$1" in
 
        # once every 60 seconds, update the statd state database for which
        # clients need notifications
-       LAST_UPDATE=`stat --printf="%Y" "$statd_update_trigger" 2>/dev/null`
-       CURRENT_TIME=`date +"%s"`
-       [ $CURRENT_TIME -ge $(($LAST_UPDATE + 60)) ] && {
-           touch "$statd_update_trigger"
-           $CTDB_BASE/statd-callout updatelocal &
-           $CTDB_BASE/statd-callout updateremote &
-       }
+       nfs_statd_update 60
        ;;
 
      *)
index 46456bc44232e59c0c93877e4138103dce5d4239..eb98ee12419640927f6d4dc78f9d46f158a0c750 100755 (executable)
@@ -32,14 +32,6 @@ loadconfig
 
 ctdb_setup_service_state_dir
 
-statd_update_trigger="$service_state_dir/update-trigger"
-# We want this file to always exist.  The corner case is when
-# auto-start/stop is switched off, NFS is added as a managed service
-# some time after ctdbd is started and someone else starts the NFS
-# service for us.  In this case this file might not otherwise exist
-# when we get to a monitor event.
-touch "$statd_update_trigger"
-
 ctdb_start_stop_service
 
 is_ctdb_managed_service || exit 0
@@ -79,15 +71,9 @@ case "$1" in
 
        nfs_check_rpc_services
 
-       # once every 600 seconds, update the statd state database for which
+       # Every 10 minutes, update the statd state database for which
        # clients need notifications
-       LAST_UPDATE=`stat --printf="%Y" "$statd_update_trigger"`
-       CURRENT_TIME=`date +"%s"`
-       [ $CURRENT_TIME -ge $(($LAST_UPDATE + 600)) ] && {
-           touch "$statd_update_trigger"
-           $CTDB_BASE/statd-callout updatelocal &
-           $CTDB_BASE/statd-callout updateremote &
-       }
+       nfs_statd_update 600
                ;;
 
     *)
index 498c94e5b7c732fd5e1ffc66cf24180fe434da1f..f4707a799d71c6e106435eb5c4dacba49fad4b29 100755 (executable)
@@ -860,6 +860,23 @@ startstop_nfslock() {
        esac
 }
 
+# Periodically update the statd database
+nfs_statd_update ()
+{
+    _update_period="$1"
+
+    _statd_update_trigger="$service_state_dir/update-trigger"
+    [ -f "$_statd_update_trigger" ] || touch "$_statd_update_trigger"
+
+    _last_update=$(stat --printf="%Y" "$_statd_update_trigger")
+    _current_time=$(date +"%s")
+    if [ $(( $_current_time - $_last_update)) -ge $_update_period ] ; then
+       touch "$_statd_update_trigger"
+       $CTDB_BASE/statd-callout updatelocal &
+       $CTDB_BASE/statd-callout updateremote &
+    fi
+}
+
 add_ip_to_iface()
 {
     _iface=$1