ctdb-scripts: Fix CTDB_DBDIR=tmpfs support
authorMartin Schwenke <martin@meltin.net>
Tue, 17 Nov 2015 03:57:44 +0000 (14:57 +1100)
committerAmitay Isaacs <amitay@samba.org>
Wed, 18 Nov 2015 10:51:54 +0000 (11:51 +0100)
Various scripts (including debug_locks.sh, 00.ctdb, 05.system) need
CTDB_DBDIR to point to the right place... but it doesn't.

Move the rewriting of CTDB_DBDIR to loadconfig() so that it happens
for all scripts.  Have this code set internal variable
CTDB_DBDIR_TMPFS_OPTIONS so that ctdbd_wrapper can do the mount.

This loses the generality that was present in dbdir_tmpfs_start() but
it wasn't being used anyway.  If it is needed in the future then it
will be in the git history.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Wed Nov 18 11:51:54 CET 2015 on sn-devel-104

ctdb/config/ctdbd_wrapper
ctdb/config/functions

index 71c7b25bcd1b6f17ec418d8ef6264639475ed9e4..be251e6472c89fb2b2548f00646256888bc35884 100755 (executable)
@@ -25,7 +25,6 @@ loadconfig "ctdb"
 [ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
 
 ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
-ctdb_rundir="/usr/local/var/run/ctdb"
 
 ############################################################
 
@@ -80,61 +79,37 @@ ctdbd_is_running ()
 
 ############################################################
 
-# Mount given database directories on tmpfs
+# If necessary, mount volatile database directory on tmpfs
 dbdir_tmpfs_start ()
 {
-    for _var ; do
-       # $_var is the name of the configuration varable, so get the
-       # value
-       eval _val="\$${_var}"
-
-       case "$_val" in
-           tmpfs|tmpfs:*)
-               _opts_defaults="mode=700"
-               # Get any extra options specified after colon
-               if [ "$_val" = "tmpfs" ] ; then
-                   _opts=""
-               else
-                   _opts="${_val#tmpfs:}"
-               fi
-               # It is OK to repeat options - last value wins
-               _opts_all="${_opts_defaults}${_opts:+,}${_opts}"
-
-               # Last component of mountpoint is variable name
-               _mnt="${ctdb_rundir}/${_var}"
-               mkdir -p "$_mnt" || exit $?
-
-               # If already mounted then remount, otherwise mount
-               if findmnt -t tmpfs "$_mnt" >/dev/null ; then
-                   mount -t tmpfs -o "remount,$_opts_all" none "$_mnt" || \
-                       exit $?
-               else
-                   mount -t tmpfs -o "$_opts_all" none "$_mnt" || exit $?
-               fi
-
-               # Replace specified value with mountpoint, to be
-               # passed to ctdbd
-               eval "${_var}=${_mnt}"
-               ;;
-       esac
-    done
+    if [ -z "$CTDB_DBDIR_TMPFS_OPTIONS" ] ; then
+       return
+    fi
+
+    # Shortcut for readability
+    _opts="$CTDB_DBDIR_TMPFS_OPTIONS"
+
+    mkdir -p "$CTDB_DBDIR" || exit $?
+
+    # If already mounted then remount, otherwise mount
+    if findmnt -t tmpfs "$CTDB_DBDIR" >/dev/null ; then
+       mount -t tmpfs -o "remount,$_opts" none "$CTDB_DBDIR" || \
+           exit $?
+    else
+       mount -t tmpfs -o "$_opts" none "$CTDB_DBDIR" || exit $?
+    fi
 }
 
-# Unmount database tmpfs directories on exit
+# If necessary, unmount volatile database tmpfs directory on exit
 dbdir_tmpfs_stop ()
 {
-    for _var ; do
-       eval _val="\$${_var}"
-
-       case "$_val" in
-           tmpfs|tmpfs:*)
-               _mnt="${ctdb_rundir}/${_var}"
-               if [ -d "$_mnt" ] && findmnt -t tmpfs "$_mnt" >/dev/null ; then
-                   umount "$_mnt"
-               fi
-               ;;
-       esac
-    done
+    if [ -z "$CTDB_DBDIR_TMPFS_OPTIONS" ] ; then
+       return
+    fi
+
+    if [ -d "$CTDB_DBDIR" ] && findmnt -t tmpfs "$CTDB_DBDIR" >/dev/null ; then
+       umount "$CTDB_DBDIR"
+    fi
 }
 
 build_ctdb_options ()
@@ -223,7 +198,7 @@ start()
     # there may still be other processes around, so do some cleanup.
     kill_ctdbd "$_session"
 
-    dbdir_tmpfs_start CTDB_DBDIR
+    dbdir_tmpfs_start
 
     build_ctdb_options
 
@@ -334,7 +309,7 @@ stop()
        fi
     fi
 
-    dbdir_tmpfs_stop CTDB_DBDIR
+    dbdir_tmpfs_stop
 
     return 0
 }
index 49bed988f5e4fec51542b47bd321a86ee8f9071e..eef8f7e38abc444f6fa25a23e5240d2649bdd0c6 100755 (executable)
@@ -8,6 +8,7 @@ if [ -z "$CTDB_BASE" ] ; then
 fi
 
 CTDB_VARDIR="/usr/local/var/lib/ctdb"
+ctdb_rundir="/usr/local/var/run/ctdb"
 
 # Only (and always) override these variables in test code
 
@@ -21,6 +22,29 @@ fi
 
 #######################################
 # pull in a system config file, if any
+
+rewrite_ctdb_options ()
+{
+    case "$CTDB_DBDIR" in
+       tmpfs|tmpfs:*)
+           _opts_defaults="mode=700"
+           # Get any extra options specified after colon
+           if [ "$CTDB_DBDIR" = "tmpfs" ] ; then
+               _opts=""
+           else
+               _opts="${CTDB_DBDIR#tmpfs:}"
+           fi
+           # This is an internal variable, only used by ctdbd_wrapper.
+           # It is OK to repeat mount options - last value wins
+           CTDB_DBDIR_TMPFS_OPTIONS="${_opts_defaults}${_opts:+,}${_opts}"
+
+           CTDB_DBDIR="${ctdb_rundir}/CTDB_DBDIR"
+           ;;
+       *)
+           CTDB_DBDIR_TMPFS_OPTIONS=""
+    esac
+}
+
 _loadconfig() {
 
     if [ -z "$1" ] ; then
@@ -52,6 +76,7 @@ _loadconfig() {
        if [ -r "$_config" ] ; then
            . "$_config"
        fi
+       rewrite_ctdb_options
     fi
 }