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