Whamcloud - gitweb
- landed b_hd_cray_merge3
[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         {"interface_list", jt_ptl_print_interfaces, 0, "print interface entries\n"
71          "usage: interface_list"},
72         {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
73          "usage: add_interface ip [netmask]"},
74         {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
75          "usage: del_interface [ip]"},
76         {"peer_list", jt_ptl_print_peers, 0, "print peer entries\n"
77          "usage: peer_list"},
78         {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
79          "usage: add_peer <nid> <host> <port>"},
80         {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
81          "usage: del_peer [<nid>] [<host>] [ks]"},
82         {"conn_list", jt_ptl_print_connections, 0, "print all the connected remote nid\n"
83          "usage: conn_list"},
84         {"connect", jt_ptl_connect, 0, "connect to a remote nid\n"
85          "usage: connect <host> <port> [iIOC]"},
86         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
87          "usage: disconnect [<nid>]"},
88         {"active_tx", jt_ptl_print_active_txs, 0, "print active transmits\n"
89          "usage: active_tx"},
90         {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
91          "The nid defaults to hostname for tcp networks and is automatically "
92          "setup for elan/myrinet networks.\n"
93          "usage: mynid [<nid>]"},
94         {"shownid", jt_ptl_shownid, 0, "print the local NID\n"
95          "usage: shownid"},
96         {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a nid\n"
97          "usage: add_uuid <uuid> <nid> <net_type>"},
98         {"close_uuid", jt_obd_close_uuid, 0, "disconnect a UUID\n"
99          "usage: close_uuid <uuid> <net_type>"},
100         {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
101          "usage: del_uuid <uuid>"},
102         {"add_route", jt_ptl_add_route, 0,
103          "add an entry to the portals routing table\n"
104          "usage: add_route <gateway> <target> [<target>]"},
105         {"del_route", jt_ptl_del_route, 0,
106          "delete route via gateway to targets from the portals routing table\n"
107          "usage: del_route <gateway> [<target>] [<target>]"},
108         {"set_route", jt_ptl_notify_router, 0,
109          "enable/disable routes via gateway in the portals routing table\n"
110          "usage: set_route <gateway> <up/down> [<time>]"},
111         {"route_list", jt_ptl_print_routes, 0,
112          "print the portals routing table, same as show_route\n"
113          "usage: route_list"},
114         {"show_route", jt_ptl_print_routes, 0,
115          "print the portals routing table, same as route_list\n"
116          "usage: show_route"},
117         {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
118          "Omitting the count means indefinitely, 0 means restore, "
119          "otherwise fail 'count' messages.\n"
120          "usage: fail nid|_all_ [count]"},
121
122         /* Device selection commands */
123         {"=== device selection ===", jt_noop, 0, "device selection"},
124         {"newdev", jt_lcfg_newdev, 0, "create a new device\n"
125          "usage: newdev"},
126         {"device", jt_obd_device, 0,
127          "set current device to <%name|$name|devno>\n"
128          "usage: device <%name|$name|devno>"},
129         {"cfg_device", jt_lcfg_device, 0,
130          "set current device being configured to <$name>\n"
131          "usage: cfg_device <name>"},
132         {"device_list", jt_obd_list, 0, "show all devices\n"
133          "usage: device_list"},
134         {"dl", jt_obd_list, 0, "show all devices\n"
135          "usage: dl"},
136         {"lustre_build_version", jt_get_version, 0,
137          "print the build version of lustre\n"
138          "usage: lustre_build_version"},
139
140         /* Device configuration commands */
141         {"==== device config =====", jt_noop, 0, "device config"},
142         {"attach", jt_lcfg_attach, 0,
143          "set the type of the current device (with <name> and <uuid>)\n"
144          "usage: attach type [name [uuid]]"},
145         {"setup", jt_lcfg_setup, 0,
146          "type specific device configuration information\n"
147          "usage: setup <args...>"},
148         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
149          "usage: cleanup [force | failover]"},
150         {"detach", jt_obd_detach, 0,
151          "remove driver (and name and uuid) from current device\n"
152          "usage: detach"},
153         {"lov_setup", jt_lcfg_lov_setup, 0, "create a LOV device\n"
154          "usage: lov_setup lov-uuid stripe-count stripe-size offset pattern"},
155         {"lmv_setup", jt_lcfg_lmv_setup, 0,
156          "create an LMV device\n"
157          "usage: lmv_setup lmv-uuid UUID1 [UUID2 ...]"},
158         {"lov_modify_tgts", jt_lcfg_lov_modify_tgts, 0,
159          "add or delete an obd to/from a LOV device\n"
160          "usage: lov_modify_tgts add|del <lov-name> <uuid> <index> <gen>"},
161         {"lov_getconfig", jt_obd_lov_getconfig, 0,
162          "read lov configuration from an mds device\n"
163          "usage: lov_getconfig lov-uuid"},
164         {"record", jt_cfg_record, 0, "record commands that follow in log\n"
165          "usage: record cfg-uuid-name"},
166         {"endrecord", jt_cfg_endrecord, 0, "stop recording\n"
167          "usage: endrecord"},
168         {"parse", jt_cfg_parse, 0, "parse the log of recorded commands for this config\n"
169          "usage: parse config-uuid-name"},
170         {"dump_log", jt_cfg_dump_log, 0, "print log of recorded commands for this config to kernel debug log\n"
171          "usage: dump_log config-uuid-name"},
172         {"clear_log", jt_cfg_clear_log, 0, "delete current config log of recorded commands\n"
173          "usage: clear_log config-name"},
174
175         /* Device operations */
176         {"=== device operations ==", jt_noop, 0, "device operations"},
177         {"probe", jt_obd_connect, 0,
178          "build a connection handle to a device.  This command is used to "
179          "suspend configuration until lctl has ensured that the mds and osc "
180          "services are available.  This is to avoid mount failures in a "
181          "rebooting cluster.\n"
182          "usage: probe [timeout]"},
183         {"close", jt_obd_disconnect, 0,
184          "close the connection handle\n"
185          "usage: close"},
186         {"getattr", jt_obd_getattr, 0,
187          "get attribute for OST object <objid>\n"
188          "usage: getattr <objid>"},
189         {"setattr", jt_obd_setattr, 0,
190          "set mode attribute for OST object <objid>\n"
191          "usage: setattr <objid> <mode>"},
192          {"create", jt_obd_create, 0,
193          "create <num> OST objects (with <mode>)\n"
194          "usage: create [num [mode [verbose [lsm data]]]]"},
195         {"destroy", jt_obd_destroy, 0,
196          "destroy OST object <objid> [num [verbose]]\n"
197          "usage: destroy <num> objects, starting at objid <objid>"},
198         {"test_getattr", jt_obd_test_getattr, 0,
199          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
200          "usage: test_getattr <num> [verbose [[t]objid]]"},
201         {"test_setattr", jt_obd_test_setattr, 0,
202          "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
203          "usage: test_setattr <num> [verbose [[t]objid]]"},
204         {"test_brw", jt_obd_test_brw, 0,
205          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
206          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
207         {"get_stripe", jt_obd_get_stripe, 0,
208          "show stripe info for an echo client object\n"
209          "usage: get_stripe objid\n"},
210         {"set_stripe", jt_obd_set_stripe, 0,
211          "set stripe info for an echo client object\n"
212          "usage: set_stripe objid[=width!count[@offset][:id:id...]\n"},
213         {"unset_stripe", jt_obd_unset_stripe, 0,
214          "unset stripe info for an echo client object\n"
215          "usage: unset_stripe objid\n"},
216         {"test_ldlm", jt_obd_test_ldlm, 0,
217          "perform lock manager test\n"
218          "usage: test_ldlm"},
219         {"ldlm_regress_start", jt_obd_ldlm_regress_start, 0,
220          "start lock manager stress test\n"
221          "usage: ldlm_regress_start [numthreads [refheld [numres [numext]]]]"},
222         {"ldlm_regress_stop", jt_obd_ldlm_regress_stop, 0,
223          "stop lock manager stress test (no args)\n"},
224         {"dump_ldlm", jt_obd_dump_ldlm, 0,
225          "dump all lock manager state (no args)"},
226         {"activate", jt_obd_activate, 0, "activate an import\n"},
227         {"deactivate", jt_obd_deactivate, 0, "deactivate an import\n"},
228         {"recover", jt_obd_recover, 0, "usage: recover [<connection UUID>]"},
229         {"lookup", jt_obd_mdc_lookup, 0, "usage: lookup <directory> <file>"},
230         {"notransno", jt_obd_no_transno, 0,
231          "disable sending of committed-transno updates\n"},
232         {"readonly", jt_obd_set_readonly, 0,
233          "disable writes to the underlying device\n"},
234         {"abort_recovery", jt_obd_abort_recovery, 0,
235          "abort recovery on MDS device\n"},
236         {"root_squash", jt_obd_root_squash, 0,
237          "squash root to 'uid:gid' except client 'nid'\n"
238          "usage: root_squash [uid:gid [nid]]\n"},
239         {"start", jt_obd_start, 0,
240          "setup mds/ost from the llog file\n"
241          "usage: start <profilename>"},
242         {"mount_option", jt_lcfg_mount_option, 0, 
243          "usage: mount_option profile osc_name [mdc_name] \n"},
244         {"del_mount_option", jt_lcfg_del_mount_option, 0,
245          "usage: del_mount_option profile\n"},
246         {"set_timeout", jt_lcfg_set_timeout, 0,
247          "usage: set_timeout <secs>\n"},
248         {"set_lustre_upcall", jt_lcfg_set_lustre_upcall, 0,
249          "usage: set_lustre_upcall </full/path/to/upcall> \n"},
250         {"add_conn ", jt_lcfg_add_conn, 0,
251          "usage: add_conn <conn_uuid> [priority]\n"},
252         {"del_conn ", jt_lcfg_del_conn, 0,
253          "usage: del_conn <conn_uuid> \n"},
254         {"set_security", jt_lcfg_set_security, 0,
255          "usage: set_security key value\n"},
256         {"lsync", jt_obd_reint_sync, 0,
257          "usage: lsync\n"},  
258         {"cache_on", jt_obd_cache_on, 0,
259          "usage: lsync\n"},  
260         {"cache_off", jt_obd_cache_off, 0,
261          "usage: lsync\n"},  
262         /*snap operations*/
263         {"snap_add", jt_obd_snap_add, 0, 
264          "usage: snap_add <dev_name> <snap_name>\n"}, 
265         /* Llog operations */ 
266         {"llog_catlist", jt_llog_catlist, 0, 
267          "list all catalog logs on current device.\n"
268          "usage: llog_catlist"},
269         {"llog_info", jt_llog_info, 0,
270          "print log header information.\n"
271          "usage: llog_info <$logname|#oid#ogr#ogen>\n"
272          "       oid, ogr and ogen are hexadecimal."},
273         {"llog_print", jt_llog_print, 0,
274          "print log content information.\n"
275          "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
276          "       oid, ogr and ogen are hexadecimal.\n"
277          "       print all records from index 1 by default."},
278         {"llog_check", jt_llog_check, 0,
279          "print log content information.\n"
280          "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
281          "       oid, ogr and ogen are hexadecimal.\n"
282          "       check all records from index 1 by default."},
283          {"llog_cancel", jt_llog_cancel, 0,
284          "cancel one record in log.\n"
285          "usage: llog_cancel <catalog id|catalog name> <log id> <index>"},
286         {"llog_remove", jt_llog_remove, 0,
287          "remove one log from catalog, erase it from disk.\n"
288          "usage: llog_remove <catalog id|catalog name> <log id>"},
289
290         /* Debug commands */
291         {"======== debug =========", jt_noop, 0, "debug"},
292         {"debug_daemon", jt_dbg_debug_daemon, 0,
293          "debug daemon control and dump to a file\n"
294          "usage: debug_daemon {start file [#MB]|stop}"},
295         {"debug_kernel", jt_dbg_debug_kernel, 0,
296          "get debug buffer and dump to a file, same as dk\n"
297          "usage: debug_kernel [file] [raw]"},
298         {"dk", jt_dbg_debug_kernel, 0,
299          "get debug buffer and dump to a file, same as debug_kernel\n"
300          "usage: dk [file] [raw]"},
301         {"debug_file", jt_dbg_debug_file, 0,
302          "read debug buffer from input and dump to output, same as df\n"
303          "usage: debug_file <input> [output] [raw]"},
304         {"df", jt_dbg_debug_file, 0,
305          "read debug buffer from input and dump to output, same as debug_file\n"
306          "usage: df <input> [output] [raw]"},
307         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
308          "usage: clear"},
309         {"mark", jt_dbg_mark_debug_buf, 0,"insert marker text in kernel debug buffer\n"
310          "usage: mark <text>"},
311         {"filter", jt_dbg_filter, 0, "filter message type\n"
312          "usage: filter <subsystem id/debug mask>"},
313         {"show", jt_dbg_show, 0, "Show specific type of messages\n"
314          "usage: show <subsystem id/debug mask>"},
315         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
316          "usage: debug_list <subs/types>"},
317         {"modules", jt_dbg_modules, 0,
318          "provide gdb-friendly module information\n"
319          "usage: modules <path>"},
320         {"panic", jt_dbg_panic, 0, "force the kernel to panic\n"
321          "usage: panic"},
322         {"lwt", jt_ptl_lwt, 0,
323          "light-weight tracing\n"
324          "usage: lwt start\n"
325          "       lwt stop [file]"},
326         {"memhog", jt_ptl_memhog, 0,
327          "memory pressure testing\n"
328          "usage: memhog <page count> [<gfp flags>]"},
329                 
330         /* User interface commands */
331         {"======= control ========", jt_noop, 0, "control commands"},
332         {"help", Parser_help, 0, "help"},
333         {"exit", jt_quit, 0, "quit"},
334         {"quit", jt_quit, 0, "quit"},
335         { 0, 0, 0, NULL }
336 };
337
338 int lctl_main(int argc, char **argv)
339 {
340         int rc;
341
342         setlinebuf(stdout);
343
344         ptl_initialize(argc, argv);
345         if (obd_initialize(argc, argv) < 0)
346                 exit(2);
347         if (dbg_initialize(argc, argv) < 0)
348                 exit(3);
349
350         Parser_init("lctl > ", cmdlist);
351
352         if (argc > 1) {
353                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
354         } else {
355                 rc = Parser_commands();
356         }
357
358         obd_finalize(argc, argv);
359         return rc;
360 }
361
362 #if !LIBLUSTRE_TEST
363 int main (int argc, char **argv)
364 {
365         return (lctl_main (argc, argv));
366 }
367 #endif