Whamcloud - gitweb
add command null_audit in lctl
[fs/lustre-release.git] / lustre / utils / lctl.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
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>
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
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.
14  *
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.
19  *
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.
23  *
24  */
25
26
27
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <errno.h>
34 #include <portals/ptlctl.h>
35 #include "obdctl.h"
36 #include "parser.h"
37
38 static int jt_quit(int argc, char **argv) {
39         Parser_quit(argc, argv);
40         return 0;
41 }
42
43 static int jt_noop(int argc, char **argv) {
44         return 0;
45 }
46
47 static int jt_opt_ignore_errors(int argc, char **argv) {
48         Parser_ignore_errors(1);
49         return 0;
50 }
51
52 #include <linux/lustre_audit.h>
53
54 static int parse_audit_ops(char * str, __u64 * mask)
55 {
56         char * op = strtok(str, ",");
57         int rc = 0;
58         
59         while (op) {
60                 if (!strcmp(op, "all")) {
61                         *mask |= AUDIT_ALL_OPS;
62                         break;
63                 }
64                 else if (!strcmp(op,"none")) {
65                         *mask &= ~AUDIT_ALL_OPS;
66                 }
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);
78                 }
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);
91                 else {
92                         fprintf(stderr, "invalid audit operation '%s'\n", op);
93                 }       
94
95                 op = strtok(NULL, ",");
96         }
97         
98         return rc;
99 }
100
101 #include <unistd.h>
102 #include <dirent.h>
103 #include <linux/unistd.h>
104
105 static int set_dir_audit(char * dir, __u64 mask)
106 {
107         int rc = 0;
108         char * buf;
109         DIR * sdr;
110         struct dirent * ent = (void*)buf;
111         
112         buf = malloc(strlen(dir) + NAME_MAX + 1);
113         
114         sdr = opendir(dir);
115         if (!sdr) {
116                 fprintf(stderr, "cannot open dir %s\n", dir);
117                 free(buf);
118                 return -1;
119         }
120         
121         while ((ent = readdir(sdr)) != NULL) {
122                 int fd;
123                 
124                 if (!strcmp(ent->d_name, ".") ||
125                     !strcmp(ent->d_name, ".."))
126                         continue;
127                 
128                 sprintf(buf, "%s/%s", dir, ent->d_name);
129                 
130                 fd = open(buf, O_RDONLY);
131                 if (fd < 0) {
132                         fprintf(stderr, "can't open: %s: %s\n", buf,
133                                 strerror(rc = errno));
134                         continue;
135                 }
136                 rc = ioctl(fd, LL_IOC_AUDIT, mask);
137                 close(fd);
138         }
139         closedir(sdr);
140         free(buf);
141         return rc;
142 }
143
144 static int set_audit(int argc, char **argv, int fs)
145 {
146         __u64 mask = 0;
147         struct stat st;
148         int rc, fd;
149
150         if (argc != 4)
151                 return CMD_HELP;
152         
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]);
159                 return -EINVAL;
160         }
161         
162         rc = parse_audit_ops(argv[2], &mask);
163         if (rc < 0)
164                 return -EINVAL;
165         
166         //open file/dir
167         fd = open(argv[3], O_RDONLY);
168         if (fd < 0) {
169                 fprintf(stderr, "can't open: %s: %s\n", argv[3],
170                         strerror(rc = errno));
171                 return -1;
172         }
173         
174         rc = fstat(fd, &st);
175         if (rc) {
176                 close(fd);
177                 return rc;
178         }
179         //audit for fs?
180         if (fs)
181                 SET_AUDIT_OP(mask, AUDIT_FS);
182         else {
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));
186                 }
187         }
188         //set audit for file/dir itself
189         rc = ioctl(fd, LL_IOC_AUDIT, mask);
190         close(fd);
191         return rc;
192 }
193
194 static int jt_set_audit(int argc, char **argv)
195 {
196         return set_audit(argc, argv, 0);
197 }
198
199 static int jt_set_fsaudit(int argc, char **argv)
200 {
201         return set_audit(argc, argv, 1);
202 }
203
204 static int jt_flush_audit(int argc, char **argv)
205 {
206         __u64 mask = 0;
207         int rc, fd;
208
209         if (argc != 2)
210                 return CMD_HELP;
211         
212         //open file/dir
213         fd = open(argv[1], O_RDONLY);
214         if (fd < 0) {
215                 fprintf(stderr, "can't open: %s: %s\n", argv[1],
216                         strerror(rc = errno));
217                 return -1;
218         }
219         
220         SET_AUDIT_OP(mask, AUDIT_SYNC);
221
222         rc = ioctl(fd, LL_IOC_AUDIT, mask);
223         close(fd);
224         return rc;
225 }
226
227 static int jt_null_audit(int argc, char **argv)
228 {
229         __u64 mask = 0;
230         int rc, fd;
231
232         if (argc != 2)
233                 return CMD_HELP;
234         
235         //open file/dir
236         fd = open(argv[1], O_RDONLY);
237         if (fd < 0) {
238                 fprintf(stderr, "can't open: %s: %s\n", argv[1],
239                         strerror(rc = errno));
240                 return -1;
241         }
242         
243         SET_AUDIT_OP(mask, AUDIT_NULL);
244
245         rc = ioctl(fd, LL_IOC_AUDIT, mask);
246         close(fd);
247         return rc;
248 }
249
250
251 /*
252  * XXX Should not belong to here
253  */
254 static int flush_cred_ioctl(char *mp)
255 {
256         int fd, rc;
257
258         fd = open(mp, O_RDONLY);
259         if (fd == -1) {
260                 fprintf(stderr, "flush_cred_ioctl: error open %s: %s\n",
261                         mp, strerror(errno));
262                 return -1;
263         }
264
265         rc = ioctl(fd, LL_IOC_FLUSH_CRED);
266         if (rc == -1) {
267                 fprintf(stderr, "flush_cred_ioctl: error ioctl %s: %s\n",
268                         mp, strerror(errno));
269         }
270
271         close(fd);
272         return rc;
273 }
274
275 static int jt_flush_cred(int argc, char **argv)
276 {
277         FILE   *proc;
278         char    procline[PATH_MAX], *line;
279         int     i, rc = 0;
280
281         /* no args means search all lustre mountpoints */
282         if (argc < 2) {
283                 proc = fopen("/proc/mounts", "r");
284                 if (!proc) {
285                         fprintf(stderr, "%s: can't open /proc/mounts\n",
286                                 jt_cmdname(argv[0]));
287                         return -1;
288                 }
289
290                 while ((line = fgets(procline, PATH_MAX, proc)) != NULL) {
291                         char dev[PATH_MAX];
292                         char mp[PATH_MAX];
293                         char fs[PATH_MAX];
294
295                         if (sscanf(line, "%s %s %s", dev, mp, fs) != 3) {
296                                 fprintf(stderr, "%s: unexpected format in "
297                                                 "/proc/mounts\n",
298                                         jt_cmdname(argv[0]));
299                                 return -1;
300                         }
301
302                         if (strcmp(fs, "lustre") &&
303                             strcmp(fs, "lustre_lite"))
304                                 continue;
305
306                         if (flush_cred_ioctl(mp))
307                                 rc = -1;
308                 }
309         } else {
310                 /* follow the exact flush sequence as supplied */
311                 for (i = 1; i < argc; i++) {
312                         if (flush_cred_ioctl(argv[i]))
313                                 rc = -1;
314                 }
315         }
316
317         return rc;
318 }
319
320 command_t cmdlist[] = {
321         /* Metacommands */
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"
330          "--ignore_errors"},
331         {"ignore_errors", jt_opt_ignore_errors, 0,
332          "ignore errors that occur during script processing\n"
333          "ignore_errors"},
334         {"dump", jt_ioc_dump, 0, "usage: dump file, save ioctl buffer to file"},
335
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"
349          "usage: peer_list"},
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"
355          "usage: conn_list"},
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"
361          "usage: active_tx"},
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"
367          "usage: shownid"},
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]"},
393
394         /* Device selection commands */
395         {"=== device selection ===", jt_noop, 0, "device selection"},
396         {"newdev", jt_lcfg_newdev, 0, "create a new device\n"
397          "usage: newdev"},
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"
407          "usage: dl"},
408         {"lustre_build_version", jt_get_version, 0,
409          "print the build version of lustre\n"
410          "usage: lustre_build_version"},
411
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"
424          "usage: detach"},
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"
442          "usage: endrecord"},
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"},
449
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"
460          "usage: close"},
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"
493          "usage: test_ldlm"},
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,
542          "usage: lsync\n"},  
543         {"cache_on", jt_obd_cache_on, 0,
544          "usage: lsync\n"},  
545         {"cache_off", jt_obd_cache_off, 0,
546          "usage: lsync\n"},  
547 /*
548         {"obd_flush_cred", jt_obd_flush_cred, 0,
549          "usage: obd_flush_cred [all]\n"},
550 */
551         /*snap operations*/
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>"},
578         
579         /* Misc commands */
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]...."},
586         
587         /* Debug commands */
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"
605          "usage: clear"},
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"
618          "usage: panic"},
619         {"lwt", jt_ptl_lwt, 0,
620          "light-weight tracing\n"
621          "usage: lwt start\n"
622          "       lwt stop [file]"},
623         {"memhog", jt_ptl_memhog, 0,
624          "memory pressure testing\n"
625          "usage: memhog <page count> [<gfp flags>]"},
626                 
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"},
632         { 0, 0, 0, NULL }
633 };
634
635 int lctl_main(int argc, char **argv)
636 {
637         int rc;
638
639         setlinebuf(stdout);
640
641         ptl_initialize(argc, argv);
642         if (obd_initialize(argc, argv) < 0)
643                 exit(2);
644         if (dbg_initialize(argc, argv) < 0)
645                 exit(3);
646
647         Parser_init("lctl > ", cmdlist);
648
649         if (argc > 1) {
650                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
651         } else {
652                 rc = Parser_commands();
653         }
654
655         obd_finalize(argc, argv);
656         return rc;
657 }
658
659 #if !LIBLUSTRE_TEST
660 int main (int argc, char **argv)
661 {
662         return (lctl_main (argc, argv));
663 }
664 #endif