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