From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heming Zhao Date: Sun, 19 Sep 2021 14:43:14 +0800 Subject: [Cluster-devel] [PATCH 02/10] dlm_tool: add run_(check|cancel) all feature In-Reply-To: <20210919064322.1670-1-heming.zhao@suse.com> References: <20210919064322.1670-1-heming.zhao@suse.com> Message-ID: <20210919064322.1670-3-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 Current run_check and run_cancel require uuid for executing. If users want to check/cancel all commands, they must input every command uuid, which is a boring action. This commit add a new option "-A", which makes one time travel all the command without uuid. Signed-off-by: Heming Zhao --- dlm_tool/dlm_tool.8 | 5 ++- dlm_tool/main.c | 80 ++++++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/dlm_tool/dlm_tool.8 b/dlm_tool/dlm_tool.8 index 056c4af0213c..086596c67dbf 100644 --- a/dlm_tool/dlm_tool.8 +++ b/dlm_tool/dlm_tool.8 @@ -110,6 +110,9 @@ Wide lockdebug output .B \-M Include MSTCPY locks in lockdump output +.B \-A +Include all uuid in run_check and run_cancel + .B \-h Print help, then exit @@ -177,7 +180,7 @@ dlm_tool run|run_start [-n] \fIcommand\fP - -dlm_tool run_check|run_cancel [-i "sec"] \fIuuid\fP +dlm_tool run_check|run_cancel [-A] [-i "sec"] \fIuuid\fP - diff --git a/dlm_tool/main.c b/dlm_tool/main.c index 53d9336d59c6..37f381f6d980 100644 --- a/dlm_tool/main.c +++ b/dlm_tool/main.c @@ -53,6 +53,7 @@ static char *lsname; static int operation; static int opt_ind; static int ls_all_nodes = 0; +static int opt_all_uuid = 0; static int opt_excl = 0; static int opt_fs = 0; static int dump_mstcpy = 0; @@ -215,7 +216,7 @@ static void print_usage(void) printf("\n"); } -#define OPTION_STRING "MhVnm:e:f:vwsi:" +#define OPTION_STRING "MhVAnm:e:f:vwsi:" static void decode_arguments(int argc, char **argv) { @@ -254,6 +255,10 @@ static void decode_arguments(int argc, char **argv) ls_all_nodes = 1; break; + case 'A': + opt_all_uuid = 1; + break; + case 's': summarize = 1; break; @@ -456,8 +461,10 @@ static void decode_arguments(int argc, char **argv) fprintf(stderr, "command required\n"); exit(EXIT_FAILURE); } else if (need_uuid) { - fprintf(stderr, "uuid required\n"); - exit(EXIT_FAILURE); + if (!opt_all_uuid) { + fprintf(stderr, "uuid required\n"); + exit(EXIT_FAILURE); + } } else { fprintf(stderr, "missing arg\n"); exit(EXIT_FAILURE); @@ -1486,14 +1493,42 @@ static void do_log_plock(void) printf("\n"); } +static int check_or_cancel(int do_cancel) +{ + uint32_t flags = 0; + uint32_t check_status = 0; + int rv = 0; + + if (do_cancel) + flags = DLMC_FLAG_RUN_CHECK_CANCEL; + else + flags = DLMC_FLAG_RUN_CHECK_CLEAR; + + rv = dlmc_run_check(run_uuid, strlen(run_uuid), wait_sec, flags, + &check_status); + + printf("check_status: "); + + if (check_status & DLMC_RUN_STATUS_WAITING) + printf("waiting "); + if (check_status & DLMC_RUN_STATUS_DONE) + printf("done "); + if (check_status & DLMC_RUN_STATUS_FAILED) + printf("failed "); + printf("\n"); + return rv; +} + static int do_run(int op) { int do_start = (op == OP_RUN) || (op == OP_RUN_START); int do_check = (op == OP_RUN) || (op == OP_RUN_CHECK); int do_cancel = (op == OP_RUN_CANCEL); uint32_t flags = 0; - uint32_t check_status = 0; - int rv = 0; + int rv = 0, pos = 0; + char buf[DLMC_DUMP_SIZE]; + char *p; + if (do_start) { /* FIXME: use proper option to specify */ @@ -1508,23 +1543,24 @@ static int do_run(int op) } if (do_check || do_cancel) { - if (do_cancel) - flags = DLMC_FLAG_RUN_CHECK_CANCEL; - else - flags = DLMC_FLAG_RUN_CHECK_CLEAR; - - rv = dlmc_run_check(run_uuid, strlen(run_uuid), wait_sec, flags, - &check_status); - - printf("check_status: "); - - if (check_status & DLMC_RUN_STATUS_WAITING) - printf("waiting "); - if (check_status & DLMC_RUN_STATUS_DONE) - printf("done "); - if (check_status & DLMC_RUN_STATUS_FAILED) - printf("failed "); - printf("\n"); + if (opt_all_uuid) { + memset(buf, 0, sizeof(buf)); + dlmc_dump_run(buf); + buf[DLMC_DUMP_SIZE-1] = '\0'; + while (1) { + p = strstr(buf + pos, "run_uuid "); + if (!p) + break; + pos = p - buf; + sscanf(buf + pos, "run_uuid %s start_nodeid", run_uuid); + pos += 10 + strlen(run_uuid); /* 10: "run_uuid" + 2 spaces */ + printf("uuid: %s\n", run_uuid); + rv += check_or_cancel(do_cancel); + } + return rv; + } else { + rv = check_or_cancel(do_cancel); + } } return rv; -- 2.32.0