From 2ec739a039e3a9af82e614afeae54359fb05b288 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 25 Jun 2025 20:46:26 +1000 Subject: [PATCH] ctdb-common: Require separate initialisation of tunable defaults 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 Reviewed-by: Amitay Isaacs --- ctdb/common/tunable.c | 2 -- ctdb/server/ctdb_tunables.c | 2 ++ ctdb/tests/UNIT/cunit/tunable_test_001.sh | 32 ++++++++++++++++------- ctdb/tests/src/tunable_test.c | 2 ++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ctdb/common/tunable.c b/ctdb/common/tunable.c index f366f231e53..73ebbe77d9c 100644 --- a/ctdb/common/tunable.c +++ b/ctdb/common/tunable.c @@ -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) { diff --git a/ctdb/server/ctdb_tunables.c b/ctdb/server/ctdb_tunables.c index 0dce656a93c..00656fde3dd 100644 --- a/ctdb/server/ctdb_tunables.c +++ b/ctdb/server/ctdb_tunables.c @@ -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"); diff --git a/ctdb/tests/UNIT/cunit/tunable_test_001.sh b/ctdb/tests/UNIT/cunit/tunable_test_001.sh index 12b970a08b8..0fc669d84a2 100755 --- a/ctdb/tests/UNIT/cunit/tunable_test_001.sh +++ b/ctdb/tests/UNIT/cunit/tunable_test_001.sh @@ -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 }')" diff --git a/ctdb/tests/src/tunable_test.c b/ctdb/tests/src/tunable_test.c index ea94aec0712..c2ff48b9b69 100644 --- a/ctdb/tests/src/tunable_test.c +++ b/ctdb/tests/src/tunable_test.c @@ -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; -- 2.47.2