From: Martin Schwenke Date: Mon, 6 Jun 2016 03:56:55 +0000 (+1000) Subject: ctdb-scripts: Move NFS callout-related code to functions file X-Git-Tag: tdb-1.3.10~913 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6096233919528e2337fa9d3269caaf0a86becf9b;p=thirdparty%2Fsamba.git ctdb-scripts: Move NFS callout-related code to functions file A second NFS eventscript may be required, so make this code available to it. The initialisation code can't be evaluated in the functions file because service_state_dir isn't yet setup, so put it in a function and call it with other initialisation code. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/events.d/60.nfs b/ctdb/config/events.d/60.nfs index 57cfbffa2e9..eb12ad6ac4c 100755 --- a/ctdb/config/events.d/60.nfs +++ b/ctdb/config/events.d/60.nfs @@ -12,63 +12,6 @@ ctdb_setup_service_state_dir ###################################################################### -if [ -z "$CTDB_NFS_CALLOUT" ] ; then - CTDB_NFS_CALLOUT="${CTDB_BASE}/nfs-linux-kernel-callout" -fi -# Always export, for statd callout -export CTDB_NFS_CALLOUT - -# If the callout wants to use this then it must create it -export CTDB_NFS_CALLOUT_STATE_DIR="${service_state_dir}/callout-state" - -# Export, if set, for use by clustered NFS callouts -if [ -n "$CTDB_NFS_STATE_FS_TYPE" ] ; then - export CTDB_NFS_STATE_FS_TYPE -fi -if [ -n "$CTDB_NFS_STATE_MNT" ] ; then - export CTDB_NFS_STATE_MNT -fi - -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 () -{ - # 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 () { # Restart lock manager, notify clients @@ -294,6 +237,8 @@ nfs_update_lock_info () ###################################################################### +nfs_callout_init + ctdb_start_stop_service is_ctdb_managed_service || exit 0 diff --git a/ctdb/config/functions b/ctdb/config/functions index 33efa517e0b..b2a0735a221 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -1164,6 +1164,69 @@ if ! type mktemp >/dev/null 2>&1 ; then } fi +###################################################################### +# NFS callout handling + +nfs_callout_init () +{ + if [ -z "$CTDB_NFS_CALLOUT" ] ; then + CTDB_NFS_CALLOUT="${CTDB_BASE}/nfs-linux-kernel-callout" + fi + # Always export, for statd callout + export CTDB_NFS_CALLOUT + + # If the callout wants to use this then it must create it + export CTDB_NFS_CALLOUT_STATE_DIR="${service_state_dir}/callout-state" + + # Export, if set, for use by clustered NFS callouts + if [ -n "$CTDB_NFS_STATE_FS_TYPE" ] ; then + export CTDB_NFS_STATE_FS_TYPE + fi + if [ -n "$CTDB_NFS_STATE_MNT" ] ; then + export CTDB_NFS_STATE_MNT + fi + + 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 () +{ + # 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 +} + ######################################################## # tickle handling ########################################################