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