Whamcloud - gitweb
- landing of b_hd_cleanup_merge to HEAD.
[fs/lustre-release.git] / lnet / utils / debug.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Portals, http://www.sf.net/projects/lustre/
7  *
8  *   Portals is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Portals is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Portals; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Some day I'll split all of this functionality into a cfs_debug module
22  * of its own.  That day is not today.
23  *
24  */
25
26 #define __USE_FILE_OFFSET64
27 #define  _GNU_SOURCE
28
29 #include <portals/list.h>
30
31 #include <stdio.h>
32 #include <netdb.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <fcntl.h>
36 #include <errno.h>
37 #include <unistd.h>
38 #ifndef __CYGWIN__
39 # include <syscall.h>
40 #endif
41
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <sys/ioctl.h>
45 #include <sys/stat.h>
46 #include <sys/mman.h>
47
48 #include <linux/version.h>
49
50 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
51 #define BUG()                            /* workaround for module.h includes */
52 #include <linux/module.h>
53 #endif
54 #include <sys/utsname.h>
55
56 #include <portals/api-support.h>
57 #include <portals/ptlctl.h>
58 #include "parser.h"
59
60 #include <time.h>
61
62 static char rawbuf[8192];
63 static char *buf = rawbuf;
64 static int max = 8192;
65 //static int g_pfd = -1;
66 static int subsystem_mask = ~0;
67 static int debug_mask = ~0;
68
69 #define MAX_MARK_SIZE 100
70
71 static const char *portal_debug_subsystems[] =
72         {"undefined", "mdc", "mds", "osc", "ost", "class", "log", "llite",
73          "rpc", "mgmt", "portals", "libcfs", "socknal", "qswnal", "pinger",
74          "filter", "ptlbd", "echo", "ldlm", "lov", "gmnal", "router", "cobd",
75          "openibnal", "lmv", "smfs", "cmobd", NULL};
76 static const char *portal_debug_masks[] =
77         {"trace", "inode", "super", "ext2", "malloc", "cache", "info", "ioctl",
78          "blocks", "net", "warning", "buffs", "other", "dentry", "portals",
79          "page", "dlmtrace", "error", "emerg", "ha", "rpctrace", "vfstrace",
80          "reada", "mmap", NULL};
81
82 struct debug_daemon_cmd {
83         char *cmd;
84         unsigned int cmdv;
85 };
86
87 static const struct debug_daemon_cmd portal_debug_daemon_cmd[] = {
88         {"start", DEBUG_DAEMON_START},
89         {"stop", DEBUG_DAEMON_STOP},
90         {0, 0}
91 };
92
93 static int do_debug_mask(char *name, int enable)
94 {
95         int found = 0, i;
96
97         for (i = 0; portal_debug_subsystems[i] != NULL; i++) {
98                 if (strcasecmp(name, portal_debug_subsystems[i]) == 0 ||
99                     strcasecmp(name, "all_subs") == 0) {
100                         printf("%s output from subsystem \"%s\"\n",
101                                 enable ? "Enabling" : "Disabling",
102                                 portal_debug_subsystems[i]);
103                         if (enable)
104                                 subsystem_mask |= (1 << i);
105                         else
106                                 subsystem_mask &= ~(1 << i);
107                         found = 1;
108                 }
109         }
110         for (i = 0; portal_debug_masks[i] != NULL; i++) {
111                 if (strcasecmp(name, portal_debug_masks[i]) == 0 ||
112                     strcasecmp(name, "all_types") == 0) {
113                         printf("%s output of type \"%s\"\n",
114                                 enable ? "Enabling" : "Disabling",
115                                 portal_debug_masks[i]);
116                         if (enable)
117                                 debug_mask |= (1 << i);
118                         else
119                                 debug_mask &= ~(1 << i);
120                         found = 1;
121                 }
122         }
123
124         return found;
125 }
126
127 int dbg_initialize(int argc, char **argv)
128 {
129         return 0;
130 }
131
132 int jt_dbg_filter(int argc, char **argv)
133 {
134         int   i;
135
136         if (argc < 2) {
137                 fprintf(stderr, "usage: %s <subsystem ID or debug mask>\n",
138                         argv[0]);
139                 return 0;
140         }
141
142         for (i = 1; i < argc; i++)
143                 if (!do_debug_mask(argv[i], 0))
144                         fprintf(stderr, "Unknown subsystem or debug type: %s\n",
145                                 argv[i]);
146         return 0;
147 }
148
149 int jt_dbg_show(int argc, char **argv)
150 {
151         int    i;
152
153         if (argc < 2) {
154                 fprintf(stderr, "usage: %s <subsystem ID or debug mask>\n",
155                         argv[0]);
156                 return 0;
157         }
158
159         for (i = 1; i < argc; i++)
160                 if (!do_debug_mask(argv[i], 1))
161                         fprintf(stderr, "Unknown subsystem or debug type: %s\n",
162                                 argv[i]);
163
164         return 0;
165 }
166
167 static int applymask(char* procpath, int value)
168 {
169         int rc;
170         char buf[64];
171         int len = snprintf(buf, 64, "%d", value);
172
173         int fd = open(procpath, O_WRONLY);
174         if (fd == -1) {
175                 fprintf(stderr, "Unable to open %s: %s\n",
176                         procpath, strerror(errno));
177                 return fd;
178         }
179         rc = write(fd, buf, len+1);
180         if (rc<0) {
181                 fprintf(stderr, "Write to %s failed: %s\n",
182                         procpath, strerror(errno));
183                 return rc;
184         }
185         close(fd);
186         return 0;
187 }
188
189 static void applymask_all(unsigned int subs_mask, unsigned int debug_mask)
190 {
191         if (!dump_filename) {
192                 applymask("/proc/sys/portals/subsystem_debug", subs_mask);
193                 applymask("/proc/sys/portals/debug", debug_mask);
194         } else {
195                 struct portals_debug_ioctl_data data;
196
197                 data.hdr.ioc_len = sizeof(data);
198                 data.hdr.ioc_version = 0;
199                 data.subs = subs_mask;
200                 data.debug = debug_mask;
201
202                 dump(OBD_DEV_ID, PTL_IOC_DEBUG_MASK, &data);
203         }
204         printf("Applied subsystem_debug=%d, debug=%d to /proc/sys/portals\n",
205                subs_mask, debug_mask);
206 }
207
208 int jt_dbg_list(int argc, char **argv)
209 {
210         int i;
211
212         if (argc != 2) {
213                 fprintf(stderr, "usage: %s <subs || types>\n", argv[0]);
214                 return 0;
215         }
216
217         if (strcasecmp(argv[1], "subs") == 0) {
218                 printf("Subsystems: all_subs");
219                 for (i = 0; portal_debug_subsystems[i] != NULL; i++)
220                         printf(", %s", portal_debug_subsystems[i]);
221                 printf("\n");
222         } else if (strcasecmp(argv[1], "types") == 0) {
223                 printf("Types: all_types");
224                 for (i = 0; portal_debug_masks[i] != NULL; i++)
225                         printf(", %s", portal_debug_masks[i]);
226                 printf("\n");
227         } else if (strcasecmp(argv[1], "applymasks") == 0) {
228                 applymask_all(subsystem_mask, debug_mask);
229         }
230         return 0;
231 }
232
233 /* all strings nul-terminated; only the struct and hdr need to be freed */
234 struct dbg_line {
235         struct ptldebug_header *hdr;
236         char *file;
237         char *fn;
238         char *text;
239         struct list_head chain;
240 };
241
242 /* nurr. */
243 static void list_add_ordered(struct dbg_line *new, struct list_head *head)
244 {
245         struct list_head *pos;
246         struct dbg_line *curr;
247
248         list_for_each(pos, head) {
249                 curr = list_entry(pos, struct dbg_line, chain);
250
251                 if (curr->hdr->ph_sec < new->hdr->ph_sec)
252                         continue;
253                 if (curr->hdr->ph_sec == new->hdr->ph_sec &&
254                     curr->hdr->ph_usec < new->hdr->ph_usec)
255                         continue;
256
257                 list_add(&new->chain, pos->prev);
258                 return;
259         }
260         list_add_tail(&new->chain, head);
261 }
262
263 static void print_saved_records(struct list_head *list, FILE *out)
264 {
265         struct list_head *pos, *tmp;
266
267         list_for_each_safe(pos, tmp, list) {
268                 struct dbg_line *line;
269                 struct ptldebug_header *hdr;
270
271                 line = list_entry(pos, struct dbg_line, chain);
272                 list_del(&line->chain);
273
274                 hdr = line->hdr;
275                 fprintf(out, "%06x:%06x:%u:%u.%06Lu:%u:%u:%u:(%s:%u:%s()) %s",
276                         hdr->ph_subsys, hdr->ph_mask, hdr->ph_cpu_id,
277                         hdr->ph_sec, (unsigned long long)hdr->ph_usec,
278                         hdr->ph_stack, hdr->ph_pid, hdr->ph_extern_pid,
279                         line->file, hdr->ph_line_num, line->fn, line->text);
280                 free(line->hdr);
281                 free(line);
282         }
283 }
284
285 static int parse_buffer(FILE *in, FILE *out)
286 {
287         struct dbg_line *line;
288         struct ptldebug_header *hdr;
289         char buf[4097], *p;
290         int rc;
291         unsigned long dropped = 0, kept = 0;
292         struct list_head chunk_list;
293
294         INIT_LIST_HEAD(&chunk_list);
295
296         while (1) {
297                 rc = fread(buf, sizeof(hdr->ph_len), 1, in);
298                 if (rc <= 0)
299                         break;
300
301                 hdr = (void *)buf;
302                 if (hdr->ph_len == 0)
303                         break;
304                 if (hdr->ph_len > 4094) {
305                         fprintf(stderr, "unexpected large record: %d bytes.  "
306                                 "aborting.\n",
307                                 hdr->ph_len);
308                         break;
309                 }
310
311                 if (hdr->ph_flags & PH_FLAG_FIRST_RECORD) {
312                         print_saved_records(&chunk_list, out);
313                         assert(list_empty(&chunk_list));
314                 }
315
316                 rc = fread(buf + sizeof(hdr->ph_len), 1,
317                            hdr->ph_len - sizeof(hdr->ph_len), in);
318                 if (rc <= 0)
319                         break;
320
321                 if (hdr->ph_mask &&
322                     (!(subsystem_mask & hdr->ph_subsys) ||
323                      (!(debug_mask & hdr->ph_mask)))) {
324                         dropped++;
325                         continue;
326                 }
327
328                 line = malloc(sizeof(*line));
329                 if (line == NULL) {
330                         fprintf(stderr, "malloc failed; printing accumulated "
331                                 "records and exiting.\n");
332                         break;
333                 }
334
335                 line->hdr = malloc(hdr->ph_len + 1);
336                 if (line->hdr == NULL) {
337                         fprintf(stderr, "malloc failed; printing accumulated "
338                                 "records and exiting.\n");
339                         break;
340                 }
341
342                 p = (void *)line->hdr;
343                 memcpy(line->hdr, buf, hdr->ph_len);
344                 p[hdr->ph_len] = '\0';
345
346                 p += sizeof(*hdr);
347                 line->file = p;
348                 p += strlen(line->file) + 1;
349                 line->fn = p;
350                 p += strlen(line->fn) + 1;
351                 line->text = p;
352
353                 list_add_ordered(line, &chunk_list);
354                 kept++;
355         }
356
357         print_saved_records(&chunk_list, out);
358
359         printf("Debug log: %lu lines, %lu kept, %lu dropped.\n",
360                 dropped + kept, kept, dropped);
361         return 0;
362 }
363
364 int jt_dbg_debug_kernel(int argc, char **argv)
365 {
366         char filename[4096];
367         int rc, raw = 0, fd;
368         FILE *in, *out = stdout;
369
370         if (argc > 3) {
371                 fprintf(stderr, "usage: %s [file] [raw]\n", argv[0]);
372                 return 0;
373         }
374         sprintf(filename, "%s.%lu.%u", argc > 1 ? argv[1] : "/tmp/lustre-log",
375                 time(NULL), getpid());
376
377         if (argc > 2)
378                 raw = atoi(argv[2]);
379         unlink(filename);
380
381         fd = open("/proc/sys/portals/dump_kernel", O_WRONLY);
382         if (fd < 0) {
383                 fprintf(stderr, "open(dump_kernel) failed: %s\n",
384                         strerror(errno));
385                 return 1;
386         }
387
388         rc = write(fd, filename, strlen(filename));
389         if (rc != strlen(filename)) {
390                 fprintf(stderr, "write(%s) failed: %s\n", filename,
391                         strerror(errno));
392                 close(fd);
393                 return 1;
394         }
395         close(fd);
396
397         if (raw)
398                 return 0;
399
400         in = fopen(filename, "r");
401         if (in == NULL) {
402                 fprintf(stderr, "fopen(%s) failed: %s\n", filename,
403                         strerror(errno));
404                 return 1;
405         }
406         if (argc > 1) {
407                 out = fopen(argv[1], "w");
408                 if (out == NULL) {
409                         fprintf(stderr, "fopen(%s) failed: %s\n", argv[1],
410                                 strerror(errno));
411                         fclose(in);
412                         return 1;
413                 }
414         }
415
416         rc = parse_buffer(in, out);
417         fclose(in);
418         if (argc > 1)
419                 fclose(out);
420         if (rc) {
421                 fprintf(stderr, "parse_buffer failed; leaving tmp file %s "
422                         "behind.\n", filename);
423         } else {
424                 rc = unlink(filename);
425                 if (rc)
426                         fprintf(stderr, "dumped successfully, but couldn't "
427                                 "unlink tmp file %s: %s\n", filename,
428                                 strerror(errno));
429         }
430         return rc;
431 }
432
433 int jt_dbg_debug_file(int argc, char **argv)
434 {
435         int fdin,fdout;
436         FILE *in, *out = stdout;
437         if (argc > 3 || argc < 2) {
438                 fprintf(stderr, "usage: %s <input> [output]\n", argv[0]);
439                 return 0;
440         }
441
442         fdin = open(argv[1], O_RDONLY | O_LARGEFILE);
443         if (fdin == -1) {
444                 fprintf(stderr, "open(%s) failed: %s\n", argv[1],
445                         strerror(errno));
446                 return 1;
447         }
448         in = fdopen(fdin, "r");
449         if (in == NULL) {
450                 fprintf(stderr, "fopen(%s) failed: %s\n", argv[1],
451                         strerror(errno));
452                 close(fdin);
453                 return 1;
454         }
455         if (argc > 2) {
456                 fdout = open(argv[2], O_CREAT | O_WRONLY | O_LARGEFILE);
457                 if (fdout == -1) {
458                         fprintf(stderr, "open(%s) failed: %s\n", argv[2],
459                                 strerror(errno));
460                         fclose(in);
461                         return 1;
462                 }
463                 out = fdopen(fdout, "w");
464                 if (out == NULL) {
465                         fprintf(stderr, "fopen(%s) failed: %s\n", argv[2],
466                                 strerror(errno));
467                         fclose(in);
468                         close(fdout);
469                         return 1;
470                 }
471         }
472
473         return parse_buffer(in, out);
474 }
475
476 const char debug_daemon_usage[]="usage: debug_daemon {start file [MB]|stop}\n";
477 int jt_dbg_debug_daemon(int argc, char **argv)
478 {
479         int rc, fd;
480                                                                                                                                                                                                      
481         if (argc <= 1) {
482                 fprintf(stderr, debug_daemon_usage);
483                 return 0;
484         }
485                                                                                                                                                                                                      
486         fd = open("/proc/sys/portals/daemon_file", O_WRONLY);
487         if (fd < 0) {
488                 fprintf(stderr, "open(daemon_file) failed: %s\n",
489                         strerror(errno));
490                 return 1;
491         }
492                                                                                                                                                                                                      
493         if (strcasecmp(argv[1], "start") == 0) {
494                 if (argc != 3) {
495                         fprintf(stderr, debug_daemon_usage);
496                         return 1;
497                 }
498                                                                                                                                                                                                      
499                 rc = write(fd, argv[2], strlen(argv[2]));
500                 if (rc != strlen(argv[2])) {
501                         fprintf(stderr, "write(%s) failed: %s\n", argv[2],
502                                 strerror(errno));
503                         close(fd);
504                         return 1;
505                 }
506         } else if (strcasecmp(argv[1], "stop") == 0) {
507                 rc = write(fd, "stop", 4);
508                 if (rc != 4) {
509                         fprintf(stderr, "write(stop) failed: %s\n",
510                                 strerror(errno));
511                         close(fd);
512                         return 1;
513                 }
514         } else {
515                 fprintf(stderr, debug_daemon_usage);
516                 return 1;
517         }
518                                                                                                                                                                                                      
519         close(fd);
520         return 0;
521 }
522
523 int jt_dbg_clear_debug_buf(int argc, char **argv)
524 {
525         int rc;
526         struct portal_ioctl_data data;
527
528         if (argc != 1) {
529                 fprintf(stderr, "usage: %s\n", argv[0]);
530                 return 0;
531         }
532
533         memset(&data, 0, sizeof(data));
534         if (portal_ioctl_pack(&data, &buf, max) != 0) {
535                 fprintf(stderr, "portal_ioctl_pack failed.\n");
536                 return -1;
537         }
538
539         rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_CLEAR_DEBUG, buf);
540         if (rc) {
541                 fprintf(stderr, "IOC_PORTAL_CLEAR_DEBUG failed: %s\n",
542                         strerror(errno));
543                 return -1;
544         }
545         return 0;
546 }
547
548 int jt_dbg_mark_debug_buf(int argc, char **argv)
549 {
550         int rc, max_size = MAX_MARK_SIZE-1;
551         struct portal_ioctl_data data;
552         char *text;
553         time_t now = time(NULL);
554
555         if (argc > 1) {
556                 int counter;
557                 text = malloc(MAX_MARK_SIZE);
558                 strncpy(text, argv[1], max_size);
559                 max_size-=strlen(argv[1]);
560                 for(counter = 2; (counter < argc) && (max_size > 0) ; counter++){
561                         strncat(text, " ", 1);
562                         max_size-=1;
563                         strncat(text, argv[counter], max_size);
564                         max_size-=strlen(argv[counter]);
565                 }
566         } else {
567                 text = ctime(&now);
568                 text[strlen(text) - 1] = '\0'; /* stupid \n */
569         }
570         if (!max_size) {
571                 text[MAX_MARK_SIZE - 1] = '\0';
572         }
573
574         memset(&data, 0, sizeof(data));
575         data.ioc_inllen1 = strlen(text) + 1;
576         data.ioc_inlbuf1 = text;
577         if (portal_ioctl_pack(&data, &buf, max) != 0) {
578                 fprintf(stderr, "portal_ioctl_pack failed.\n");
579                 return -1;
580         }
581
582         rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_MARK_DEBUG, buf);
583         if (rc) {
584                 fprintf(stderr, "IOC_PORTAL_MARK_DEBUG failed: %s\n",
585                         strerror(errno));
586                 return -1;
587         }
588         return 0;
589 }
590
591 static struct mod_paths {
592         char *name, *path;
593 } mod_paths[] = {
594         {"libcfs", "lustre/portals/libcfs"},
595         {"portals", "lustre/portals/portals"},
596         {"ksocknal", "lustre/portals/knals/socknal"},
597         {"kptlrouter", "lustre/portals/router"},
598         {"lvfs", "lustre/lvfs"},
599         {"obdclass", "lustre/obdclass"},
600         {"llog_test", "lustre/obdclass"},
601         {"ptlrpc", "lustre/ptlrpc"},
602         {"obdext2", "lustre/obdext2"},
603         {"ost", "lustre/ost"},
604         {"osc", "lustre/osc"},
605         {"mds", "lustre/mds"},
606         {"mdc", "lustre/mdc"},
607         {"llite", "lustre/llite"},
608         {"smfs", "lustre/smfs"},
609         {"obdecho", "lustre/obdecho"},
610         {"ldlm", "lustre/ldlm"},
611         {"obdfilter", "lustre/obdfilter"},
612         {"extN", "lustre/extN"},
613         {"lov", "lustre/lov"},
614         {"lmv", "lustre/lmv"},
615         {"fsfilt_ext3", "lustre/lvfs"},
616         {"fsfilt_extN", "lustre/lvfs"},
617         {"fsfilt_reiserfs", "lustre/lvfs"},
618         {"fsfilt_smfs", "lustre/lvfs"},
619         {"fsfilt_ldiskfs", "lustre/lvfs"},
620         {"mds_ext2", "lustre/mds"},
621         {"mds_ext3", "lustre/mds"},
622         {"mds_extN", "lustre/mds"},
623         {"ptlbd", "lustre/ptlbd"},
624         {"mgmt_svc", "lustre/mgmt"},
625         {"mgmt_cli", "lustre/mgmt"},
626         {"cobd", "lustre/cobd"},
627         {"cmobd", "lustre/cmobd"},
628         {NULL, NULL}
629 };
630
631 static int jt_dbg_modules_2_4(int argc, char **argv)
632 {
633 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
634         struct mod_paths *mp;
635         char *path = "..";
636         char *kernel = "linux";
637
638         if (argc >= 2)
639                 path = argv[1];
640         if (argc == 3)
641                 kernel = argv[2];
642         if (argc > 3) {
643                 printf("%s [path] [kernel]\n", argv[0]);
644                 return 0;
645         }
646
647         for (mp = mod_paths; mp->name != NULL; mp++) {
648                 struct module_info info;
649                 int rc;
650                 size_t crap;
651                 int query_module(const char *name, int which, void *buf,
652                                  size_t bufsize, size_t *ret);
653
654                 rc = query_module(mp->name, QM_INFO, &info, sizeof(info),
655                                   &crap);
656                 if (rc < 0) {
657                         if (errno != ENOENT)
658                                 printf("query_module(%s) failed: %s\n",
659                                        mp->name, strerror(errno));
660                 } else {
661                         printf("add-symbol-file %s/%s/%s.o 0x%0lx\n", path,
662                                mp->path, mp->name,
663                                info.addr + sizeof(struct module));
664                 }
665         }
666
667         return 0;
668 #else /* Headers are 2.6-only */
669         return -EINVAL;
670 #endif
671 }
672
673 static int jt_dbg_modules_2_5(int argc, char **argv)
674 {
675         struct mod_paths *mp;
676         char *path = "..";
677         char *kernel = "linux";
678         const char *proc = "/proc/modules";
679         char modname[128], others[128];
680         long modaddr;
681         int rc;
682         FILE *file;
683
684         if (argc >= 2)
685                 path = argv[1];
686         if (argc == 3)
687                 kernel = argv[2];
688         if (argc > 3) {
689                 printf("%s [path] [kernel]\n", argv[0]);
690                 return 0;
691         }
692
693         file = fopen(proc, "r");
694         if (!file) {
695                 printf("failed open %s: %s\n", proc, strerror(errno));
696                 return 0;
697         }
698
699         while ((rc = fscanf(file, "%s %s %s %s %s %lx\n",
700                 modname, others, others, others, others, &modaddr)) == 6) {
701                 for (mp = mod_paths; mp->name != NULL; mp++) {
702                         if (!strcmp(mp->name, modname))
703                                 break;
704                 }
705                 if (mp->name) {
706                         printf("add-symbol-file %s/%s/%s.o 0x%0lx\n", path,
707                                mp->path, mp->name, modaddr);
708                 }
709         }
710
711         return 0;
712 }
713
714 int jt_dbg_modules(int argc, char **argv)
715 {
716         int rc = 0;
717         struct utsname sysinfo;
718
719         rc = uname(&sysinfo);
720         if (rc) {
721                 printf("uname() failed: %s\n", strerror(errno));
722                 return 0;
723         }
724
725         if (sysinfo.release[2] > '4') {
726                 return jt_dbg_modules_2_5(argc, argv);
727         } else {
728                 return jt_dbg_modules_2_4(argc, argv);
729         }
730
731         return 0;
732 }
733
734 int jt_dbg_panic(int argc, char **argv)
735 {
736         int rc;
737         struct portal_ioctl_data data;
738
739         if (argc != 1) {
740                 fprintf(stderr, "usage: %s\n", argv[0]);
741                 return 0;
742         }
743
744         memset(&data, 0, sizeof(data));
745         if (portal_ioctl_pack(&data, &buf, max) != 0) {
746                 fprintf(stderr, "portal_ioctl_pack failed.\n");
747                 return -1;
748         }
749
750         rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_PANIC, buf);
751         if (rc) {
752                 fprintf(stderr, "IOC_PORTAL_PANIC failed: %s\n",
753                         strerror(errno));
754                 return -1;
755         }
756         return 0;
757 }