Whamcloud - gitweb
land portals part of b_hd_sec on HEAD.
[fs/lustre-release.git] / lnet / utils / debug.c
index 9d49174..df78d08 100644 (file)
 #define __USE_FILE_OFFSET64
 #define  _GNU_SOURCE
 
-#include <portals/list.h>
-
 #include <stdio.h>
 #ifdef HAVE_NETDB_H
 #include <netdb.h>
 #endif
 #include <stdlib.h>
 #include <string.h>
-#include "ioctl.h"
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
-#ifndef __CYGWIN__
-# include <syscall.h>
-#endif
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
-
-#ifdef HAVE_LINUX_VERSION_H
-#include <linux/version.h>
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-#define BUG()                            /* workaround for module.h includes */
-#include <linux/module.h>
-#endif
-#endif /* !HAVE_LINUX_VERSION_H */
-
 #include <sys/utsname.h>
 
 #include <portals/api-support.h>
 #include <portals/ptlctl.h>
+#include <libcfs/portals_utils.h>
 #include "parser.h"
 
 #include <time.h>
@@ -81,7 +66,7 @@ static const char *portal_debug_subsystems[] =
          "pinger", "filter", "ptlbd", "echo", 
          "ldlm", "lov", "router", "cobd", 
          "sm", "asobd", "confobd", "lmv", 
