Whamcloud - gitweb
LU-5170 utils: Add utility and command name to llapi messages
[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, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/utils/lctl.c
33  *
34  * Author: Peter J. Braam <braam@clusterfs.com>
35  * Author: Phil Schwan <phil@clusterfs.com>
36  * Author: Robert Read <rread@clusterfs.com>
37  */
38
39 #include <errno.h>
40 #include <limits.h>
41 #include <stdlib.h>
42 #include <stdio.h>
43 #include <string.h>
44 #include <libcfs/util/parser.h>
45 #include <linux/lnet/lnetctl.h>
46 #include "obdctl.h"
47 #include <linux/lustre/lustre_ver.h>
48 #include <lustre/lustreapi.h>
49
50 static int lctl_list_commands(int argc, char **argv);
51
52 static int jt_opt_ignore_errors(int argc, char **argv) {
53         Parser_ignore_errors(1);
54         return 0;
55 }
56
57 command_t cmdlist[] = {
58         /* Metacommands */
59         {"===== metacommands =======", NULL, 0, "metacommands"},
60         {"--device", jt_opt_device, 0,
61          "run <command> after connecting to device <devno>\n"
62          "--device <devno> <command [args ...]>"},
63         {"--ignore_errors", jt_opt_ignore_errors, 0,
64          "ignore errors that occur during script processing\n"
65          "--ignore_errors"},
66         {"ignore_errors", jt_opt_ignore_errors, 0,
67          "ignore errors that occur during script processing\n"
68          "ignore_errors"},
69
70         /* User interface commands */
71         {"======== control =========", NULL, 0, "control commands"},
72         {"help", Parser_help, 0, "help"},
73         {"lustre_build_version", jt_get_version, 0,
74          "print version of Lustre modules\n"
75          "usage: lustre_build_version"},
76         {"exit", Parser_quit, 0, "quit"},
77         {"quit", Parser_quit, 0, "quit"},
78         {"--version", Parser_version, 0,
79          "print build version of this utility and exit"},
80         {"--list-commands", lctl_list_commands, 0,
81          "list commands supported by this utility and exit"},
82
83         /* Network configuration commands */
84         {"===== network config =====", NULL, 0, "network config"},
85         {"--net", jt_opt_net, 0, "run <command> after selecting network <net>\n"
86          "usage: --net <tcp/o2ib/...> <command>"},
87         {"network", jt_ptl_network, 0, "configure LNET"
88          "usage: network up|down"},
89         {"net", jt_ptl_network, 0, "configure LNET"
90          "usage: net up|down"},
91         {"list_nids", jt_ptl_list_nids, 0, "list local NIDs"
92          "usage: list_nids [all]"},
93         {"which_nid", jt_ptl_which_nid, 0, "choose a NID"
94          "usage: which_nid NID [NID...]"},
95         {"replace_nids", jt_replace_nids, 0,
96          "replace primary NIDs for a device\n"
97          "usage: replace_nids <device> <nid1>[,nid2,nid3]"},
98         {"interface_list", jt_ptl_print_interfaces, 0,
99          "print network interface entries\n"
100          "usage: interface_list"},
101         {"peer_list", jt_ptl_print_peers, 0, "print peer LNet NIDs\n"
102          "usage: peer_list"},
103         {"conn_list", jt_ptl_print_connections, 0,
104          "print all the remote LNet connections\n"
105          "usage: conn_list"},
106         {"route_list", jt_ptl_print_routes, 0,
107          "print the LNet routing table, same as show_route\n"
108          "usage: route_list"},
109         {"show_route", jt_ptl_print_routes, 0,
110          "print the LNet routing table, same as route_list\n"
111          "usage: show_route"},
112         {"ping", jt_ptl_ping, 0, "Check LNET connectivity\n"
113          "usage: ping nid [timeout] [pid]"},
114         {"net_drop_add", jt_ptl_drop_add, 0, "Add LNet drop rule\n"
115          "usage: net_drop_add <-s | --source NID>\n"
116          "                    <-d | --dest NID>\n"
117          "                    <<-r | --rate DROP_RATE> |\n"
118          "                     <-i | --interval SECONDS>>\n"
119          "                    [<-p | --portal> PORTAL...]\n"
120          "                    [<-m | --message> <PUT|ACK|GET|REPLY>...]\n"},
121         {"net_drop_del", jt_ptl_drop_del, 0, "remove LNet drop rule\n"
122          "usage: net_drop_del <[-a | --all] |\n"
123          "                    <-s | --source NID>\n"
124          "                    <-d | --dest NID>>\n"},
125         {"net_drop_reset", jt_ptl_drop_reset, 0, "reset drop rule stats\n"
126          "usage: net_drop_reset"},
127         {"net_drop_list", jt_ptl_drop_list, 0, "list LNet drop rules\n"
128          "usage: net_drop_list"},
129         {"net_delay_add", jt_ptl_delay_add, 0, "Add LNet delay rule\n"
130          "usage: net_delay_add <-s | --source NID>\n"
131          "                     <-d | --dest NID>\n"
132          "                     <<-r | --rate DROP_RATE> |\n"
133          "                      <-i | --interval SECONDS>>\n"
134          "                     <-l | --latency SECONDS>\n"
135          "                     [<-p | --portal> PORTAL...]\n"
136          "                     [<-m | --message> <PUT|ACK|GET|REPLY>...]\n"},
137         {"net_delay_del", jt_ptl_delay_del, 0, "remove LNet delay rule\n"
138          "usage: net_delay_del <[-a | --all] |\n"
139          "                     <-s | --source NID>\n"
140          "                     <-d | --dest NID>>\n"},
141         {"net_delay_reset", jt_ptl_delay_reset, 0, "reset delay rule stats\n"
142          "usage: net_delay_reset"},
143         {"net_delay_list", jt_ptl_delay_list, 0, "list LNet delay rules\n"
144          "usage: net_delay_list"},
145
146         /* Device selection commands */
147         {"==== obd device selection ====", NULL, 0, "device selection"},
148         {"device", jt_obd_device, 0,
149          "set current device to <name|devno>\n"
150          "usage: device <%name|$name|devno>"},
151         {"device_list", jt_obd_list, 0, "show all devices\n"
152          "usage: device_list"},
153         {"dl", jt_obd_list, 0, "show all devices\n"
154          "usage: dl [-t]"},
155
156         /* Device operations */
157         {"==== obd device operations ====", NULL, 0, "device operations"},
158         {"activate", jt_obd_activate, 0, "activate an import\n"},
159         {"deactivate", jt_obd_deactivate, 0, "deactivate an import. "
160          "This command should be used on failed OSC devices in an MDT LOV.\n"},
161         {"abort_recovery", jt_obd_abort_recovery, 0,
162          "abort recovery on a restarting MDT or OST device\n"},
163         {"set_timeout", jt_lcfg_set_timeout, 0,
164          "usage: conf_param obd_timeout=<secs>\n"},
165 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
166         {"conf_param", jt_lcfg_mgsparam, 0,"set a permanent config parameter.\n"
167          "This command must be run on the MGS node\n"
168          "usage: conf_param [-d] <target.keyword=val>\n"
169          "  -d  Delete the permanent setting from the configuration."},
170 #endif
171         {"local_param", jt_lcfg_param, 0, "set a temporary, local param\n"
172          "usage: local_param <target.keyword=val>\n"},
173         {"get_param", jt_lcfg_getparam, 0, "get the Lustre or LNET parameter\n"
174          "usage: get_param [-F|n|-N|-R] <param_path1 param_path2 ...>\n"
175          "Get the value of Lustre or LNET parameter from the specified path.\n"
176          "The path can contain shell-style filename patterns.\n"
177          "  -F  When -N specified, add '/', '@' or '=' for directories,\n"
178          "      symlinks and writeable files, respectively.\n"
179          "  -n  Print only the value and not parameter name.\n"
180          "  -N  Print only matched parameter names and not the values.\n"
181          "      (Especially useful when using patterns.)\n"
182          "  -R  Get parameters recursively from the specified entry.\n"},
183         {"set_param", jt_lcfg_setparam, 0, "set the Lustre or LNET parameter\n"
184          "usage: set_param [-n] [-P] [-d]"
185          "<param_path1=value1 param_path2=value2 ...>\n"
186          "Set the value of the Lustre or LNET parameter at the specified path.\n"
187          "  -n  Disable printing of the key name when printing values.\n"
188          "  -P  Set the parameter permanently, filesystem-wide.\n"
189          "  -d  Remove the permanent setting (only with -P option).\n"},
190         {"list_param", jt_lcfg_listparam, 0,
191          "list the Lustre or LNET parameter name\n"
192          "usage: list_param [-F|-R|-D] <param_path1 param_path2 ...>\n"
193          "List the name of Lustre or LNET parameter from the specified path.\n"
194          "  -F  Add '/', '@' or '=' for dirs, symlinks and writeable files,\n"
195                 "respectively.\n"
196          "  -D  Only list directories.\n"
197          "  -R  Recursively list all parameters under the specified path.\n"},
198
199         /* Debug commands */
200         {"==== debugging control ====", NULL, 0, "debug"},
201         {"debug_daemon", jt_dbg_debug_daemon, 0,
202          "debug daemon control and dump to a file\n"
203          "usage: debug_daemon {start file [#MB]|stop}"},
204         {"debug_kernel", jt_dbg_debug_kernel, 0,
205          "get debug buffer and dump to a file, same as dk\n"
206          "usage: debug_kernel [file] [raw]"},
207         {"dk", jt_dbg_debug_kernel, 0,
208          "get debug buffer and dump to a file, same as debug_kernel\n"
209          "usage: dk [file] [raw]"},
210         {"debug_file", jt_dbg_debug_file, 0,
211          "convert a binary debug file dumped by the kernel to ASCII text\n"
212          "usage: debug_file <input> [output]"},
213         {"df", jt_dbg_debug_file, 0,
214          "read debug buffer from input and dump to output, same as debug_file\n"
215          "usage: df <input> [output]"},
216         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
217          "usage: clear"},
218         {"mark", jt_dbg_mark_debug_buf, 0,
219          "insert marker text in kernel debug buffer\n"
220          "usage: mark <text>"},
221         {"filter", jt_dbg_filter, 0, "filter message type\n"
222          "usage: filter <subsystem id/debug mask>"},
223         {"show", jt_dbg_show, 0, "Show specific type of messages\n"
224          "usage: show <subsystem id/debug mask>"},
225         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
226          "usage: debug_list <subs/types>"},
227         {"modules", jt_dbg_modules, 0,
228          "provide gdb-friendly module information\n"
229          "usage: modules <path>"},
230
231         /* Pool commands */
232         {"===  Pools ==", NULL, 0, "pool management"},
233         {"pool_new", jt_pool_cmd, 0,
234          "add a new pool\n"
235          "usage: pool_new <fsname>.<poolname>"},
236         {"pool_add", jt_pool_cmd, 0,
237          "add the named OSTs to the pool\n"
238          "usage: pool_add <fsname>.<poolname> <ostname indexed list>"},
239         {"pool_remove", jt_pool_cmd, 0,
240          "remove the named OST from the pool\n"
241          "usage: pool_remove <fsname>.<poolname> <ostname indexed list>"},
242         {"pool_destroy", jt_pool_cmd, 0,
243          "destroy a pool\n"
244          "usage: pool_destroy <fsname>.<poolname>"},
245         {"pool_list", jt_pool_cmd, 0,
246          "list pools and pools members\n"
247          "usage: pool_list  <fsname>[.<poolname>] | <pathname>"},
248
249 #ifdef HAVE_SERVER_SUPPORT
250         /* Barrier commands */
251         {"===  Barrier ==", NULL, 0, "barrier management"},
252         {"barrier_freeze", jt_barrier_freeze, 0,
253          "freeze write barrier on MDTs\n"
254          "usage: barrier_freeze <fsname> [timeout (in seconds)]"},
255         {"barrier_thaw", jt_barrier_thaw, 0,
256          "thaw write barrier on MDTs\n"
257          "usage: barrier_thaw <fsname>"},
258         {"barrier_stat", jt_barrier_stat, 0,
259          "query write barrier status on MDTs\n"
260          "usage: barrier_stat [--state|-s] [--timeout|-t] <fsname>"},
261         {"barrier_rescan", jt_barrier_rescan, 0,
262          "rescan the system to filter out inactive MDT(s) for barrier\n"
263          "usage: barrier_rescan <fsname> [timeout (in seconds)]"},
264
265         /* Snapshot commands */
266         {"===  Snapshot ==", NULL, 0, "Snapshot management"},
267         {"snapshot_create", jt_snapshot_create, 0,
268          "create the snapshot\n"
269          "usage: snapshot_create [-b | --barrier [on | off]]\n"
270          "                       [-c | --comment comment]\n"
271          "                       <-F | --fsname fsname>\n"
272          "                       [-h | --help] <-n | --name ssname>\n"
273          "                       [-r | --rsh remote_shell]\n"
274          "                       [-t | --timeout timeout]"},
275         {"snapshot_destroy", jt_snapshot_destroy, 0,
276          "destroy the snapshot\n"
277          "usage: snapshot_destroy [-f | --force]\n"
278          "                        <-F | --fsname fsname> [-h | --help]\n"
279          "                        <-n | --name ssname>\n"
280          "                        [-r | --rsh remote_shell]"},
281         {"snapshot_modify", jt_snapshot_modify, 0,
282          "modify the snapshot\n"
283          "usage: snapshot_modify [-c | --comment comment]\n"
284          "                       <-F | --fsname fsname> [-h | --help]\n"
285          "                       <-n | --name ssname> [-N | --new new_ssname]\n"
286          "                       [-r | --rsh remote_shell]"},
287         {"snapshot_list", jt_snapshot_list, 0,
288          "query the snapshot(s)\n"
289          "usage: snapshot_list [-d | --detail]\n"
290          "                     <-F | --fsname fsname> [-h | --help]\n"
291          "                     [-n | --name ssname] [-r | --rsh remote_shell]"},
292         {"snapshot_mount", jt_snapshot_mount, 0,
293          "mount the snapshot\n"
294          "usage: snapshot_mount <-F | --fsname fsname> [-h | --help]\n"
295          "                      <-n | --name ssname>\n"
296          "                      [-r | --rsh remote_shell]"},
297         {"snapshot_umount", jt_snapshot_umount, 0,
298          "umount the snapshot\n"
299          "usage: snapshot_umount <-F | --fsname fsname> [-h | --help]\n"
300          "                       <-n | --name ssname>\n"
301          "                       [-r | --rsh remote_shell]"},
302 #endif /* HAVE_SERVER_SUPPORT */
303         /* Nodemap commands */
304         {"=== Nodemap ===", NULL, 0, "nodemap management"},
305         {"nodemap_activate", jt_nodemap_activate, 0,
306          "activate nodemap idmapping functions\n"
307          "usage: nodemap_activate {0|1}"},
308         {"nodemap_add", jt_nodemap_add, 0,
309          "add a new nodemap\n"
310          "usage: nodemap_add <nodemap_name>"},
311         {"nodemap_del", jt_nodemap_del, 0,
312          "remove a nodemap\n"
313          "usage: nodemap_del <nodemap_name>"},
314         {"nodemap_add_range", jt_nodemap_add_range, 0,
315          "add a range to a nodemap\n"
316          "usage: nodemap_add_range <nid_range>"},
317         {"nodemap_del_range", jt_nodemap_del_range, 0,
318          "add a range to a nodemap\n"
319          "usage: nodemap_del_range <nid_range>"},
320         {"nodemap_modify", jt_nodemap_modify, 0,
321          "modify a nodemap parameters"
322          "usage: nodemap_modify nodemap_name param value"},
323         {"nodemap_add_idmap", jt_nodemap_add_idmap, 0,
324          "add a UID or GID mapping to a nodemap"},
325         {"nodemap_del_idmap", jt_nodemap_del_idmap, 0,
326          "delete a UID or GID mapping from a nodemap"},
327         {"nodemap_set_fileset", jt_nodemap_set_fileset, 0,
328          "set a fileset on a nodemap\n"
329          "usage: nodemap_set_fileset <fileset>"},
330         {"nodemap_test_nid", jt_nodemap_test_nid, 0,
331          "usage: nodemap_test_nid <nid>"},
332         {"nodemap_test_id", jt_nodemap_test_id, 0,
333          "Usage: nodemap_test_id --nid <nid> --idtype [uid|gid] --id <id>"},
334         {"nodemap_info", jt_nodemap_info, 0,
335          "Usage: nodemap_info [list|nodemap_name|all]"},
336
337         /* Changelog commands */
338         {"===  Changelogs ==", NULL, 0, "changelog user management"},
339         {"changelog_register", jt_changelog_register, 0,
340          "register a new persistent changelog user, returns id\n"
341          "usage: --device <mdtname> changelog_register [-n]"},
342         {"changelog_deregister", jt_changelog_deregister, 0,
343          "deregister an existing changelog user\n"
344          "usage: --device <mdtname> changelog_deregister <id>"},
345
346         /* Device configuration commands */
347         {"== device setup (these are not normally used post 1.4) ==",
348                 NULL, 0, "device config"},
349         {"attach", jt_lcfg_attach, 0,
350          "set the type, name, and uuid of the current device\n"
351          "usage: attach type name uuid"},
352         {"detach", jt_obd_detach, 0,
353          "remove driver (and name and uuid) from current device\n"
354          "usage: detach"},
355         {"setup", jt_lcfg_setup, 0,
356          "type specific device configuration information\n"
357          "usage: setup <args...>"},
358         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
359          "usage: cleanup [force | failover]"},
360         {"fork_lcfg", jt_lcfg_fork, 0,
361          "copy configuration files for named filesystem with given name\n"
362          "usage: fork_lcfg <fsname> <newname>"},
363         {"erase_lcfg", jt_lcfg_erase, 0,
364          "permanently erase configuration for the named filesystem\n"
365          "usage: erase_lcfg <fsname>"},
366
367         /* Test only commands */
368         {"==== testing (DANGEROUS) ====", NULL, 0, "testing (DANGEROUS)"},
369         {"--threads", jt_opt_threads, 0,
370          "run <threads> separate instances of <command> on device <devno>\n"
371          "--threads <threads> <verbose> <devno> <command [args ...]>"},
372         {"lookup", jt_obd_mdc_lookup, 0, "report file mode info\n"
373          "usage: lookup <directory> <file>"},
374         {"readonly", jt_obd_set_readonly, 0,
375          "disable writes to the underlying device\n"},
376         {"notransno", jt_obd_no_transno, 0,
377          "disable sending of committed-transno updates\n"},
378         {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a NID\n"
379          "usage: add_uuid <uuid> <nid>"},
380         {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
381          "usage: del_uuid <uuid>"},
382         {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
383          "usage: add_peer <nid> <host> <port>"},
384         {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
385          "usage: del_peer [<nid>] [<ipaddr|pid>]"},
386         {"add_conn ", jt_lcfg_add_conn, 0,
387          "usage: add_conn <conn_uuid> [priority]\n"},
388         {"del_conn ", jt_lcfg_del_conn, 0,
389          "usage: del_conn <conn_uuid>"},
390         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote NID\n"
391          "usage: disconnect [<nid>]"},
392         {"push", jt_ptl_push_connection, 0, "flush connection to a remote NID\n"
393          "usage: push [<nid>]"},
394         {"mynid", jt_ptl_mynid, 0, "inform the LND of the local NID. "
395          "The NID defaults to hostname for TCP networks.\n"
396          "usage: mynid [<nid>]"},
397         {"fail", jt_ptl_fail_nid, 0, "fail/restore network communications\n"
398          "Omitting the count means indefinitely, 0 means restore, "
399          "otherwise fail 'count' messages.\n"
400          "usage: fail nid|_all_ [count]"},
401
402         /*Test commands for echo client*/
403         {"test_create", jt_obd_test_create, 0,
404          "create files on MDT by echo client\n"
405          "usage: test_create [-d parent_basedir] <-D parent_count> "
406          "[-b child_base_id] <-c stripe_count> <-n count> <-t time>\n"},
407         {"test_mkdir", jt_obd_test_mkdir, 0,
408          "mkdir on MDT by echo client\n"
409          "usage: test_mkdir [-d parent_basedir] <-D parent_count>"
410          "[-b child_base_id] [-n count] <-t time>\n"},
411         {"test_destroy", jt_obd_test_destroy, 0,
412          "Destroy files on MDT by echo client\n"
413          "usage: test_destroy [-d parent_basedir] <-D parent_count>"
414          "[-b child_base_id] [-n count] <-t time>\n"},
415         {"test_rmdir", jt_obd_test_rmdir, 0,
416          "rmdir on MDT by echo client\n"
417          "usage: test_rmdir [-d parent_basedir] <-D parent_count>"
418          "[-b child_base_id] [-n count] <-t time>\n"},
419         {"test_lookup", jt_obd_test_lookup, 0,
420          "lookup files on MDT by echo client\n"
421          "usage: test_lookup [-d parent_basedir] <-D parent_count>"
422          "[-b child_base_id] [-n count] <-t time>\n"},
423         {"test_setxattr", jt_obd_test_setxattr, 0,
424          "Set EA for files/directory on MDT by echo client\n"
425          "usage: test_setxattr [-d parent_baseid] <-D parent_count>"
426          "[-b child_base_id] [-n count] <-t time>\n"},
427         {"test_md_getattr", jt_obd_test_md_getattr, 0,
428          "getattr files on MDT by echo client\n"
429          "usage: test_md_getattr [-d parent_basedir] <-D parent_count>"
430          "[-b child_base_id] [-n count] <-t time>\n"},
431         {"getattr", jt_obd_getattr, 0,
432          "get attribute for OST object <objid>\n"
433          "usage: getattr <objid>"},
434         {"setattr", jt_obd_setattr, 0,
435          "set mode attribute for OST object <objid>\n"
436          "usage: setattr <objid> <mode>"},
437         {"create", jt_obd_create, 0,
438          "create <num> OST objects (with <mode>)\n"
439          "usage: create [num [mode [verbose [lsm data]]]]"},
440         {"destroy", jt_obd_destroy, 0,
441          "destroy OST object <objid> [num [verbose]]\n"
442          "usage: destroy <num> objects, starting at objid <objid>"},
443         {"test_getattr", jt_obd_test_getattr, 0,
444          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
445          "usage: test_getattr <num> [verbose [[t]objid]]"},
446         {"test_setattr", jt_obd_test_setattr, 0,
447          "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
448          "usage: test_setattr <num> [verbose [[t]objid]]"},
449         {"test_brw", jt_obd_test_brw, 0,
450          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
451          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
452         {"getobjversion", jt_get_obj_version, 0,
453          "get the version of an object on servers\n"
454          "usage: getobjversion <fid>\n"
455          "       getobjversion -i <id> -g <group>"},
456 #ifdef HAVE_SERVER_SUPPORT
457         /* LFSCK commands */
458         {"==== LFSCK ====", NULL, 0, "LFSCK"},
459         {"lfsck_start", jt_lfsck_start, 0, "start LFSCK\n"
460          "usage: lfsck_start [-M | --device [MDT,OST]_device]\n"
461          "                   [-A | --all] [-c | --create-ostobj [on | off]]\n"
462          "                   [-C | --create-mdtobj [on | off]]\n"
463          "                   [-d | --delay-create-ostobj [on | off]]\n"
464          "                   [-e | --error {continue | abort}] [-h | --help]\n"
465          "                   [-n | --dryrun [on | off]] [-o | --orphan]\n"
466          "                   [-r | --reset] [-s | --speed speed_limit]\n"
467          "                   [-t | --type lfsck_type[,lfsck_type...]]\n"
468          "                   [-w | --window-size size]"},
469         {"lfsck_stop", jt_lfsck_stop, 0, "stop lfsck(s)\n"
470          "usage: lfsck_stop [-M | --device [MDT,OST]_device]\n"
471          "                  [-A | --all] [-h | --help]"},
472         {"lfsck_query", jt_lfsck_query, 0, "check lfsck(s) status\n"
473          "usage: lfsck_query [-M | --device MDT_device] [-h | --help]\n"
474          "                   [-t | --type lfsck_type[,lfsck_type...]]\n"
475          "                   [-w | --wait]"},
476 #endif /* HAVE_SERVER_SUPPORT */
477         {"==== obsolete (DANGEROUS) ====", NULL, 0, "obsolete (DANGEROUS)"},
478         /* some test scripts still use these */
479         {"cfg_device", jt_obd_device, 0,
480          "set current device to <name>\n"
481          "usage: device <name>"},
482         {"recover", jt_obd_recover, 0,
483          "try to restore a lost connection immediately\n"
484          "usage: recover [MDC/OSC device]"},
485         /* saving for sanity 44a */
486         {"lov_getconfig", jt_obd_lov_getconfig, 0,
487          "read lov configuration from an mds device\n"
488          "usage: lov_getconfig <mountpoint>"},
489         /* Llog operations */
490         {"llog_catlist", jt_llog_catlist, 0,
491          "list all catalog logs on current device.\n"
492          "usage: llog_catlist"},
493         {"llog_info", jt_llog_info, 0,
494          "print log header information.\n"
495          "usage: llog_info <logname|[FID]>\n"
496          "       oid, ogr and ogen are hexadecimal."},
497         {"llog_print", jt_llog_print, 0,
498          "print log content information.\n"
499          "usage: llog_print <logname|[FID]> [start_index [end_index]]\n"
500          "       print all records from index 1 by default."},
501         {"llog_check", jt_llog_check, 0,
502          "print log content information.\n"
503          "usage: llog_check <logname|[FID]> [start_index] [end_index]\n"
504          "       check all records from index 1 by default."},
505         {"llog_cancel", jt_llog_cancel, 0,
506          "cancel one record in log.\n"
507          "This command supports both positional and optional arguments\n"
508          "usage (positional args): "
509          "llog_cancel <catalog name|[FID]> [log id] <index>\n"
510          "usage (optional args): "
511          "llog_cancel --catalog <catalog id|catalog name> --log_id <log_id> "
512          "--log_idx <index>"},
513         {"llog_remove", jt_llog_remove, 0,
514          "remove one log from catalog or plain log, erase it from disk.\n"
515          "usage: llog_remove <catalog name|[FID]> <log id>"},
516         /* network operations */
517         {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
518          "usage: add_interface ip [netmask]"},
519         {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
520          "usage: del_interface [ip]"},
521         {"add_route", jt_ptl_add_route, 0,
522          "add an entry to the LNet routing table\n"
523          "usage: add_route <gateway> [<hops> [<priority>]]"},
524         {"del_route", jt_ptl_del_route, 0,
525          "delete route via gateway to targets from the LNet routing table\n"
526          "usage: del_route <gateway> [<target>] [<target>]"},
527         {"set_route", jt_ptl_notify_router, 0,
528          "enable/disable routes via gateway in the LNet routing table\n"
529          "usage: set_route <gateway> <up/down> [<time>]"},
530
531         { 0, 0, 0, NULL }
532 };
533
534 int lctl_main(int argc, char **argv)
535 {
536         int rc;
537
538         setlinebuf(stdout);
539
540         if (ptl_initialize(argc, argv) < 0)
541                 exit(1);
542         if (obd_initialize(argc, argv) < 0)
543                 exit(2);
544         if (dbg_initialize(argc, argv) < 0)
545                 exit(3);
546
547         Parser_init("lctl > ", cmdlist);
548
549         if (argc > 1) {
550                 llapi_set_command_name(argv[1]);
551                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
552                 llapi_clear_command_name();
553         } else {
554                 rc = Parser_commands();
555         }
556
557         obd_finalize(argc, argv);
558         return rc < 0 ? -rc : rc;
559 }
560
561 static int lctl_list_commands(int argc, char **argv)
562 {
563         char buffer[81] = ""; /* 80 printable chars + terminating NUL */
564         command_t *cmd;
565         int rc;
566
567         cmd = cmdlist;
568         while (cmd->pc_name != NULL) {
569                 printf("\n%s\n", cmd->pc_name); /* Command category */
570                 cmd++;
571                 rc = Parser_list_commands(cmd, buffer, sizeof(buffer), NULL,
572                                          0, 4);
573                 cmd += rc;
574         }
575
576         return 0;
577 }
578
579 int main(int argc, char **argv)
580 {
581         return lctl_main(argc, argv);
582 }