From: Martin Schwenke Date: Fri, 27 Jun 2025 05:11:59 +0000 (+1000) Subject: ctdb-common: Add tunable directory loading X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4f1e3844b432dc2b72e62bf17cb4dd36f28d6380;p=thirdparty%2Fsamba.git ctdb-common: Add tunable directory loading This is simpler than include files and more general than just allowing a 2nd file to be loaded. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/common/tunable.c b/ctdb/common/tunable.c index 0641fde7066..e7525f586b6 100644 --- a/ctdb/common/tunable.c +++ b/ctdb/common/tunable.c @@ -18,7 +18,9 @@ */ #include "replace.h" +#include "system/dir.h" #include "system/filesys.h" +#include "system/glob.h" #include "system/locale.h" #include "system/network.h" @@ -400,3 +402,76 @@ bool ctdb_tunable_load_file(TALLOC_CTX *mem_ctx, return status && state.status; } + +static int tunables_filter(const struct dirent *de) +{ + int ret; + + /* Match a script pattern */ + ret = fnmatch("*.tunables", de->d_name, 0); + if (ret == 0) { + return 1; + } + + return 0; +} + +bool ctdb_tunable_load_directory(TALLOC_CTX *mem_ctx, + struct ctdb_tunable_list *tun_list, + const char *dir) +{ + struct dirent **namelist = NULL; + int count = 0; + bool status = true; + int i = 0; + + count = scandir(dir, &namelist, tunables_filter, alphasort); + if (count == -1) { + switch (errno) { + case ENOENT: + D_INFO("Optional tunables directory %s not found\n", + dir); + break; + default: + DBG_ERR("Failed to open directory %s (err=%d)\n", + dir, + errno); + status = false; + } + goto done; + } + + if (count == 0) { + goto done; + } + + for (i = 0; i < count; i++) { + char *file = NULL; + bool file_status = false; + + file = talloc_asprintf(mem_ctx, + "%s/%s", + dir, + namelist[i]->d_name); + if (file == NULL) { + DBG_ERR("Memory allocation error\n"); + goto done; + } + + file_status = ctdb_tunable_load_file(mem_ctx, tun_list, file); + if (!file_status) { + status = false; + } + TALLOC_FREE(file); + } + +done: + if (namelist != NULL && count != -1) { + for (i = 0; i < count; i++) { + free(namelist[i]); + } + free(namelist); + } + + return status; +} diff --git a/ctdb/common/tunable.h b/ctdb/common/tunable.h index b7cd62c4ba5..bd8ee45bf1a 100644 --- a/ctdb/common/tunable.h +++ b/ctdb/common/tunable.h @@ -38,5 +38,8 @@ char *ctdb_tunable_names_to_string(TALLOC_CTX *mem_ctx); bool ctdb_tunable_load_file(TALLOC_CTX *mem_ctx, struct ctdb_tunable_list *tun_list, const char *file); +bool ctdb_tunable_load_directory(TALLOC_CTX *mem_ctx, + struct ctdb_tunable_list *tun_list, + const char *dir); #endif /* __CTDB_TUNABLE_H__ */