Whamcloud - gitweb
Branch 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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/utils/lctl.c
37  *
38  * Author: Peter J. Braam <braam@clusterfs.com>
39  * Author: Phil Schwan <phil@clusterfs.com>
40  * Author: Robert Read <rread@clusterfs.com>
41  */
42
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <lnet/lnetctl.h>
46 #include "obdctl.h"
47 #include <libcfs/libcfsutil.h>
48
49 static int jt_quit(int argc, char **argv) {
50         Parser_quit(argc, argv);
51         return 0;
52 }
53
54 static int jt_noop(int argc, char **argv) {
55         return 0;
56 }
57
58 static int jt_opt_ignore_errors(int argc, char **argv) {
59         Parser_ignore_errors(1);
60         return 0;
61 }
62
63 command_t cmdlist[] = {
64         /* Metacommands */
65         {"===== metacommands =======", jt_noop, 0, "metacommands"},
66         {"--device", jt_opt_device, 0,
67          "run <command> after connecting to device <devno>\n"
68          "--device <devno> <command [args ...]>"},
69         {"--ignore_errors", jt_opt_ignore_errors, 0,
70          "ignore errors that occur during script processing\n"
71          "--ignore_errors"},
72         {"ignore_errors", jt_opt_ignore_errors, 0,
73          "ignore errors that occur during script processing\n"
74          "ignore_errors"},
75
76         /* User interface commands */
77         {"======== control =========", jt_noop, 0, "control commands"},
78         {"help", Parser_help, 0, "help"},
79         {"lustre_build_version", jt_get_version, 0,
80          "print the build version of lustre\n"
81          "usage: lustre_build_version"},
82         {"exit", jt_quit, 0, "quit"},
83         {"quit", jt_quit, 0, "quit"},
84
85         /* Network configuration commands */
86         {"===== network config =====", jt_noop, 0, "network config"},
87         {"--net", jt_opt_net, 0,"run <command> after setting network to <net>\n"
88          "usage: --net <tcp/elan/gm/...> <command>"},
89         {"network", jt_ptl_network, 0, "configure LNET"
90          "usage: network up|down"},
91         {"net", jt_ptl_network, 0, "configure LNET"
92          "usage: net up|down"},
93         {"list_nids", jt_ptl_list_nids, 0, "list local NIDs"
94          "usage: list_nids [all]"},
95         {"which_nid", jt_ptl_which_nid, 0, "choose a NID"
96          "usage: which_nid NID [NID...]"},
97         {"interface_list", jt_ptl_print_interfaces,0,"print interface entries\n"
98          "usage: interface_list"},
99         {"peer_list", jt_ptl_print_peers, 0, "print peer entries\n"
100          "usage: peer_list"},
101         {"conn_list", jt_ptl_print_connections, 0,
102          "print all the connected remote nid\n"
103          "usage: conn_list"},
104         {"active_tx", jt_ptl_print_active_txs, 0, "print active transmits\n"
105          "usage: active_tx"},
106         {"route_list", jt_ptl_print_routes, 0,
107          "print the portals routing table, same as show_route\n"
108          "usage: route_list"},
109         {"show_route", jt_ptl_print_routes, 0,
110          "print the portals routing table, same as route_list\n"
111          "usage: show_route"},
112         {"ping", jt_ptl_ping, 0, "Check LNET connectivity\n"
113          "usage: ping nid [timeout] [pid]"},
114
115         /* Device selection commands */
116         {"==== obd device selection ====", jt_noop, 0, "device selection"},
117         {"device", jt_obd_device, 0,
118          "set current device to <name|devno>\n"
119          "usage: device <%name|$name|devno>"},
120         {"device_list", jt_obd_list, 0, "show all devices\n"
121          "usage: device_list"},
122         {"dl", jt_obd_list, 0, "show all devices\n"
123          "usage: dl [-t]"},
124
125         /* Device operations */
126         {"==== obd device operations ====", jt_noop, 0, "device operations"},
127         {"activate", jt_obd_activate, 0, "activate an import\n"},
128         {"deactivate", jt_obd_deactivate, 0, "deactivate an import. "
129          "This command should be used on failed OSC devices in an MDT LOV.\n"},
130         {"abort_recovery", jt_obd_abort_recovery, 0,
131          "abort recovery on a restarting MDT or OST device\n"},
132         {"set_timeout", jt_lcfg_set_timeout, 0,
133          "usage: conf_param obd_timeout=<secs>\n"},
134         {"conf_param", jt_lcfg_mgsparam, 0, "set a permanent config param. "
135          "This command must be run on the MGS node\n"
136          "usage: conf_param <target.keyword=val> ...\n"},
137         {"local_param", jt_lcfg_param, 0, "set a temporary, local param\n"
138          "usage: local_param <target.keyword=val> ...\n"},
139         {"get_param", jt_lcfg_getparam, 0, "get the Lustre or LNET parameter\n"
140          "usage: get_param [-n|-N|-F] <param_path1 param_path2 ...>\n"
141          "Get the value of Lustre or LNET parameter from the specified path.\n"
142          "The path can contain shell-style filename patterns.\n"
143          "  -n  Print only the value and not parameter name.\n"
144          "  -N  Print only matched parameter names and not the values.\n"
145          "      (Especially useful when using patterns.)\n"
146          "  -F  When -N specified, add '/', '@' or '=' for directories,\n"
147          "      symlinks and writeable files, respectively."},
148         {"set_param", jt_lcfg_setparam, 0, "set the Lustre or LNET parameter\n"
149          "usage: set_param [-n] <param_path1=value1 param_path2 value2 ...>\n"
150          "Set the value of the Lustre or LNET parameter at the specified path\n"
151          "  -n  Disable printing of the key name when printing values."},
152         {"list_param", jt_lcfg_listparam, 0,
153          "list the Lustre or LNET parameter name\n"
154          "usage: list_param [-F] <param_path1 param_path2 ...>\n"
155          "List the name of Lustre or LNET parameter from the specified path.\n"
156          "  -F  Add '/', '@' or '=' for dirs, symlinks and writeable files,\n"
157                 "respectively."},
158
159         /* Debug commands */
160         {"==== debugging control ====", jt_noop, 0, "debug"},
161         {"debug_daemon", jt_dbg_debug_daemon, 0,
162          "debug daemon control and dump to a file\n"
163          "usage: debug_daemon {start file [#MB]|stop}"},
164         {"debug_kernel", jt_dbg_debug_kernel, 0,
165          "get debug buffer and dump to a file, same as dk\n"
166          "usage: debug_kernel [file] [raw]"},
167         {"dk", jt_dbg_debug_kernel, 0,
168          "get debug buffer and dump to a file, same as debug_kernel\n"
169          "usage: dk [file] [raw]"},
170         {"debug_file", jt_dbg_debug_file, 0,
171          "convert a binary debug file dumped by the kernel to ASCII text\n"
172          "usage: debug_file <input> [output]"},
173         {"df", jt_dbg_debug_file, 0,
174          "read debug buffer from input and dump to output, same as debug_file\n"
175          "usage: df <input> [output]"},
176         {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
177          "usage: clear"},
178         {"mark", jt_dbg_mark_debug_buf, 0,
179          "insert marker text in kernel debug buffer\n"
180          "usage: mark <text>"},
181         {"filter", jt_dbg_filter, 0, "filter message type\n"
182          "usage: filter <subsystem id/debug mask>"},
183         {"show", jt_dbg_show, 0, "Show specific type of messages\n"
184          "usage: show <subsystem id/debug mask>"},
185         {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
186          "usage: debug_list <subs/types>"},
187         {"modules", jt_dbg_modules, 0,
188          "provide gdb-friendly module information\n"
189          "usage: modules <path>"},
190
191         /* virtual block operations */
192         {"==== virtual block device ====", jt_noop, 0, "virtual block device"},
193         {"blockdev_attach", jt_blockdev_attach, 0,
194          "attach a lustre regular file to a virtual block device\n"
195          "usage: blockdev_attach <file_name> <device_name>"},
196         {"blockdev_detach", jt_blockdev_detach, 0,
197          "detach a lustre regular file from a virtual block device\n"
198          "usage: blockdev_detach <device_name>"},
199         {"blockdev_info", jt_blockdev_info, 0,
200          "get the device info of a attached file\n"
201          "usage: blockdev_info <device_name>"},
202
203         /* Pool commands */
204         {"===  Pools ==", jt_noop, 0, "pool management"},
205         {"pool_new", jt_pool_cmd, 0,
206          "add a new pool\n"
207          "usage pool_new <fsname>.<poolname>"},
208         {"pool_add", jt_pool_cmd, 0,
209          "add the named OSTs to the pool\n"
210          "usage pool_add <fsname>.<poolname> <ostname indexed list>"},
211         {"pool_remove", jt_pool_cmd, 0,
212          "remove the named OST from the pool\n"
213          "usage pool_remove <fsname>.<poolname> <ostname indexed list>"},
214         {"pool_destroy", jt_pool_cmd, 0,
215          "destroy a pool\n"
216          "usage pool_destroy <fsname>.<poolname>"},
217         {"pool_list", jt_pool_cmd, 0,
218          "list pools and pools members\n"
219          "usage pool_list  <fsname>[.<poolname>] | <pathname>"},
220
221         /* Changelog commands */
222         {"===  Changelogs ==", jt_noop, 0, "changelog user management"},
223         {"changelog_register", jt_changelog_register, 0,
224          "register a new persistent changelog user, returns id\n"
225          "usage:\tdevice <mdtname>\n\tchangelog_register [-n]"},
226         {"changelog_deregister", jt_changelog_deregister, 0,
227          "deregister an existing changelog user\n"
228          "usage:\tdevice <mdtname>\n\tchangelog_deregister <id>"},
229
230         /* Device configuration commands */
231         {"== device setup (these are not normally used post 1.4) ==",
232                 jt_noop, 0, "device config"},
233         {"attach", jt_lcfg_attach, 0,
234          "set the type, name, and uuid of the current device\n"
235          "usage: attach type name uuid"},
236         {"detach", jt_obd_detach, 0,
237          "remove driver (and name and uuid) from current device\n"
238          "usage: detach"},
239         {"setup", jt_lcfg_setup, 0,
240          "type specific device configuration information\n"
241          "usage: setup <args...>"},
242         {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
243          "usage: cleanup [force | failover]"},
244         {"dump_cfg", jt_cfg_dump_log, 0,
245          "print log of recorded commands for this config to kernel debug log\n"
246          "usage: dump_cfg config-uuid-name"},
247
248         /* Test only commands */
249         {"==== testing (DANGEROUS) ====", jt_noop, 0, "testing (DANGEROUS)"},
250         {"--threads", jt_opt_threads, 0,
251          "run <threads> separate instances of <command> on device <devno>\n"
252          "--threads <threads> <verbose> <devno> <command [args ...]>"},
253         {"lookup", jt_obd_mdc_lookup, 0, "report file mode info\n"
254          "usage: lookup <directory> <file>"},
255         {"readonly", jt_obd_set_readonly, 0,
256          "disable writes to the underlying device\n"},
257         {"notransno", jt_obd_no_transno, 0,
258          "disable sending of committed-transno updates\n"},
259         {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a nid\n"
260          "usage: add_uuid <uuid> <nid>"},
261         {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
262          "usage: del_uuid <uuid>"},
263         {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
264          "usage: add_peer <nid> <host> <port>"},
265         {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
266          "usage: del_peer [<nid>] [<ipaddr|pid>]"},
267         {"add_conn ", jt_lcfg_add_conn, 0,
268          "usage: add_conn <conn_uuid> [priority]\n"},
269         {"del_conn ", jt_lcfg_del_conn, 0,
270          "usage: del_conn <conn_uuid> \n"},
271         {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
272          "usage: disconnect [<nid>]"},
273         {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
274          "The nid defaults to hostname for tcp networks and is automatically "
275          "setup for elan/myrinet networks.\n"
276          "usage: mynid [<nid>]"},
277         {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
278          "Omitting the count means indefinitely, 0 means restore, "
279          "otherwise fail 'count' messages.\n"
280          "usage: fail nid|_all_ [count]"},
281         {"getattr", jt_obd_getattr, 0,
282          "get attribute for OST object <objid>\n"
283          "usage: getattr <objid>"},
284         {"setattr", jt_obd_setattr, 0,
285          "set mode attribute for OST object <objid>\n"
286          "usage: setattr <objid> <mode>"},
287          {"create", jt_obd_create, 0,
288          "create <num> OST objects (with <mode>)\n"
289          "usage: create [num [mode [verbose [lsm data]]]]"},
290         {"destroy", jt_obd_destroy, 0,
291          "destroy OST object <objid> [num [verbose]]\n"
292          "usage: destroy <num> objects, starting at objid <objid>"},
293         {"test_getattr", jt_obd_test_getattr, 0,
294          "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
295          "usage: test_getattr <num> [verbose [[t]objid]]"},
296         {"test_setattr", jt_obd_test_setattr, 0,
297          "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
298          "usage: test_setattr <num> [verbose [[t]objid]]"},
299         {"test_brw", jt_obd_test_brw, 0,
300          "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
301          "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
302         {"lwt", jt_ptl_lwt, 0,
303          "light-weight tracing\n"
304          "usage: lwt start\n"
305          "       lwt stop [file]"},
306         {"memhog", jt_ptl_memhog, 0,
307          "memory pressure testing\n"
308          "usage: memhog <page count> [<gfp flags>]"},
309         {"getobjversion", jt_get_obj_version, 0,
310          "get the version of an object on servers\n"
311          "usage: getobjversion <fid>"},
312
313         {"==== obsolete (DANGEROUS) ====", jt_noop, 0, "obsolete (DANGEROUS)"},
314         /* some test scripts still use these */
315         {"cfg_device", jt_obd_device, 0,
316          "set current device to <name>\n"
317          "usage: device <name>"},
318         {"recover", jt_obd_recover, 0,
319          "try to restore a lost connection immediately\n"
320          "usage: recover [MDC/OSC device]"},
321         /* saving for sanity 44a */
322         {"lov_getconfig", jt_obd_lov_getconfig, 0,
323          "read lov configuration from an mds device\n"
324          "usage: lov_getconfig <mountpoint>"},
325         /* Llog operations */
326         {"llog_catlist", jt_llog_catlist, 0,
327          "list all catalog logs on current device.\n"
328          "usage: llog_catlist"},
329         {"llog_info", jt_llog_info, 0,
330          "print log header information.\n"
331          "usage: llog_info <$logname|#oid#ogr#ogen>\n"
332          "       oid, ogr and ogen are hexadecimal."},
333         {"llog_print", jt_llog_print, 0,
334          "print log content information.\n"
335          "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
336          "       oid, ogr and ogen are hexadecimal.\n"
337          "       print all records from index 1 by default."},
338         {"llog_check", jt_llog_check, 0,
339          "print log content information.\n"
340          "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
341          "       oid, ogr and ogen are hexadecimal.\n"
342          "       check all records from index 1 by default."},
343          {"llog_cancel", jt_llog_cancel, 0,
344          "cancel one record in log.\n"
345          "usage: llog_cancel <catalog id|catalog name> <log id> <index>"},
346         {"llog_remove", jt_llog_remove, 0,
347          "remove one log from catalog, erase it from disk.\n"
348          "usage: llog_remove <catalog id|catalog name> <log id>"},
349         /* network operations */
350         {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
351          "usage: add_interface ip [netmask]"},
352         {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
353          "usage: del_interface [ip]"},
354         {"add_route", jt_ptl_add_route, 0,
355          "add an entry to the portals routing table\n"
356          "usage: add_route <gateway> <target> [<target>]"},
357         {"del_route", jt_ptl_del_route, 0,
358          "delete route via gateway to targets from the portals routing table\n"
359          "usage: del_route <gateway> [<target>] [<target>]"},
360         {"set_route", jt_ptl_notify_router, 0,
361          "enable/disable routes via gateway in the portals routing table\n"
362          "usage: set_route <gateway> <up/down> [<time>]"},
363
364         { 0, 0, 0, NULL }
365 };
366
367 int lctl_main(int argc, char **argv)
368 {
369         int rc;
370
371         setlinebuf(stdout);
372
373         ptl_initialize(argc, argv);
374         if (obd_initialize(argc, argv) < 0)
375                 exit(2);
376         if (dbg_initialize(argc, argv) < 0)
377                 exit(3);
378
379         Parser_init("lctl > ", cmdlist);
380
381         if (argc > 1) {
382                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
383         } else {
384                 rc = Parser_commands();
385         }
386
387         obd_finalize(argc, argv);
388         return rc < 0 ? -rc : rc;
389 }
390
391 #ifndef LIBLUSTRE_TEST
392 int main (int argc, char **argv)
393 {
394         return (lctl_main (argc, argv));
395 }
396 #endif