Whamcloud - gitweb
134e6fe3683609066aececb107897ddc4d80eae4
[fs/lustre-release.git] / lustre / utils / lctl.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/utils/lctl.c
32  *
33  * Author: Peter J. Braam <braam@clusterfs.com>
34  * Author: Phil Schwan <phil@clusterfs.com>
35  * Author: Robert Read <rread@clusterfs.com>
36  */
37
38 #include <errno.h>
39 #include <limits.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <libcfs/util/parser.h>
44 #include <linux/lnet/lnetctl.h>
45 #include "obdctl.h"
46 #include <linux/lustre/lustre_ver.h>
47 #include <lustre/lustreapi.h>
48
49 static int lctl_list_commands(int argc, char **argv);
50
51 static int jt_opt_ignore_errors(int argc, char **argv)
52 {
53         Parser_ignore_errors(1);
54         return 0;
55 }
56
57 static int jt_pcc_list_commands(int argc, char **argv);
58 static int jt_pcc(int argc, char **argv);
59
60 /**
61  * command_t pccdev_cmdlist - lctl pcc commands.
62  */
63 command_t pccdev_cmdlist[] = {
64         { .pc_name = "add", .pc_func = jt_pcc_add,
65           .pc_help = "Add a PCC backend to a client.\n"
66                 "usage: lctl pcc add <mntpath> <pccpath> [--param|-p <param>]\n"
67                 "\tmntpath: Lustre mount point.\n"
68                 "\tpccpath: Path of the PCC backend.\n"
69                 "\tparam:   Setting parameters for PCC backend.\n" },
70         { .pc_name = "del", .pc_func = jt_pcc_del,
71           .pc_help = "Delete the specified PCC backend on a client.\n"
72                 "usage: clt pcc del <mntpath> <pccpath>\n" },
73         { .pc_name = "clear", .pc_func = jt_pcc_clear,
74           .pc_help = "Remove all PCC backend on a client.\n"
75                 "usage: lctl pcc clear <mntpath>\n" },
76         { .pc_name = "list", .pc_func = jt_pcc_list,
77           .pc_help = "List all PCC backends on a client.\n"
78                 "usage: lctl pcc list <mntpath>\n" },
79         { .pc_name = "--list-commands", .pc_func = jt_pcc_list_commands,
80           .pc_help = "list commands supported by lctl pcc"},
81         { .pc_name = "help", .pc_func = Parser_help, .pc_help = "help" },
82         { .pc_name = "exit", .pc_func = Parser_quit, .pc_help = "quit" },
83         { .pc_name = "quit", .pc_func = Parser_quit, .pc_help = "quit" },
84         { .pc_help = NULL }
85 };
86
87 command_t cmdlist[] = {
88         /* Metacommands */
89         {"===== metacommands =======", NULL, 0, "metacommands"},
90         {"--device", jt_opt_device, 0,
91          "run <command> after connecting to device <devno>\n"
92          "--device <devno> <command [args ...]>"},
93         {"--ignore_errors", jt_opt_ignore_errors, 0,
94          "ignore errors that occur during script processing\n"
95          "--ignore_errors"},
96         {"ignore_errors", jt_opt_ignore_errors, 0,
97          "ignore errors that occur during script processing\n"
98          "ignore_errors"},
99
100         /* User interface commands */
101         {"======== control =========", NULL, 0, "control commands"},
102         {"help", Parser_help, 0, "help"},
103         {"lustre_build_version", jt_get_version, 0,
104          "print version of Lustre modules\n"
105          "usage: lustre_build_version"},
106         {"exit", Parser_quit, 0, "quit"},
107         {"quit", Parser_quit, 0, "quit"},
108         {"--version", Parser_version, 0,
109          "print build version of this utility and exit"},
110         {"--list-commands", lctl_list_commands, 0,
111          "list commands supported by this utility and exit"},
112         /* help is a synonym of --list-commands */
113         {"--help", lctl_list_commands, 0,
114          "list commands supported by this utility and exit"},
115
116         /* Network configuration commands */
117         {"===== network config =====", NULL, 0, "network config"},
118         {"--net", jt_opt_net, 0, "run <command> after selecting network <net>\n"
119          "usage: --net <tcp/o2ib/...> <command>"},
120         {"network", jt_ptl_network, 0, "configure LNET\n"
121          "usage: network up|down"},
122         {"net", jt_ptl_network, 0, "configure LNET\n"
123          "usage: net up|down"},
124         {"list_nids", jt_ptl_list_nids, 0, "list local NIDs\n"
125          "usage: list_nids [all]"},
126         {"which_nid", jt_ptl_which_nid, 0, "choose a NID\n"
127          "usage: which_nid NID [NID...]"},
128         {"replace_nids", jt_replace_nids, 0,
129          "replace primary NIDs for device (clients/servers must be unmounted)\n"
130          "usage: replace_nids <DEVICE> <NID1>[,NID2,NID3:NID4,NID5:NID6]"},
131         {"interface_list", jt_ptl_print_interfaces, 0,
132          "print network interface entries\n"
133          "usage: interface_list"},
134         {"peer_list", jt_ptl_print_peers, 0, "print peer LNet NIDs\n"
135          "usage: peer_list"},
136         {"conn_list", jt_ptl_print_connections, 0,
137          "print all the remote LNet connections\n"
138          "usage: conn_list"},
139         {"route_list", jt_ptl_print_routes, 0,
140          "print the LNet routing table, same as 'show_route'\n"
141          "usage: route_list"},
142         {"show_route", jt_ptl_print_routes, 0,
143          "print the LNet routing table, same as 'route_list'\n"
144          "usage: show_route"},
145         {"ping", jt_ptl_ping, 0, "Check LNET connectivity\n"
146          "usage: ping nid [timeout] [pid]"},
147         {"net_drop_add", jt_ptl_drop_add, 0, "Add LNet drop rule\n"
148          "usage: net_drop_add <-s | --source NID>\n"
149          "                    <-d | --dest NID>\n"
150          "                    <<-r | --rate DROP_RATE> |\n"
151          "                    <-i | --interval SECONDS>>\n"
152          "                    [<-p | --portal> PORTAL...]\n"
153          "                    [<-m | --message> <PUT|ACK|GET|REPLY>...]\n"
154          "                    [< -e | --health_error]\n"},
155         {"net_drop_del", jt_ptl_drop_del, 0, "remove LNet drop rule\n"
156          "usage: net_drop_del <[-a | --all] |\n"
157          "                    <-s | --source NID>\n"
158          "                    <-d | --dest NID>>\n"},
159         {"net_drop_reset", jt_ptl_drop_reset, 0, "reset drop rule stats\n"
160          "usage: net_drop_reset"},
161         {"net_drop_list", jt_ptl_drop_list, 0, "list LNet drop rules\n"
162          "usage: net_drop_list"},
163         {"net_delay_add", jt_ptl_delay_add, 0, "Add LNet delay rule\n"
164          "usage: net_delay_add <-s | --source NID>\n"
165          "                     <-d | --dest NID>\n"
166          "                     <<-r | --rate DROP_RATE> |\n"
167          "                      <-i | --interval SECONDS>>\n"
168          "                     <-l | --latency SECONDS>\n"
169          "                     [<-p | --portal> PORTAL...]\n"
170          "                     [<-m | --message> <PUT|ACK|GET|REPLY>...]\n"},
171         {"net_delay_del", jt_ptl_delay_del, 0, "remove LNet delay rule\n"
172          "usage: net_delay_del <[-a | --all] |\n"
173          "                     <-s | --source NID>\n"
174          "                     <-d | --dest NID>>\n"},
175         {"net_delay_reset", jt_ptl_delay_reset, 0, "reset delay rule stats\n"
176          "usage: net_delay_reset"},
177         {"net_delay_list", jt_ptl_delay_list, 0, "list LNet delay rules\n"
178          "usage: net_delay_list"},
179
180         /* Device selection commands */
181         {"==== obd device selection ====", NULL, 0, "device selection"},
182         {"device", jt_obd_device, 0,
183          "set current device to <name|devno>\n"
184          "usage: device <%name|$name|devno>"},
185         {"cfg_device", jt_obd_device, 0,
186          "set current device to <name>, same as 'device'\n"
187          "usage: cfg_device <name>"},
188         {"device_list", jt_device_list, 0, "show all devices\n"
189          "usage: device_list [--target|-t] [--yaml|-y]"},
190         {"dl", jt_device_list, 0, "show all devices, same as 'device_list'\n"
191          "usage: dl [--target|-t] [--yaml|-y]"},
192
193         /* Device operations */
194         {"==== obd device operations ====", NULL, 0, "device operations"},
195         {"activate", jt_obd_activate, 0, "activate an import\n"},
196         {"deactivate", jt_obd_deactivate, 0, "deactivate an import. "
197          "This command should be used on failed OSC devices in an MDT LOV.\n"},
198         {"abort_recovery", jt_obd_abort_recovery, 0,
199          "abort recovery on a restarting MDT or OST device\n"},
200         {"abort_recovery_mdt", jt_obd_abort_recovery_mdt, 0,
201          "abort recovery between MDTs\n"},
202         {"recover", jt_obd_recover, 0,
203          "try to restore a lost connection immediately\n"
204          "usage: recover [MDC/OSC device]"},
205         {"set_timeout", jt_lcfg_set_timeout, 0,
206          "usage: conf_param obd_timeout=<secs>\n"},
207 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
208         {"conf_param", jt_lcfg_confparam, 0,
209          "set a permanent config parameter.\n"
210          "This command must be run on the MGS node\n"
211          "usage: conf_param [-d] <target.keyword=val>\n"
212          "  -d  Delete the permanent setting from the configuration."},
213 #endif
214         {"local_param", jt_lcfg_param, 0, "set a temporary, local param\n"
215          "usage: local_param <target.keyword=val>\n"},
216         {"get_param", jt_lcfg_getparam, 0, "get the Lustre or LNET parameter\n"
217          "usage: get_param [-F|n|-N|-R] <param_path1 param_path2 ...>\n"
218          "Get the value of Lustre or LNET parameter from the specified path.\n"
219          "The path can contain shell-style filename patterns.\n"
220          "  -F  When -N specified, add '/', '@' or '=' for directories,\n"
221          "      symlinks and writeable files, respectively.\n"
222          "  -n  Print only the value and not parameter name.\n"
223          "  -N  Print only matched parameter names and not the values.\n"
224          "      (Especially useful when using patterns.)\n"
225          "  -R  Get parameters recursively from the specified entry.\n"},
226         {"set_param", jt_lcfg_setparam, 0, "set the Lustre or LNET parameter\n"
227          "usage: set_param [-n] [-P] [-d] [-F]"
228          "<param_path1=value1 param_path2=value2 ...>\n"
229          "Set the value of the Lustre or LNET parameter at the specified path.\n"
230          "  -n  Disable printing of the key name when printing values.\n"
231          "  -P  Set the parameter permanently, filesystem-wide.\n"
232          "  -d  Remove the permanent setting (only with -P option).\n"
233          "  -F  Read permanent configuration from a YAML file.\n"},
234         {"list_param", jt_lcfg_listparam, 0,
235          "list the Lustre or LNET parameter name\n"
236          "usage: list_param [-F|-R|-D] <param_path1 param_path2 ...>\n"
237          "List the name of Lustre or LNET parameter from the specified path.\n"
238          "  -F  Add '/', '@' or '=' for dirs, symlinks and writeable files,\n"
239                 "respectively.\n"
240          "  -D  Only list directories.\n"
241          "  -R  Recursively list all parameters under the specified path.\n"},
242         {"del_ost", jt_del_ost, 0, "permanently delete OST records\n"
243          "usage: del_ost [--dryrun] --target <$fsname-OSTxxxx>\n"
244          "Cancel the config records for a specific OST to forget about it.\n"},
245
246         /* Debug commands */
247         {"==== debugging control ====", NULL, 0, "debug"},
248         {"debug_daemon", jt_dbg_debug_daemon, 0,
249          "debug daemon control and dump to a file\n"
250          "usage: debug_daemon {start file [#MB]|stop}"},
251         {"debug_kernel", jt_dbg_debug_kernel, 0,
252          "get debug buffer and dump to a file, same as 'dk'\n"
253          "usage: debug_kernel [file] [raw]"},
254         {"dk", jt_dbg_debug_kernel, 0,
255          "get debug buffer and dump to a file, same as 'debug_kernel'\n"
256          "usage: dk [file] [raw]"},
257         {"debug_file", jt_dbg_debug_file, 0,
258          "convert a binary debug file dumped by the kernel to ASCII text\n"
259          "usage: debug_file <input> [output]"},
260         {"df", jt_dbg_debug_file, 0,
261          "read debug log from input convert to ASCII, same as 'debug_file'\n"
262          "usage: df <input> [output]"},
263         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
264          "usage: clear"},
265         {"mark", jt_dbg_mark_debug_buf, 0,
266          "insert marker text in kernel debug buffer\n"
267          "usage: mark <text>"},
268         {"filter", jt_dbg_filter, 0, "filter message type\n"
269          "usage: filter <subsystem id/debug mask>"},
270         {"show", jt_dbg_show, 0, "Show specific type of messages\n"
271          "usage: show <subsystem id/debug mask>"},
272         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
273          "usage: debug_list <subs/types>"},
274         {"modules", jt_dbg_modules, 0,
275          "provide gdb-friendly module information\n"
276          "usage: modules <path>"},
277
278         /* Pool commands */
279         {"===  Pools ==", NULL, 0, "pool management"},
280         {"pool_new", jt_pool_cmd, 0,
281          "add a new pool\n"
282          "usage: pool_new <fsname>.<poolname>"},
283         {"pool_add", jt_pool_cmd, 0,
284          "add the named OSTs to the pool\n"
285          "usage: pool_add <fsname>.<poolname> <ostname indexed list>"},
286         {"pool_remove", jt_pool_cmd, 0,
287          "remove the named OST from the pool\n"
288          "usage: pool_remove <fsname>.<poolname> <ostname indexed list>"},
289         {"pool_destroy", jt_pool_cmd, 0,
290          "destroy a pool\n"
291          "usage: pool_destroy <fsname>.<poolname>"},
292         {"pool_list", jt_pool_cmd, 0,
293          "list pools and pools members\n"
294          "usage: pool_list  <fsname>[.<poolname>] | <pathname>"},
295
296 #ifdef HAVE_SERVER_SUPPORT
297         /* Barrier commands */
298         {"===  Barrier ==", NULL, 0, "barrier management"},
299         {"barrier_freeze", jt_barrier_freeze, 0,
300          "freeze write barrier on MDTs\n"
301          "usage: barrier_freeze <fsname> [timeout (in seconds)]"},
302         {"barrier_thaw", jt_barrier_thaw, 0,
303          "thaw write barrier on MDTs\n"
304          "usage: barrier_thaw <fsname>"},
305         {"barrier_stat", jt_barrier_stat, 0,
306          "query write barrier status on MDTs\n"
307          "usage: barrier_stat [--state|-s] [--timeout|-t] <fsname>"},
308         {"barrier_rescan", jt_barrier_rescan, 0,
309          "rescan the system to filter out inactive MDT(s) for barrier\n"
310          "usage: barrier_rescan <fsname> [timeout (in seconds)]"},
311
312         /* Snapshot commands */
313         {"===  Snapshot ==", NULL, 0, "Snapshot management"},
314         {"snapshot_create", jt_snapshot_create, 0,
315          "create the snapshot\n"
316          "usage: snapshot_create [-b | --barrier [on | off]]\n"
317          "                       [-c | --comment comment]\n"
318          "                       <-F | --fsname fsname>\n"
319          "                       [-h | --help] <-n | --name ssname>\n"
320          "                       [-r | --rsh remote_shell]\n"
321          "                       [-t | --timeout timeout]"},
322         {"snapshot_destroy", jt_snapshot_destroy, 0,
323          "destroy the snapshot\n"
324          "usage: snapshot_destroy [-f | --force]\n"
325          "                        <-F | --fsname fsname> [-h | --help]\n"
326          "                        <-n | --name ssname>\n"
327          "                        [-r | --rsh remote_shell]"},
328         {"snapshot_modify", jt_snapshot_modify, 0,
329          "modify the snapshot\n"
330          "usage: snapshot_modify [-c | --comment comment]\n"
331          "                       <-F | --fsname fsname> [-h | --help]\n"
332          "                       <-n | --name ssname> [-N | --new new_ssname]\n"
333          "                       [-r | --rsh remote_shell]"},
334         {"snapshot_list", jt_snapshot_list, 0,
335          "query the snapshot(s)\n"
336          "usage: snapshot_list [-d | --detail]\n"
337          "                     <-F | --fsname fsname> [-h | --help]\n"
338          "                     [-n | --name ssname] [-r | --rsh remote_shell]"},
339         {"snapshot_mount", jt_snapshot_mount, 0,
340          "mount the snapshot\n"
341          "usage: snapshot_mount <-F | --fsname fsname> [-h | --help]\n"
342          "                      <-n | --name ssname>\n"
343          "                      [-r | --rsh remote_shell]"},
344         {"snapshot_umount", jt_snapshot_umount, 0,
345          "umount the snapshot\n"
346          "usage: snapshot_umount <-F | --fsname fsname> [-h | --help]\n"
347          "                       <-n | --name ssname>\n"
348          "                       [-r | --rsh remote_shell]"},
349 #endif /* HAVE_SERVER_SUPPORT */
350         /* Nodemap commands */
351         {"=== Nodemap ===", NULL, 0, "nodemap management"},
352         {"nodemap_activate", jt_nodemap_activate, 0,
353          "activate nodemap idmapping functions\n"
354          "usage: nodemap_activate {0|1}"},
355         {"nodemap_add", jt_nodemap_add, 0,
356          "add a new nodemap\n"
357          "usage: nodemap_add <nodemap_name>"},
358         {"nodemap_del", jt_nodemap_del, 0,
359          "remove a nodemap\n"
360          "usage: nodemap_del <nodemap_name>"},
361         {"nodemap_add_range", jt_nodemap_add_range, 0,
362          "add a range to a nodemap\n"
363          "usage: nodemap_add_range <nid_range>"},
364         {"nodemap_del_range", jt_nodemap_del_range, 0,
365          "add a range to a nodemap\n"
366          "usage: nodemap_del_range <nid_range>"},
367         {"nodemap_modify", jt_nodemap_modify, 0,
368          "modify a nodemap parameters\n"
369          "usage: nodemap_modify nodemap_name param value"},
370         {"nodemap_add_idmap", jt_nodemap_add_idmap, 0,
371          "add a UID or GID mapping to a nodemap"},
372         {"nodemap_del_idmap", jt_nodemap_del_idmap, 0,
373          "delete a UID or GID mapping from a nodemap"},
374         {"nodemap_set_fileset", jt_nodemap_set_fileset, 0,
375          "set a fileset on a nodemap\n"
376          "usage: nodemap_set_fileset <fileset>"},
377         {"nodemap_set_sepol", jt_nodemap_set_sepol, 0,
378          "set SELinux policy info on a nodemap\n"
379          "usage: nodemap_set_sepol <SELinux policy info>"},
380         {"nodemap_test_nid", jt_nodemap_test_nid, 0,
381          "usage: nodemap_test_nid <nid>"},
382         {"nodemap_test_id", jt_nodemap_test_id, 0,
383          "Usage: nodemap_test_id --nid <nid> --idtype [uid|gid] --id <id>"},
384         {"nodemap_info", jt_nodemap_info, 0,
385          "Usage: nodemap_info [list|nodemap_name|all]"},
386
387         /* Changelog commands */
388         {"===  Changelogs ==", NULL, 0, "changelog user management"},
389         {"changelog_register", jt_changelog_register, 0,
390          "register a new persistent changelog user, returns id\n"
391          "usage: --device <mdtname> changelog_register [--help|-h]\n"
392          "                                             [--mask|-m <[+|-]mask1[<,|+|->mask2...]>]\n"
393          "                                             [--nameonly|-n]\n"
394          "                                             [--user|-u <username>]"},
395         {"changelog_deregister", jt_changelog_deregister, 0,
396          "deregister an existing changelog user\n"
397          "usage: --device <mdtname> changelog_deregister [<id>|cl<id>...]\n"
398          "                                               [--help|-h]\n"
399          "                                               [--user|-u <username>]\n"},
400
401         /* Persistent Client Cache (PCC) commands */
402         {"=== Persistent Client Cache ===", NULL, 0, "PCC user management"},
403         {"pcc", jt_pcc, pccdev_cmdlist,
404          "lctl commands used to interact with PCC features:\n"
405          "lctl pcc add    - add a PCC backend to a client\n"
406          "lctl pcc del    - delete a PCC backend on a client\n"
407          "lctl pcc clear  - remove all PCC backends on a client\n"
408          "lctl pcc list   - list all PCC backends on a client\n"},
409
410         /* Device configuration commands */
411         {"== device setup (these are not normally used post 1.4) ==",
412                 NULL, 0, "device config"},
413         {"attach", jt_lcfg_attach, 0,
414          "set the type, name, and uuid of the current device\n"
415          "usage: attach type name uuid"},
416         {"detach", jt_obd_detach, 0,
417          "remove driver (and name and uuid) from current device\n"
418          "usage: detach"},
419         {"setup", jt_lcfg_setup, 0,
420          "type specific device configuration information\n"
421          "usage: setup <args...>"},
422         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
423          "usage: cleanup [force | failover]"},
424
425 #ifdef HAVE_SERVER_SUPPORT
426         /* LFSCK commands */
427         {"==== LFSCK ====", NULL, 0, "LFSCK"},
428         {"lfsck_start", jt_lfsck_start, 0, "start LFSCK\n"
429          "usage: lfsck_start [--device|-M [MDT,OST]_device]\n"
430          "                   [--all|-A] [--create-ostobj|-c [on | off]]\n"
431          "                   [--create-mdtobj|-C [on | off]]\n"
432          "                   [--delay-create-ostobj|-d [on | off]]\n"
433          "                   [--error|-e {continue | abort}] [--help|-h]\n"
434          "                   [--dryrun|-n [on | off]] [--orphan|-o]\n"
435          "                   [--reset|-r] [--speed|-s speed_limit]\n"
436          "                   [--type|-t lfsck_type[,lfsck_type...]]\n"
437          "                   [--window-size|-w size]"},
438         {"lfsck_stop", jt_lfsck_stop, 0, "stop lfsck(s)\n"
439          "usage: lfsck_stop [--device|-M [MDT,OST]_device]\n"
440          "                  [--all|-A] [--help|-h]"},
441         {"lfsck_query", jt_lfsck_query, 0, "check lfsck(s) status\n"
442          "usage: lfsck_query [--device|-M MDT_device] [--help|-h]\n"
443          "                   [--type|-t lfsck_type[,lfsck_type...]]\n"
444          "                   [--wait|-w]"},
445
446         /* Llog operations */
447         {"==== LLOG ====", NULL, 0, "LLOG"},
448         {"llog_catlist", jt_llog_catlist, 0,
449          "list all catalog files on current device. If current device is not\n"
450          "set, MGS device is used by default.\n"
451          "usage: llog_catlist"},
452         {"llog_info", jt_llog_info, 0,
453          "print log header information.\n"
454          "usage: llog_info {LOGNAME|FID}\n"},
455         {"llog_print", jt_llog_print, 0,
456          "print all effective log records by default, or within given range.\n"
457          "With --raw option skipped records are printed as well.\n"
458          "usage: llog_print {LOGNAME|FID} [--start INDEX] [--end INDEX]\n"
459          "                  [--raw]\n"},
460         {"llog_cancel", jt_llog_cancel, 0,
461          "cancel one record in specified log.\n"
462          "usage:llog_cancel {LOGNAME|FID} --log_idx INDEX\n"},
463         {"llog_check", jt_llog_check, 0,
464          "verify that log content is valid.\n"
465          "usage: llog_check {LOGNAME|FID} [--start INDEX] [--end INDEX]\n"
466          "       check all records from index 1 by default."},
467         {"llog_remove", jt_llog_remove, 0,
468          "remove one log from catalog or plain log, erase it from disk.\n"
469          "usage: llog_remove {LOGNAME|FID} [--log_id ID]"},
470         {"lcfg_clear", jt_lcfg_clear, 0,
471          "drop unused config llog records for a device or filesystem.\n"
472          "clients and servers must be unmounted during this operation.\n"
473          "usage: clear_conf {FSNAME|DEVNAME}"},
474         {"clear_conf", jt_lcfg_clear, 0, "alias for 'lcfg_clear'\n"},
475         {"lcfg_fork", jt_lcfg_fork, 0,
476          "copy configuration logs for named filesystem with given name\n"
477          "usage: fork_lcfg FSNAME NEWNAME"},
478         {"fork_lcfg", jt_lcfg_fork, 0, "alias for 'lcfg_fork'\n"},
479         {"lcfg_erase", jt_lcfg_erase, 0,
480          "permanently erase configuration logs for the named filesystem\n"
481          "usage: erase_lcfg FSNAME"},
482         {"erase_lcfg", jt_lcfg_erase, 0, "alias for 'lcfg_erase'\n"},
483 #endif /* HAVE_SERVER_SUPPORT */
484
485         {"==== obsolete (DANGEROUS) ====", NULL, 0, "obsolete (DANGEROUS)"},
486         /* network operations */
487         {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
488          "usage: add_interface ip [netmask]"},
489         {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
490          "usage: del_interface [ip]"},
491         {"add_route", jt_ptl_add_route, 0,
492          "add an entry to the LNet routing table\n"
493          "usage: add_route <gateway> [<hops> [<priority>]]"},
494         {"del_route", jt_ptl_del_route, 0,
495          "delete route via gateway to targets from the LNet routing table\n"
496          "usage: del_route <gateway> [<target>] [<target>]"},
497         {"set_route", jt_ptl_notify_router, 0,
498          "enable/disable routes via gateway in the LNet routing table\n"
499          "usage: set_route <gateway> <up/down> [<time>]"},
500
501         /* Test only commands */
502         {"==== testing (DANGEROUS) ====", NULL, 0, "testing (DANGEROUS)"},
503         {"--threads", jt_opt_threads, 0,
504          "run <threads> separate instances of <command> on device <devno>\n"
505          "--threads <threads> <verbose> <devno> <command [args ...]>"},
506         {"lookup", jt_obd_mdc_lookup, 0, "report file mode info\n"
507          "usage: lookup <directory> <file>"},
508         {"readonly", jt_obd_set_readonly, 0,
509          "disable writes to the underlying device\n"},
510 #ifdef HAVE_SERVER_SUPPORT
511         {"notransno", jt_obd_no_transno, 0,
512          "disable sending of committed-transno updates\n"},
513 #endif
514         {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a NID\n"
515          "usage: add_uuid <uuid> <nid>"},
516         {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
517          "usage: del_uuid <uuid>"},
518         {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
519          "usage: add_peer <nid> <host> <port>"},
520         {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
521          "usage: del_peer [<nid>] [<ipaddr|pid>]"},
522         {"add_conn ", jt_lcfg_add_conn, 0,
523          "usage: add_conn <conn_uuid> [priority]\n"},
524         {"del_conn ", jt_lcfg_del_conn, 0,
525          "usage: del_conn <conn_uuid>"},
526         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote NID\n"
527          "usage: disconnect [<nid>]"},
528         {"push", jt_ptl_push_connection, 0, "flush connection to a remote NID\n"
529          "usage: push [<nid>]"},
530         {"mynid", jt_ptl_mynid, 0, "inform the LND of the local NID. "
531          "The NID defaults to hostname for TCP networks.\n"
532          "usage: mynid [<nid>]"},
533         {"fail", jt_ptl_fail_nid, 0, "fail/restore network communications\n"
534          "Omitting the count means indefinitely, 0 means restore, "
535          "otherwise fail 'count' messages.\n"
536          "usage: fail nid|_all_ [count]"},
537
538         /* Test commands for echo client */
539         {"test_create", jt_obd_test_create, 0,
540          "create files on MDT by echo client\n"
541          "usage: test_create [-d parent_basedir] <-D parent_count> "
542          "[-b child_base_id] <-c stripe_count> <-n count> <-t time>\n"},
543         {"test_mkdir", jt_obd_test_mkdir, 0,
544          "mkdir on MDT by echo client\n"
545          "usage: test_mkdir [-d parent_basedir] <-D parent_count>"
546          "[-b child_base_id] [-n count] <-t time>\n"},
547         {"test_destroy", jt_obd_test_destroy, 0,
548          "Destroy files on MDT by echo client\n"
549          "usage: test_destroy [-d parent_basedir] <-D parent_count>"
550          "[-b child_base_id] [-n count] <-t time>\n"},
551         {"test_rmdir", jt_obd_test_rmdir, 0,
552          "rmdir on MDT by echo client\n"
553          "usage: test_rmdir [-d parent_basedir] <-D parent_count>"
554          "[-b child_base_id] [-n count] <-t time>\n"},
555         {"test_lookup", jt_obd_test_lookup, 0,
556          "lookup files on MDT by echo client\n"
557          "usage: test_lookup [-d parent_basedir] <-D parent_count>"
558          "[-b child_base_id] [-n count] <-t time>\n"},
559         {"test_setxattr", jt_obd_test_setxattr, 0,
560          "Set EA for files/directory on MDT by echo client\n"
561          "usage: test_setxattr [-d parent_baseid] <-D parent_count>"
562          "[-b child_base_id] [-n count] <-t time>\n"},
563         {"test_md_getattr", jt_obd_test_md_getattr, 0,
564          "getattr files on MDT by echo client\n"
565          "usage: test_md_getattr [-d parent_basedir] <-D parent_count>"
566          "[-b child_base_id] [-n count] <-t time>\n"},
567         {"getattr", jt_obd_getattr, 0,
568          "get attribute for OST object <objid>\n"
569          "usage: getattr <objid>"},
570         {"setattr", jt_obd_setattr, 0,
571          "set mode attribute for OST object <objid>\n"
572          "usage: setattr <objid> <mode>"},
573         {"create", jt_obd_create, 0,
574          "create <num> OST objects (with <mode>)\n"
575          "usage: create [num [mode [verbose [lsm data]]]]"},
576         {"destroy", jt_obd_destroy, 0,
577          "destroy OST object <objid> [num [verbose]]\n"
578          "usage: destroy <num> objects, starting at objid <objid>"},
579         {"test_getattr", jt_obd_test_getattr, 0,
580          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
581          "usage: test_getattr <num> [verbose [[t]objid]]"},
582         {"test_setattr", jt_obd_test_setattr, 0,
583          "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
584          "usage: test_setattr <num> [verbose [[t]objid]]"},
585         {"test_brw", jt_obd_test_brw, 0,
586          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
587          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
588         {"getobjversion", jt_get_obj_version, 0,
589          "get the version of an object on servers\n"
590          "usage: getobjversion <fid>\n"
591          "       getobjversion -i <id> -g <group>"},
592         { 0, 0, 0, NULL }
593 };
594
595 /**
596  * jt_pcc_list_commands() - List lctl pcc commands.
597  * @argc: The count of command line arguments.
598  * @argv: Array of strings for command line arguments.
599  *
600  * This function lists lctl pcc commands defined in pccdev_cmdlist[].
601  *
602  * Return: 0 on success.
603  */
604 static int jt_pcc_list_commands(int argc, char **argv)
605 {
606         Parser_list_commands(pccdev_cmdlist, 80, 4);
607
608         return 0;
609 }
610
611 /**
612  * jt_pcc() - Parse and execute lctl pcc commands.
613  * @argc: The count of lctl pcc command line arguments.
614  * @argv: Array of strings for lctl pcc command line arguments.
615  *
616  * This function parses lfs pcc commands and performs the
617  * corresponding functions specified in pccdev_cmdlist[].
618  *
619  * Return: 0 on success or an error code on failure.
620  */
621 static int jt_pcc(int argc, char **argv)
622 {
623         char cmd[PATH_MAX];
624         int rc = 0;
625
626         setlinebuf(stdout);
627
628         Parser_init("lctl-pcc > ", pccdev_cmdlist);
629
630         snprintf(cmd, sizeof(cmd), "%s %s", program_invocation_short_name,
631                  argv[0]);
632         program_invocation_short_name = cmd;
633         if (argc > 1)
634                 rc = Parser_execarg(argc - 1, argv + 1, pccdev_cmdlist);
635         else
636                 rc = Parser_commands();
637
638         return rc < 0 ? -rc : rc;
639 }
640
641 int lctl_main(int argc, char **argv)
642 {
643         int rc;
644
645         setlinebuf(stdout);
646
647         if (ptl_initialize(argc, argv) < 0)
648                 exit(1);
649         if (obd_initialize(argc, argv) < 0)
650                 exit(2);
651         if (dbg_initialize(argc, argv) < 0)
652                 exit(3);
653
654         Parser_init("lctl > ", cmdlist);
655
656         if (argc > 1) {
657                 llapi_set_command_name(argv[1]);
658                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
659                 llapi_clear_command_name();
660         } else {
661                 rc = Parser_commands();
662         }
663
664         obd_finalize(argc, argv);
665         Parser_exit(argc, argv);
666         return rc < 0 ? -rc : rc;
667 }
668
669 static int lctl_list_commands(int argc, char **argv)
670 {
671         command_t *cmd;
672         int rc;
673
674         cmd = cmdlist;
675         while (cmd->pc_name != NULL) {
676                 printf("\n%s\n", cmd->pc_name); /* Command category */
677                 cmd++;
678                 rc = Parser_list_commands(cmd, 80, 4);
679                 cmd += rc;
680         }
681
682         return 0;
683 }
684
685 int main(int argc, char **argv)
686 {
687         return lctl_main(argc, argv);
688 }