-         "cmobd", NULL};
+         "cmobd", "sec", NULL};
 static const char *portal_debug_masks[] =
         {"trace", "inode", "super", "ext2", 
          "malloc", "cache", "info", "ioctl",
@@ -89,7 +74,7 @@ static const char *portal_debug_masks[] =
          "other", "dentry", "portals", "page", 
          "dlmtrace", "error", "emerg", "ha", 
          "rpctrace", "vfstrace", "reada", "mmap",
-         "config", NULL};
+         "config", "console", "quota", "sec", NULL};
 
 struct debug_daemon_cmd {
         char *cmd;
@@ -303,7 +288,7 @@ static int parse_buffer(FILE *in, FILE *out)
         unsigned long dropped = 0, kept = 0;
         struct list_head chunk_list;
 
-        INIT_LIST_HEAD(&chunk_list);
+        CFS_INIT_LIST_HEAD(&chunk_list);
 
         while (1) {
                 rc = fread(buf, sizeof(hdr->ph_len), 1, in);
@@ -460,8 +445,12 @@ int jt_dbg_debug_kernel(int argc, char **argv)
 
 int jt_dbg_debug_file(int argc, char **argv)
 {
-        int fdin,fdout;
-        FILE *in, *out = stdout;
+        int    fdin;
+        int    fdout;
+        FILE  *in;
+        FILE  *out = stdout;
+        int    rc;
+
         if (argc > 3 || argc < 2) {
                 fprintf(stderr, "usage: %s <input> [output]\n", argv[0]);
                 return 0;
@@ -481,7 +470,9 @@ int jt_dbg_debug_file(int argc, char **argv)
                 return 1;
         }
         if (argc > 2) {
-                fdout = open(argv[2], O_CREAT | O_WRONLY | O_LARGEFILE);
+                fdout = open(argv[2], 
+                             O_CREAT | O_TRUNC | O_WRONLY | O_LARGEFILE, 
+                             0600);
                 if (fdout == -1) {
                         fprintf(stderr, "open(%s) failed: %s\n", argv[2],
                                 strerror(errno));
@@ -498,7 +489,13 @@ int jt_dbg_debug_file(int argc, char **argv)
                 }
         }
 
-        return parse_buffer(in, out);
+        rc = parse_buffer(in, out);
+
+        fclose(in);
+        if (out != stdout)
+                fclose(out);
+
+        return rc;
 }
 
 static int
@@ -531,12 +528,11 @@ int jt_dbg_debug_daemon(int argc, char **argv)
         
         rc = -1;
         if (strcasecmp(argv[1], "start") == 0) {
-                if (argc < 3 || argc > 4 ||
+             if (argc < 3 || argc > 4 ||
                     (argc == 4 && strlen(argv[3]) > 5)) {
                         fprintf(stderr, debug_daemon_usage, argv[0]);
                         goto out;
                 }
-
                 if (argc == 4) {
                         char       buf[12];
                         const long min_size = 10;
@@ -545,7 +541,7 @@ int jt_dbg_debug_daemon(int argc, char **argv)
                         char      *end;
 
                         size = strtoul(argv[3], &end, 0);
-                        if (size < min_size || 
+                        if (size < min_size ||
                             size > max_size ||
                             *end != 0) {
                                 fprintf(stderr, "size %s invalid, must be in "
@@ -553,9 +549,9 @@ int jt_dbg_debug_daemon(int argc, char **argv)
                                         min_size, max_size);
                                 goto out;
                         }
-
                         snprintf(buf, sizeof(buf), "size=%ld", size);
                         rc = dbg_write_cmd(fd, buf);
+
                         if (rc != 0) {
                                 fprintf(stderr, "set %s failed: %s\n",
                                         buf, strerror(errno));
@@ -563,17 +559,15 @@ int jt_dbg_debug_daemon(int argc, char **argv)
                         }
                 }
 
-                rc = dbg_write_cmd(fd, "start");
+                rc = dbg_write_cmd(fd, argv[2]);
                 if (rc != 0) {
                         fprintf(stderr, "start debug_daemon on %s failed: %s\n",
                                 argv[2], strerror(errno));
                         goto out;
                 }
-
                 rc = 0;
                 goto out;
         }
-        
         if (strcasecmp(argv[1], "stop") == 0) {
                 rc = dbg_write_cmd(fd, "stop");
                 if (rc != 0) {
@@ -664,42 +658,44 @@ int jt_dbg_mark_debug_buf(int argc, char **argv)
 static struct mod_paths {
         char *name, *path;
 } mod_paths[] = {
-        {"libcfs", "lustre/portals/libcfs"},
-        {"portals", "lustre/portals/portals"},
-        {"ksocknal", "lustre/portals/knals/socknal"},
-        {"kptlrouter", "lustre/portals/router"},
-        {"lvfs", "lustre/lustre/lvfs"},
-        {"obdclass", "lustre/lustre/obdclass"},
-        {"llog_test", "lustre/lustre/obdclass"},
-        {"ptlrpc", "lustre/lustre/ptlrpc"},
-        {"obdext2", "lustre/lustre/obdext2"},
-        {"ost", "lustre/lustre/ost"},
-        {"osc", "lustre/lustre/osc"},
-        {"mds", "lustre/lustre/mds"},
-        {"mdc", "lustre/lustre/mdc"},
-        {"llite", "lustre/lustre/llite"},
-        {"ldiskfs", "lustre/lustre/ldiskfs"},
-        {"smfs", "lustre/lustre/smfs"},
-        {"obdecho", "lustre/lustre/obdecho"},
-        {"ldlm", "lustre/lustre/ldlm"},
-        {"obdfilter", "lustre/lustre/obdfilter"},
-        {"extN", "lustre/lustre/extN"},
-        {"lov", "lustre/lustre/lov"},
-        {"lmv", "lustre/lustre/lmv"},
-        {"fsfilt_ext3", "lustre/lustre/lvfs"},
-        {"fsfilt_extN", "lustre/lustre/lvfs"},
-        {"fsfilt_reiserfs", "lustre/lustre/lvfs"},
-        {"fsfilt_smfs", "lustre/lustre/lvfs"},
-        {"fsfilt_ldiskfs", "lustre/lustre/lvfs"},
-        {"mds_ext2", "lustre/lustre/mds"},
-        {"mds_ext3", "lustre/lustre/mds"},
-        {"mds_extN", "lustre/lustre/mds"},
-        {"ptlbd", "lustre/lustre/ptlbd"},
-        {"mgmt_svc", "lustre/lustre/mgmt"},
-        {"mgmt_cli", "lustre/lustre/mgmt"},
-        {"cobd", "lustre/lustre/cobd"},
-        {"cmobd", "lustre/lustre/cmobd"},
-        {"conf_obd", "lustre/lustre/obdclass"},
+        {"libcfs", "portals/libcfs"},
+        {"portals", "portals/portals"},
+        {"ksocknal", "portals/knals/socknal"},
+        {"kptlrouter", "portals/router"},
+        {"lvfs", "lustre/lvfs"},
+        {"obdclass", "lustre/obdclass"},
+        {"llog_test", "lustre/obdclass"},
+        {"ptlrpcs", "lustre/sec"},
+        {"ptlrpcs_gss", "lustre/sec/gss"},
+        {"ptlrpc", "lustre/ptlrpc"},
+        {"obdext2", "lustre/obdext2"},
+        {"ost", "lustre/ost"},
+        {"osc", "lustre/osc"},
+        {"mds", "lustre/mds"},
+        {"mdc", "lustre/mdc"},
+        {"llite", "lustre/llite"},
+        {"ldiskfs", "lustre/ldiskfs"},
+        {"smfs", "lustre/smfs"},
+        {"obdecho", "lustre/obdecho"},
+        {"ldlm", "lustre/ldlm"},
+        {"obdfilter", "lustre/obdfilter"},
+        {"extN", "lustre/extN"},
+        {"lov", "lustre/lov"},
+        {"lmv", "lustre/lmv"},
+        {"fsfilt_ext3", "lustre/lvfs"},
+        {"fsfilt_extN", "lustre/lvfs"},
+        {"fsfilt_reiserfs", "lustre/lvfs"},
+        {"fsfilt_smfs", "lustre/lvfs"},
+        {"fsfilt_ldiskfs", "lustre/lvfs"},
+        {"mds_ext2", "lustre/mds"},
+        {"mds_ext3", "lustre/mds"},
+        {"mds_extN", "lustre/mds"},
+        {"ptlbd", "lustre/ptlbd"},
+        {"mgmt_svc", "lustre/mgmt"},
+        {"mgmt_cli", "lustre/mgmt"},
+        {"cobd", "lustre/cobd"},
+        {"cmobd", "lustre/cmobd"},
+        {"confobd", "lustre/obdclass"},
         {NULL, NULL}
 };
 
@@ -741,8 +737,8 @@ static int jt_dbg_modules_2_4(int argc, char **argv)
         }
 
         return 0;
-#endif /* Headers are 2.6-only */
-#endif /* !HAVE_LINUX_VERSION_H */
+#endif // Headers are 2.6-only
+#endif // !HAVE_LINUX_VERSION_H
         return -EINVAL;
 }