scripts: Fix CTDB_DBDIR=tmpfs support
authorMartin Schwenke <martin@meltin.net>
Tue, 17 Nov 2015 03:57:44 +0000 (14:57 +1100)
committerMartin Schwenke <martin@meltin.net>
Wed, 24 Feb 2016 05:15:14 +0000 (16:15 +1100)
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

(Imported from commit d9677894b7aa2248e1884ab9e21667879bf1e3c4)

config/ctdbd_wrapper
config/functions [changed mode: 0755->0644]

index 2483020174c5b5884b5ff23aa08753b80ae9508c..c6209844279fec76a75030247756c0970f0145e3 100644 (file)
@@ -23,7 +23,6 @@ loadconfig "ctdb"
 [ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
 
 ctdbd="${CTDBD:-/usr/sbin/ctdbd}"
-ctdb_rundir="/var/run/ctdb"
 
 ############################################################
 
@@ -78,61 +77,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 ()
@@ -225,7 +200,7 @@ start()
     # will be, so this can really do no harm.
     kill_ctdbd "$_session"
 
-    dbdir_tmpfs_start CTDB_DBDIR
+    dbdir_tmpfs_start
 
     build_ctdb_options
 
@@ -324,7 +299,7 @@ stop()
        fi
     fi
 
-    dbdir_tmpfs_stop CTDB_DBDIR
+    dbdir_tmpfs_stop
 
     return 0
 }
old mode 100755 (executable)
new mode 100644 (file)
index 80639c4..7f0b3bf
     export CTDB_ETCDIR="/etc"
 }
 
+ctdb_rundir="/var/run/ctdb"
+
 #######################################
 # 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
@@ -46,6 +71,7 @@ _loadconfig() {
        if [ -r "$_config" ] ; then
            . "$_config"
        fi
+       rewrite_ctdb_options
     fi
 }