]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-common: Require separate initialisation of tunable defaults
authorMartin Schwenke <mschwenke@ddn.com>
Wed, 25 Jun 2025 10:46:26 +0000 (20:46 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 22 Jul 2025 23:02:34 +0000 (23:02 +0000)
Dropping this from ctdb_tunable_load_file() allows that function to be
called multiple times for different files.  The caller sets the
defaults.

In the test script, factor out the handling of a single tunables file
in a similar way.  Ignoring missing/unreadable files is OK because
this function will only be called for test successes (hence "ok" in
the name).  There will never be existing, unreadable files.  The code
being tested ignores missing files, so do that here too.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/common/tunable.c
ctdb/server/ctdb_tunables.c
ctdb/tests/UNIT/cunit/tunable_test_001.sh
ctdb/tests/src/tunable_test.c

index f366f231e53eb23387122ad73c37a4e4ec670065..73ebbe77d9c39687d2c66f29d2194c781e9892f7 100644 (file)
@@ -362,8 +362,6 @@ bool ctdb_tunable_load_file(TALLOC_CTX *mem_ctx,
        FILE *fp;
        bool status;
 
-       ctdb_tunable_set_defaults(tun_list);
-
        fp = fopen(file, "r");
        if (fp == NULL) {
                if (errno == ENOENT) {
index 0dce656a93cc3c70f54652bdc9d54bae914f9ff0..00656fde3dd74ffab97f92ac754e316163c76a93 100644 (file)
@@ -155,6 +155,8 @@ bool ctdb_tunables_load(struct ctdb_context *ctdb)
                goto done;
        }
 
+       ctdb_tunable_set_defaults(&ctdb->tunable);
+
        file = path_etcdir_append(tmp_ctx, "ctdb.tunables");
        if (file == NULL) {
                D_ERR("Failed to construct path for ctdb.tunables\n");
index 12b970a08b87c1e84a597f1cb2cd2999cd661063..0fc669d84a24c28484406924e18afc8cc33135ca 100755 (executable)
@@ -67,6 +67,27 @@ ok_tunable_defaults()
        ok "$defaults"
 }
 
+# Update $_map with tunable settings from 1 file
+# values
+ok_tunable_1()
+{
+       _file="$1"
+
+       if [ ! -r "$_file" ]; then
+               return
+       fi
+
+       while IFS='=    ' read -r _var _val; do
+               case "$_var" in
+               \#* | "") continue ;;
+               esac
+               _decval=$((_val))
+               _vl=$(echo "$_var" | tr '[:upper:]' '[:lower:]')
+               _map=$(echo "$_map" |
+                       sed -e "s|^\\(${_vl}:.*=\\).*\$|\\1${_decval}|")
+       done <"$_file"
+}
+
 # Set required output to a version of $defaults where values for
 # tunables specified in $tfile replace the default values
 ok_tunable()
@@ -80,16 +101,7 @@ ok_tunable()
        _map=$(echo "$defaults" |
                awk -F= '$0 { printf "%s:%s=%s\n", tolower($1), $1, $2 }')
 
-       # Replace values for tunables set in $tfile
-       while IFS='=    ' read -r _var _val; do
-               case "$_var" in
-               \#* | "") continue ;;
-               esac
-               _decval=$((_val))
-               _vl=$(echo "$_var" | tr '[:upper:]' '[:lower:]')
-               _map=$(echo "$_map" |
-                       sed -e "s|^\\(${_vl}:.*=\\).*\$|\\1${_decval}|")
-       done <"$tfile"
+       ok_tunable_1 "$tfile"
 
        # Set result, stripping off lowercase tunable prefix
        ok "$(echo "$_map" | awk -F: '{ print $2 }')"
index ea94aec07127a51eb89e4acc68f21da30f247caa..c2ff48b9b69d3331449b584803c56508c4b72f42 100644 (file)
@@ -42,6 +42,8 @@ int main(int argc, const char **argv)
        mem_ctx = talloc_new(NULL);
        assert(mem_ctx != NULL);
 
+       ctdb_tunable_set_defaults(&tun_list);
+
        status = ctdb_tunable_load_file(mem_ctx, &tun_list, argv[1]);
        if (!status) {
                ret = EINVAL;