Whamcloud - gitweb
Add support for FAILCONN ioctl, for recovery testing and (possibly) adminstrative
[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/ptlctl.h>
30 #include "obdctl.h"
31 #include "parser.h"
32
33 static int jt_quit(int argc, char **argv) {
34         Parser_quit(argc, argv);
35         return 0;
36 }
37
38 static int jt_noop(int argc, char **argv) {
39         return 0;
40 }
41
42 static int jt_opt_ignore_errors(int argc, char **argv) {
43         Parser_ignore_errors(1);
44         return 0;
45 }
46
47 command_t cmdlist[] = {
48         /* Metacommands */
49         {"--device", jt_opt_device, 0,
50          "run <command> after connecting to device <devno>\n"
51          "--device <devno> <command [args ...]>"},
52         {"--threads", jt_opt_threads, 0,
53          "run <threads> separate instances of <command> on device <devno>\n"
54          "--threads <threads> <verbose> <devno> <command [args ...]>"},
55         {"--ignore_errors", jt_opt_ignore_errors, 0,
56          "ignore errors that occur during script processing\n"
57          "--ignore_errors"},
58         {"ignore_errors", jt_opt_ignore_errors, 0,
59          "ignore errors that occur during script processing\n"
60          "ignore_errors"},
61
62         /* Network configuration commands */
63         {"==== network config ====", jt_noop, 0, "network config"},
64         {"network", jt_ptl_network, 0, "commands that follow apply to net\n"
65          "usage: network <tcp/elan/myrinet>"},       
66         {"connect", jt_ptl_connect, 0, "connect to a remote nid\n"
67          "usage: connect [[<hostname> <port>] | <elan id>]"},
68         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
69          "usage: disconnect <nid>"},
70         {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
71          "The nid defaults to hostname for tcp networks and is automatically "
72          "setup for elan/myrinet networks.\n"
73          "usage: mynid [nid]"},
74         {"add_uuid", jt_ptl_add_uuid, 0, "associate a UUID with a nid\n"
75          "usage: add_uuid <uuid> <nid>"},
76         {"close_uuid", jt_ptl_close_uuid, 0, "disconnect a UUID\n"
77          "usage: close_uuid <uuid>)"},
78         {"del_uuid", jt_ptl_del_uuid, 0, "delete a UUID association\n"
79          "usage: del_uuid <uuid>"},
80         {"add_route", jt_ptl_add_route, 0,
81          "add an entry to the routing table\n"
82          "usage: add_route <gateway> <target> [target]"},
83         {"del_route", jt_ptl_del_route, 0,
84          "delete an entry from the routing table\n"
85          "usage: del_route <target>"},
86         {"route_list", jt_ptl_print_routes, 0, "print the routing table\n"
87          "usage: route_list"},
88         {"recv_mem", jt_ptl_rxmem, 0, "set socket receive buffer size, "
89          "if size is omited the current size is reported.\n"
90          "usage: recv_mem [size]"},
91         {"send_mem", jt_ptl_txmem, 0, "set socket send buffer size, "
92          "if size is omited the current size is reported.\n"
93          "usage: send_mem [size]"},
94         {"nagle", jt_ptl_nagle, 0, "enable/disable nagle, omiting the "
95          "argument will cause the current nagle setting to be reported.\n" 
96          "usage: nagle [on/off]"},       
97                 
98         /* Device selection commands */
99         {"=== device selection ===", jt_noop, 0, "device selection"},
100         {"newdev", jt_obd_newdev, 0, "create a new device\n"
101          "usage: newdev"},
102 #if 0
103         {"uuid2dev", jt_obd_uuid2dev, 0,
104          "find device attached with <uuid> and make it the current device\n"
105          "usage: uuid2dev <uuid>"},
106 #endif
107         {"name2dev", jt_obd_name2dev, 0,
108          "find device attached with <name> and make it the current device\n"
109          "usage: name2dev <name>"},
110         {"device", jt_obd_device, 0, "set current device to <devno>\n"
111          "usage: device <devno>"},
112         {"device_list", jt_obd_list, 0, "show all devices\n"
113          "usage: device_list"},
114          
115         /* Device configuration commands */
116         {"==== device config =====", jt_noop, 0, "device config"},
117         {"attach", jt_obd_attach, 0,
118          "set the type of the current device (with <name> and <uuid>)\n"
119          "usage: attach type [name [uuid]]"},
120         {"setup", jt_obd_setup, 0,
121          "type specific device configuration information\n"
122          "usage: setup <args...>"},
123         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
124          "usage: cleanup"},
125         {"detach", jt_obd_detach, 0,
126          "remove driver (and name and uuid) from current device\n"
127          "usage: detach"},
128         {"lovconfig", jt_obd_lov_config, 0,
129          "write lov configuration to an mds device\n"
130          "usage: lovconfig lov-uuid stripe-count stripe-size offset pattern UUID1 [UUID2 ...]"},
131
132         /* Device operations */
133         {"=== device operations ==", jt_noop, 0, "device operations"},
134         {"probe", jt_obd_connect, 0,
135          "build a connection handle to a device.  This command is used to "
136          "suspend configuration until lctl has ensured that the mds and osc "
137          "services are available.  This is to avoid mount failures in a "
138          "rebooting cluster.\n"
139          "usage: probe [timeout]"},
140         {"close", jt_obd_disconnect, 0,
141          "close the connection handle\n"
142          "usage: close"},
143         {"getattr", jt_obd_getattr, 0,
144          "get attribute for OST object <objid>\n"
145          "usage: getattr <objid>"},
146         {"setattr", jt_obd_setattr, 0,
147          "set mode attribute for OST object <objid>\n"
148          "usage: setattr <objid> <mode>"},
149         {"create", jt_obd_create, 0,
150          "create <num> OST objects (with <mode>)\n"
151          "usage: create [num [mode [verbose]]]"},
152         {"destroy", jt_obd_destroy, 0,
153          "destroy OST object <objid>\n"
154          "usage: destroy <objid>"},
155         {"test_getattr", jt_obd_test_getattr, 0,
156          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
157          "usage: test_getattr <num> [verbose [[t]objid]]"},
158         {"test_brw", jt_obd_test_brw, 0,
159          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
160          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
161         {"test_ldlm", jt_obd_test_ldlm, 0,
162          "perform lock manager test\n"
163          "usage: test_ldlm"},
164         {"ldlm_regress_start", jt_obd_ldlm_regress_start, 0,
165          "start lock manager stress test\n"
166          "usage: %s [numthreads [refheld [numres [numext]]]]"},
167         {"ldlm_regress_stop", jt_obd_ldlm_regress_stop, 0,
168          "stop lock manager stress test (no args)\n"},
169         {"dump_ldlm", jt_obd_dump_ldlm, 0,
170          "dump all lock manager state (no args)"},
171         {"newconn", jt_obd_newconn, 0, "newconn <olduuid> [newuuid]"},
172         {"failconn", jt_obd_failconn, 0, "failconn <uuid>"},
173
174         /* Debug commands */
175         {"======== debug =========", jt_noop, 0, "debug"},
176         {"debug_kernel", jt_dbg_debug_kernel, 0,
177          "get debug buffer and dump to a file"
178          "usage: debug_kernel [file] [raw]"},
179         {"debug_file", jt_dbg_debug_file, 0,
180          "read debug buffer from input and dump to output"
181          "usage: debug_file <input> [output] [raw]"},
182         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
183          "usage: clear"},
184         {"mark", jt_dbg_mark_debug_buf, 0,"insert marker text in kernel debug buffer\n"
185          "usage: mark <text>"},
186         {"filter", jt_dbg_filter, 0, "filter message type\n"
187          "usage: filter <subsystem id/debug mask>"},
188         {"show", jt_dbg_show, 0, "show message type\n"
189          "usage: show <subsystem id/debug mask>"},
190         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
191          "usage: debug_list <subs/types>"},
192         {"modules", jt_dbg_modules, 0,
193          "provide gdb-friendly module information\n"
194          "usage: modules <path>"},
195         {"panic", jt_dbg_panic, 0, "force the kernel to panic\n"
196          "usage: panic"},
197          
198         /* User interface commands */
199         {"======= control ========", jt_noop, 0, "control commands"},
200         {"help", Parser_help, 0, "help"},
201         {"exit", jt_quit, 0, "quit"},
202         {"quit", jt_quit, 0, "quit"},
203         { 0, 0, 0, NULL }
204 };
205
206
207
208 int main(int argc, char **argv) 
209 {
210         int rc;
211
212         setlinebuf(stdout);
213
214         ptl_initialize(argc, argv);
215         if (obd_initialize(argc, argv) < 0)
216                 exit(2);
217         if (dbg_initialize(argc, argv) < 0)
218                 exit(3);
219         
220         if (argc > 1) {
221                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
222         } else {
223                 Parser_init("lctl > ", cmdlist);
224                 rc = Parser_commands();
225         }
226
227         obd_cleanup(argc, argv);
228         return rc;
229 }
230