1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
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>
9 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
28 #include <sys/types.h>
34 #include <portals/ptlctl.h>
38 static int jt_quit(int argc, char **argv) {
39 Parser_quit(argc, argv);
43 static int jt_noop(int argc, char **argv) {
47 static int jt_opt_ignore_errors(int argc, char **argv) {
48 Parser_ignore_errors(1);
52 #include <linux/lustre_audit.h>
54 static int parse_audit_ops(char * str, __u64 * mask)
56 char * op = strtok(str, ",");
60 if (!strcmp(op, "all")) {
61 *mask |= AUDIT_ALL_OPS;
64 else if (!strcmp(op,"none")) {
65 *mask &= ~AUDIT_ALL_OPS;
67 else if (!strcmp(op,"create"))
68 SET_AUDIT_OP((*mask), AUDIT_CREATE);
69 else if (!strcmp(op,"link"))
70 SET_AUDIT_OP((*mask), AUDIT_LINK);
71 else if (!strcmp(op,"delete"))
72 SET_AUDIT_OP((*mask), AUDIT_UNLINK);
73 else if (!strcmp(op,"rename"))
74 SET_AUDIT_OP((*mask), AUDIT_RENAME);
75 else if (!strcmp(op,"read")) {
76 SET_AUDIT_OP((*mask), AUDIT_READ);
77 SET_AUDIT_OP((*mask), AUDIT_MMAP);
79 else if (!strcmp(op,"write"))
80 SET_AUDIT_OP((*mask), AUDIT_WRITE);
81 else if (!strcmp(op,"open"))
82 SET_AUDIT_OP((*mask), AUDIT_OPEN);
83 else if (!strcmp(op,"stat"))
84 SET_AUDIT_OP((*mask), AUDIT_STAT);
85 else if (!strcmp(op,"readdir"))
86 SET_AUDIT_OP((*mask), AUDIT_READDIR);
87 else if (!strcmp(op,"readlink"))
88 SET_AUDIT_OP((*mask), AUDIT_READLINK);
89 else if (!strcmp(op,"setattr"))
90 SET_AUDIT_OP((*mask), AUDIT_SETATTR);
92 fprintf(stderr, "invalid audit operation '%s'\n", op);
95 op = strtok(NULL, ",");
103 #include <linux/unistd.h>
105 static int set_dir_audit(char * dir, __u64 mask)
110 struct dirent * ent = (void*)buf;
112 buf = malloc(strlen(dir) + NAME_MAX + 1);
116 fprintf(stderr, "cannot open dir %s\n", dir);
121 while ((ent = readdir(sdr)) != NULL) {
124 if (!strcmp(ent->d_name, ".") ||
125 !strcmp(ent->d_name, ".."))
128 sprintf(buf, "%s/%s", dir, ent->d_name);
130 fd = open(buf, O_RDONLY);
132 fprintf(stderr, "can't open: %s: %s\n", buf,
133 strerror(rc = errno));
136 rc = ioctl(fd, LL_IOC_AUDIT, mask);
144 static int set_audit(int argc, char **argv, int fs)
153 /* audit can be for all operations or for failed only */
154 if (!strcmp(argv[1], "fail"))
155 SET_AUDIT_OP(mask, AUDIT_FAIL);
156 else if (strcmp(argv[1], "all")) {
157 fprintf(stderr, "%s: invalid audit type %s\n",
158 jt_cmdname(argv[0]), argv[1]);
162 rc = parse_audit_ops(argv[2], &mask);
167 fd = open(argv[3], O_RDONLY);
169 fprintf(stderr, "can't open: %s: %s\n", argv[3],
170 strerror(rc = errno));
181 SET_AUDIT_OP(mask, AUDIT_FS);
183 //if dir then set audit for childs also
184 if (S_ISDIR(st.st_mode)) {
185 //rc = set_dir_audit(argv[3], mask | AUD_BIT(AUDIT_DIR));
188 //set audit for file/dir itself
189 rc = ioctl(fd, LL_IOC_AUDIT, mask);
194 static int jt_set_audit(int argc, char **argv)
196 return set_audit(argc, argv, 0);
199 static int jt_set_fsaudit(int argc, char **argv)
201 return set_audit(argc, argv, 1);
205 * XXX Should not belong to here
207 static int flush_cred_ioctl(char *mp)
211 fd = open(mp, O_RDONLY);
213 fprintf(stderr, "flush_cred_ioctl: error open %s: %s\n",
214 mp, strerror(errno));
218 rc = ioctl(fd, LL_IOC_FLUSH_CRED);
220 fprintf(stderr, "flush_cred_ioctl: error ioctl %s: %s\n",
221 mp, strerror(errno));
228 static int jt_flush_cred(int argc, char **argv)
231 char procline[PATH_MAX], *line;
234 /* no args means search all lustre mountpoints */
236 proc = fopen("/proc/mounts", "r");
238 fprintf(stderr, "%s: can't open /proc/mounts\n",
239 jt_cmdname(argv[0]));
243 while ((line = fgets(procline, PATH_MAX, proc)) != NULL) {
248 if (sscanf(line, "%s %s %s", dev, mp, fs) != 3) {
249 fprintf(stderr, "%s: unexpected format in "
251 jt_cmdname(argv[0]));
255 if (strcmp(fs, "lustre") &&
256 strcmp(fs, "lustre_lite"))
259 if (flush_cred_ioctl(mp))
263 /* follow the exact flush sequence as supplied */
264 for (i = 1; i < argc; i++) {
265 if (flush_cred_ioctl(argv[i]))
273 command_t cmdlist[] = {
275 {"--device", jt_opt_device, 0,
276 "run <command> after connecting to device <devno>\n"
277 "--device <devno> <command [args ...]>"},
278 {"--threads", jt_opt_threads, 0,
279 "run <threads> separate instances of <command> on device <devno>\n"
280 "--threads <threads> <verbose> <devno> <command [args ...]>"},
281 {"--ignore_errors", jt_opt_ignore_errors, 0,
282 "ignore errors that occur during script processing\n"
284 {"ignore_errors", jt_opt_ignore_errors, 0,
285 "ignore errors that occur during script processing\n"
287 {"dump", jt_ioc_dump, 0, "usage: dump file, save ioctl buffer to file"},
289 /* Network configuration commands */
290 {"==== network config ====", jt_noop, 0, "network config"},
291 {"--net", jt_opt_net, 0, "run <command> after setting network to <net>\n"
292 "usage: --net <tcp/elan/myrinet> <command>"},
293 {"network", jt_ptl_network, 0, "commands that follow apply to net\n"
294 "usage: network <tcp/elan/myrinet>"},
295 {"interface_list", jt_ptl_print_interfaces, 0, "print interface entries\n"
296 "usage: interface_list"},
297 {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
298 "usage: add_interface ip [netmask]"},
299 {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
300 "usage: del_interface [ip]"},
301 {"peer_list", jt_ptl_print_peers, 0, "print peer entries\n"
303 {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
304 "usage: add_peer <nid> <host> <port>"},
305 {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
306 "usage: del_peer [<nid>] [<host>] [ks]"},
307 {"conn_list", jt_ptl_print_connections, 0, "print all the connected remote nid\n"
309 {"connect", jt_ptl_connect, 0, "connect to a remote nid\n"
310 "usage: connect <host> <port> [iIOC]"},
311 {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
312 "usage: disconnect [<nid>]"},
313 {"active_tx", jt_ptl_print_active_txs, 0, "print active transmits\n"
315 {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
316 "The nid defaults to hostname for tcp networks and is automatically "
317 "setup for elan/myrinet networks.\n"
318 "usage: mynid [<nid>]"},
319 {"shownid", jt_ptl_shownid, 0, "print the local NID\n"
321 {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a nid\n"
322 "usage: add_uuid <uuid> <nid> <net_type>"},
323 {"close_uuid", jt_obd_close_uuid, 0, "disconnect a UUID\n"
324 "usage: close_uuid <uuid> <net_type>"},
325 {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
326 "usage: del_uuid <uuid>"},
327 {"add_route", jt_ptl_add_route, 0,
328 "add an entry to the portals routing table\n"
329 "usage: add_route <gateway> <target> [<target>]"},
330 {"del_route", jt_ptl_del_route, 0,
331 "delete route via gateway to targets from the portals routing table\n"
332 "usage: del_route <gateway> [<target>] [<target>]"},
333 {"set_route", jt_ptl_notify_router, 0,
334 "enable/disable routes via gateway in the portals routing table\n"
335 "usage: set_route <gateway> <up/down> [<time>]"},
336 {"route_list", jt_ptl_print_routes, 0,
337 "print the portals routing table, same as show_route\n"
338 "usage: route_list"},
339 {"show_route", jt_ptl_print_routes, 0,
340 "print the portals routing table, same as route_list\n"
341 "usage: show_route"},
342 {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
343 "Omitting the count means indefinitely, 0 means restore, "
344 "otherwise fail 'count' messages.\n"
345 "usage: fail nid|_all_ [count]"},
347 /* Device selection commands */
348 {"=== device selection ===", jt_noop, 0, "device selection"},
349 {"newdev", jt_lcfg_newdev, 0, "create a new device\n"
351 {"device", jt_obd_device, 0,
352 "set current device to <%name|$name|devno>\n"
353 "usage: device <%name|$name|devno>"},
354 {"cfg_device", jt_lcfg_device, 0,
355 "set current device being configured to <$name>\n"
356 "usage: cfg_device <name>"},
357 {"device_list", jt_obd_list, 0, "show all devices\n"
358 "usage: device_list"},
359 {"dl", jt_obd_list, 0, "show all devices\n"
361 {"lustre_build_version", jt_get_version, 0,
362 "print the build version of lustre\n"
363 "usage: lustre_build_version"},
365 /* Device configuration commands */
366 {"==== device config =====", jt_noop, 0, "device config"},
367 {"attach", jt_lcfg_attach, 0,
368 "set the type of the current device (with <name> and <uuid>)\n"
369 "usage: attach type [name [uuid]]"},
370 {"setup", jt_lcfg_setup, 0,
371 "type specific device configuration information\n"
372 "usage: setup <args...>"},
373 {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
374 "usage: cleanup [force | failover]"},
375 {"detach", jt_obd_detach, 0,
376 "remove driver (and name and uuid) from current device\n"
378 {"lov_setup", jt_lcfg_lov_setup, 0, "create a LOV device\n"
379 "usage: lov_setup lov-uuid stripe-count stripe-size offset pattern"},
380 {"lmv_setup", jt_lcfg_lmv_setup, 0,
381 "create an LMV device\n"
382 "usage: lmv_setup lmv-uuid UUID1 [UUID2 ...]"},
383 {"lov_modify_tgts", jt_lcfg_lov_modify_tgts, 0,
384 "add or delete an obd to/from a LOV device\n"
385 "usage: lov_modify_tgts add|del <lov-name> <uuid> <index> <gen>"},
386 {"lov_getconfig", jt_obd_lov_getconfig, 0,
387 "read lov configuration from an mds device\n"
388 "usage: lov_getconfig lov-uuid"},
389 {"lmv_modify_tgts", jt_lcfg_lmv_modify_tgts, 0,
390 "add an mdc to a LMV device\n"
391 "usage: lmv_modify_tgts add <lmv_name> <mdc_uuid>"},
392 {"record", jt_cfg_record, 0, "record commands that follow in log\n"
393 "usage: record cfg-uuid-name"},
394 {"endrecord", jt_cfg_endrecord, 0, "stop recording\n"
396 {"parse", jt_cfg_parse, 0, "parse the log of recorded commands for this config\n"
397 "usage: parse config-uuid-name"},
398 {"dump_log", jt_cfg_dump_log, 0, "print log of recorded commands for this config to kernel debug log\n"
399 "usage: dump_log config-uuid-name"},
400 {"clear_log", jt_cfg_clear_log, 0, "delete current config log of recorded commands\n"
401 "usage: clear_log config-name"},
403 /* Device operations */
404 {"=== device operations ==", jt_noop, 0, "device operations"},
405 {"probe", jt_obd_connect, 0,
406 "build a connection handle to a device. This command is used to "
407 "suspend configuration until lctl has ensured that the mds and osc "
408 "services are available. This is to avoid mount failures in a "
409 "rebooting cluster.\n"
410 "usage: probe [timeout]"},
411 {"close", jt_obd_disconnect, 0,
412 "close the connection handle\n"
414 {"getattr", jt_obd_getattr, 0,
415 "get attribute for OST object <objid>\n"
416 "usage: getattr <objid>"},
417 {"setattr", jt_obd_setattr, 0,
418 "set mode attribute for OST object <objid>\n"
419 "usage: setattr <objid> <mode>"},
420 {"create", jt_obd_create, 0,
421 "create <num> OST objects (with <mode>)\n"
422 "usage: create [num [mode [verbose [lsm data]]]]"},
423 {"destroy", jt_obd_destroy, 0,
424 "destroy OST object <objid> [num [verbose]]\n"
425 "usage: destroy <num> objects, starting at objid <objid>"},
426 {"test_getattr", jt_obd_test_getattr, 0,
427 "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
428 "usage: test_getattr <num> [verbose [[t]objid]]"},
429 {"test_setattr", jt_obd_test_setattr, 0,
430 "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
431 "usage: test_setattr <num> [verbose [[t]objid]]"},
432 {"test_brw", jt_obd_test_brw, 0,
433 "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
434 "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
435 {"get_stripe", jt_obd_get_stripe, 0,
436 "show stripe info for an echo client object\n"
437 "usage: get_stripe objid\n"},
438 {"set_stripe", jt_obd_set_stripe, 0,
439 "set stripe info for an echo client object\n"
440 "usage: set_stripe objid[=width!count[@offset][:id:id...]\n"},
441 {"unset_stripe", jt_obd_unset_stripe, 0,
442 "unset stripe info for an echo client object\n"
443 "usage: unset_stripe objid\n"},
444 {"test_ldlm", jt_obd_test_ldlm, 0,
445 "perform lock manager test\n"
447 {"ldlm_regress_start", jt_obd_ldlm_regress_start, 0,
448 "start lock manager stress test\n"
449 "usage: ldlm_regress_start [numthreads [refheld [numres [numext]]]]"},
450 {"ldlm_regress_stop", jt_obd_ldlm_regress_stop, 0,
451 "stop lock manager stress test (no args)\n"},
452 {"dump_ldlm", jt_obd_dump_ldlm, 0,
453 "dump all lock manager state (no args)"},
454 {"disable_recovery", jt_obd_disable_recovery, 0, "disable recovery on an import\n"},
455 {"enable_recovery", jt_obd_enable_recovery, 0, "enable recovery on an import\n"},
456 {"activate", jt_obd_activate, 0, "activate an import\n"},
457 {"deactivate", jt_obd_deactivate, 0, "deactivate an import\n"},
458 {"recover", jt_obd_recover, 0, "usage: recover [<connection UUID>]"},
459 {"lookup", jt_obd_mdc_lookup, 0, "usage: lookup <directory> <file>"},
460 {"notransno", jt_obd_no_transno, 0,
461 "disable sending of committed-transno updates\n"},
462 {"readonly", jt_obd_set_readonly, 0,
463 "disable writes to the underlying device\n"},
464 {"abort_recovery", jt_obd_abort_recovery, 0,
465 "abort recovery on MDS device\n"},
466 {"root_squash", jt_obd_root_squash, 0,
467 "squash root to 'uid:gid' except client 'nid'\n"
468 "usage: root_squash [uid:gid [nid]]\n"},
469 {"start", jt_obd_start, 0,
470 "setup mds/ost from the llog file\n"
471 "usage: start <profilename>"},
472 {"mount_option", jt_lcfg_mount_option, 0,
473 "usage: mount_option profile osc_name [mdc_name] [gsc_name] \n"},
474 {"del_mount_option", jt_lcfg_del_mount_option, 0,
475 "usage: del_mount_option profile\n"},
476 {"set_timeout", jt_lcfg_set_timeout, 0,
477 "usage: set_timeout <secs>\n"},
478 {"set_lustre_upcall", jt_lcfg_set_lustre_upcall, 0,
479 "usage: set_lustre_upcall </full/path/to/upcall> \n"},
480 {"add_conn ", jt_lcfg_add_conn, 0,
481 "usage: add_conn <conn_uuid> [priority]\n"},
482 {"del_conn ", jt_lcfg_del_conn, 0,
483 "usage: del_conn <conn_uuid> \n"},
484 {"set_security", jt_lcfg_set_security, 0,
485 "usage: set_security key value\n"},
486 {"audit", jt_set_audit, 0,
487 "usage: audit type operations filename\n"},
488 {"fs_audit", jt_set_fsaudit, 0,
489 "usage: fs_audit type operations mountpoint\n"},
490 {"lsync", jt_obd_reint_sync, 0,
492 {"cache_on", jt_obd_cache_on, 0,
494 {"cache_off", jt_obd_cache_off, 0,
497 {"obd_flush_cred", jt_obd_flush_cred, 0,
498 "usage: obd_flush_cred [all]\n"},
501 {"snap_add", jt_obd_snap_add, 0,
502 "usage: snap_add <dev_name> <snap_name>\n"},
503 /* Llog operations */
504 {"llog_catlist", jt_llog_catlist, 0,
505 "list all catalog logs on current device.\n"
506 "usage: llog_catlist"},
507 {"llog_info", jt_llog_info, 0,
508 "print log header information.\n"
509 "usage: llog_info <$logname|#oid#ogr#ogen>\n"
510 " oid, ogr and ogen are hexadecimal."},
511 {"llog_print", jt_llog_print, 0,
512 "print log content information.\n"
513 "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
514 " oid, ogr and ogen are hexadecimal.\n"
515 " print all records from index 1 by default."},
516 {"llog_check", jt_llog_check, 0,
517 "print log content information.\n"
518 "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
519 " oid, ogr and ogen are hexadecimal.\n"
520 " check all records from index 1 by default."},
521 {"llog_cancel", jt_llog_cancel, 0,
522 "cancel one record in log.\n"
523 "usage: llog_cancel <catalog id|catalog name> <log id> <index>"},
524 {"llog_remove", jt_llog_remove, 0,
525 "remove one log from catalog, erase it from disk.\n"
526 "usage: llog_remove <catalog id|catalog name> <log id>"},
529 {"flush_cred", jt_flush_cred, 0,
530 "flush the client side credential.\n"
531 "usage: flush_cred [mountpoint]..."},
532 {"set_crypt", jt_set_lkey_type, 0,
533 "set lustre key management type, only support gks and mks\n"
534 "usage: set_crypt [dir] [gks|mks]...."},
537 {"======== debug =========", jt_noop, 0, "debug"},
538 {"debug_daemon", jt_dbg_debug_daemon, 0,
539 "debug daemon control and dump to a file\n"
540 "usage: debug_daemon {start file [#MB]|stop}"},
541 {"debug_kernel", jt_dbg_debug_kernel, 0,
542 "get debug buffer and dump to a file, same as dk\n"
543 "usage: debug_kernel [file] [raw]"},
544 {"dk", jt_dbg_debug_kernel, 0,
545 "get debug buffer and dump to a file, same as debug_kernel\n"
546 "usage: dk [file] [raw]"},
547 {"debug_file", jt_dbg_debug_file, 0,
548 "read debug buffer from input and dump to output, same as df\n"
549 "usage: debug_file <input> [output] [raw]"},
550 {"df", jt_dbg_debug_file, 0,
551 "read debug buffer from input and dump to output, same as debug_file\n"
552 "usage: df <input> [output] [raw]"},
553 {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
555 {"mark", jt_dbg_mark_debug_buf, 0,"insert marker text in kernel debug buffer\n"
556 "usage: mark <text>"},
557 {"filter", jt_dbg_filter, 0, "filter message type\n"
558 "usage: filter <subsystem id/debug mask>"},
559 {"show", jt_dbg_show, 0, "Show specific type of messages\n"
560 "usage: show <subsystem id/debug mask>"},
561 {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
562 "usage: debug_list <subs/types>"},
563 {"modules", jt_dbg_modules, 0,
564 "provide gdb-friendly module information\n"
565 "usage: modules <path>"},
566 {"panic", jt_dbg_panic, 0, "force the kernel to panic\n"
568 {"lwt", jt_ptl_lwt, 0,
569 "light-weight tracing\n"
572 {"memhog", jt_ptl_memhog, 0,
573 "memory pressure testing\n"
574 "usage: memhog <page count> [<gfp flags>]"},
576 /* User interface commands */
577 {"======= control ========", jt_noop, 0, "control commands"},
578 {"help", Parser_help, 0, "help"},
579 {"exit", jt_quit, 0, "quit"},
580 {"quit", jt_quit, 0, "quit"},
584 int lctl_main(int argc, char **argv)
590 ptl_initialize(argc, argv);
591 if (obd_initialize(argc, argv) < 0)
593 if (dbg_initialize(argc, argv) < 0)
596 Parser_init("lctl > ", cmdlist);
599 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
601 rc = Parser_commands();
604 obd_finalize(argc, argv);
609 int main (int argc, char **argv)
611 return (lctl_main (argc, argv));