From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heming Zhao Date: Sun, 19 Sep 2021 14:43:21 +0800 Subject: [Cluster-devel] [PATCH 09/10] dlm_controld: add new API set_opt_online() In-Reply-To: <20210919064322.1670-1-heming.zhao@suse.com> References: <20210919064322.1670-1-heming.zhao@suse.com> Message-ID: <20210919064322.1670-10-heming.zhao@suse.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This API has ability to change dlm_controld settings on the fly. Signed-off-by: Heming Zhao --- dlm_controld/config.c | 128 ++++++++++++++++++++++++++++++++++++++ dlm_controld/dlm_daemon.h | 1 + 2 files changed, 129 insertions(+) diff --git a/dlm_controld/config.c b/dlm_controld/config.c index d77f3826bfe6..9e799c8c04d2 100644 --- a/dlm_controld/config.c +++ b/dlm_controld/config.c @@ -292,3 +292,129 @@ void set_opt_file(int update) fclose(file); } +static void reset_opt_value(struct dlm_option *o) +{ + /* config priority: cli, config file, default */ + + if (o->cli_set) { + o->use_int = o->cli_int; + o->use_uint = o->cli_uint; + o->use_str = o->cli_str; + return; + } + + if (o->file_set) { + o->use_int = o->file_int; + o->use_uint = o->file_uint; + o->use_str = o->file_str; + return; + } + + o->use_int = o->default_int; + o->use_uint = o->default_uint; + o->use_str = (char *)o->default_str; + + return; +} + +/* + * do the clean/restore job: + * - clean up dlm_options[].dynamic_xx + * - using high priority config to set use_xx items. + */ +static void reset_dynamic(struct dlm_option *o) +{ + o->dynamic_set = 0; + o->dynamic_int = 0; + if (o->dynamic_str){ + free(o->dynamic_str); + o->dynamic_str = NULL; + } + o->dynamic_uint = 0; + reset_opt_value(o); + + set_configfs_opt("log_debug", NULL, opt(log_debug_ind)); + set_logfile_priority(); + + return; +} + +void set_opt_online(int argc, char **argv) +{ + int i = -1, val = 0, ind; + unsigned int uval = 0; + struct dlm_option *o; + char str[MAX_LINE]; + + if (!strcmp(argv[0], "restore_all")) { + for (i = 0; i < dlm_options_max; i++) + reset_dynamic(&dlm_options[i]); + + return; + } + + while (++i < argc) { + ind = get_ind_name(argv[i]); + if (ind < 0) + continue; + o = &dlm_options[ind]; + if (!o || !o->dynamic) + continue; + + get_val_str(argv[i], str); + if (!strcmp(str, "restore")) { + reset_dynamic(o); + continue; + } + + o->dynamic_set++; + + if (!o->req_arg || o->req_arg == req_arg_int) { + get_val_int(argv[i], &val); + if (!o->req_arg) + val = val ? 1 : 0; + + o->dynamic_int = val; + + log_debug("config dynamic %s = %d previous use %d", + o->name, o->dynamic_int, o->use_int); + o->use_int = o->dynamic_int; + + } else if (o->req_arg == req_arg_uint) { + get_val_uint(argv[i], &uval); + o->dynamic_uint = uval; + + log_debug("config dynamic %s = %u previous use %u", + o->name, o->dynamic_uint, o->use_uint); + o->use_uint = o->dynamic_uint; + + } else if (o->req_arg == req_arg_bool) { + get_val_int(argv[i], &val); + o->dynamic_int = val ? 1 : 0; + + log_debug("config dynamic %s = %d previous use %d", + o->name, o->dynamic_int, o->use_int); + o->use_int = o->dynamic_int; + + } else if (o->req_arg == req_arg_str) { + memset(str, 0, sizeof(str)); + get_val_str(argv[i], str); + + o->dynamic_str = strdup(str); + + log_debug("config dynamic %s = %s previous use %s", + o->name, o->dynamic_str, o->use_str); + o->use_str = o->dynamic_str; + } + + if (ind == log_debug_ind) { + set_configfs_opt("log_debug", NULL, opt(log_debug_ind)); + } else if (ind == debug_logfile_ind) { + set_logfile_priority(); + } + + } + + return; +} + diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h index 904bb0b50df9..8cc9f666872e 100644 --- a/dlm_controld/dlm_daemon.h +++ b/dlm_controld/dlm_daemon.h @@ -398,6 +398,7 @@ int set_configfs_opt(const char *name, char *str, int num); void set_opt_file(int update); int get_weight(struct lockspace *ls, int nodeid); void setup_lockspace_config(struct lockspace *ls); +void set_opt_online(int argc, char **argv); /* cpg.c */ void process_lockspace_changes(void); -- 2.32.0