All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heming Zhao <heming.zhao@suse.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 10/10] dlm_controld: enable "dlm_tool run|run_start" dynamic setting feature
Date: Sun, 19 Sep 2021 14:43:22 +0800	[thread overview]
Message-ID: <20210919064322.1670-11-heming.zhao@suse.com> (raw)
In-Reply-To: <20210919064322.1670-1-heming.zhao@suse.com>

This commit gives dlm_tool the ability to change dlm_controld settings
on the fly.

Signed-off-by: Heming Zhao <heming.zhao@suse.com>
---
 dlm_controld/helper.c | 41 ++++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/dlm_controld/helper.c b/dlm_controld/helper.c
index a20965b76195..dd03cb1c973f 100644
--- a/dlm_controld/helper.c
+++ b/dlm_controld/helper.c
@@ -48,6 +48,7 @@ do { \
 
 #define CMD_ID_LVCHANGE_REFRESH 1
 #define CMD_ID_LVS 2
+#define CMD_ID_OPT 3
 
 static int _get_cmd_id(char **av, int av_count)
 {
@@ -64,6 +65,11 @@ static int _get_cmd_id(char **av, int av_count)
 		return CMD_ID_LVS;
 	}
 
+	if ((av_count >= 2) &&
+	    (!strcmp(av[0], "option") || !strcmp(av[0], "opt"))) {
+		return CMD_ID_OPT;
+	}
+
 	return 0;
 }
 
@@ -133,19 +139,19 @@ static void _clear_running_cmd(struct running *running)
 
 /* runs in child process that was forked by helper */
 
-static void exec_command(char *cmd_str, int out_fd)
+static int exec_command(char *cmd_str, int out_fd)
 {
 	char cmd_buf[16];
 	char arg[ONE_ARG_LEN];
 	char *av[MAX_AV_COUNT + 1]; /* +1 for NULL */
 	int av_count = 0;
-	int i, rv, arg_len, cmd_len, cmd_id;
+	int i, rv = -1, arg_len, cmd_len, cmd_id;
 
 	for (i = 0; i < MAX_AV_COUNT + 1; i++)
 		av[i] = NULL;
 
 	if (!cmd_str[0])
-		return;
+		return rv;
 
 	/* this should already be done, but make sure */
 	cmd_str[RUN_COMMAND_LEN - 1] = '\0';
@@ -214,11 +220,26 @@ static void exec_command(char *cmd_str, int out_fd)
 		log_helper("write cmd_buf from child error %d", rv);
 	close(out_fd);
 
-	/* if we return before exec, the child does exit(1) (failure) */
-	if (!cmd_id)
-		return;
+	switch (cmd_id) {
+	case 0:
+		/* if we return from here, the child does exit(1) (failure) */
+		rv = -1;
+		break;
+	case 1:
+	case 2:
+		rv = 0;
+		execvp(av[0], av);
+		break; /* useless */
+	case 3:
+		set_opt_online(av_count-1, av+1);
+		rv = 0;
+		break;
+	default:
+		rv = -1;
+		break;
+	}
 
-	execvp(av[0], av);
+	return rv;
 }
 
 static int read_request(int fd, struct run_request *req)
@@ -352,8 +373,10 @@ int run_helper(int in_fd, int out_fd, int log_stderr)
 				pid = fork();
 				if (!pid) {
 					close(cmd_pipe[0]);
-					exec_command(req.command, cmd_pipe[1]);
-					exit(1);
+					if (exec_command(req.command, cmd_pipe[1]) < 0)
+						exit(1);
+					else
+						exit(0);
 				}
 
 				close(cmd_pipe[1]);
-- 
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 ` [Cluster-devel] [PATCH 09/10] dlm_controld: add new API set_opt_online() Heming Zhao
2021-09-19  6:43 ` Heming Zhao [this message]
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-11-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.