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