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