Whamcloud - gitweb
LU-9710 utils: adjust barrier_stat input/output 10/27810/5
authorFan Yong <fan.yong@intel.com>
Wed, 19 Jul 2017 05:58:06 +0000 (13:58 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 1 Aug 2017 05:34:38 +0000 (05:34 +0000)
The command format will be:
lctl barrier_stat [--state|-s] [--timeout|-t] <fsname>

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 <fan.yong@intel.com>
Change-Id: If39f95ef984be3ab709b1366fdefe8eedb4b2453
Reviewed-on: https://review.whamcloud.com/27810
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
lustre/doc/lctl-barrier.8
lustre/tests/sanity.sh
lustre/utils/lctl.c
lustre/utils/lsnapshot.c
lustre/utils/obd.c
lustre/utils/obdctl.h

index 9fe55ad..a08c359 100644 (file)
@@ -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
index 41471e4..d3c80b4 100755 (executable)
@@ -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"
 
index 0184412..788fc53 100644 (file)
@@ -255,7 +255,7 @@ command_t cmdlist[] = {
         "usage: barrier_thaw <fsname>"},
        {"barrier_stat", jt_barrier_stat, 0,
         "query write barrier status on MDTs\n"
-        "usage: barrier_stat <fsname>"},
+        "usage: barrier_stat [--state|-s] [--timeout|-t] <fsname>"},
        {"barrier_rescan", jt_barrier_rescan, 0,
         "rescan the system to filter out inactive MDT(s) for barrier\n"
         "usage: barrier_rescan <fsname> [timeout (in seconds)]"},
index 4fef5c0..856c6e9 100644 (file)
@@ -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",
index 05c6498..2e24e39 100644 (file)
@@ -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;
index bfb6b26..ad2c56a 100644 (file)
@@ -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);