Whamcloud - gitweb
merge b_multinet into HEAD
[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 #include <stdlib.h>
28 #include <stdio.h>
29 #include <portals/api-support.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         {"network", jt_ptl_network, 0, "commands that follow apply to net\n"
67          "usage: network <tcp/elan/myrinet/scimac>"},
68         {"autoconn_list", jt_ptl_print_autoconnects, 0, "print autoconnect entries\n"
69          "usage: print_autoconns"},
70         {"add_autoconn", jt_ptl_add_autoconnect, 0, "add an autoconnect entry\n"
71          "usage: add_autoconn <nid> <host> <port> [ixs]"},
72         {"del_autoconn", jt_ptl_del_autoconnect, 0, "remove an autoconnect entry\n"
73          "usage: del_autoconn [<nid>] [<host>] [ks]"},
74         {"conn_list", jt_ptl_print_connections, 0, "connect to a remote nid\n"
75          "usage: print_conns"},
76         {"connect", jt_ptl_connect, 0, "connect to a remote nid\n"
77          "usage: connect <host> <port> [ix]"},
78         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
79          "usage: disconnect [<nid>]"},
80         {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
81          "The nid defaults to hostname for tcp networks and is automatically "
82          "setup for elan/myrinet/scimac networks.\n"
83          "usage: mynid [<nid>]"},
84         {"shownid", jt_ptl_shownid, 0, "print the local NID\n"
85          "usage: shownid"},
86         {"add_uuid", jt_obd_add_uuid, 0, "associate a UUID with a nid\n"
87          "usage: add_uuid <uuid> <nid> <net_type>"},
88         {"close_uuid", jt_obd_close_uuid, 0, "disconnect a UUID\n"
89          "usage: close_uuid <uuid> <net-type>)"},
90         {"del_uuid", jt_obd_del_uuid, 0, "delete a UUID association\n"
91          "usage: del_uuid <uuid>"},
92         {"add_route", jt_ptl_add_route, 0,
93          "add an entry to the routing table\n"
94          "usage: add_route <gateway> <target> [target]"},
95         {"del_route", jt_ptl_del_route, 0,
96          "delete an entry from the routing table\n"
97          "usage: del_route <target>"},
98         {"route_list", jt_ptl_print_routes, 0, "print the routing table\n"
99          "usage: route_list"},
100         {"recv_mem", jt_ptl_rxmem, 0, "set socket receive buffer size, "
101          "if size is omited the current size is reported.\n"
102          "usage: recv_mem [size]"},
103         {"send_mem", jt_ptl_txmem, 0, "set socket send buffer size, "
104          "if size is omited the current size is reported.\n"
105          "usage: send_mem [size]"},
106         {"nagle", jt_ptl_nagle, 0, "enable/disable nagle, omitting the "
107          "argument will cause the current nagle setting to be reported.\n"
108          "usage: nagle [on/off]"},
109         {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
110          "Omitting the count means indefinitely, 0 means restore, "
111          "otherwise fail 'count' messages.\n"
112          "usage: fail nid|_all_ [count]"},
113
114         /* Device selection commands */
115         {"=== device selection ===", jt_noop, 0, "device selection"},
116         {"newdev", jt_obd_newdev, 0, "create a new device\n"
117          "usage: newdev"},
118         {"device", jt_obd_device, 0,
119          "set current device to <%name|$name|devno>\n"
120          "usage: device <%name|$name|devno>"},
121         {"device_list", jt_obd_list, 0, "show all devices\n"
122          "usage: device_list"},
123         {"lustre_build_version", jt_get_version, 0,
124          "print the build version of lustre\n"
125          "usage: lustre_build_version"},
126
127         /* Device configuration commands */
128         {"==== device config =====", jt_noop, 0, "device config"},
129         {"attach", jt_obd_attach, 0,
130          "set the type of the current device (with <name> and <uuid>)\n"
131          "usage: attach type [name [uuid]]"},
132         {"setup", jt_obd_setup, 0,
133          "type specific device configuration information\n"
134          "usage: setup <args...>"},
135         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
136          "usage: cleanup [force | failover]"},
137         {"detach", jt_obd_detach, 0,
138          "remove driver (and name and uuid) from current device\n"
139          "usage: detach"},
140         {"lov_setconfig", jt_obd_lov_setconfig, 0,
141          "write lov configuration to an mds device\n"
142          "usage: lov_setconfig lov-uuid stripe-count stripe-size offset pattern UUID1 [UUID2 ...]"},
143         {"lov_getconfig", jt_obd_lov_getconfig, 0,
144          "read lov configuration from an mds device\n"
145          "usage: lov_getconfig lov-uuid"},
146
147         /* Device operations */
148         {"=== device operations ==", jt_noop, 0, "device operations"},
149         {"probe", jt_obd_connect, 0,
150          "build a connection handle to a device.  This command is used to "
151          "suspend configuration until lctl has ensured that the mds and osc "
152          "services are available.  This is to avoid mount failures in a "
153          "rebooting cluster.\n"
154          "usage: probe [timeout]"},
155         {"close", jt_obd_disconnect, 0,
156          "close the connection handle\n"
157          "usage: close"},
158         {"getattr", jt_obd_getattr, 0,
159          "get attribute for OST object <objid>\n"
160          "usage: getattr <objid>"},
161         {"setattr", jt_obd_setattr, 0,
162          "set mode attribute for OST object <objid>\n"
163          "usage: setattr <objid> <mode>"},
164          {"create", jt_obd_create, 0,
165          "create <num> OST objects (with <mode>)\n"
166          "usage: create [num [mode [verbose [lsm data]]]]"},
167         {"destroy", jt_obd_destroy, 0,
168          "destroy OST object <objid> [num [verbose]]\n"
169          "usage: destroy <num> objects, starting at objid <objid>"},
170         {"test_getattr", jt_obd_test_getattr, 0,
171          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
172          "usage: test_getattr <num> [verbose [[t]objid]]"},
173         {"test_brw", jt_obd_test_brw, 0,
174          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
175          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
176         {"get_stripe", jt_obd_get_stripe, 0,
177          "show stripe info for an echo client object\n"
178          "usage: get_stripe objid\n"},
179         {"set_stripe", jt_obd_set_stripe, 0,
180          "set stripe info for an echo client object\n"
181          "usage: set_stripe objid[=width!count[@offset][:id:id...]\n"},
182         {"unset_stripe", jt_obd_unset_stripe, 0,
183          "unset stripe info for an echo client object\n"
184          "usage: unset_stripe objid\n"},
185         {"test_ldlm", jt_obd_test_ldlm, 0,
186          "perform lock manager test\n"
187          "usage: test_ldlm"},
188         {"ldlm_regress_start", jt_obd_ldlm_regress_start, 0,
189          "start lock manager stress test\n"
190          "usage: ldlm_regress_start [numthreads [refheld [numres [numext]]]]"},
191         {"ldlm_regress_stop", jt_obd_ldlm_regress_stop, 0,
192          "stop lock manager stress test (no args)\n"},
193         {"dump_ldlm", jt_obd_dump_ldlm, 0,
194          "dump all lock manager state (no args)"},
195         {"activate", jt_obd_activate, 0, "activate an import\n"},
196         {"deactivate", jt_obd_deactivate, 0, "deactivate an import\n"},
197         {"recover", jt_obd_recover, 0, "usage: recover [<connection UUID>]"},
198         {"lookup", jt_obd_mdc_lookup, 0, "usage: lookup <directory> <file>"},
199         {"notransno", jt_obd_no_transno, 0,
200          "disable sending of committed-transno updates\n"},
201         {"readonly", jt_obd_set_readonly, 0,
202          "disable writes to the underlying device\n"},
203         {"abort_recovery", jt_obd_abort_recovery, 0,
204          "abort recovery on MDS device\n"},
205         {"mount_option", jt_obd_mount_option, 0,
206          "dump mount options to file\n"},
207
208         /* Debug commands */
209         {"======== debug =========", jt_noop, 0, "debug"},
210         {"debug_daemon", jt_dbg_debug_daemon, 0,
211          "debug daemon control and dump to a file"
212          "usage: debug_daemon [start file <#MB>|stop|pause|continue]"},
213         {"debug_kernel", jt_dbg_debug_kernel, 0,
214          "get debug buffer and dump to a file"
215          "usage: debug_kernel [file] [raw]"},
216         {"dk", jt_dbg_debug_kernel, 0,
217          "get debug buffer and dump to a file"
218          "usage: dk [file] [raw]"},
219         {"debug_file", jt_dbg_debug_file, 0,
220          "read debug buffer from input and dump to output"
221          "usage: debug_file <input> [output] [raw]"},
222         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
223          "usage: clear"},
224         {"mark", jt_dbg_mark_debug_buf, 0,"insert marker text in kernel debug buffer\n"
225          "usage: mark <text>"},
226         {"filter", jt_dbg_filter, 0, "filter message type\n"
227          "usage: filter <subsystem id/debug mask>"},
228         {"show", jt_dbg_show, 0, "show message type\n"
229          "usage: show <subsystem id/debug mask>"},
230         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
231          "usage: debug_list <subs/types>"},
232         {"modules", jt_dbg_modules, 0,
233          "provide gdb-friendly module information\n"
234          "usage: modules <path>"},
235         {"panic", jt_dbg_panic, 0, "force the kernel to panic\n"
236          "usage: panic"},
237
238         /* User interface commands */
239         {"======= control ========", jt_noop, 0, "control commands"},
240         {"help", Parser_help, 0, "help"},
241         {"exit", jt_quit, 0, "quit"},
242         {"quit", jt_quit, 0, "quit"},
243         { 0, 0, 0, NULL }
244 };
245
246
247
248 int main(int argc, char **argv)
249 {
250         int rc;
251
252         setlinebuf(stdout);
253
254         ptl_initialize(argc, argv);
255         if (obd_initialize(argc, argv) < 0)
256                 exit(2);
257         if (dbg_initialize(argc, argv) < 0)
258                 exit(3);
259
260         Parser_init("lctl > ", cmdlist);
261
262         if (argc > 1) {
263                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
264         } else {
265                 rc = Parser_commands();
266         }
267
268         obd_cleanup(argc, argv);
269         return rc;
270 }
271