[Cluster-devel] [PATCH 10/10] dlm_controld: enable "dlm_tool run|run_start" dynamic setting feature

Heming Zhao heming.zhao at suse.com
Sun Sep 19 06:43:22 UTC 2021


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

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





More information about the Cluster-devel mailing list