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