Whamcloud - gitweb
landing smfs.
[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
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <portals/ptlctl.h>
31 #include "obdctl.h"
32 #include "parser.h"
33
34 static int jt_quit(int argc, char **argv) {
35         Parser_quit(argc, argv);
36         return 0;
37 }
38
39 static int jt_noop(int argc, char **argv) {
40         return 0;
41 }
42
43 static int jt_opt_ignore_errors(int argc, char **argv) {
44         Parser_ignore_errors(1);
45         return 0;
46 }
47
48 command_t cmdlist[] = {
49         /* Metacommands */
50         {"--device", jt_opt_device, 0,
51          "run <command> after connecting to device <devno>\n"
52          "--device <devno> <command [args ...]>"},
53         {"--threads", jt_opt_threads, 0,
54          "run <threads> separate instances of <command> on device <devno>\n"
55          "--threads <threads> <verbose> <devno> <command [args ...]>"},
56         {"--ignore_errors", jt_opt_ignore_errors, 0,
57          "ignore errors that occur during script processing\n"
58          "--ignore_errors"},
59         {"ignore_errors", jt_opt_ignore_errors, 0,
60          "ignore errors that occur during script processing\n"
61          "ignore_errors"},
62         {"dump", jt_ioc_dump, 0, "usage: dump file, save ioctl buffer to file"},
63
64         /* Network configuration commands */
65         {"==== network config ====", jt_noop, 0, "network config"},
66         {"--net", jt_opt_net, 0, "run <command> after setting network to <net>\n"
67          "usage: --net <tcp/elan/myrinet> <command>"},
68         {"network", jt_ptl_network, 0, "commands that follow apply to net\n"
69          "usage: network <tcp/elan/myrinet>"},
70         {"autoconn_list", jt_ptl_print_autoconnects, 0, "print autoconnect entries\n"
71          "usage: print_autoconns"},
72         {"add_autoconn", jt_ptl_add_autoconnect, 0, "add an autoconnect entry\n"
73          "usage: add_autoconn <nid> <host> <port> [ise]"},
74         {"del_autoconn", jt_ptl_del_autoconnect, 0, "remove an autoconnect entry\n"
75          "usage: del_autoconn [<nid>] [<host>] [ks]"},
76         {"conn_list", jt_ptl_print_connections, 0, "connect to a remote nid\n"
77          "usage: print_conns"},
78         {"connect", jt_ptl_connect, 0, "connect to a remote nid\n"
79          "usage: connect <host> <port> [iIOC]"},
80         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
81          "usage: disconnect [<nid>]"},
82         {"active_tx", jt_ptl_print_active_txs, 0, "print active transmits (no args)\n"
83          "usage: active_tx"},
84         {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
85          "The nid defaults to hostname for tcp networks and is automatically "
86          "setup for elan/myrinet networks.\n"
87          "usage: mynid [<nid>]"},
88         {"shownid", jt_ptl_shownid, 0, "print the local NID\n"
89          "usage: shownid"},
90         {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a nid\n"
91          "usage: add_uuid <uuid> <nid> <net_type>"},
92         {"close_uuid", jt_obd_close_uuid, 0, "disconnect a UUID\n"
93          "usage: close_uuid <uuid> <net-type>)"},
94         {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
95          "usage: del_uuid <uuid>"},
96         {"add_route", jt_ptl_add_route, 0,
97          "add an entry to the portals routing table\n"
98          "usage: add_route <gateway> <target> [<target>]"},
99         {"del_route", jt_ptl_del_route, 0,
100          "delete the route via the given gateway to the given targets from the portals routing table\n"
101          "usage: del_route <gateway> [<target>] [<target>]"},
102         {"set_route", jt_ptl_notify_router, 0,
103          "enable/disable routes via the given gateway in the portals routing table\n"
104          "usage: set_route <gateway> <up/down> [<time>]"},
105         {"route_list", jt_ptl_print_routes, 0, "print the portals routing table\n"
106          "usage: route_list"},
107         {"recv_mem", jt_ptl_rxmem, 0, "set socket receive buffer size, "
108          "if size is omited the current size is reported.\n"
109          "usage: recv_mem [size]"},
110         {"send_mem", jt_ptl_txmem, 0, "set socket send buffer size, "
111          "if size is omited the current size is reported.\n"
112          "usage: send_mem [size]"},
113         {"nagle", jt_ptl_nagle, 0, "enable/disable nagle, omitting the "
114          "argument will cause the current nagle setting to be reported.\n"
115          "usage: nagle [on/off]"},
116         {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
117          "Omitting the count means indefinitely, 0 means restore, "
118          "otherwise fail 'count' messages.\n"
119          "usage: fail nid|_all_ [count]"},
120
121         /* Device selection commands */
122         {"=== device selection ===", jt_noop, 0, "device selection"},
123         {"newdev", jt_lcfg_newdev, 0, "create a new device\n"
124          "usage: newdev"},
125         {"device", jt_obd_device, 0,
126          "set current device to <%name|$name|devno>\n"
127          "usage: device <%name|$name|devno>"},
128         {"cfg_device", jt_lcfg_device, 0,
129          "set current device being configured to <$name>\n"
130          "usage: device <name>"},
131         {"device_list", jt_obd_list, 0, "show all devices\n"
132          "usage: device_list"},
133         {"dl", jt_obd_list, 0, "show all devices\n"
134          "usage: dl"},
135         {"lustre_build_version", jt_get_version, 0,
136          "print the build version of lustre\n"
137          "usage: lustre_build_version"},
138
139         /* Device configuration commands */
140         {"==== device config =====", jt_noop, 0, "device config"},
141         {"attach", jt_lcfg_attach, 0,
142          "set the type of the current device (with <name> and <uuid>)\n"
143          "usage: attach type [name [uuid]]"},
144         {"setup", jt_lcfg_setup, 0,
145          "type specific device configuration information\n"
146          "usage: setup <args...>"},
147         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
148          "usage: cleanup [force | failover]"},
149         {"detach", jt_obd_detach, 0,
150          "remove driver (and name and uuid) from current device\n"
151          "usage: detach"},
152         {"lov_setup", jt_lcfg_lov_setup, 0,
153          "write setup an lov device\n"
154          "usage: lov_setconfig lov-uuid stripe-count stripe-size offset pattern UUID1 [UUID2 ...]"},
155         {"lov_getconfig", jt_obd_lov_getconfig, 0,
156          "read lov configuration from an mds device\n"
157          "usage: lov_getconfig lov-uuid"},
158         {"record", jt_cfg_record, 0, "record commands that follow in log\n"
159          "usage: record cfg-uuid-name"},
160         {"endrecord", jt_cfg_endrecord, 0, "stop recording\n"
161          "usage: endrecord"},
162         {"parse", jt_cfg_parse, 0, "parse the log of recorded commands for this config\n"
163          "usage: parse config-uuid-name"},
164         {"dump_log", jt_cfg_dump_log, 0, "print log of recorded commands for this config to kernel debug log\n"
165          "usage: dump_log config-uuid-name"},
166         {"clear_log", jt_cfg_clear_log, 0, "delete current config log of recorded commands\n"
167          "usage: clear_log config-name"},
168
169         /* Device operations */
170         {"=== device operations ==", jt_noop, 0, "device operations"},
171         {"probe", jt_obd_connect, 0,
172          "build a connection handle to a device.  This command is used to "
173          "suspend configuration until lctl has ensured that the mds and osc "
174          "services are available.  This is to avoid mount failures in a "
175          "rebooting cluster.\n"
176          "usage: probe [timeout]"},
177         {"close", jt_obd_disconnect, 0,
178          "close the connection handle\n"
179          "usage: close"},
180         {"getattr", jt_obd_getattr, 0,
181          "get attribute for OST object <objid>\n"
182          "usage: getattr <objid>"},
183         {"setattr", jt_obd_setattr, 0,
184          "set mode attribute for OST object <objid>\n"
185          "usage: setattr <objid> <mode>"},
186          {"create", jt_obd_create, 0,
187          "create <num> OST objects (with <mode>)\n"
188          "usage: create [num [mode [verbose [lsm data]]]]"},
189         {"destroy", jt_obd_destroy, 0,
190          "destroy OST object <objid> [num [verbose]]\n"
191          "usage: destroy <num> objects, starting at objid <objid>"},
192         {"test_getattr", jt_obd_test_getattr, 0,
193          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
194          "usage: test_getattr <num> [verbose [[t]objid]]"},
195         {"test_brw", jt_obd_test_brw, 0,
196          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
197          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
198         {"get_stripe", jt_obd_get_stripe, 0,
199          "show stripe info for an echo client object\n"
200          "usage: get_stripe objid\n"},
201         {"set_stripe", jt_obd_set_stripe, 0,
202          "set stripe info for an echo client object\n"
203          "usage: set_stripe objid[=width!count[@offset][:id:id...]\n"},
204         {"unset_stripe", jt_obd_unset_stripe, 0,
205          "unset stripe info for an echo client object\n"
206          "usage: unset_stripe objid\n"},
207         {"test_ldlm", jt_obd_test_ldlm, 0,
208          "perform lock manager test\n"
209          "usage: test_ldlm"},
210         {"ldlm_regress_start", jt_obd_ldlm_regress_start, 0,
211          "start lock manager stress test\n"
212          "usage: ldlm_regress_start [numthreads [refheld [numres [numext]]]]"},
213         {"ldlm_regress_stop", jt_obd_ldlm_regress_stop, 0,
214          "stop lock manager stress test (no args)\n"},
215         {"dump_ldlm", jt_obd_dump_ldlm, 0,
216          "dump all lock manager state (no args)"},
217         {"activate", jt_obd_activate, 0, "activate an import\n"},
218         {"deactivate", jt_obd_deactivate, 0, "deactivate an import\n"},
219         {"recover", jt_obd_recover, 0, "usage: recover [<connection UUID>]"},
220         {"lookup", jt_obd_mdc_lookup, 0, "usage: lookup <directory> <file>"},
221         {"notransno", jt_obd_no_transno, 0,
222          "disable sending of committed-transno updates\n"},
223         {"readonly", jt_obd_set_readonly, 0,
224          "disable writes to the underlying device\n"},
225         {"abort_recovery", jt_obd_abort_recovery, 0,
226          "abort recovery on MDS device\n"},
227         {"mount_option", jt_lcfg_mount_option, 0, 
228          "usage: mount_option profile osc_name [mdc_name] \n"},
229         {"del_mount_option", jt_lcfg_del_mount_option, 0,
230          "usage: del_mount_option profile\n"},
231         {"set_timeout", jt_lcfg_set_timeout, 0,
232          "usage: set_timeout <secs>\n"},
233         {"set_lustre_upcall", jt_lcfg_set_lustre_upcall, 0,
234          "usage: set_lustre_upcall </full/path/to/upcall> \n"},
235        
236         /* Llog operations */ 
237         {"llog_catlist", jt_llog_catlist, 0, 
238          "list all catalog logs on current device.\n"
239          "usage: llog_catlist"},
240         {"llog_info", jt_llog_info, 0,
241          "print log header information.\n"
242          "usage: llog_info <$logname|#oid#ogr#ogen>\n"
243          "       oid, ogr and ogen are hexadecimal."},
244         {"llog_print", jt_llog_print, 0,
245          "print log content information.\n"
246          "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
247          "       oid, ogr and ogen are hexadecimal.\n"
248          "       print all records from index 1 by default."},
249         {"llog_check", jt_llog_check, 0,
250          "print log content information.\n"
251          "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
252          "       oid, ogr and ogen are hexadecimal.\n"
253          "       check all records from index 1 by default."},
254          {"llog_cancel", jt_llog_cancel, 0,
255          "cancel one record in log.\n"
256          "usage: llog_cancel <catalog id|catalog name> <log id> <index>"},
257         {"llog_remove", jt_llog_remove, 0,
258          "remove one log from catalog, erase it from disk.\n"
259          "usage: llog_remove <catalog id|catalog name> <log id>"},
260
261         /* Debug commands */
262         {"======== debug =========", jt_noop, 0, "debug"},
263         {"debug_daemon", jt_dbg_debug_daemon, 0,
264          "debug daemon control and dump to a file"
265          "usage: debug_daemon [start file <#MB>|stop|pause|continue]"},
266         {"debug_kernel", jt_dbg_debug_kernel, 0,
267          "get debug buffer and dump to a file"
268          "usage: debug_kernel [file] [raw]"},
269         {"dk", jt_dbg_debug_kernel, 0,
270          "get debug buffer and dump to a file"
271          "usage: dk [file] [raw]"},
272         {"debug_file", jt_dbg_debug_file, 0,
273          "read debug buffer from input and dump to output"
274          "usage: debug_file <input> [output] [raw]"},
275         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
276          "usage: clear"},
277         {"mark", jt_dbg_mark_debug_buf, 0,"insert marker text in kernel debug buffer\n"
278          "usage: mark <text>"},
279         {"filter", jt_dbg_filter, 0, "filter message type\n"
280          "usage: filter <subsystem id/debug mask>"},
281         {"show", jt_dbg_show, 0, "show message type\n"
282          "usage: show <subsystem id/debug mask>"},
283         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
284          "usage: debug_list <subs/types>"},
285         {"modules", jt_dbg_modules, 0,
286          "provide gdb-friendly module information\n"
287          "usage: modules <path>"},
288         {"panic", jt_dbg_panic, 0, "force the kernel to panic\n"
289          "usage: panic"},
290         {"lwt", jt_ptl_lwt, 0,
291          "light-weight tracing\n"
292          "usage: lwt start\n"
293          "       lwt stop [file]"},
294         {"memhog", jt_ptl_memhog, 0,
295          "memory pressure testing\n"
296          "usage: memhog <page count> [<gfp flags>]"},
297                 
298         /* User interface commands */
299         {"======= control ========", jt_noop, 0, "control commands"},
300         {"help", Parser_help, 0, "help"},
301         {"exit", jt_quit, 0, "quit"},
302         {"quit", jt_quit, 0, "quit"},
303         { 0, 0, 0, NULL }
304 };
305
306 int lctl_main(int argc, char **argv)
307 {
308         int rc;
309
310         setlinebuf(stdout);
311
312         ptl_initialize(argc, argv);
313         if (obd_initialize(argc, argv) < 0)
314                 exit(2);
315         if (dbg_initialize(argc, argv) < 0)
316                 exit(3);
317
318         Parser_init("lctl > ", cmdlist);
319
320         if (argc > 1) {
321                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
322         } else {
323                 rc = Parser_commands();
324         }
325
326         obd_finalize(argc, argv);
327         return rc;
328 }
329
330 #if !LIBLUSTRE_TEST
331 int main (int argc, char **argv)
332 {
333         return (lctl_main (argc, argv));
334 }
335 #endif