4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
40 * Author: Robert Read <rread@clusterfs.com>
45 #include <lnet/lnetctl.h>
47 #include <libcfs/libcfsutil.h>
49 static int jt_quit(int argc, char **argv) {
50 Parser_quit(argc, argv);
54 static int jt_noop(int argc, char **argv) {
58 static int jt_opt_ignore_errors(int argc, char **argv) {
59 Parser_ignore_errors(1);
63 command_t cmdlist[] = {
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"
72 {"ignore_errors", jt_opt_ignore_errors, 0,
73 "ignore errors that occur during script processing\n"
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"},
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/o2ib/...> <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 {"replace_nids", jt_replace_nids, 0,
98 "replace primary NIDs for a device\n"
99 "usage: replace_nids <device> <nid1>[,nid2,nid3]"},
100 {"interface_list", jt_ptl_print_interfaces,0,"print interface entries\n"
101 "usage: interface_list"},
102 {"peer_list", jt_ptl_print_peers, 0, "print peer entries\n"
104 {"conn_list", jt_ptl_print_connections, 0,
105 "print all the connected remote nid\n"
107 {"active_tx", jt_ptl_print_active_txs, 0, "print active transmits\n"
109 {"route_list", jt_ptl_print_routes, 0,
110 "print the portals routing table, same as show_route\n"
111 "usage: route_list"},
112 {"show_route", jt_ptl_print_routes, 0,
113 "print the portals routing table, same as route_list\n"
114 "usage: show_route"},
115 {"ping", jt_ptl_ping, 0, "Check LNET connectivity\n"
116 "usage: ping nid [timeout] [pid]"},
118 /* Device selection commands */
119 {"==== obd device selection ====", jt_noop, 0, "device selection"},
120 {"device", jt_obd_device, 0,
121 "set current device to <name|devno>\n"
122 "usage: device <%name|$name|devno>"},
123 {"device_list", jt_obd_list, 0, "show all devices\n"
124 "usage: device_list"},
125 {"dl", jt_obd_list, 0, "show all devices\n"
128 /* Device operations */
129 {"==== obd device operations ====", jt_noop, 0, "device operations"},
130 {"activate", jt_obd_activate, 0, "activate an import\n"},
131 {"deactivate", jt_obd_deactivate, 0, "deactivate an import. "
132 "This command should be used on failed OSC devices in an MDT LOV.\n"},
133 {"abort_recovery", jt_obd_abort_recovery, 0,
134 "abort recovery on a restarting MDT or OST device\n"},
135 {"set_timeout", jt_lcfg_set_timeout, 0,
136 "usage: conf_param obd_timeout=<secs>\n"},
137 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
138 {"conf_param", jt_lcfg_mgsparam, 0,"set a permanent config parameter.\n"
139 "This command must be run on the MGS node\n"
140 "usage: conf_param [-d] <target.keyword=val>\n"
141 " -d Remove the permanent setting."},
143 {"local_param", jt_lcfg_param, 0, "set a temporary, local param\n"
144 "usage: local_param <target.keyword=val>\n"},
145 {"get_param", jt_lcfg_getparam, 0, "get the Lustre or LNET parameter\n"
146 "usage: get_param [-n|-N|-F] <param_path1 param_path2 ...>\n"
147 "Get the value of Lustre or LNET parameter from the specified path.\n"
148 "The path can contain shell-style filename patterns.\n"
149 " -n Print only the value and not parameter name.\n"
150 " -N Print only matched parameter names and not the values.\n"
151 " (Especially useful when using patterns.)\n"
152 " -F When -N specified, add '/', '@' or '=' for directories,\n"
153 " symlinks and writeable files, respectively."},
154 {"set_param", jt_lcfg_setparam, 0, "set the Lustre or LNET parameter\n"
155 "usage: set_param [-n] [-P] [-d]"
156 "<param_path1=value1 param_path2=value2 ...>\n"
157 "Set the value of the Lustre or LNET parameter at the specified path.\n"
158 " -n Disable printing of the key name when printing values.\n"
159 " -P Set the parameter permanently, filesystem-wide.\n"
160 " -d Remove the permanent setting (only with -P option).\n"},
161 {"list_param", jt_lcfg_listparam, 0,
162 "list the Lustre or LNET parameter name\n"
163 "usage: list_param [-F|-R] <param_path1 param_path2 ...>\n"
164 "List the name of Lustre or LNET parameter from the specified path.\n"
165 " -F Add '/', '@' or '=' for dirs, symlinks and writeable files,\n"
167 " -R Recursively list all parameters under the specified path.\n"},
170 {"==== debugging control ====", jt_noop, 0, "debug"},
171 {"debug_daemon", jt_dbg_debug_daemon, 0,
172 "debug daemon control and dump to a file\n"
173 "usage: debug_daemon {start file [#MB]|stop}"},
174 {"debug_kernel", jt_dbg_debug_kernel, 0,
175 "get debug buffer and dump to a file, same as dk\n"
176 "usage: debug_kernel [file] [raw]"},
177 {"dk", jt_dbg_debug_kernel, 0,
178 "get debug buffer and dump to a file, same as debug_kernel\n"
179 "usage: dk [file] [raw]"},
180 {"debug_file", jt_dbg_debug_file, 0,
181 "convert a binary debug file dumped by the kernel to ASCII text\n"
182 "usage: debug_file <input> [output]"},
183 {"df", jt_dbg_debug_file, 0,
184 "read debug buffer from input and dump to output, same as debug_file\n"
185 "usage: df <input> [output]"},
186 {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
188 {"mark", jt_dbg_mark_debug_buf, 0,
189 "insert marker text in kernel debug buffer\n"
190 "usage: mark <text>"},
191 {"filter", jt_dbg_filter, 0, "filter message type\n"
192 "usage: filter <subsystem id/debug mask>"},
193 {"show", jt_dbg_show, 0, "Show specific type of messages\n"
194 "usage: show <subsystem id/debug mask>"},
195 {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
196 "usage: debug_list <subs/types>"},
197 {"modules", jt_dbg_modules, 0,
198 "provide gdb-friendly module information\n"
199 "usage: modules <path>"},
201 /* virtual block operations */
202 {"==== virtual block device ====", jt_noop, 0, "virtual block device"},
203 {"blockdev_attach", jt_blockdev_attach, 0,
204 "attach a lustre regular file to a virtual block device\n"
205 "usage: blockdev_attach <file_name> <device_name>"},
206 {"blockdev_detach", jt_blockdev_detach, 0,
207 "detach a lustre regular file from a virtual block device\n"
208 "usage: blockdev_detach <device_name>"},
209 {"blockdev_info", jt_blockdev_info, 0,
210 "get the device info of a attached file\n"
211 "usage: blockdev_info <device_name>"},
214 {"=== Pools ==", jt_noop, 0, "pool management"},
215 {"pool_new", jt_pool_cmd, 0,
217 "usage: pool_new <fsname>.<poolname>"},
218 {"pool_add", jt_pool_cmd, 0,
219 "add the named OSTs to the pool\n"
220 "usage: pool_add <fsname>.<poolname> <ostname indexed list>"},
221 {"pool_remove", jt_pool_cmd, 0,
222 "remove the named OST from the pool\n"
223 "usage: pool_remove <fsname>.<poolname> <ostname indexed list>"},
224 {"pool_destroy", jt_pool_cmd, 0,
226 "usage: pool_destroy <fsname>.<poolname>"},
227 {"pool_list", jt_pool_cmd, 0,
228 "list pools and pools members\n"
229 "usage: pool_list <fsname>[.<poolname>] | <pathname>"},
231 /* Nodemap commands */
232 {"=== Nodemap ===", jt_noop, 0, "nodemap management"},
233 {"nodemap_activate_idmap", jt_nodemap_activate, 0,
234 "activate nodemap idmapping functions\n"
235 "usage: nodemap_activate_idmap"},
236 {"nodemap_add", jt_nodemap_add, 0,
237 "add a new nodemap\n"
238 "usage: nodemap_add <nodemap_name>"},
239 {"nodemap_del", jt_nodemap_del, 0,
241 "usage: nodemap_del <nodemap_name>"},
243 /* Changelog commands */
244 {"=== Changelogs ==", jt_noop, 0, "changelog user management"},
245 {"changelog_register", jt_changelog_register, 0,
246 "register a new persistent changelog user, returns id\n"
247 "usage:\tdevice <mdtname>\n\tchangelog_register [-n]"},
248 {"changelog_deregister", jt_changelog_deregister, 0,
249 "deregister an existing changelog user\n"
250 "usage:\tdevice <mdtname>\n\tchangelog_deregister <id>"},
252 /* Device configuration commands */
253 {"== device setup (these are not normally used post 1.4) ==",
254 jt_noop, 0, "device config"},
255 {"attach", jt_lcfg_attach, 0,
256 "set the type, name, and uuid of the current device\n"
257 "usage: attach type name uuid"},
258 {"detach", jt_obd_detach, 0,
259 "remove driver (and name and uuid) from current device\n"
261 {"setup", jt_lcfg_setup, 0,
262 "type specific device configuration information\n"
263 "usage: setup <args...>"},
264 {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
265 "usage: cleanup [force | failover]"},
266 {"dump_cfg", jt_cfg_dump_log, 0,
267 "print log of recorded commands for this config to kernel debug log\n"
268 "usage: dump_cfg config-uuid-name"},
270 /* Test only commands */
271 {"==== testing (DANGEROUS) ====", jt_noop, 0, "testing (DANGEROUS)"},
272 {"--threads", jt_opt_threads, 0,
273 "run <threads> separate instances of <command> on device <devno>\n"
274 "--threads <threads> <verbose> <devno> <command [args ...]>"},
275 {"lookup", jt_obd_mdc_lookup, 0, "report file mode info\n"
276 "usage: lookup <directory> <file>"},
277 {"readonly", jt_obd_set_readonly, 0,
278 "disable writes to the underlying device\n"},
279 {"notransno", jt_obd_no_transno, 0,
280 "disable sending of committed-transno updates\n"},
281 {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a nid\n"
282 "usage: add_uuid <uuid> <nid>"},
283 {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
284 "usage: del_uuid <uuid>"},
285 {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
286 "usage: add_peer <nid> <host> <port>"},
287 {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
288 "usage: del_peer [<nid>] [<ipaddr|pid>]"},
289 {"add_conn ", jt_lcfg_add_conn, 0,
290 "usage: add_conn <conn_uuid> [priority]\n"},
291 {"del_conn ", jt_lcfg_del_conn, 0,
292 "usage: del_conn <conn_uuid> \n"},
293 {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
294 "usage: disconnect [<nid>]"},
295 {"push", jt_ptl_push_connection, 0, "flush connection to a remote nid\n"
296 "usage: push [<nid>]"},
297 {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
298 "The nid defaults to hostname for tcp networks and is automatically "
299 "setup for elan/myrinet networks.\n"
300 "usage: mynid [<nid>]"},
301 {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
302 "Omitting the count means indefinitely, 0 means restore, "
303 "otherwise fail 'count' messages.\n"
304 "usage: fail nid|_all_ [count]"},
306 /*Test commands for echo client*/
307 {"test_create", jt_obd_test_create, 0,
308 "create files on MDT by echo client\n"
309 "usage: test_create [-d parent_basedir] <-D parent_count> "
310 "[-b child_base_id] <-c stripe_count> <-n count> <-t time>\n"},
311 {"test_mkdir", jt_obd_test_mkdir, 0,
312 "mkdir on MDT by echo client\n"
313 "usage: test_mkdir [-d parent_basedir] <-D parent_count>"
314 "[-b child_base_id] [-n count] <-t time>\n"},
315 {"test_destroy", jt_obd_test_destroy, 0,
316 "Destroy files on MDT by echo client\n"
317 "usage: test_destroy [-d parent_basedir] <-D parent_count>"
318 "[-b child_base_id] [-n count] <-t time>\n"},
319 {"test_rmdir", jt_obd_test_rmdir, 0,
320 "rmdir on MDT by echo client\n"
321 "usage: test_rmdir [-d parent_basedir] <-D parent_count>"
322 "[-b child_base_id] [-n count] <-t time>\n"},
323 {"test_lookup", jt_obd_test_lookup, 0,
324 "lookup files on MDT by echo client\n"
325 "usage: test_lookup [-d parent_basedir] <-D parent_count>"
326 "[-b child_base_id] [-n count] <-t time>\n"},
327 {"test_setxattr", jt_obd_test_setxattr, 0,
328 "Set EA for files/directory on MDT by echo client\n"
329 "usage: test_setxattr [-d parent_baseid] <-D parent_count>"
330 "[-b child_base_id] [-n count] <-t time>\n"},
331 {"test_md_getattr", jt_obd_test_md_getattr, 0,
332 "getattr files on MDT by echo client\n"
333 "usage: test_md_getattr [-d parent_basedir] <-D parent_count>"
334 "[-b child_base_id] [-n count] <-t time>\n"},
335 {"getattr", jt_obd_getattr, 0,
336 "get attribute for OST object <objid>\n"
337 "usage: getattr <objid>"},
338 {"setattr", jt_obd_setattr, 0,
339 "set mode attribute for OST object <objid>\n"
340 "usage: setattr <objid> <mode>"},
341 {"create", jt_obd_create, 0,
342 "create <num> OST objects (with <mode>)\n"
343 "usage: create [num [mode [verbose [lsm data]]]]"},
344 {"destroy", jt_obd_destroy, 0,
345 "destroy OST object <objid> [num [verbose]]\n"
346 "usage: destroy <num> objects, starting at objid <objid>"},
347 {"test_getattr", jt_obd_test_getattr, 0,
348 "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
349 "usage: test_getattr <num> [verbose [[t]objid]]"},
350 {"test_setattr", jt_obd_test_setattr, 0,
351 "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
352 "usage: test_setattr <num> [verbose [[t]objid]]"},
353 {"test_brw", jt_obd_test_brw, 0,
354 "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
355 "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
356 {"memhog", jt_ptl_memhog, 0,
357 "memory pressure testing\n"
358 "usage: memhog <page count> [<gfp flags>]"},
359 {"getobjversion", jt_get_obj_version, 0,
360 "get the version of an object on servers\n"
361 "usage: getobjversion <fid>\n"
362 " getobjversion -i <id> -g <group>"},
365 {"==== LFSCK ====", jt_noop, 0, "LFSCK"},
366 {"lfsck_start", jt_lfsck_start, 0, "start LFSCK\n"
367 "usage: lfsck_start <-M | --device [MDT,OST]_device>\n"
368 " [-e | --error error_handle] [-h | --help]\n"
369 " [-n | --dryrun switch] [-r | --reset]\n"
370 " [-s | --speed speed_limit] [-A | --all]\n"
371 " [-t | --type lfsck_type[,lfsck_type...]]\n"
372 " [-w | --windows win_size]"},
373 {"lfsck_stop", jt_lfsck_stop, 0, "stop lfsck(s)\n"
374 "usage: lfsck_stop <-M | --device [MDT,OST]_device>\n"
375 " [-A | --all] [-h | --help]"},
377 {"==== obsolete (DANGEROUS) ====", jt_noop, 0, "obsolete (DANGEROUS)"},
378 /* some test scripts still use these */
379 {"cfg_device", jt_obd_device, 0,
380 "set current device to <name>\n"
381 "usage: device <name>"},
382 {"recover", jt_obd_recover, 0,
383 "try to restore a lost connection immediately\n"
384 "usage: recover [MDC/OSC device]"},
385 /* saving for sanity 44a */
386 {"lov_getconfig", jt_obd_lov_getconfig, 0,
387 "read lov configuration from an mds device\n"
388 "usage: lov_getconfig <mountpoint>"},
389 /* Llog operations */
390 {"llog_catlist", jt_llog_catlist, 0,
391 "list all catalog logs on current device.\n"
392 "usage: llog_catlist"},
393 {"llog_info", jt_llog_info, 0,
394 "print log header information.\n"
395 "usage: llog_info <$logname|#oid#ogr#ogen>\n"
396 " oid, ogr and ogen are hexadecimal."},
397 {"llog_print", jt_llog_print, 0,
398 "print log content information.\n"
399 "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
400 " oid, ogr and ogen are hexadecimal.\n"
401 " print all records from index 1 by default."},
402 {"llog_check", jt_llog_check, 0,
403 "print log content information.\n"
404 "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
405 " oid, ogr and ogen are hexadecimal.\n"
406 " check all records from index 1 by default."},
407 {"llog_cancel", jt_llog_cancel, 0,
408 "cancel one record in log.\n"
409 "This command supports both positional and optional arguments\n"
410 "usage (positional args): "
411 "llog_cancel <catalog id|catalog name> [log id] <index>\n"
412 "usage (optional args): "
413 "llog_cancel --catalog <catalog id|catalog name> --log_id <log_id> "
414 "--log_idx <index>"},
415 {"llog_remove", jt_llog_remove, 0,
416 "remove one log from catalog or plain log, erase it from disk.\n"
417 "usage: llog_remove <catalog id|catalog name> <log id>"},
418 /* network operations */
419 {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
420 "usage: add_interface ip [netmask]"},
421 {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
422 "usage: del_interface [ip]"},
423 {"add_route", jt_ptl_add_route, 0,
424 "add an entry to the portals routing table\n"
425 "usage: add_route <gateway> [<hops> [<priority>]]"},
426 {"del_route", jt_ptl_del_route, 0,
427 "delete route via gateway to targets from the portals routing table\n"
428 "usage: del_route <gateway> [<target>] [<target>]"},
429 {"set_route", jt_ptl_notify_router, 0,
430 "enable/disable routes via gateway in the portals routing table\n"
431 "usage: set_route <gateway> <up/down> [<time>]"},
436 int lctl_main(int argc, char **argv)
442 ptl_initialize(argc, argv);
443 if (obd_initialize(argc, argv) < 0)
445 if (dbg_initialize(argc, argv) < 0)
448 Parser_init("lctl > ", cmdlist);
451 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
453 rc = Parser_commands();
456 obd_finalize(argc, argv);
457 return rc < 0 ? -rc : rc;
460 #ifndef LIBLUSTRE_TEST
461 int main (int argc, char **argv)
463 return (lctl_main (argc, argv));