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);
204 static int jt_flush_audit(int argc, char **argv)
213 fd = open(argv[1], O_RDONLY);
215 fprintf(stderr, "can't open: %s: %s\n", argv[1],
216 strerror(rc = errno));
220 SET_AUDIT_OP(mask, AUDIT_SYNC);
222 rc = ioctl(fd, LL_IOC_AUDIT, mask);
227 static int jt_null_audit(int argc, char **argv)
236 fd = open(argv[1], O_RDONLY);
238 fprintf(stderr, "can't open: %s: %s\n", argv[1],
239 strerror(rc = errno));
243 SET_AUDIT_OP(mask, AUDIT_NULL);
245 rc = ioctl(fd, LL_IOC_AUDIT, mask);
252 * XXX Should not belong to here
254 static int flush_cred_ioctl(char *mp)
258 fd = open(mp, O_RDONLY);
260 fprintf(stderr, "flush_cred_ioctl: error open %s: %s\n",
261 mp, strerror(errno));
265 rc = ioctl(fd, LL_IOC_FLUSH_CRED);
267 fprintf(stderr, "flush_cred_ioctl: error ioctl %s: %s\n",
268 mp, strerror(errno));
275 static int jt_flush_cred(int argc, char **argv)
278 char procline[PATH_MAX], *line;
281 /* no args means search all lustre mountpoints */
283 proc = fopen("/proc/mounts", "r");
285 fprintf(stderr, "%s: can't open /proc/mounts\n",
286 jt_cmdname(argv[0]));
290 while ((line = fgets(procline, PATH_MAX, proc)) != NULL) {
295 if (sscanf(line, "%s %s %s", dev, mp, fs) != 3) {
296 fprintf(stderr, "%s: unexpected format in "
298 jt_cmdname(argv[0]));
302 if (strcmp(fs, "lustre") &&
303 strcmp(fs, "lustre_lite"))
306 if (flush_cred_ioctl(mp))
310 /* follow the exact flush sequence as supplied */
311 for (i = 1; i < argc; i++) {
312 if (flush_cred_ioctl(argv[i]))
320 command_t cmdlist[] = {
322 {"--device", jt_opt_device, 0,
323 "run <command> after connecting to device <devno>\n"
324 "--device <devno> <command [args ...]>"},
325 {"--threads", jt_opt_threads, 0,
326 "run <threads> separate instances of <command> on device <devno>\n"
327 "--threads <threads> <verbose> <devno> <command [args ...]>"},
328 {"--ignore_errors", jt_opt_ignore_errors, 0,
329 "ignore errors that occur during script processing\n"
331 {"ignore_errors", jt_opt_ignore_errors, 0,
332 "ignore errors that occur during script processing\n"
334 {"dump", jt_ioc_dump, 0, "usage: dump file, save ioctl buffer to file"},
336 /* Network configuration commands */
337 {"==== network config ====", jt_noop, 0, "network config"},
338 {"--net", jt_opt_net, 0, "run <command> after setting network to <net>\n"
339 "usage: --net <tcp/elan/myrinet> <command>"},
340 {"network", jt_ptl_network, 0, "commands that follow apply to net\n"
341 "usage: network <tcp/elan/myrinet>"},
342 {"interface_list", jt_ptl_print_interfaces, 0, "print interface entries\n"
343 "usage: interface_list"},
344 {"add_interface", jt_ptl_add_interface, 0, "add interface entry\n"
345 "usage: add_interface ip [netmask]"},
346 {"del_interface", jt_ptl_del_interface, 0, "del interface entry\n"
347 "usage: del_interface [ip]"},
348 {"peer_list", jt_ptl_print_peers, 0, "print peer entries\n"
350 {"add_peer", jt_ptl_add_peer, 0, "add an peer entry\n"
351 "usage: add_peer <nid> <host> <port>"},
352 {"del_peer", jt_ptl_del_peer, 0, "remove an peer entry\n"
353 "usage: del_peer [<nid>] [<host>] [ks]"},
354 {"conn_list", jt_ptl_print_connections, 0, "print all the connected remote nid\n"
356 {"connect", jt_ptl_connect, 0, "connect to a remote nid\n"
357 "usage: connect <host> <port> [iIOC]"},
358 {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
359 "usage: disconnect [<nid>]"},
360 {"active_tx", jt_ptl_print_active_txs, 0, "print active transmits\n"
362 {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
363 "The nid defaults to hostname for tcp networks and is automatically "
364 "setup for elan/myrinet networks.\n"
365 "usage: mynid [<nid>]"},
366 {"shownid", jt_ptl_shownid, 0, "print the local NID\n"
368 {"add_uuid", jt_lcfg_add_uuid, 0, "associate a UUID with a nid\n"
369 "usage: add_uuid <uuid> <nid> <net_type>"},
370 {"close_uuid", jt_obd_close_uuid, 0, "disconnect a UUID\n"
371 "usage: close_uuid <uuid> <net_type>"},
372 {"del_uuid", jt_lcfg_del_uuid, 0, "delete a UUID association\n"
373 "usage: del_uuid <uuid>"},
374 {"add_route", jt_ptl_add_route, 0,
375 "add an entry to the portals routing table\n"
376 "usage: add_route <gateway> <target> [<target>]"},
377 {"del_route", jt_ptl_del_route, 0,
378 "delete route via gateway to targets from the portals routing table\n"
379 "usage: del_route <gateway> [<target>] [<target>]"},
380 {"set_route", jt_ptl_notify_router, 0,
381 "enable/disable routes via gateway in the portals routing table\n"
382 "usage: set_route <gateway> <up/down> [<time>]"},
383 {"route_list", jt_ptl_print_routes, 0,
384 "print the portals routing table, same as show_route\n"
385 "usage: route_list"},
386 {"show_route", jt_ptl_print_routes, 0,
387 "print the portals routing table, same as route_list\n"
388 "usage: show_route"},
389 {"fail", jt_ptl_fail_nid, 0, "fail/restore communications.\n"
390 "Omitting the count means indefinitely, 0 means restore, "
391 "otherwise fail 'count' messages.\n"
392 "usage: fail nid|_all_ [count]"},
394 /* Device selection commands */
395 {"=== device selection ===", jt_noop, 0, "device selection"},
396 {"newdev", jt_lcfg_newdev, 0, "create a new device\n"
398 {"device", jt_obd_device, 0,
399 "set current device to <%name|$name|devno>\n"
400 "usage: device <%name|$name|devno>"},
401 {"cfg_device", jt_lcfg_device, 0,
402 "set current device being configured to <$name>\n"
403 "usage: cfg_device <name>"},
404 {"device_list", jt_obd_list, 0, "show all devices\n"
405 "usage: device_list"},
406 {"dl", jt_obd_list, 0, "show all devices\n"
408 {"lustre_build_version", jt_get_version, 0,
409 "print the build version of lustre\n"
410 "usage: lustre_build_version"},
412 /* Device configuration commands */
413 {"==== device config =====", jt_noop, 0, "device config"},
414 {"attach", jt_lcfg_attach, 0,
415 "set the type of the current device (with <name> and <uuid>)\n"
416 "usage: attach type [name [uuid]]"},
417 {"setup", jt_lcfg_setup, 0,
418 "type specific device configuration information\n"
419 "usage: setup <args...>"},
420 {"cleanup", jt_obd_cleanup, 0, "cleanup previously setup device\n"
421 "usage: cleanup [force | failover]"},
422 {"detach", jt_obd_detach, 0,
423 "remove driver (and name and uuid) from current device\n"
425 {"lov_setup", jt_lcfg_lov_setup, 0, "create a LOV device\n"
426 "usage: lov_setup lov-uuid stripe-count stripe-size offset pattern"},
427 {"lmv_setup", jt_lcfg_lmv_setup, 0,
428 "create an LMV device\n"
429 "usage: lmv_setup lmv-uuid UUID1 [UUID2 ...]"},
430 {"lov_modify_tgts", jt_lcfg_lov_modify_tgts, 0,
431 "add or delete an obd to/from a LOV device\n"
432 "usage: lov_modify_tgts add|del <lov-name> <uuid> <index> <gen>"},
433 {"lov_getconfig", jt_obd_lov_getconfig, 0,
434 "read lov configuration from an mds device\n"
435 "usage: lov_getconfig lov-uuid"},
436 {"lmv_modify_tgts", jt_lcfg_lmv_modify_tgts, 0,
437 "add an mdc to a LMV device\n"
438 "usage: lmv_modify_tgts add <lmv_name> <mdc_uuid>"},
439 {"record", jt_cfg_record, 0, "record commands that follow in log\n"
440 "usage: record cfg-uuid-name"},
441 {"endrecord", jt_cfg_endrecord, 0, "stop recording\n"
443 {"parse", jt_cfg_parse, 0, "parse the log of recorded commands for this config\n"
444 "usage: parse config-uuid-name"},
445 {"dump_log", jt_cfg_dump_log, 0, "print log of recorded commands for this config to kernel debug log\n"
446 "usage: dump_log config-uuid-name"},
447 {"clear_log", jt_cfg_clear_log, 0, "delete current config log of recorded commands\n"
448 "usage: clear_log config-name"},
450 /* Device operations */
451 {"=== device operations ==", jt_noop, 0, "device operations"},
452 {"probe", jt_obd_connect, 0,
453 "build a connection handle to a device. This command is used to "
454 "suspend configuration until lctl has ensured that the mds and osc "
455 "services are available. This is to avoid mount failures in a "
456 "rebooting cluster.\n"
457 "usage: probe [timeout]"},
458 {"close", jt_obd_disconnect, 0,
459 "close the connection handle\n"
461 {"getattr", jt_obd_getattr, 0,
462 "get attribute for OST object <objid>\n"
463 "usage: getattr <objid>"},
464 {"setattr", jt_obd_setattr, 0,
465 "set mode attribute for OST object <objid>\n"
466 "usage: setattr <objid> <mode>"},
467 {"create", jt_obd_create, 0,
468 "create <num> OST objects (with <mode>)\n"
469 "usage: create [num [mode [verbose [lsm data]]]]"},
470 {"destroy", jt_obd_destroy, 0,
471 "destroy OST object <objid> [num [verbose]]\n"
472 "usage: destroy <num> objects, starting at objid <objid>"},
473 {"test_getattr", jt_obd_test_getattr, 0,
474 "do <num> getattrs (on OST object <objid> (objid+1 on each thread))\n"
475 "usage: test_getattr <num> [verbose [[t]objid]]"},
476 {"test_setattr", jt_obd_test_setattr, 0,
477 "do <num> setattrs (on OST object <objid> (objid+1 on each thread))\n"
478 "usage: test_setattr <num> [verbose [[t]objid]]"},
479 {"test_brw", jt_obd_test_brw, 0,
480 "do <num> bulk read/writes (<npages> per I/O, on OST object <objid>)\n"
481 "usage: test_brw [t]<num> [write [verbose [npages [[t]objid]]]]"},
482 {"get_stripe", jt_obd_get_stripe, 0,
483 "show stripe info for an echo client object\n"
484 "usage: get_stripe objid\n"},
485 {"set_stripe", jt_obd_set_stripe, 0,
486 "set stripe info for an echo client object\n"
487 "usage: set_stripe objid[=width!count[@offset][:id:id...]\n"},
488 {"unset_stripe", jt_obd_unset_stripe, 0,
489 "unset stripe info for an echo client object\n"
490 "usage: unset_stripe objid\n"},
491 {"test_ldlm", jt_obd_test_ldlm, 0,
492 "perform lock manager test\n"
494 {"ldlm_regress_start", jt_obd_ldlm_regress_start, 0,
495 "start lock manager stress test\n"
496 "usage: ldlm_regress_start [numthreads [refheld [numres [numext]]]]"},
497 {"ldlm_regress_stop", jt_obd_ldlm_regress_stop, 0,
498 "stop lock manager stress test (no args)\n"},
499 {"dump_ldlm", jt_obd_dump_ldlm, 0,
500 "dump all lock manager state (no args)"},
501 {"disable_recovery", jt_obd_disable_recovery, 0, "disable recovery on an import\n"},
502 {"enable_recovery", jt_obd_enable_recovery, 0, "enable recovery on an import\n"},
503 {"activate", jt_obd_activate, 0, "activate an import\n"},
504 {"deactivate", jt_obd_deactivate, 0, "deactivate an import\n"},
505 {"recover", jt_obd_recover, 0, "usage: recover [<connection UUID>]"},
506 {"lookup", jt_obd_mdc_lookup, 0, "usage: lookup <directory> <file>"},
507 {"notransno", jt_obd_no_transno, 0,
508 "disable sending of committed-transno updates\n"},
509 {"readonly", jt_obd_set_readonly, 0,
510 "disable writes to the underlying device\n"},
511 {"abort_recovery", jt_obd_abort_recovery, 0,
512 "abort recovery on MDS device\n"},
513 {"root_squash", jt_obd_root_squash, 0,
514 "squash root to 'uid:gid' except client 'nid'\n"
515 "usage: root_squash [uid:gid [nid]]\n"},
516 {"start", jt_obd_start, 0,
517 "setup mds/ost from the llog file\n"
518 "usage: start <profilename>"},
519 {"mount_option", jt_lcfg_mount_option, 0,
520 "usage: mount_option profile osc_name [mdc_name] [gsc_name] \n"},
521 {"del_mount_option", jt_lcfg_del_mount_option, 0,
522 "usage: del_mount_option profile\n"},
523 {"set_timeout", jt_lcfg_set_timeout, 0,
524 "usage: set_timeout <secs>\n"},
525 {"set_lustre_upcall", jt_lcfg_set_lustre_upcall, 0,
526 "usage: set_lustre_upcall </full/path/to/upcall> \n"},
527 {"add_conn ", jt_lcfg_add_conn, 0,
528 "usage: add_conn <conn_uuid> [priority]\n"},
529 {"del_conn ", jt_lcfg_del_conn, 0,
530 "usage: del_conn <conn_uuid> \n"},
531 {"set_security", jt_lcfg_set_security, 0,
532 "usage: set_security key value\n"},
533 {"audit", jt_set_audit, 0,
534 "usage: audit type operations filename\n"},
535 {"fs_audit", jt_set_fsaudit, 0,
536 "usage: fs_audit type operations mountpoint\n"},
537 {"flush_audit", jt_flush_audit, 0,
538 "usage: flush_audit mountpoin\n"},
539 {"null_audit", jt_null_audit, 0,
540 "usage: null_audit mountpoin\n"},
541 {"lsync", jt_obd_reint_sync, 0,
543 {"cache_on", jt_obd_cache_on, 0,
545 {"cache_off", jt_obd_cache_off, 0,
548 {"obd_flush_cred", jt_obd_flush_cred, 0,
549 "usage: obd_flush_cred [all]\n"},
552 {"snap_add", jt_obd_snap_add, 0,
553 "usage: snap_add <dev_name> <snap_name>\n"},
554 /* Llog operations */
555 {"llog_catlist", jt_llog_catlist, 0,
556 "list all catalog logs on current device.\n"
557 "usage: llog_catlist"},
558 {"llog_info", jt_llog_info, 0,
559 "print log header information.\n"
560 "usage: llog_info <$logname|#oid#ogr#ogen>\n"
561 " oid, ogr and ogen are hexadecimal."},
562 {"llog_print", jt_llog_print, 0,
563 "print log content information.\n"
564 "usage: llog_print <$logname|#oid#ogr#ogen> [from] [to]\n"
565 " oid, ogr and ogen are hexadecimal.\n"
566 " print all records from index 1 by default."},
567 {"llog_check", jt_llog_check, 0,
568 "print log content information.\n"
569 "usage: llog_check <$logname|#oid#ogr#ogen> [from] [to]\n"
570 " oid, ogr and ogen are hexadecimal.\n"
571 " check all records from index 1 by default."},
572 {"llog_cancel", jt_llog_cancel, 0,
573 "cancel one record in log.\n"
574 "usage: llog_cancel <catalog id|catalog name> <log id> <index>"},
575 {"llog_remove", jt_llog_remove, 0,
576 "remove one log from catalog, erase it from disk.\n"
577 "usage: llog_remove <catalog id|catalog name> <log id>"},
580 {"flush_cred", jt_flush_cred, 0,
581 "flush the client side credential.\n"
582 "usage: flush_cred [mountpoint]..."},
583 {"set_crypt", jt_set_lkey_type, 0,
584 "set lustre key management type, only support gks and mks\n"
585 "usage: set_crypt [dir] [gks|mks]...."},
588 {"======== debug =========", jt_noop, 0, "debug"},
589 {"debug_daemon", jt_dbg_debug_daemon, 0,
590 "debug daemon control and dump to a file\n"
591 "usage: debug_daemon {start file [#MB]|stop}"},
592 {"debug_kernel", jt_dbg_debug_kernel, 0,
593 "get debug buffer and dump to a file, same as dk\n"
594 "usage: debug_kernel [file] [raw]"},
595 {"dk", jt_dbg_debug_kernel, 0,
596 "get debug buffer and dump to a file, same as debug_kernel\n"
597 "usage: dk [file] [raw]"},
598 {"debug_file", jt_dbg_debug_file, 0,
599 "read debug buffer from input and dump to output, same as df\n"
600 "usage: debug_file <input> [output] [raw]"},
601 {"df", jt_dbg_debug_file, 0,
602 "read debug buffer from input and dump to output, same as debug_file\n"
603 "usage: df <input> [output] [raw]"},
604 {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
606 {"mark", jt_dbg_mark_debug_buf, 0,"insert marker text in kernel debug buffer\n"
607 "usage: mark <text>"},
608 {"filter", jt_dbg_filter, 0, "filter message type\n"
609 "usage: filter <subsystem id/debug mask>"},
610 {"show", jt_dbg_show, 0, "Show specific type of messages\n"
611 "usage: show <subsystem id/debug mask>"},
612 {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
613 "usage: debug_list <subs/types>"},
614 {"modules", jt_dbg_modules, 0,
615 "provide gdb-friendly module information\n"
616 "usage: modules <path>"},
617 {"panic", jt_dbg_panic, 0, "force the kernel to panic\n"
619 {"lwt", jt_ptl_lwt, 0,
620 "light-weight tracing\n"
623 {"memhog", jt_ptl_memhog, 0,
624 "memory pressure testing\n"
625 "usage: memhog <page count> [<gfp flags>]"},
627 /* User interface commands */
628 {"======= control ========", jt_noop, 0, "control commands"},
629 {"help", Parser_help, 0, "help"},
630 {"exit", jt_quit, 0, "quit"},
631 {"quit", jt_quit, 0, "quit"},
635 int lctl_main(int argc, char **argv)
641 ptl_initialize(argc, argv);
642 if (obd_initialize(argc, argv) < 0)
644 if (dbg_initialize(argc, argv) < 0)
647 Parser_init("lctl > ", cmdlist);
650 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
652 rc = Parser_commands();
655 obd_finalize(argc, argv);
660 int main (int argc, char **argv)
662 return (lctl_main (argc, argv));