From: Fan Yong Date: Wed, 19 Jul 2017 05:58:06 +0000 (+0800) Subject: LU-9710 utils: adjust barrier_stat input/output X-Git-Tag: 2.10.51~5 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=3f198baf4fe343b679ce14ee11069126f4be3e72;p=fs%2Flustre-release.git LU-9710 utils: adjust barrier_stat input/output The command format will be: lctl barrier_stat [--state|-s] [--timeout|-t] If no option is specified, or both "state" and "timeout" options are specified, then the output format will be: state: xxx timeout: nnn seconds Otherwise, only the value ('xxx' or 'nnn') corresponding to the given option will be printed. Signed-off-by: Fan Yong Change-Id: If39f95ef984be3ab709b1366fdefe8eedb4b2453 Reviewed-on: https://review.whamcloud.com/27810 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Jian Yu --- diff --git a/lustre/doc/lctl-barrier.8 b/lustre/doc/lctl-barrier.8 index 9fe55ad..a08c359 100644 --- a/lustre/doc/lctl-barrier.8 +++ b/lustre/doc/lctl-barrier.8 @@ -7,7 +7,7 @@ .B lctl barrier_thaw \fR{fsname} .br .br -.B lctl barrier_stat \fR{fsname} +.B lctl barrier_stat \fR[--state|-s] [--timeout|-t] {fsname} .br .br .B lctl barrier_rescan \fR{fsname} [timeout] @@ -37,7 +37,7 @@ blocked metadata modifications (because of the former .B barrier_freeze command) will be handled normally. .TP -.B barrier_stat \fR{fsname} +.B barrier_stat \fR[--state|-s] [--timeout|-t] {fsname} .br Query the write barrier status, the possible status and related meanings are as following: @@ -54,7 +54,14 @@ as following: 'unknown': other cases .br If the barrier is in 'freezing_p1', 'freezing_p2' or 'frozen' status, then -the lifetime remaining will be returned also. +the lifetime remaining will be returned also. If no option is specified, +or both "-s" and "-t" options are specified, then the output format is: + + state: xxx + timeout: nnn seconds + +Otherwise, only the value ('xxx' or 'nnn') corresponding to the given option +will be printed. .TP .B barrier_rescan \fR{fsname} [timeout] .br diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 41471e4..d3c80b4 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -16457,6 +16457,30 @@ post_801() { stop_full_debug_logging } +barrier_stat() { + if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then + local st=$(do_facet mgs $LCTL barrier_stat $FSNAME | + awk '/The barrier for/ { print $7 }') + echo $st + else + local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME) + echo \'$st\' + fi +} + +barrier_expired() { + local expired + + if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then + expired=$(do_facet mgs $LCTL barrier_stat $FSNAME | + awk '/will be expired/ { print $7 }') + else + expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME) + fi + + echo $expired +} + test_801a() { prep_801 @@ -16466,34 +16490,29 @@ test_801a() { do_facet mgs $LCTL barrier_freeze $FSNAME 10 & sleep 2 - local b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + local b_status=$(barrier_stat) echo "Got barrier status at: $(date)" [ "$b_status" = "'freezing_p1'" ] || error "(1) unexpected barrier status $b_status" do_facet mgs $LCTL set_param fail_val=0 fail_loc=0 wait - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'frozen'" ] || error "(2) unexpected barrier status $b_status" - local expired=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/will be expired/ { print $7 }') + local expired=$(barrier_expired) echo "sleep $((expired + 3)) seconds, then the barrier will be expired" sleep $((expired + 3)) - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'expired'" ] || error "(3) unexpected barrier status $b_status" do_facet mgs $LCTL barrier_freeze $FSNAME 10 || error "(4) fail to freeze barrier" - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'frozen'" ] || error "(5) unexpected barrier status $b_status" @@ -16503,16 +16522,14 @@ test_801a() { do_facet mgs $LCTL barrier_thaw $FSNAME & sleep 2 - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) echo "Got barrier status at: $(date)" [ "$b_status" = "'thawing'" ] || error "(6) unexpected barrier status $b_status" do_facet mgs $LCTL set_param fail_val=0 fail_loc=0 wait - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'thawed'" ] || error "(7) unexpected barrier status $b_status" @@ -16520,8 +16537,7 @@ test_801a() { do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203 do_facet mgs $LCTL barrier_freeze $FSNAME - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'failed'" ] || error "(8) unexpected barrier status $b_status" @@ -16546,8 +16562,7 @@ test_801b() { # 180 seconds should be long enough do_facet mgs $LCTL barrier_freeze $FSNAME 180 - local b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + local b_status=$(barrier_stat) [ "$b_status" = "'frozen'" ] || error "(6) unexpected barrier status $b_status" @@ -16569,8 +16584,7 @@ test_801b() { stat $DIR/$tdir/d5 || error "(7) stat should succeed" # To guarantee taht the 'stat' is not blocked - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'frozen'" ] || error "(8) unexpected barrier status $b_status" @@ -16583,14 +16597,12 @@ test_801b() { ps -p $mv_pid || error "(12) rename should be blocked" ps -p $rm_pid || error "(13) unlink should be blocked" - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'frozen'" ] || error "(14) unexpected barrier status $b_status" do_facet mgs $LCTL barrier_thaw $FSNAME - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'thawed'" ] || error "(15) unexpected barrier status $b_status" @@ -16613,8 +16625,7 @@ test_801c() { do_facet mgs $LCTL barrier_freeze $FSNAME 30 - local b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + local b_status=$(barrier_stat) [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || { do_facet mgs $LCTL barrier_thaw $FSNAME error "(2) unexpected barrier status $b_status" @@ -16625,14 +16636,12 @@ test_801c() { do_facet mgs $LCTL barrier_freeze $FSNAME 10 - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'frozen'" ] || error "(4) unexpected barrier status $b_status" do_facet mgs $LCTL barrier_thaw $FSNAME - b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME | - awk '/The barrier for/ { print $7 }') + b_status=$(barrier_stat) [ "$b_status" = "'thawed'" ] || error "(5) unexpected barrier status $b_status" diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 0184412..788fc53 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -255,7 +255,7 @@ command_t cmdlist[] = { "usage: barrier_thaw "}, {"barrier_stat", jt_barrier_stat, 0, "query write barrier status on MDTs\n" - "usage: barrier_stat "}, + "usage: barrier_stat [--state|-s] [--timeout|-t] "}, {"barrier_rescan", jt_barrier_rescan, 0, "rescan the system to filter out inactive MDT(s) for barrier\n" "usage: barrier_rescan [timeout (in seconds)]"}, diff --git a/lustre/utils/lsnapshot.c b/lustre/utils/lsnapshot.c index 4fef5c0..856c6e9 100644 --- a/lustre/utils/lsnapshot.c +++ b/lustre/utils/lsnapshot.c @@ -1379,8 +1379,7 @@ out: if (!rc && !rc1) { struct barrier_ctl bc; - __argv[0] = "barrier_stat"; - rc = __jt_barrier_stat(2, __argv, &bc); + rc = __jt_barrier_stat(__argv[1], &bc); if (rc) { SNAPSHOT_ADD_LOG(si, "Can't get barrier status " "on %s: rc = %d\n", diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 05c6498..2e24e39 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -4202,7 +4202,7 @@ int jt_barrier_thaw(int argc, char **argv) return rc; } -int __jt_barrier_stat(int argc, char **argv, struct barrier_ctl *bc) +int __jt_barrier_stat(const char *fsname, struct barrier_ctl *bc) { struct obd_ioctl_data data; char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; @@ -4216,7 +4216,7 @@ int __jt_barrier_stat(int argc, char **argv, struct barrier_ctl *bc) memset(bc, 0, sizeof(*bc)); bc->bc_version = BARRIER_VERSION_V1; bc->bc_cmd = BC_STAT; - strncpy(bc->bc_name, argv[1], sizeof(bc->bc_name)); + strncpy(bc->bc_name, fsname, sizeof(bc->bc_name)); data.ioc_inlbuf1 = (char *)bc; data.ioc_inllen1 = sizeof(*bc); memset(buf, 0, sizeof(rawbuf)); @@ -4229,7 +4229,7 @@ int __jt_barrier_stat(int argc, char **argv, struct barrier_ctl *bc) rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf); if (rc < 0) fprintf(stderr, "Fail to query barrier for %s: %s\n", - argv[1], strerror(errno)); + fsname, strerror(errno)); else obd_ioctl_unpack(&data, buf, sizeof(rawbuf)); @@ -4239,26 +4239,68 @@ int __jt_barrier_stat(int argc, char **argv, struct barrier_ctl *bc) int jt_barrier_stat(int argc, char **argv) { struct barrier_ctl bc; + static struct option long_opt_barrier_stat[] = { + { + .val = 's', + .name = "state", + .has_arg = no_argument, + }, + { .val = 't', + .name = "timeout", + .has_arg = no_argument, + }, + { + NULL + } + }; + const char *name; + int index; + int opt; int rc; + bool state = false; + bool timeout = false; + + while ((opt = getopt_long(argc, argv, "st", long_opt_barrier_stat, + &index)) != EOF) { + switch (opt) { + case 's': + state = true; + break; + case 't': + timeout = true; + break; + default: + return CMD_HELP; + } + } - if (argc != 2) + if (optind >= argc) return CMD_HELP; - if (strlen(argv[1]) > 8) { + name = argv[optind]; + if (strlen(name) > 8) { fprintf(stderr, "fsname name %s is too long. " - "It should not exceed 8.\n", argv[1]); + "It should not exceed 8.\n", name); return -EINVAL; } - rc = __jt_barrier_stat(argc, argv, &bc); + rc = __jt_barrier_stat(name, &bc); if (!rc) { - printf("The barrier for %s is in '%s'\n", - argv[1], barrier_status2name(bc.bc_status)); - if (bc.bc_status == BS_FREEZING_P1 || - bc.bc_status == BS_FREEZING_P2 || - bc.bc_status == BS_FROZEN) - printf("The barrier will be expired after %d " - "seconds\n", bc.bc_timeout); + if (state && !timeout) + printf("%s\n", barrier_status2name(bc.bc_status)); + else if (timeout && !state) + printf("%d\n", + (bc.bc_status == BS_FREEZING_P1 || + bc.bc_status == BS_FREEZING_P2 || + bc.bc_status == BS_FROZEN) ? + bc.bc_timeout : 0); + else + printf("state: %s\ntimeout: %d seconds\n", + barrier_status2name(bc.bc_status), + (bc.bc_status == BS_FREEZING_P1 || + bc.bc_status == BS_FREEZING_P2 || + bc.bc_status == BS_FROZEN) ? + bc.bc_timeout : 0); } return rc; diff --git a/lustre/utils/obdctl.h b/lustre/utils/obdctl.h index bfb6b26..ad2c56a 100644 --- a/lustre/utils/obdctl.h +++ b/lustre/utils/obdctl.h @@ -167,7 +167,7 @@ int jt_lcfg_listparam(int argc, char **argv); int jt_pool_cmd(int argc, char **argv); int jt_barrier_freeze(int argc, char **argv); int jt_barrier_thaw(int argc, char **argv); -int __jt_barrier_stat(int argc, char **argv, struct barrier_ctl *bc); +int __jt_barrier_stat(const char *fsname, struct barrier_ctl *bc); int jt_barrier_stat(int argc, char **argv); int jt_barrier_rescan(int argc, char **argv); int jt_snapshot_create(int argc, char **argv);