ctdb-scripts: Add support for CTDB_DBDIR in tmpfs
authorMartin Schwenke <martin@meltin.net>
Fri, 23 Oct 2015 03:04:04 +0000 (14:04 +1100)
committerMichael Adam <obnox@samba.org>
Mon, 9 Nov 2015 09:58:32 +0000 (10:58 +0100)
The tmpfs is mounted and unmounted by ctdbd_wrapper.  Format is
CTDB_DBDIR=tmpfs:<tmpfs-options>.  The only default for the tmpfs is
mode=700 - to override, specify a different value in <tmpfs-options>.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Michael Adam <obnox@samba.org>
Autobuild-User(master): Michael Adam <obnox@samba.org>
Autobuild-Date(master): Mon Nov  9 10:58:32 CET 2015 on sn-devel-104

ctdb/config/ctdbd_wrapper
ctdb/doc/ctdbd.conf.5.xml

index 2ff8183b6fa55845f1e86e00e245b8291c21e9a7..71c7b25bcd1b6f17ec418d8ef6264639475ed9e4 100755 (executable)
@@ -25,6 +25,7 @@ loadconfig "ctdb"
 [ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
 
 ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
+ctdb_rundir="/usr/local/var/run/ctdb"
 
 ############################################################
 
@@ -79,6 +80,63 @@ ctdbd_is_running ()
 
 ############################################################
 
+# Mount given database directories 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
+}
+
+# Unmount database tmpfs directories 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
+}
+
 build_ctdb_options ()
 {
     ctdb_options=""
@@ -165,6 +223,8 @@ start()
     # there may still be other processes around, so do some cleanup.
     kill_ctdbd "$_session"
 
+    dbdir_tmpfs_start CTDB_DBDIR
+
     build_ctdb_options
 
     export_debug_variables
@@ -274,6 +334,8 @@ stop()
        fi
     fi
 
+    dbdir_tmpfs_stop CTDB_DBDIR
+
     return 0
 }
 
index 15ee7467d3932da575cef66ae7547d42bb4f30d8..40296ba7983762993c86a0f54b16e0a086251ffb 100644 (file)
          <para>
            Defaults to <filename>/usr/local/var/lib/ctdb</filename>.
          </para>
+         <para>
+           Apart from a DIRECTORY, this can take a special value of
+           the form
+           <option>tmpfs</option><optional>:<parameter>OPTIONS</parameter></optional>.
+           OPTIONS is a comma-separated list of any permissible
+           options to the tmpfs filesystem.  The only pre-specified
+           default is <option>mode=700</option>, which can
+           overriden by specifying <option>mode</option> in
+           OPTIONS.  It probably makes sense to specify a maximum
+           <option>size</option>.
+         </para>
          <para>
            Corresponds to <option>--dbdir</option>.
          </para>