Whamcloud - gitweb
LU-13107 utils: clean up lctl command usage
[fs/lustre-release.git] / lustre / utils / lctl.c
index 4ed25e8..7e7bb7c 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/utils/lctl.c
  *
 
 static int lctl_list_commands(int argc, char **argv);
 
-static int jt_opt_ignore_errors(int argc, char **argv) {
-        Parser_ignore_errors(1);
-        return 0;
+static int jt_opt_ignore_errors(int argc, char **argv)
+{
+       Parser_ignore_errors(1);
+       return 0;
 }
 
+static int jt_pcc_list_commands(int argc, char **argv);
+static int jt_pcc(int argc, char **argv);
+
+/**
+ * command_t pccdev_cmdlist - lctl pcc commands.
+ */
+command_t pccdev_cmdlist[] = {
+       { .pc_name = "add", .pc_func = jt_pcc_add,
+         .pc_help = "Add a PCC backend to a client.\n"
+               "usage: lctl pcc add <mntpath> <pccpath> [--param|-p <param>]\n"
+               "\tmntpath: Lustre mount point.\n"
+               "\tpccpath: Path of the PCC backend.\n"
+               "\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 <mntpath> <pccpath>\n" },
+       { .pc_name = "clear", .pc_func = jt_pcc_clear,
+         .pc_help = "Remove all PCC backend on a client.\n"
+               "usage: lctl pcc clear <mntpath>\n" },
+       { .pc_name = "list", .pc_func = jt_pcc_list,
+         .pc_help = "List all PCC backends on a client.\n"
+               "usage: lctl pcc list <mntpath>\n" },
+       { .pc_name = "list-commands", .pc_func = jt_pcc_list_commands,
+         .pc_help = "list commands supported by lctl pcc"},
+       { .pc_name = "help", .pc_func = Parser_help, .pc_help = "help" },
+       { .pc_name = "exit", .pc_func = Parser_quit, .pc_help = "quit" },
+       { .pc_name = "quit", .pc_func = Parser_quit, .pc_help = "quit" },
+       { .pc_help = NULL }
+};
+
 command_t cmdlist[] = {
        /* Metacommands */
        {"===== metacommands =======", NULL, 0, "metacommands"},
@@ -84,13 +114,13 @@ command_t cmdlist[] = {
        {"===== network config =====", NULL, 0, "network config"},
        {"--net", jt_opt_net, 0, "run <command> after selecting network <net>\n"
         "usage: --net <tcp/o2ib/...> <command>"},
-       {"network", jt_ptl_network, 0, "configure LNET"
+       {"network", jt_ptl_network, 0, "configure LNET\n"
         "usage: network up|down"},
-       {"net", jt_ptl_network, 0, "configure LNET"
+       {"net", jt_ptl_network, 0, "configure LNET\n"
         "usage: net up|down"},
-       {"list_nids", jt_ptl_list_nids, 0, "list local NIDs"
+       {"list_nids", jt_ptl_list_nids, 0, "list local NIDs\n"
         "usage: list_nids [all]"},
-       {"which_nid", jt_ptl_which_nid, 0, "choose a NID"
+       {"which_nid", jt_ptl_which_nid, 0, "choose a NID\n"
         "usage: which_nid NID [NID...]"},
        {"replace_nids", jt_replace_nids, 0,
         "replace primary NIDs for a device\n"
@@ -104,10 +134,10 @@ command_t cmdlist[] = {
         "print all the remote LNet connections\n"
         "usage: conn_list"},
        {"route_list", jt_ptl_print_routes, 0,
-        "print the LNet routing table, same as show_route\n"
+        "print the LNet routing table, same as 'show_route'\n"
         "usage: route_list"},
        {"show_route", jt_ptl_print_routes, 0,
-        "print the LNet routing table, same as route_list\n"
+        "print the LNet routing table, same as 'route_list'\n"
         "usage: show_route"},
        {"ping", jt_ptl_ping, 0, "Check LNET connectivity\n"
         "usage: ping nid [timeout] [pid]"},
@@ -149,9 +179,12 @@ command_t cmdlist[] = {
        {"device", jt_obd_device, 0,
         "set current device to <name|devno>\n"
         "usage: device <%name|$name|devno>"},
+       {"cfg_device", jt_obd_device, 0,
+        "set current device to <name>, same as 'device'\n"
+        "usage: cfg_device <name>"},
        {"device_list", jt_obd_list, 0, "show all devices\n"
         "usage: device_list"},
-       {"dl", jt_obd_list, 0, "show all devices\n"
+       {"dl", jt_obd_list, 0, "show all devices, same as 'device_list'\n"
         "usage: dl [-t]"},
 
        /* Device operations */
@@ -161,6 +194,11 @@ command_t cmdlist[] = {
         "This command should be used on failed OSC devices in an MDT LOV.\n"},
        {"abort_recovery", jt_obd_abort_recovery, 0,
         "abort recovery on a restarting MDT or OST device\n"},
+       {"abort_recovery_mdt", jt_obd_abort_recovery_mdt, 0,
+        "abort recovery between MDTs\n"},
+       {"recover", jt_obd_recover, 0,
+        "try to restore a lost connection immediately\n"
+        "usage: recover [MDC/OSC device]"},
        {"set_timeout", jt_lcfg_set_timeout, 0,
         "usage: conf_param obd_timeout=<secs>\n"},
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
@@ -205,16 +243,16 @@ command_t cmdlist[] = {
         "debug daemon control and dump to a file\n"
         "usage: debug_daemon {start file [#MB]|stop}"},
        {"debug_kernel", jt_dbg_debug_kernel, 0,
-        "get debug buffer and dump to a file, same as dk\n"
+        "get debug buffer and dump to a file, same as 'dk'\n"
         "usage: debug_kernel [file] [raw]"},
        {"dk", jt_dbg_debug_kernel, 0,
-        "get debug buffer and dump to a file, same as debug_kernel\n"
+        "get debug buffer and dump to a file, same as 'debug_kernel'\n"
         "usage: dk [file] [raw]"},
        {"debug_file", jt_dbg_debug_file, 0,
         "convert a binary debug file dumped by the kernel to ASCII text\n"
         "usage: debug_file <input> [output]"},
        {"df", jt_dbg_debug_file, 0,
-        "read debug buffer from input and dump to output, same as debug_file\n"
+        "read debug log from input convert to ASCII, same as 'debug_file'\n"
         "usage: df <input> [output]"},
        {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
         "usage: clear"},
@@ -302,6 +340,12 @@ command_t cmdlist[] = {
         "usage: snapshot_umount <-F | --fsname fsname> [-h | --help]\n"
         "                       <-n | --name ssname>\n"
         "                       [-r | --rsh remote_shell]"},
+       {"fork_lcfg", jt_lcfg_fork, 0,
+        "copy configuration files for named filesystem with given name\n"
+        "usage: fork_lcfg <fsname> <newname>"},
+       {"erase_lcfg", jt_lcfg_erase, 0,
+        "permanently erase configuration for the named filesystem\n"
+        "usage: erase_lcfg <fsname>"},
 #endif /* HAVE_SERVER_SUPPORT */
        /* Nodemap commands */
        {"=== Nodemap ===", NULL, 0, "nodemap management"},
@@ -321,7 +365,7 @@ command_t cmdlist[] = {
         "add a range to a nodemap\n"
         "usage: nodemap_del_range <nid_range>"},
        {"nodemap_modify", jt_nodemap_modify, 0,
-        "modify a nodemap parameters"
+        "modify a nodemap parameters\n"
         "usage: nodemap_modify nodemap_name param value"},
        {"nodemap_add_idmap", jt_nodemap_add_idmap, 0,
         "add a UID or GID mapping to a nodemap"},
@@ -349,6 +393,15 @@ command_t cmdlist[] = {
         "deregister an existing changelog user\n"
         "usage: --device <mdtname> changelog_deregister <id>"},
 
+       /* Persistent Client Cache (PCC) commands */
+       {"=== Persistent Client Cache ===", NULL, 0, "PCC user management"},
+       {"pcc", jt_pcc, pccdev_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"
+        "lctl pcc clear  - remove all PCC backends on a client\n"
+        "lctl pcc list   - list all PCC backends on a client\n"},
+
        /* Device configuration commands */
        {"== device setup (these are not normally used post 1.4) ==",
                NULL, 0, "device config"},
@@ -373,6 +426,68 @@ command_t cmdlist[] = {
         "permanently erase configuration for the named filesystem\n"
         "usage: erase_lcfg <fsname>"},
 
+#ifdef HAVE_SERVER_SUPPORT
+       /* LFSCK commands */
+       {"==== LFSCK ====", NULL, 0, "LFSCK"},
+       {"lfsck_start", jt_lfsck_start, 0, "start LFSCK\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 lfsck_type[,lfsck_type...]]\n"
+        "                   [--window-size|-w size]"},
+       {"lfsck_stop", jt_lfsck_stop, 0, "stop lfsck(s)\n"
+        "usage: lfsck_stop [--device|-M [MDT,OST]_device]\n"
+        "                  [--all|-A] [--help|-h]"},
+       {"lfsck_query", jt_lfsck_query, 0, "check lfsck(s) status\n"
+        "usage: lfsck_query [--device|-M MDT_device] [--help|-h]\n"
+        "                   [--type|-t lfsck_type[,lfsck_type...]]\n"
+        "                   [--wait|-w]"},
+#endif /* HAVE_SERVER_SUPPORT */
+
+       /* Llog operations */
+       {"==== LLOG ====", NULL, 0, "LLOG"},
+       {"llog_catlist", jt_llog_catlist, 0,
+        "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"
+        "usage: llog_info <logname|FID>\n"},
+       {"llog_print", jt_llog_print, 0,
+        "print log content information.\n"
+        "usage: llog_print <logname|FID> [--start <index>] [--end <index>j]\n"
+        "       print all records by default, or within given index range."},
+       {"llog_cancel", jt_llog_cancel, 0,
+        "cancel one record in specified log.\n"
+        "usage:llog_cancel <logname|FID> --log_idx <idx>\n"},
+       {"llog_check", jt_llog_check, 0,
+        "verify that log content is valid.\n"
+        "usage: llog_check <logname|FID> [--start <index>] [--end <index>j]\n"
+        "       check all records from index 1 by default."},
+       {"llog_remove", jt_llog_remove, 0,
+        "remove one log from catalog or plain log, erase it from disk.\n"
+        "usage: llog_remove <logname|FID> [--log_id <id>]"},
+
+       {"==== obsolete (DANGEROUS) ====", NULL, 0, "obsolete (DANGEROUS)"},
+       /* network operations */
+       {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
+        "usage: add_interface ip [netmask]"},
+       {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
+        "usage: del_interface [ip]"},
+       {"add_route", jt_ptl_add_route, 0,
+        "add an entry to the LNet routing table\n"
+        "usage: add_route <gateway> [<hops> [<priority>]]"},
+       {"del_route", jt_ptl_del_route, 0,
+        "delete route via gateway to targets from the LNet routing table\n"
+        "usage: del_route <gateway> [<target>] [<target>]"},
+       {"set_route", jt_ptl_notify_router, 0,
+        "enable/disable routes via gateway in the LNet routing table\n"
+        "usage: set_route <gateway> <up/down> [<time>]"},
+
        /* Test only commands */
        {"==== testing (DANGEROUS) ====", NULL, 0, "testing (DANGEROUS)"},
        {"--threads", jt_opt_threads, 0,
@@ -382,8 +497,10 @@ command_t cmdlist[] = {
         "usage: lookup <directory> <file>"},
        {"readonly", jt_obd_set_readonly, 0,
         "disable writes to the underlying device\n"},
+#ifdef HAVE_SERVER_SUPPORT
        {"notransno", jt_obd_no_transno, 0,
         "disable sending of committed-transno updates\n"},
+#endif
        {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a NID\n"
         "usage: add_uuid <uuid> <nid>"},
        {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
@@ -408,7 +525,7 @@ command_t cmdlist[] = {
         "otherwise fail 'count' messages.\n"
         "usage: fail nid|_all_ [count]"},
 
-       /*Test commands for echo client*/
+       /* Test commands for echo client */
        {"test_create", jt_obd_test_create, 0,
         "create files on MDT by echo client\n"
         "usage: test_create [-d parent_basedir] <-D parent_count> "
@@ -462,109 +579,83 @@ command_t cmdlist[] = {
         "get the version of an object on servers\n"
         "usage: getobjversion <fid>\n"
         "       getobjversion -i <id> -g <group>"},
-#ifdef HAVE_SERVER_SUPPORT
-       /* LFSCK commands */
-       {"==== LFSCK ====", NULL, 0, "LFSCK"},
-       {"lfsck_start", jt_lfsck_start, 0, "start LFSCK\n"
-        "usage: lfsck_start [-M | --device [MDT,OST]_device]\n"
-        "                   [-A | --all] [-c | --create-ostobj [on | off]]\n"
-        "                   [-C | --create-mdtobj [on | off]]\n"
-        "                   [-d | --delay-create-ostobj [on | off]]\n"
-        "                   [-e | --error {continue | abort}] [-h | --help]\n"
-        "                   [-n | --dryrun [on | off]] [-o | --orphan]\n"
-        "                   [-r | --reset] [-s | --speed speed_limit]\n"
-        "                   [-t | --type lfsck_type[,lfsck_type...]]\n"
-        "                   [-w | --window-size size]"},
-       {"lfsck_stop", jt_lfsck_stop, 0, "stop lfsck(s)\n"
-        "usage: lfsck_stop [-M | --device [MDT,OST]_device]\n"
-        "                  [-A | --all] [-h | --help]"},
-       {"lfsck_query", jt_lfsck_query, 0, "check lfsck(s) status\n"
-        "usage: lfsck_query [-M | --device MDT_device] [-h | --help]\n"
-        "                   [-t | --type lfsck_type[,lfsck_type...]]\n"
-        "                   [-w | --wait]"},
-#endif /* HAVE_SERVER_SUPPORT */
-       {"==== obsolete (DANGEROUS) ====", NULL, 0, "obsolete (DANGEROUS)"},
-       /* some test scripts still use these */
-       {"cfg_device", jt_obd_device, 0,
-        "set current device to <name>\n"
-        "usage: device <name>"},
-       {"recover", jt_obd_recover, 0,
-        "try to restore a lost connection immediately\n"
-        "usage: recover [MDC/OSC device]"},
-       /* saving for sanity 44a */
-       {"lov_getconfig", jt_obd_lov_getconfig, 0,
-        "read lov configuration from an mds device\n"
-        "usage: lov_getconfig <mountpoint>"},
-       /* Llog operations */
-       {"llog_catlist", jt_llog_catlist, 0,
-        "list all catalog logs on current device.\n"
-        "usage: llog_catlist"},
-       {"llog_info", jt_llog_info, 0,
-        "print log header information.\n"
-        "usage: llog_info <logname|[FID]>\n"
-        "       oid, ogr and ogen are hexadecimal."},
-       {"llog_print", jt_llog_print, 0,
-        "print log content information.\n"
-        "usage: llog_print <logname|[FID]> [start_index [end_index]]\n"
-        "       print all records from index 1 by default."},
-       {"llog_check", jt_llog_check, 0,
-        "print log content information.\n"
-        "usage: llog_check <logname|[FID]> [start_index] [end_index]\n"
-        "       check all records from index 1 by default."},
-       {"llog_cancel", jt_llog_cancel, 0,
-        "cancel one record in log.\n"
-        "This command supports both positional and optional arguments\n"
-        "usage (positional args): "
-        "llog_cancel <catalog name|[FID]> [log id] <index>\n"
-        "usage (optional args): "
-        "llog_cancel --catalog <catalog id|catalog name> --log_id <log_id> "
-        "--log_idx <index>"},
-       {"llog_remove", jt_llog_remove, 0,
-        "remove one log from catalog or plain log, erase it from disk.\n"
-        "usage: llog_remove <catalog name|[FID]> <log id>"},
-       /* network operations */
-       {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
-        "usage: add_interface ip [netmask]"},
-       {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
-        "usage: del_interface [ip]"},
-       {"add_route", jt_ptl_add_route, 0,
-        "add an entry to the LNet routing table\n"
-        "usage: add_route <gateway> [<hops> [<priority>]]"},
-       {"del_route", jt_ptl_del_route, 0,
-        "delete route via gateway to targets from the LNet routing table\n"
-        "usage: del_route <gateway> [<target>] [<target>]"},
-       {"set_route", jt_ptl_notify_router, 0,
-        "enable/disable routes via gateway in the LNet routing table\n"
-        "usage: set_route <gateway> <up/down> [<time>]"},
-
        { 0, 0, 0, NULL }
 };
 
+/**
+ * jt_pcc_list_commands() - List lctl pcc commands.
+ * @argc: The count of command line arguments.
+ * @argv: Array of strings for command line arguments.
+ *
+ * This function lists lctl pcc commands defined in pccdev_cmdlist[].
+ *
+ * Return: 0 on success.
+ */
+static int jt_pcc_list_commands(int argc, char **argv)
+{
+       char buffer[81] = "";
+
+       Parser_list_commands(pccdev_cmdlist, buffer, sizeof(buffer),
+                            NULL, 0, 4);
+
+       return 0;
+}
+
+/**
+ * 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);
+
+       Parser_init("lctl-pcc > ", pccdev_cmdlist);
+
+       snprintf(cmd, sizeof(cmd), "%s %s", program_invocation_short_name,
+                argv[0]);
+       program_invocation_short_name = cmd;
+       if (argc > 1)
+               rc = Parser_execarg(argc - 1, argv + 1, pccdev_cmdlist);
+       else
+               rc = Parser_commands();
+
+       return rc < 0 ? -rc : rc;
+}
+
 int lctl_main(int argc, char **argv)
 {
-        int rc;
+       int rc;
 
-        setlinebuf(stdout);
+       setlinebuf(stdout);
 
        if (ptl_initialize(argc, argv) < 0)
                exit(1);
-        if (obd_initialize(argc, argv) < 0)
-                exit(2);
-        if (dbg_initialize(argc, argv) < 0)
-                exit(3);
+       if (obd_initialize(argc, argv) < 0)
+               exit(2);
+       if (dbg_initialize(argc, argv) < 0)
+               exit(3);
 
        Parser_init("lctl > ", cmdlist);
 
-        if (argc > 1) {
+       if (argc > 1) {
                llapi_set_command_name(argv[1]);
-                rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
+               rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
                llapi_clear_command_name();
-        } else {
-                rc = Parser_commands();
-        }
+       } else {
+               rc = Parser_commands();
+       }
 
-        obd_finalize(argc, argv);
-        return rc < 0 ? -rc : rc;
+       obd_finalize(argc, argv);
+       return rc < 0 ? -rc : rc;
 }
 
 static int lctl_list_commands(int argc, char **argv)