From 25860230aa806351e946a5c1c585e50521983d8e Mon Sep 17 00:00:00 2001 From: Etienne AUJAMES Date: Fri, 12 Jun 2020 18:06:43 +0200 Subject: [PATCH] LU-13056 utils: Default MGS device llog_print/llog_catlist Add the default device "MGS" for lctl llog_catlist, llog_print, llog_check, llog_remove, llog_cancel and llog_info. Example: The two lines below are equivalent. $ lctl --device MGS llog_catlist $ lctl llog_catlist Tests 123xx of conf_sanity have been modified to mix between the old and new syntax. lctl-llog_* man page have been modified to match the new syntax. Signed-off-by: Etienne AUJAMES Change-Id: If988dfc5d8171b2ca47bb68dd06f9d2953548cb2 Reviewed-on: https://review.whamcloud.com/38940 Reviewed-by: Andreas Dilger Reviewed-by: Emoly Liu Tested-by: jenkins Tested-by: Maloo --- lustre/doc/lctl-llog_cancel.8 | 7 ++-- lustre/doc/lctl-llog_catlist.8 | 13 +++++-- lustre/doc/lctl-llog_info.8 | 12 +++---- lustre/doc/lctl-llog_print.8 | 4 +-- lustre/tests/conf-sanity.sh | 26 ++++++++++---- lustre/utils/lctl.c | 3 +- lustre/utils/obd.c | 80 +++++++++++++++++++++++++++++++++++++----- 7 files changed, 113 insertions(+), 32 deletions(-) diff --git a/lustre/doc/lctl-llog_cancel.8 b/lustre/doc/lctl-llog_cancel.8 index 98d5a2e..ee60d81 100644 --- a/lustre/doc/lctl-llog_cancel.8 +++ b/lustre/doc/lctl-llog_cancel.8 @@ -2,8 +2,7 @@ .SH NAME lctl llog_cancel \- cancel a record in a Lustre llog file .SH SYNOPSIS -.B lctl --device -.RI < device > +.B lctl .B llog_cancel --log_idx .RI < index > .RI < logname > @@ -35,11 +34,11 @@ for that log. .TP To cancel record 15 from the \fBtestfs-client\fR conf_param log: .br -# lctl --device MGS llog_cancel --log_idx=15 testfs-client +# lctl llog_cancel --log_idx=15 testfs-client .TP To cancel record 22 from the \fBparams\fR set_param log: .br -# lctl --device MGS llog_cancel --log_idx=22 params +# lctl llog_cancel --log_idx=22 params .SH AVAILABILITY .B lctl llog_cancel is a subcommand of diff --git a/lustre/doc/lctl-llog_catlist.8 b/lustre/doc/lctl-llog_catlist.8 index 4c15432..0c0fa45 100644 --- a/lustre/doc/lctl-llog_catlist.8 +++ b/lustre/doc/lctl-llog_catlist.8 @@ -2,8 +2,9 @@ .SH NAME lctl llog_catlist \- list Lustre configuration log files .SH SYNOPSIS -.B lctl llog_catlist - +.B lctl +[--device <\fIdevice\fR>] +.B llog_catlist .SH DESCRIPTION .B lctl llog_catlist is used to list the configuration log files on the MGS, or other target. @@ -21,11 +22,17 @@ parameters are stored in these log files for the specified filesystem. The log file contains the .B lctl set_param -P parameters for all filesystems serviced by this MGS. +.SH OPTIONS +.TP +.B --device \fIdevice\fR +The +.I device +to be used. By default MGS device is used for this operation. .SH EXAMPLES .TP To list all of the configuration logs on the MGS: .br -# lctl --device MGS llog_catlist +# lctl llog_catlist .br config_log: testfs-OST0000 .br diff --git a/lustre/doc/lctl-llog_info.8 b/lustre/doc/lctl-llog_info.8 index eab53db..141055d 100644 --- a/lustre/doc/lctl-llog_info.8 +++ b/lustre/doc/lctl-llog_info.8 @@ -10,18 +10,18 @@ lctl llog_info \- print information about a Lustre configuration log is used to print information about the configuration log given by .IR logname . .SH OPTIONS -.B logname +.TP +.I logname The name of the configuration log, in the form .IR fsname - target , -like -.B testfs-client -or -.BR lustrefs-MDT0000 . +like \fBtestfs-client\fR or \fBlustrefs-MDT0000\fR. See +.BR lctl-llog_catlist (8) +for a list of configuration logs. .SH EXAMPLES .TP To print all of the records from the testfs-client configuration log: .br -# lctl --device MGS llog_info testfs-client +# lctl llog_info testfs-client .br logid: [0x4:0xa:0x0]:0 .br diff --git a/lustre/doc/lctl-llog_print.8 b/lustre/doc/lctl-llog_print.8 index ef0f208..30b4c9a 100644 --- a/lustre/doc/lctl-llog_print.8 +++ b/lustre/doc/lctl-llog_print.8 @@ -51,7 +51,7 @@ index number. .TP To print the configuration records from the \fBtestfs-client\fR logfile: .br -# lctl --device MGS llog_print testfs-client +# lctl llog_print testfs-client .br - { index: 3, event: attach, device: testfs-clilov, type: lov, .br @@ -74,7 +74,7 @@ To print the configuration records from the \fBtestfs-client\fR logfile: : .TP To print the first 10 \fBset_param -P\fR records from \fBparams\fR: -# lctl --device MGS llog_print --end=10 params +# lctl llog_print --end=10 params .br - { index: 2, event: set_param, device: general, parameter: osc.*.max_dirty_mb, value: 32 } .br diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh index 2de8aa6..d04a4bf 100644 --- a/lustre/tests/conf-sanity.sh +++ b/lustre/tests/conf-sanity.sh @@ -8677,11 +8677,15 @@ test_123ab() { local yaml local orig_val + local mgs_arg="" + + [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] || + mgs_arg="--device MGS" orig_val=$(do_facet mgs $LCTL get_param jobid_name) do_facet mgs $LCTL set_param -P jobid_name="TESTNAME" - yaml=$(do_facet mgs $LCTL --device MGS llog_print params | + yaml=$(do_facet mgs $LCTL $mgs_arg llog_print params | grep jobid_name | tail -n 1) local param=$(awk '{ print $10 }' <<< "$yaml") @@ -8700,12 +8704,16 @@ test_123ac() { # LU-11566 local start=10 local end=50 + local mgs_arg="" + + [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] || + mgs_arg="--device MGS" [ -d $MOUNT/.lustre ] || setup # - { index: 10, event: add_uuid, nid: 192.168.20.1@tcp(0x20000c0a81401, # node: 192.168.20.1@tcp } - do_facet mgs $LCTL --device MGS \ + do_facet mgs $LCTL $mgs_arg \ llog_print --start $start --end $end $FSNAME-client | tr -d , | while read DASH BRACE INDEX idx EVENT BLAH BLAH BLAH; do (( idx >= start )) || error "llog_print index $idx < $start" @@ -8745,26 +8753,30 @@ test_123ae() { # LU-11566 [ -d $MOUNT/.lustre ] || setupall local max=$($LCTL get_param -n osc.*-OST0000-*.max_dirty_mb | head -1) + local mgs_arg="" + + [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] || + mgs_arg="--device MGS" if do_facet mgs "$LCTL help llog_cancel" 2>&1| grep -q -- --log_id; then # save one set_param -P record in case none exist do_facet mgs $LCTL set_param -P osc.*.max_dirty_mb=$max local log=params - local orig=$(do_facet mgs $LCTL --device MGS llog_print $log | + local orig=$(do_facet mgs $LCTL $mgs_arg llog_print $log | tail -1 | awk '{ print $4 }' | tr -d , ) do_facet mgs $LCTL set_param -P osc.*.max_dirty_mb=$max - do_facet mgs $LCTL --device MGS llog_print $log | tail -1 | + do_facet mgs $LCTL $mgs_arg llog_print $log | tail -1 | grep "parameter: osc.*.max_dirty_mb" || error "new set_param -P wasn't stored in params log" # - { index: 71, event: set_param, device: general, # param: osc.*.max_dirty_mb, value: 256 } - local id=$(do_facet mgs $LCTL --device MGS llog_print $log | + local id=$(do_facet mgs $LCTL $mgs_arg llog_print $log | tail -1 | awk '{ print $4 }' | tr -d , ) - do_facet mgs $LCTL --device MGS llog_cancel $log --log_idx=$id - local new=$(do_facet mgs $LCTL --device MGS llog_print $log | + do_facet mgs $LCTL $mgs_arg llog_cancel $log --log_idx=$id + local new=$(do_facet mgs $LCTL $mgs_arg llog_print $log | tail -1 | awk '{ print $4 }' | tr -d , ) (( new == orig )) || error "new llog_cancel now $new, not at $orig records" diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 117d2a8..dde98b3 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -533,7 +533,8 @@ command_t cmdlist[] = { "usage: recover [MDC/OSC device]"}, /* Llog operations */ {"llog_catlist", jt_llog_catlist, 0, - "list all catalog files on current device.\n" + "list all catalog files on current device. If current device is not\n" + "set, MGS device is used by default.\n" "usage: llog_catlist"}, {"llog_info", jt_llog_info, 0, "print log header information.\n" diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index f245a35..2940dfe 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -2635,6 +2635,30 @@ int jt_lcfg_erase(int argc, char **argv) return rc; } +enum llog_default_dev_op { + LLOG_DFLT_MGS_SET = 0, + LLOG_DFLT_DEV_RESET +}; + +static int llog_default_device(enum llog_default_dev_op op) +{ + int rc = 0; + static int dflt_dev = -1; + + if (op == LLOG_DFLT_MGS_SET && (cur_device == -1)) { + char mgs[] = "$MGS"; + + rc = do_device("llog_default_device", mgs); + dflt_dev = cur_device; + + } else if (op == LLOG_DFLT_DEV_RESET && (dflt_dev != -1)) { + do_disconnect(NULL, 1); + dflt_dev = -1; + } + + return rc; +} + int jt_llog_catlist(int argc, char **argv) { struct obd_ioctl_data data; @@ -2646,6 +2670,9 @@ int jt_llog_catlist(int argc, char **argv) if (argc != 1) return CMD_HELP; + if (llog_default_device(LLOG_DFLT_MGS_SET)) + return CMD_INCOMPLETE; + do { memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; @@ -2657,7 +2684,7 @@ int jt_llog_catlist(int argc, char **argv) if (rc) { fprintf(stderr, "error: %s: invalid ioctl\n", jt_cmdname(argv[0])); - return rc; + goto err; } rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CATLOGLIST, buf); if (rc < 0) @@ -2674,6 +2701,9 @@ int jt_llog_catlist(int argc, char **argv) fprintf(stderr, "OBD_IOC_CATLOGLIST failed: %s\n", strerror(errno)); +err: + llog_default_device(LLOG_DFLT_DEV_RESET); + return rc; } @@ -2715,6 +2745,10 @@ int jt_llog_info(int argc, char **argv) return CMD_HELP; } + /* Manage default device */ + if (llog_default_device(LLOG_DFLT_MGS_SET)) + return CMD_INCOMPLETE; + data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(catalog) + 1; data.ioc_inlbuf1 = catalog; @@ -2724,7 +2758,7 @@ int jt_llog_info(int argc, char **argv) if (rc) { fprintf(stderr, "%s: ioctl_pack failed for catalog '%s': %s\n", jt_cmdname(cmd), catalog, strerror(-rc)); - return rc; + goto err; } rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_INFO, buf); @@ -2734,6 +2768,9 @@ int jt_llog_info(int argc, char **argv) fprintf(stderr, "%s: OBD_IOC_LLOG_INFO failed: %s\n", jt_cmdname(cmd), strerror(errno)); +err: + llog_default_device(LLOG_DFLT_DEV_RESET); + return rc; } @@ -2999,9 +3036,14 @@ int jt_llog_print(int argc, char **argv) if (rc) return rc; + if (llog_default_device(LLOG_DFLT_MGS_SET)) + return CMD_INCOMPLETE; + rc = jt_llog_print_iter(catalog, start, end, jt_llog_print_cb, NULL, false); + llog_default_device(LLOG_DFLT_DEV_RESET); + return rc; } @@ -3075,6 +3117,10 @@ int jt_llog_cancel(int argc, char **argv) char *cmd = argv[0]; int rc; + /* Manage default device */ + if (llog_default_device(LLOG_DFLT_MGS_SET)) + return CMD_INCOMPLETE; + /* Parse catalog file (in inlbuf1) and named parameters */ rc = llog_parse_catalog_log_idx(&argc, &argv, "c:hi:l:", 3, &data); @@ -3094,15 +3140,17 @@ int jt_llog_cancel(int argc, char **argv) data.ioc_inlbuf3 = argv[1]; } - if (!data.ioc_inlbuf1 || !data.ioc_inlbuf3) + if (!data.ioc_inlbuf1 || !data.ioc_inlbuf3) { /* missing mandatory parameters */ - return CMD_HELP; + rc = CMD_HELP; + goto err; + } rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { fprintf(stderr, "%s: ioctl_pack for catalog '%s' failed: %s\n", jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc)); - return rc; + goto err; } rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CANCEL, buf); @@ -3111,6 +3159,8 @@ int jt_llog_cancel(int argc, char **argv) jt_cmdname(cmd), data.ioc_inlbuf1, data.ioc_inlbuf3, strerror(errno)); +err: + llog_default_device(LLOG_DFLT_DEV_RESET); return rc; } @@ -3128,6 +3178,9 @@ int jt_llog_check(int argc, char **argv) if (rc) return rc; + if (llog_default_device(LLOG_DFLT_MGS_SET)) + return CMD_INCOMPLETE; + if (end == -1) end = 0x7fffffff; @@ -3151,7 +3204,7 @@ int jt_llog_check(int argc, char **argv) if (rc) { fprintf(stderr, "%s: ioctl_pack failed for catalog '%s': %s\n", jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc)); - return rc; + goto err; } rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_CHECK, buf); @@ -3160,6 +3213,8 @@ int jt_llog_check(int argc, char **argv) else fprintf(stderr, "%s: OBD_IOC_LLOG_CHECK failed: %s\n", jt_cmdname(cmd), strerror(errno)); +err: + llog_default_device(LLOG_DFLT_DEV_RESET); return rc; } @@ -3170,26 +3225,31 @@ int jt_llog_remove(int argc, char **argv) char *cmd = argv[0]; int rc; + if (llog_default_device(LLOG_DFLT_MGS_SET)) + return CMD_INCOMPLETE; + rc = llog_parse_catalog_log_idx(&argc, &argv, "c:hl:", 2, &data); if (rc) - return rc; + goto err; if (argc == 1) { if (data.ioc_inlbuf2) { fprintf(stderr, "%s: --log_id is set, unknown argument '%s'\n", jt_cmdname(cmd), argv[0]); - return CMD_HELP; + rc = CMD_HELP; + goto err; } data.ioc_inllen2 = strlen(argv[0]) + 1; data.ioc_inlbuf2 = argv[0]; } + rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { fprintf(stderr, "%s: ioctl_pack for catalog '%s' failed: %s\n", jt_cmdname(cmd), data.ioc_inlbuf1, strerror(-rc)); - return rc; + goto err; } rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LLOG_REMOVE, buf); @@ -3198,6 +3258,8 @@ int jt_llog_remove(int argc, char **argv) jt_cmdname(cmd), data.ioc_inlbuf1, data.ioc_inlbuf2, strerror(-rc)); +err: + llog_default_device(LLOG_DFLT_DEV_RESET); return rc; } -- 1.8.3.1