Whamcloud - gitweb
Merge b_md 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/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         {"lustre_build_version", jt_get_version, 0,
115          "print the build version of lustre\n"
116          "usage: lustre_build_version"},
117
118         /* Device configuration commands */
119         {"==== device config =====", jt_noop, 0, "device config"},
120         {"attach", jt_obd_attach, 0,
121          "set the type of the current device (with <name> and <uuid>)\n"
122          "usage: attach type [name [uuid]]"},
123         {"setup", jt_obd_setup, 0,
124          "type specific device configuration information\n"
125          "usage: setup <args...>"},
126         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
127          "usage: cleanup [force]"},
128         {"detach", jt_obd_detach, 0,
129          "remove driver (and name and uuid) from current device\n"
130          "usage: detach"},
131         {"lov_setconfig", jt_obd_lov_setconfig, 0,
132          "write lov configuration to an mds device\n"
133          "usage: lov_setconfig lov-uuid stripe-count stripe-size offset pattern UUID1 [UUID2 ...]"},
134         {"lov_getconfig", jt_obd_lov_getconfig, 0,
135          "read lov configuration from an mds device\n"
136          "usage: lov_getconfig lov-uuid"},
137
138         /* Device operations */
139         {"=== device operations ==", jt_noop, 0, "device operations"},
140         {"probe", jt_obd_connect, 0,
141          "build a connection handle to a device.  This command is used to "
142          "suspend configuration until lctl has ensured that the mds and osc "
143          "services are available.  This is to avoid mount failures in a "
144          "rebooting cluster.\n"
145          "usage: probe [timeout]"},
146         {"close", jt_obd_disconnect, 0,
147          "close the connection handle\n"
148          "usage: close"},
149         {"getattr", jt_obd_getattr, 0,
150          "get attribute for OST object <objid>\n"
151          "usage: getattr <objid>"},
152         {"setattr", jt_obd_setattr, 0,
153          "set mode attribute for OST object <objid>\n"
154          "usage: setattr <objid> <mode>"},
155         {"create", jt_obd_create, 0,
156          "create <num> OST objects (with <mode>)\n"
157          "usage: create [num [mode [verbose]]]"},
158         {"destroy", jt_obd_destroy, 0,
159          "destroy OST object <objid> [num [verbose]]\n"
160          "usage: destroy <num> objects, starting at objid <objid>"},
161         {"test_getattr", jt_obd_test_getattr, 0,
162          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
163          "usage: test_getattr <num> [verbose [[t]objid]]"},
164         {"test_brw", jt_obd_test_brw, 0,
165          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
166          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
167         {"get_stripe", jt_obd_get_stripe, 0,
168          "show stripe info for an echo client object\n"
169          "usage: get_stripe objid\n"},
170         {"set_stripe", jt_obd_set_stripe, 0,
171          "set stripe info for an echo client object\n"
172          "usage: set_stripe objid[=width!count[@offset][:id:id...]\n"},
173         {"unset_stripe", jt_obd_unset_stripe, 0,
174          "unset stripe info for an echo client object\n"
175          "usage: unset_stripe objid\n"},
176         {"test_ldlm", jt_obd_test_ldlm, 0,
177          "perform lock manager test\n"
178          "usage: test_ldlm"},
179         {"ldlm_regress_start", jt_obd_ldlm_regress_start, 0,
180          "start lock manager stress test\n"
181          "usage: ldlm_regress_start [numthreads [refheld [numres [numext]]]]"},
182         {"ldlm_regress_stop", jt_obd_ldlm_regress_stop, 0,
183          "stop lock manager stress test (no args)\n"},
184         {"dump_ldlm", jt_obd_dump_ldlm, 0,
185          "dump all lock manager state (no args)"},
186         {"lov_set_osc_active", jt_obd_lov_set_osc_active, 0,
187          "(de)activate an OSC in a LOV\n"
188          "usage: lov_set_osc_active <OSC UUID> <1|0 (active|inactive)>"},
189         {"newconn", jt_obd_newconn, 0, "newconn <olduuid> [newuuid]"},
190         {"failconn", jt_obd_failconn, 0, "failconn <uuid>"},
191         {"lookup", jt_obd_mdc_lookup, 0, "usage: lookup <directory> <file>"},
192         {"notransno", jt_obd_no_transno, 0,
193          "disable sending of committed-transno updates\n"
194          "usage: notransno"},
195         {"readonly", jt_obd_set_readonly, 0,
196          "disable writes to the underlying device\n"
197          "usage: readonly"},
198
199         /* Debug commands */
200         {"======== debug =========", jt_noop, 0, "debug"},
201         {"debug_kernel", jt_dbg_debug_kernel, 0,
202          "get debug buffer and dump to a file"
203          "usage: debug_kernel [file] [raw]"},
204         {"debug_file", jt_dbg_debug_file, 0,
205          "read debug buffer from input and dump to output"
206          "usage: debug_file <input> [output] [raw]"},
207         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
208          "usage: clear"},
209         {"mark", jt_dbg_mark_debug_buf, 0,"insert marker text in kernel debug buffer\n"
210          "usage: mark <text>"},
211         {"filter", jt_dbg_filter, 0, "filter message type\n"
212          "usage: filter <subsystem id/debug mask>"},
213         {"show", jt_dbg_show, 0, "show message type\n"
214          "usage: show <subsystem id/debug mask>"},
215         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
216          "usage: debug_list <subs/types>"},
217         {"modules", jt_dbg_modules, 0,
218          "provide gdb-friendly module information\n"
219          "usage: modules <path>"},
220         {"panic", jt_dbg_panic, 0, "force the kernel to panic\n"
221          "usage: panic"},
222
223         /* User interface commands */
224         {"======= control ========", jt_noop, 0, "control commands"},
225         {"help", Parser_help, 0, "help"},
226         {"exit", jt_quit, 0, "quit"},
227         {"quit", jt_quit, 0, "quit"},
228         { 0, 0, 0, NULL }
229 };
230
231
232
233 int main(int argc, char **argv)
234 {
235         int rc;
236
237         setlinebuf(stdout);
238
239         ptl_initialize(argc, argv);
240         if (obd_initialize(argc, argv) < 0)
241                 exit(2);
242         if (dbg_initialize(argc, argv) < 0)
243                 exit(3);
244
245         if (argc > 1) {
246                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
247         } else {
248                 Parser_init("lctl > ", cmdlist);
249                 rc = Parser_commands();
250         }
251
252         obd_cleanup(argc, argv);
253         return rc;
254 }
255