cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Heming Zhao <heming.zhao@suse.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 09/10] dlm_controld: add new API set_opt_online()
Date: Sun, 19 Sep 2021 14:43:21 +0800	[thread overview]
Message-ID: <20210919064322.1670-10-heming.zhao@suse.com> (raw)
In-Reply-To: <20210919064322.1670-1-heming.zhao@suse.com>

This API has ability to change dlm_controld settings on the fly.

Signed-off-by: Heming Zhao <heming.zhao@suse.com>
---
 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




  parent reply	other threads:[~2021-09-19  6:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-19  6:43 [Cluster-devel] [RFC PATCH dlm 00/10] dlm_controld config settings can be Heming Zhao
2021-09-19  6:43 ` [Cluster-devel] [PATCH 01/10] dlm_tool man: add command "joinleave", add "USAGE" section Heming Zhao
2021-09-19  6:43 ` [Cluster-devel] [PATCH 02/10] dlm_tool: add run_(check|cancel) all feature Heming Zhao
2021-09-19  6:43 ` [Cluster-devel] [PATCH 03/10] dlm_tool man: add dynamic setting and examples Heming Zhao
2021-09-19  6:43 ` [Cluster-devel] [PATCH 04/10] dlm_controld: put MAX_LINE in header file Heming Zhao
2021-09-19  6:43 ` [Cluster-devel] [PATCH 05/10] dlm_controld: add dynamic setting items in "struct dlm_option" Heming Zhao
2021-09-19  6:43 ` [Cluster-devel] [PATCH 06/10] dlm_controld: change dlm_options[] to shared memory type Heming Zhao
2021-09-19  6:43 ` [Cluster-devel] [PATCH 07/10] dlm_controld: make few APIs public Heming Zhao
2021-09-19  6:43 ` [Cluster-devel] [PATCH 08/10] dlm_controld: support "dlm_tool dump_config" to show dynamic setting Heming Zhao
2021-09-19  6:43 ` Heming Zhao [this message]
2021-09-19  6:43 ` [Cluster-devel] [PATCH 10/10] dlm_controld: enable "dlm_tool run|run_start" dynamic setting feature Heming Zhao
2021-09-20 17:57 ` [Cluster-devel] [RFC PATCH dlm 00/10] dlm_controld config settings can be David Teigland
2021-09-21  6:38   ` heming.zhao
2021-09-21 13:54     ` David Teigland
2021-09-22  9:32       ` heming.zhao
2021-09-22 13:46         ` David Teigland
2021-09-22 14:35           ` heming.zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210919064322.1670-10-heming.zhao@suse.com \
    --to=heming.zhao@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).