Whamcloud - gitweb
b=14471
[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         {"get_param", jt_lcfg_getparam, 0, "get the Lustre or LNET parameter\n"
123          "usage: get_param [-n] path/to/param/file \n"
124          "Get the value of Lustre or LNET parameter from the specified path\n"
125          "Use '-n' to disable printing of the key name when printing values."},
126         {"set_param", jt_lcfg_setparam, 0, "set the Lustre or LNET parameter\n"
127          "usage: set_param [-n] path/to/param/file value\n"
128          "Set the value of the Lustre or LNET parameter at the specified path\n"
129          "Use '-n' to disable printing of the key name when printing values."},
130
131         /* Debug commands */
132         {"==== debugging control ====", jt_noop, 0, "debug"},
133         {"debug_daemon", jt_dbg_debug_daemon, 0,
134          "debug daemon control and dump to a file\n"
135          "usage: debug_daemon {start file [#MB]|stop}"},
136         {"debug_kernel", jt_dbg_debug_kernel, 0,
137          "get debug buffer and dump to a file, same as dk\n"
138          "usage: debug_kernel [file] [raw]"},
139         {"dk", jt_dbg_debug_kernel, 0,
140          "get debug buffer and dump to a file, same as debug_kernel\n"
141          "usage: dk [file] [raw]"},
142         {"debug_file", jt_dbg_debug_file, 0,
143          "convert a binary debug file dumped by the kernel to ASCII text\n"
144          "usage: debug_file <input> [output]"},
145         {"df", jt_dbg_debug_file, 0,
146          "read debug buffer from input and dump to output, same as debug_file\n"
147          "usage: df <input> [output]"},
148         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
149          "usage: clear"},
150         {"mark", jt_dbg_mark_debug_buf, 0,
151          "insert marker text in kernel debug buffer\n"
152          "usage: mark <text>"},
153         {"filter", jt_dbg_filter, 0, "filter message type\n"
154          "usage: filter <subsystem id/debug mask>"},
155         {"show", jt_dbg_show, 0, "Show specific type of messages\n"
156          "usage: show <subsystem id/debug mask>"},
157         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
158          "usage: debug_list <subs/types>"},
159         {"modules", jt_dbg_modules, 0,
160          "provide gdb-friendly module information\n"
161          "usage: modules <path>"},
162
163         /* Device configuration commands */
164         {"== device setup (these are not normally used post 1.4) ==",
165                 jt_noop, 0, "device config"},
166         {"attach", jt_lcfg_attach, 0,
167          "set the type, name, and uuid of the current device\n"
168          "usage: attach type name uuid"},
169         {"detach", jt_obd_detach, 0,
170          "remove driver (and name and uuid) from current device\n"
171          "usage: detach"},
172         {"setup", jt_lcfg_setup, 0,
173          "type specific device configuration information\n"
174          "usage: setup <args...>"},
175         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
176          "usage: cleanup [force | failover]"},
177         {"dump_cfg", jt_cfg_dump_log, 0,
178          "print log of recorded commands for this config to kernel debug log\n"
179          "usage: dump_cfg config-uuid-name"},
180
181         /* virtual block operations */
182         {"==== virtual block device ====", jt_noop, 0, "virtual block device"},
183         {"blockdev_attach", jt_blockdev_attach, 0,
184          "attach a lustre regular file to a virtual block device\n"
185          "usage: blockdev_attach <file_name> <device_name>"},
186         {"blockdev_detach", jt_blockdev_detach, 0,
187          "detach a lustre regular file from a virtual block device\n"
188          "usage: blockdev_detach <device_name>"},
189         {"blockdev_info", jt_blockdev_info, 0,
190          "get the device info of a attached file\n"
191          "usage: blockdev_info <device_name>"},
192
193         /* Test only commands */
194         {"==== testing (DANGEROUS) ====", jt_noop, 0, "testing (DANGEROUS)"},
195         {"--threads", jt_opt_threads, 0,
196          "run <threads> separate instances of <command> on device <devno>\n"
197          "--threads <threads> <verbose> <devno> <command [args ...]>"},
198         {"lookup", jt_obd_mdc_lookup, 0, "report file mode info\n"
199          "usage: lookup <directory> <file>"},
200         {"readonly", jt_obd_set_readonly, 0,
201          "disable writes to the underlying device\n"},
202         {"notransno", jt_obd_no_transno, 0,
203          "disable sending of committed-transno updates\n"},
204         {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a nid\n"
205          "usage: add_uuid <uuid> <nid>"},
206         {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
207          "usage: del_uuid <uuid>"},
208         {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
209          "usage: add_peer <nid> <host> <port>"},
210         {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
211          "usage: del_autoconn [<nid>] [<host>] [ks]"},
212         {"add_conn ", jt_lcfg_add_conn, 0,
213          "usage: add_conn <conn_uuid> [priority]\n"},
214         {"del_conn ", jt_lcfg_del_conn, 0,
215          "usage: del_conn <conn_uuid> \n"},
216         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
217          "usage: disconnect [<nid>]"},
218         {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
219          "The nid defaults to hostname for tcp networks and is automatically "
220          "setup for elan/myrinet networks.\n"
221          "usage: mynid [<nid>]"},
222         {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
223          "Omitting the count means indefinitely, 0 means restore, "
224          "otherwise fail 'count' messages.\n"
225          "usage: fail nid|_all_ [count]"},
226         {"getattr", jt_obd_getattr, 0,
227          "get attribute for OST object <objid>\n"
228          "usage: getattr <objid>"},
229         {"setattr", jt_obd_setattr, 0,
230          "set mode attribute for OST object <objid>\n"
231          "usage: setattr <objid> <mode>"},
232          {"create", jt_obd_create, 0,
233          "create <num> OST objects (with <mode>)\n"
234          "usage: create [num [mode [verbose [lsm data]]]]"},
235         {"destroy", jt_obd_destroy, 0,
236          "destroy OST object <objid> [num [verbose]]\n"
237          "usage: destroy <num> objects, starting at objid <objid>"},
238         {"test_getattr", jt_obd_test_getattr, 0,
239          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
240          "usage: test_getattr <num> [verbose [[t]objid]]"},
241         {"test_setattr", jt_obd_test_setattr, 0,
242          "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
243          "usage: test_setattr <num> [verbose [[t]objid]]"},
244         {"test_brw", jt_obd_test_brw, 0,
245          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
246          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
247         {"lwt", jt_ptl_lwt, 0,
248          "light-weight tracing\n"
249          "usage: lwt start\n"
250          "       lwt stop [file]"},
251         {"memhog", jt_ptl_memhog, 0,
252          "memory pressure testing\n"
253          "usage: memhog <page count> [<gfp flags>]"},
254
255         {"==== obsolete (DANGEROUS) ====", jt_noop, 0, "obsolete (DANGEROUS)"},
256         /* some test scripts still use these */
257         {"cfg_device", jt_obd_device, 0,
258          "set current device to <name>\n"
259          "usage: device <name>"},
260         {"recover", jt_obd_recover, 0,
261          "try to restore a lost connection immediately\n"
262          "usage: recover [MDC/OSC device]"},
263         /* saving for sanity 44a */
264         {"lov_getconfig", jt_obd_lov_getconfig, 0,
265          "read lov configuration from an mds device\n"
266          "usage: lov_getconfig <mountpoint>"},
267         /* Llog operations */
268         {"llog_catlist", jt_llog_catlist, 0,
269          "list all catalog logs on current device.\n"
270          "usage: llog_catlist"},
271         {"llog_info", jt_llog_info, 0,
272          "print log header information.\n"
273          "usage: llog_info <$logname|#oid#ogr#ogen>\n"
274          "       oid, ogr and ogen are hexadecimal."},
275         {"llog_print", jt_llog_print, 0,
276          "print log content information.\n"
277          "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
278          "       oid, ogr and ogen are hexadecimal.\n"
279          "       print all records from index 1 by default."},
280         {"llog_check", jt_llog_check, 0,
281          "print log content information.\n"
282          "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
283          "       oid, ogr and ogen are hexadecimal.\n"
284          "       check all records from index 1 by default."},
285          {"llog_cancel", jt_llog_cancel, 0,
286          "cancel one record in log.\n"
287          "usage: llog_cancel <catalog id|catalog name> <log id> <index>"},
288         {"llog_remove", jt_llog_remove, 0,
289          "remove one log from catalog, erase it from disk.\n"
290          "usage: llog_remove <catalog id|catalog name> <log id>"},
291         /* network operations */
292         {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
293          "usage: add_interface ip [netmask]"},
294         {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
295          "usage: del_interface [ip]"},
296         {"add_route", jt_ptl_add_route, 0,
297          "add an entry to the portals routing table\n"
298          "usage: add_route <gateway> <target> [<target>]"},
299         {"del_route", jt_ptl_del_route, 0,
300          "delete route via gateway to targets from the portals routing table\n"
301          "usage: del_route <gateway> [<target>] [<target>]"},
302         {"set_route", jt_ptl_notify_router, 0,
303          "enable/disable routes via gateway in the portals routing table\n"
304          "usage: set_route <gateway> <up/down> [<time>]"},
305
306         { 0, 0, 0, NULL }
307 };
308
309 int lctl_main(int argc, char **argv)
310 {
311         int rc;
312
313         setlinebuf(stdout);
314
315         ptl_initialize(argc, argv);
316         if (obd_initialize(argc, argv) < 0)
317                 exit(2);
318         if (dbg_initialize(argc, argv) < 0)
319                 exit(3);
320
321         Parser_init("lctl > ", cmdlist);
322
323         if (argc > 1) {
324                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
325         } else {
326                 rc = Parser_commands();
327         }
328
329         obd_finalize(argc, argv);
330         return rc;
331 }
332
333 #ifndef LIBLUSTRE_TEST
334 int main (int argc, char **argv)
335 {
336         return (lctl_main (argc, argv));
337 }
338 #endif