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