ctdb-scripts: Add registration for CTDB_NFS_CALLOUT operations
authorMartin Schwenke <martin@meltin.net>
Tue, 14 Jul 2015 02:11:39 +0000 (12:11 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 14 Jul 2015 07:57:18 +0000 (09:57 +0200)
This is an optimisation to avoid forking the callout for operations
that are not implemented.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/events.d/60.nfs
ctdb/config/nfs-ganesha-callout
ctdb/config/nfs-linux-kernel-callout

index 957d8eaab75861fded84a422e789b7aba30c03f4..fce6beb911838f02ac30cf83b5f6a06e3b78f3a0 100755 (executable)
@@ -7,6 +7,10 @@
 . $CTDB_BASE/functions
 
 service_name="nfs"
+loadconfig
+ctdb_setup_service_state_dir
+
+######################################################################
 
 if [ -z "$CTDB_NFS_CALLOUT" ] ; then
     CTDB_NFS_CALLOUT="${CTDB_BASE}/nfs-linux-kernel-callout"
@@ -14,9 +18,44 @@ fi
 # Always export, for statd callout
 export CTDB_NFS_CALLOUT
 
+nfs_callout_cache="${service_state_dir}/nfs_callout_cache"
+nfs_callout_cache_callout="${nfs_callout_cache}/CTDB_NFS_CALLOUT"
+nfs_callout_cache_ops="${nfs_callout_cache}/ops"
+
+nfs_callout_register ()
+{
+    mkdir -p "$nfs_callout_cache_ops"
+    rm -f "$nfs_callout_cache_ops"/*
+
+    echo "$CTDB_NFS_CALLOUT" >"$nfs_callout_cache_callout"
+
+    _t=$(eval "$CTDB_NFS_CALLOUT" "register")
+    if [ -n "$_t" ] ; then
+       echo "$_t" |
+           while IFS="" read _op ; do
+               touch "${nfs_callout_cache_ops}/${_op}"
+           done
+    else
+       touch "${nfs_callout_cache_ops}/ALL"
+    fi
+}
+
 nfs_callout ()
 {
-    eval "$CTDB_NFS_CALLOUT" "$@"
+    # Re-run registration if $CTDB_NFS_CALLOUT has changed
+    _prev=""
+    if [ -r "$nfs_callout_cache_callout" ] ; then
+       read _prev <"$nfs_callout_cache_callout"
+    fi
+    if [ "$CTDB_NFS_CALLOUT" != "$_prev" ] ; then
+       nfs_callout_register
+    fi
+
+    # Run the operation if it is registered...
+    if [ -e "${nfs_callout_cache_ops}/${1}" ] || \
+          [ -e "${nfs_callout_cache_ops}/ALL" ]; then
+       eval "$CTDB_NFS_CALLOUT" "$@"
+    fi
 }
 
 service_reconfigure ()
@@ -234,10 +273,6 @@ nfs_update_lock_info ()
 
 ######################################################################
 
-loadconfig
-
-ctdb_setup_service_state_dir
-
 ctdb_start_stop_service
 
 is_ctdb_managed_service || exit 0
index 0d510e779eadfe083d03ed3457767bab98f33d09..b66611c84f9a86a04cff3521163a073cb899b498 100755 (executable)
@@ -290,7 +290,7 @@ case "$action" in
     releaseip)           nfs_releaseip "$@"      ;;
     takeip)              nfs_takeip "$@"         ;;
     monitor-list-shares) nfs_monitor_list_shares ;;
-    monitor-pre|monitor-post)
+    register|monitor-pre|monitor-post)
        # Not required/implemented
        :
        ;;
index 59618d79dfb541fdb58bce0e7bf155cc4f02f686..31810d0f7d4eecb1f563be1db57770b104891932 100755 (executable)
@@ -32,6 +32,7 @@ usage ()
 usage: $_c { shutdown | startup }
        $_c { stop | start } { nfs | nlockmgr }
        $_c { monitor-list-shares | monitor-post }
+       $_c { register }
 EOF
     exit 1
 }
@@ -196,6 +197,9 @@ case "$1" in
     monitor-post)
        nfs_check_thread_count
        ;;
+    register)
+       : # Nothing yet
+       ;;
     monitor-pre|releaseip|takeip)
        # Not required/implemented
        :