scripts: Add support for CTDB_DBDIR in tmpfs
authorMartin Schwenke <martin@meltin.net>
Fri, 23 Oct 2015 03:04:04 +0000 (14:04 +1100)
committerMartin Schwenke <martin@meltin.net>
Wed, 24 Feb 2016 05:15:14 +0000 (16:15 +1100)
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

(Imported from commit be670ef0103878d8d939de5972b567c4db404082)

config/ctdbd_wrapper [changed mode: 0755->0644]
doc/ctdbd.conf.5.xml

old mode 100755 (executable)
new mode 100644 (file)
index 76d21ba..2483020
@@ -23,6 +23,7 @@ loadconfig "ctdb"
 [ -n "$CTDB_SOCKET" ] && export CTDB_SOCKET
 
 ctdbd="${CTDBD:-/usr/sbin/ctdbd}"
+ctdb_rundir="/var/run/ctdb"
 
 ############################################################
 
@@ -77,6 +78,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=""
@@ -167,6 +225,8 @@ start()
     # will be, so this can really do no harm.
     kill_ctdbd "$_session"
 
+    dbdir_tmpfs_start CTDB_DBDIR
+
     build_ctdb_options
 
     export_debug_variables
@@ -264,6 +324,8 @@ stop()
        fi
     fi
 
+    dbdir_tmpfs_stop CTDB_DBDIR
+
     return 0
 }
 
index 9067aed0c47bd47c2491b8d6e7de2b546f8f0254..d73a2ab1917a684ada82e50baf83967030016405 100644 (file)
        <term>CTDB_DBDIR=<parameter>DIRECTORY</parameter></term>
        <listitem>
          <para>
-           Defaults to <varname>CTDB_VARDIR</varname>.  Corresponds to
-           <option>--dbdir</option>.
+           Defaults to <filename>/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>
        </listitem>
       </varlistentry>