Whamcloud - gitweb
b=12797
[fs/lustre-release.git] / lustre / utils / lctl.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *   Author: Peter J. Braam <braam@clusterfs.com>
6  *   Author: Phil Schwan <phil@clusterfs.com>
7  *   Author: Robert Read <rread@clusterfs.com>
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  */
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <lnet/lnetctl.h>
29 #include "obdctl.h"
30 #include "parser.h"
31
32 static int jt_quit(int argc, char **argv) {
33         Parser_quit(argc, argv);
34         return 0;
35 }
36
37 static int jt_noop(int argc, char **argv) {
38         return 0;
39 }
40
41 static int jt_opt_ignore_errors(int argc, char **argv) {
42         Parser_ignore_errors(1);
43         return 0;
44 }
45
46 command_t cmdlist[] = {
47         /* Metacommands */
48         {"===== metacommands =======", jt_noop, 0, "metacommands"},
49         {"--device", jt_opt_device, 0,
50          "run <command> after connecting to device <devno>\n"
51          "--device <devno> <command [args ...]>"},
52         {"--ignore_errors", jt_opt_ignore_errors, 0,
53          "ignore errors that occur during script processing\n"
54          "--ignore_errors"},
55         {"ignore_errors", jt_opt_ignore_errors, 0,
56          "ignore errors that occur during script processing\n"
57          "ignore_errors"},
58
59         /* User interface commands */
60         {"======== control =========", jt_noop, 0, "control commands"},
61         {"help", Parser_help, 0, "help"},
62         {"lustre_build_version", jt_get_version, 0,
63          "print the build version of lustre\n"
64          "usage: lustre_build_version"},
65         {"exit", jt_quit, 0, "quit"},
66         {"quit", jt_quit, 0, "quit"},
67
68         /* Network configuration commands */
69         {"===== network config =====", jt_noop, 0, "network config"},
70         {"--net", jt_opt_net, 0,"run <command> after setting network to <net>\n"
71          "usage: --net <tcp/elan/gm/...> <command>"},
72         {"network", jt_ptl_network, 0, "configure LNET"
73          "usage: network up|down"},
74         {"net", jt_ptl_network, 0, "configure LNET"
75          "usage: net up|down"},
76         {"list_nids", jt_ptl_list_nids, 0, "list local NIDs"
77          "usage: list_nids [all]"},
78         {"which_nid", jt_ptl_which_nid, 0, "choose a NID"
79          "usage: which_nid NID [NID...]"},
80         {"interface_list", jt_ptl_print_interfaces,0,"print interface entries\n"
81          "usage: interface_list"},
82         {"peer_list", jt_ptl_print_peers, 0, "print peer entries\n"
83          "usage: peer_list"},
84         {"conn_list", jt_ptl_print_connections, 0,
85          "print all the connected remote nid\n"
86          "usage: conn_list"},
87         {"active_tx", jt_ptl_print_active_txs, 0, "print active transmits\n"
88          "usage: active_tx"},
89         {"route_list", jt_ptl_print_routes, 0,
90          "print the portals routing table, same as show_route\n"
91          "usage: route_list"},
92         {"show_route", jt_ptl_print_routes, 0,
93          "print the portals routing table, same as route_list\n"
94          "usage: show_route"},
95         {"ping", jt_ptl_ping, 0, "Check LNET connectivity\n"
96          "usage: ping nid [timeout] [pid]"},
97
98         /* Device selection commands */
99         {"==== obd device selection ====", jt_noop, 0, "device selection"},
100         {"device", jt_obd_device, 0,
101          "set current device to <name|devno>\n"
102          "usage: device <%name|$name|devno>"},
103         {"device_list", jt_obd_list, 0, "show all devices\n"
104          "usage: device_list"},
105         {"dl", jt_obd_list, 0, "show all devices\n"
106          "usage: dl"},
107
108         /* Device operations */
109         {"==== obd device operations ====", jt_noop, 0, "device operations"},
110         {"activate", jt_obd_activate, 0, "activate an import\n"},
111         {"deactivate", jt_obd_deactivate, 0, "deactivate an import. "
112          "This command should be used on failed OSC devices in an MDT LOV.\n"},
113         {"abort_recovery", jt_obd_abort_recovery, 0,
114          "abort recovery on a restarting MDT or OST device\n"},
115         {"set_timeout", jt_lcfg_set_timeout, 0,
116          "usage: conf_param obd_timeout=<secs>\n"},
117         {"conf_param", jt_lcfg_mgsparam, 0, "set a permanent config param. "
118          "This command must be run on the MGS node\n"
119          "usage: conf_param <target.keyword=val> ...\n"},
120         {"local_param", jt_lcfg_param, 0, "set a temporary, local param\n"
121          "usage: local_param <target.keyword=val> ...\n"},
122
123         /* Debug commands */
124         {"==== debugging control ====", jt_noop, 0, "debug"},
125         {"debug_daemon", jt_dbg_debug_daemon, 0,
126          "debug daemon control and dump to a file\n"
127          "usage: debug_daemon {start file [#MB]|stop}"},
128         {"debug_kernel", jt_dbg_debug_kernel, 0,
129          "get debug buffer and dump to a file, same as dk\n"
130          "usage: debug_kernel [file] [raw]"},
131         {"dk", jt_dbg_debug_kernel, 0,
132          "get debug buffer and dump to a file, same as debug_kernel\n"
133          "usage: dk [file] [raw]"},
134         {"debug_file", jt_dbg_debug_file, 0,
135          "convert a binary debug file dumped by the kernel to ASCII text\n"
136          "usage: debug_file <input> [output]"},
137         {"df", jt_dbg_debug_file, 0,
138          "read debug buffer from input and dump to output, same as debug_file\n"
139          "usage: df <input> [output]"},
140         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
141          "usage: clear"},
142         {"mark", jt_dbg_mark_debug_buf, 0,
143          "insert marker text in kernel debug buffer\n"
144          "usage: mark <text>"},
145         {"filter", jt_dbg_filter, 0, "filter message type\n"
146          "usage: filter <subsystem id/debug mask>"},
147         {"show", jt_dbg_show, 0, "Show specific type of messages\n"
148          "usage: show <subsystem id/debug mask>"},
149         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
150          "usage: debug_list <subs/types>"},
151         {"modules", jt_dbg_modules, 0,
152          "provide gdb-friendly module information\n"
153          "usage: modules <path>"},
154
155         /* Device configuration commands */
156         {"== device setup (these are not normally used post 1.4) ==",
157                 jt_noop, 0, "device config"},
158         {"attach", jt_lcfg_attach, 0,
159          "set the type, name, and uuid of the current device\n"
160          "usage: attach type name uuid"},
161         {"detach", jt_obd_detach, 0,
162          "remove driver (and name and uuid) from current device\n"
163          "usage: detach"},
164         {"setup", jt_lcfg_setup, 0,
165          "type specific device configuration information\n"
166          "usage: setup <args...>"},
167         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
168          "usage: cleanup [force | failover]"},
169         {"dump_cfg", jt_cfg_dump_log, 0,
170          "print log of recorded commands for this config to kernel debug log\n"
171          "usage: dump_cfg config-uuid-name"},
172
173         /* virtual block operations */
174         {"==== virtual block device ====", jt_noop, 0, "virtual block device"},
175         {"blockdev_attach", jt_blockdev_attach, 0,
176          "attach a lustre regular file to a virtual block device\n"
177          "usage: blockdev_attach <file_name> <device_name>"},
178         {"blockdev_detach", jt_blockdev_detach, 0,
179          "detach a lustre regular file from a virtual block device\n"
180          "usage: blockdev_detach <device_name>"},
181         {"blockdev_info", jt_blockdev_info, 0,
182          "get the device info of a attached file\n"
183          "usage: blockdev_info <device_name>"},
184
185         /* Test only commands */
186         {"==== testing (DANGEROUS) ====", jt_noop, 0, "testing (DANGEROUS)"},
187         {"--threads", jt_opt_threads, 0,
188          "run <threads> separate instances of <command> on device <devno>\n"
189          "--threads <threads> <verbose> <devno> <command [args ...]>"},
190         {"lookup", jt_obd_mdc_lookup, 0, "report file mode info\n"
191          "usage: lookup <directory> <file>"},
192         {"readonly", jt_obd_set_readonly, 0,
193          "disable writes to the underlying device\n"},
194         {"notransno", jt_obd_no_transno, 0,
195          "disable sending of committed-transno updates\n"},
196         {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a nid\n"
197          "usage: add_uuid <uuid> <nid>"},
198         {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
199          "usage: del_uuid <uuid>"},
200         {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
201          "usage: add_peer <nid> <host> <port>"},
202         {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
203          "usage: del_autoconn [<nid>] [<host>] [ks]"},
204         {"add_conn ", jt_lcfg_add_conn, 0,
205          "usage: add_conn <conn_uuid> [priority]\n"},
206         {"del_conn ", jt_lcfg_del_conn, 0,
207          "usage: del_conn <conn_uuid> \n"},
208         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
209          "usage: disconnect [<nid>]"},
210         {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
211          "The nid defaults to hostname for tcp networks and is automatically "
212          "setup for elan/myrinet networks.\n"
213          "usage: mynid [<nid>]"},
214         {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
215          "Omitting the count means indefinitely, 0 means restore, "
216          "otherwise fail 'count' messages.\n"
217          "usage: fail nid|_all_ [count]"},
218         {"getattr", jt_obd_getattr, 0,
219          "get attribute for OST object <objid>\n"
220          "usage: getattr <objid>"},
221         {"setattr", jt_obd_setattr, 0,
222          "set mode attribute for OST object <objid>\n"
223          "usage: setattr <objid> <mode>"},
224          {"create", jt_obd_create, 0,
225          "create <num> OST objects (with <mode>)\n"
226          "usage: create [num [mode [verbose [lsm data]]]]"},
227         {"destroy", jt_obd_destroy, 0,
228          "destroy OST object <objid> [num [verbose]]\n"
229          "usage: destroy <num> objects, starting at objid <objid>"},
230         {"test_getattr", jt_obd_test_getattr, 0,
231          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
232          "usage: test_getattr <num> [verbose [[t]objid]]"},
233         {"test_setattr", jt_obd_test_setattr, 0,
234          "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
235          "usage: test_setattr <num> [verbose [[t]objid]]"},
236         {"test_brw", jt_obd_test_brw, 0,
237          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
238          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
239         {"lwt", jt_ptl_lwt, 0,
240          "light-weight tracing\n"
241          "usage: lwt start\n"
242          "       lwt stop [file]"},
243         {"memhog", jt_ptl_memhog, 0,
244          "memory pressure testing\n"
245          "usage: memhog <page count> [<gfp flags>]"},
246
247         {"==== obsolete (DANGEROUS) ====", jt_noop, 0, "obsolete (DANGEROUS)"},
248         /* some test scripts still use these */
249         {"cfg_device", jt_obd_device, 0,
250          "set current device to <name>\n"
251          "usage: device <name>"},
252         {"recover", jt_obd_recover, 0,
253          "try to restore a lost connection immediately\n"
254          "usage: recover [MDC/OSC device]"},
255         /* saving for sanity 44a */
256         {"lov_getconfig", jt_obd_lov_getconfig, 0,
257          "read lov configuration from an mds device\n"
258          "usage: lov_getconfig <mountpoint>"},
259         /* Llog operations */
260         {"llog_catlist", jt_llog_catlist, 0,
261          "list all catalog logs on current device.\n"
262          "usage: llog_catlist"},
263         {"llog_info", jt_llog_info, 0,
264          "print log header information.\n"
265          "usage: llog_info <$logname|#oid#ogr#ogen>\n"
266          "       oid, ogr and ogen are hexadecimal."},
267         {"llog_print", jt_llog_print, 0,
268          "print log content information.\n"
269          "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
270          "       oid, ogr and ogen are hexadecimal.\n"
271          "       print all records from index 1 by default."},
272         {"llog_check", jt_llog_check, 0,
273          "print log content information.\n"
274          "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
275          "       oid, ogr and ogen are hexadecimal.\n"
276          "       check all records from index 1 by default."},
277          {"llog_cancel", jt_llog_cancel, 0,
278          "cancel one record in log.\n"
279          "usage: llog_cancel <catalog id|catalog name> <log id> <index>"},
280         {"llog_remove", jt_llog_remove, 0,
281          "remove one log from catalog, erase it from disk.\n"
282          "usage: llog_remove <catalog id|catalog name> <log id>"},
283         /* network operations */
284         {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
285          "usage: add_interface ip [netmask]"},
286         {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
287          "usage: del_interface [ip]"},
288         {"add_route", jt_ptl_add_route, 0,
289          "add an entry to the portals routing table\n"
290          "usage: add_route <gateway> <target> [<target>]"},
291         {"del_route", jt_ptl_del_route, 0,
292          "delete route via gateway to targets from the portals routing table\n"
293          "usage: del_route <gateway> [<target>] [<target>]"},
294         {"set_route", jt_ptl_notify_router, 0,
295          "enable/disable routes via gateway in the portals routing table\n"
296          "usage: set_route <gateway> <up/down> [<time>]"},
297
298         { 0, 0, 0, NULL }
299 };
300
301 int lctl_main(int argc, char **argv)
302 {
303         int rc;
304
305         setlinebuf(stdout);
306
307         ptl_initialize(argc, argv);
308         if (obd_initialize(argc, argv) < 0)
309                 exit(2);
310         if (dbg_initialize(argc, argv) < 0)
311                 exit(3);
312
313         Parser_init("lctl > ", cmdlist);
314
315         if (argc > 1) {
316                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
317         } else {
318                 rc = Parser_commands();
319         }
320
321         obd_finalize(argc, argv);
322         return rc;
323 }
324
325 #ifndef LIBLUSTRE_TEST
326 int main (int argc, char **argv)
327 {
328         return (lctl_main (argc, argv));
329 }
330 #endif