From: Emoly Liu Date: Thu, 15 Aug 2024 08:00:55 +0000 (+0800) Subject: LU-18114 lfsck: split "lctl lfsck_*" group into subcommands X-Git-Tag: 2.15.91~54 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=89b0bcdab5d7030cf8ad00f541e340fe539f3013;p=fs%2Flustre-release.git LU-18114 lfsck: split "lctl lfsck_*" group into subcommands Split "lctl lfsck_*" command group into subcommands, e.g. "lctl lfsck_start" to "lctl lfsck start". Also, sanity-lfsck.sh test_12a is modified a little to verify this patch. Signed-off-by: Emoly Liu Change-Id: I039f8942b45a16a26386b579919018163e0d8c7c Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55997 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Frederick Dilger Reviewed-by: Oleg Drokin --- diff --git a/lustre/tests/sanity-lfsck.sh b/lustre/tests/sanity-lfsck.sh index b9fb321..971fdbe 100755 --- a/lustre/tests/sanity-lfsck.sh +++ b/lustre/tests/sanity-lfsck.sh @@ -1492,6 +1492,13 @@ test_12a() { [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" (( $MDS1_VERSION > $(version_code 2.5.55) )) || skip "MDS older than 2.5.55, LU-3950" + if (( $MDS1_VERSION >= $(version_code 2.15.65) )); then + lfsck_start="lfsck start" + lfsck_stop="lfsck stop" + else + lfsck_start="lfsck_start" + lfsck_stop="lfsck_stop" + fi check_mount_and_prep for k in $(seq $MDSCOUNT); do @@ -1501,21 +1508,21 @@ test_12a() { done echo "Start namespace LFSCK on all targets by single command (-s 1)." - do_facet mds1 $LCTL lfsck_start -M ${FSNAME}-MDT0000 -t namespace -A \ + do_facet mds1 $LCTL $lfsck_start -M ${FSNAME}-MDT0000 -t namespace -A \ -s 1 -r || error "(2) Fail to start LFSCK on all devices!" echo "All the LFSCK targets should be in 'scanning-phase1' status." wait_all_targets namespace scanning-phase1 3 echo "Stop namespace LFSCK on all targets by single lctl command." - do_facet mds1 $LCTL lfsck_stop -M ${FSNAME}-MDT0000 -A || + do_facet mds1 $LCTL $lfsck_stop -M ${FSNAME}-MDT0000 -A || error "(4) Fail to stop LFSCK on all devices!" echo "All the LFSCK targets should be in 'stopped' status." wait_all_targets_blocked namespace stopped 5 echo "Re-start namespace LFSCK on all targets by single command (-s 0)." - do_facet mds1 $LCTL lfsck_start -M ${FSNAME}-MDT0000 -t namespace -A \ + do_facet mds1 $LCTL $lfsck_start -M ${FSNAME}-MDT0000 -t namespace -A \ -s 0 -r || error "(6) Fail to start LFSCK on all devices!" echo "All the LFSCK targets should be in 'completed' status." @@ -1524,14 +1531,14 @@ test_12a() { start_full_debug_logging echo "Start layout LFSCK on all targets by single command (-s 1)." - do_facet mds1 $LCTL lfsck_start -M ${FSNAME}-MDT0000 -t layout -A \ + do_facet mds1 $LCTL $lfsck_start -M ${FSNAME}-MDT0000 -t layout -A \ -s 1 -r || error "(8) Fail to start LFSCK on all devices!" echo "All the LFSCK targets should be in 'scanning-phase1' status." wait_all_targets layout scanning-phase1 9 echo "Stop layout LFSCK on all targets by single lctl command." - do_facet mds1 $LCTL lfsck_stop -M ${FSNAME}-MDT0000 -A || + do_facet mds1 $LCTL $lfsck_stop -M ${FSNAME}-MDT0000 -A || error "(10) Fail to stop LFSCK on all devices!" echo "All the LFSCK targets should be in 'stopped' status." @@ -1546,7 +1553,7 @@ test_12a() { done echo "Re-start layout LFSCK on all targets by single command (-s 0)." - do_facet mds1 $LCTL lfsck_start -M ${FSNAME}-MDT0000 -t layout -A \ + do_facet mds1 $LCTL $lfsck_start -M ${FSNAME}-MDT0000 -t layout -A \ -s 0 -r || error "(13) Fail to start LFSCK on all devices!" echo "All the LFSCK targets should be in 'completed' status." diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 564acfd..6cc06eb 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -47,12 +47,26 @@ #include #include "lctl_thread.h" -static int jt_pcc(int argc, char **argv); +#define JT_SUBCMD(name) \ +static int jt_##name(int argc, char **argv) \ +{ \ + char cmd[PATH_MAX]; \ + int rc = 0; \ + \ + setlinebuf(stdout); \ + \ + snprintf(cmd, sizeof(cmd), "%s %s", \ + program_invocation_short_name, argv[0]); \ + program_invocation_short_name = cmd; \ + rc = cfs_parser(argc, argv, name##_cmdlist); \ + \ + return rc < 0 ? -rc : rc; \ +} /** * command_t pccdev_cmdlist - lctl pcc commands. */ -command_t pccdev_cmdlist[] = { +command_t pcc_cmdlist[] = { { .pc_name = "add", .pc_func = jt_pcc_add, .pc_help = "Add a PCC backend to a client.\n" "usage: lctl pcc add [--param|-p ]\n" @@ -61,7 +75,7 @@ command_t pccdev_cmdlist[] = { "\tparam: Setting parameters for PCC backend.\n" }, { .pc_name = "del", .pc_func = jt_pcc_del, .pc_help = "Delete the specified PCC backend on a client.\n" - "usage: clt pcc del \n" }, + "usage: lctl pcc del \n" }, { .pc_name = "clear", .pc_func = jt_pcc_clear, .pc_help = "Remove all PCC backend on a client.\n" "usage: lctl pcc clear \n" }, @@ -70,6 +84,37 @@ command_t pccdev_cmdlist[] = { "usage: lctl pcc list \n" }, { .pc_help = NULL } }; +JT_SUBCMD(pcc); + +#ifdef HAVE_SERVER_SUPPORT +/** + * command_t lfsck_cmdlist - lctl lfsck commands. + */ +command_t lfsck_cmdlist[] = { + { .pc_name = "start", .pc_func = jt_lfsck_start, + .pc_help = "Start online Lustre File System Check.\n" + "usage: lfsck start [--device|-M {MDT,OST}_DEVICE]\n" + " [--all|-A] [--create-ostobj|-c [on | off]]\n" + " [--create-mdtobj|-C [on | off]]\n" + " [--delay-create-ostobj|-d [on | off]]\n" + " [--error|-e {continue | abort}] [--help|-h]\n" + " [--dryrun|-n [on | off]] [--orphan|-o]\n" + " [--reset|-r] [--speed|-s SPEED_LIMIT]\n" + " [--type|-t {all|default|scrub|layout|namespace}]\n" + " [--window-size|-w SIZE]"}, + { .pc_name = "stop", .pc_func = jt_lfsck_stop, + .pc_help = "Stop online Lustre File System Check.\n" + "usage: lfsck stop [--device|-M {MDT,OST}_DEVICE]\n" + " [--all|-A] [--help|-h]"}, + { .pc_name = "query", .pc_func = jt_lfsck_query, + .pc_help = "Get Lustre File System Check global status.\n" + "usage: lfsck query [--device|-M MDT_DEVICE] [--help|-h]\n" + " [--type|-t {all|default|scrub|layout|namespace}]\n" + " [--wait|-w]"}, + { .pc_help = NULL } +}; +JT_SUBCMD(lfsck); +#endif command_t cmdlist[] = { /* Metacommands */ @@ -366,7 +411,7 @@ command_t cmdlist[] = { /* Persistent Client Cache (PCC) commands */ {"=== Persistent Client Cache ===", NULL, 0, "PCC user management"}, - {"pcc", jt_pcc, pccdev_cmdlist, + {"pcc", jt_pcc, pcc_cmdlist, "lctl commands used to interact with PCC features:\n" "lctl pcc add - add a PCC backend to a client\n" "lctl pcc del - delete a PCC backend on a client\n" @@ -408,6 +453,7 @@ command_t cmdlist[] = { "usage: lfsck_query [--device|-M MDT_device] [--help|-h]\n" " [--type|-t lfsck_type[,lfsck_type...]]\n" " [--wait|-w]"}, + {"lfsck", jt_lfsck, lfsck_cmdlist, ""}, /* Llog operations */ {"==== LLOG ====", NULL, 0, "LLOG"}, @@ -558,31 +604,6 @@ command_t cmdlist[] = { { 0, 0, 0, NULL } }; -/** - * jt_pcc() - Parse and execute lctl pcc commands. - * @argc: The count of lctl pcc command line arguments. - * @argv: Array of strings for lctl pcc command line arguments. - * - * This function parses lfs pcc commands and performs the - * corresponding functions specified in pccdev_cmdlist[]. - * - * Return: 0 on success or an error code on failure. - */ -static int jt_pcc(int argc, char **argv) -{ - char cmd[PATH_MAX]; - int rc = 0; - - setlinebuf(stdout); - - snprintf(cmd, sizeof(cmd), "%s %s", program_invocation_short_name, - argv[0]); - program_invocation_short_name = cmd; - rc = cfs_parser(argc, argv, pccdev_cmdlist); - - return rc < 0 ? -rc : rc; -} - static int lctl_main(int argc, char **argv) { int rc;