Whamcloud - gitweb
LU-2456 lnet: Dynamic LNet Configuration (DLC) IOCTL changes
[fs/lustre-release.git] / lnet / utils / debug.c
index 33699ff..e1dd37b 100644 (file)
@@ -59,7 +59,6 @@ static int debug_mask = ~0;
 static const char *libcfs_debug_subsystems[] = LIBCFS_DEBUG_SUBSYS_NAMES;
 static const char *libcfs_debug_masks[] = LIBCFS_DEBUG_MASKS_NAMES;
 
-#ifdef __linux__
 
 #define DAEMON_CTL_NAME         "/proc/sys/lnet/daemon_file"
 #define SUBSYS_DEBUG_CTL_NAME   "/proc/sys/lnet/subsystem_debug"
@@ -93,84 +92,6 @@ dbg_write_cmd(int fd, char *str, int len)
         return (rc == len ? 0 : 1);
 }
 
-#elif defined(__DARWIN__)
-
-#define DAEMON_CTL_NAME         "lnet.trace_daemon"
-#define SUBSYS_DEBUG_CTL_NAME   "lnet.subsystem_debug"
-#define DEBUG_CTL_NAME          "lnet.debug"
-#define DUMP_KERNEL_CTL_NAME    "lnet.trace_dumpkernel"
-
-static char     sysctl_name[128];
-static int
-dbg_open_ctlhandle(const char *str)
-{
-
-        if (strlen(str)+1 > 128) {
-                fprintf(stderr, "sysctl name is too long: %s.\n", str);
-                return -1;
-        }
-        strcpy(sysctl_name, str);
-
-        return 0;
-}
-
-static void
-dbg_close_ctlhandle(int fd)
-{
-        sysctl_name[0] = '\0';
-        return;
-}
-
-static int
-dbg_write_cmd(int fd, char *str, int len)
-{
-        int     rc;
-
-        rc = sysctlbyname(sysctl_name, NULL, NULL, str, len+1);
-        if (rc != 0) {
-                fprintf(stderr, "sysctl %s with cmd (%s) error: %d\n",
-                        sysctl_name, str, errno);
-        }
-        return (rc == 0 ? 0: 1);
-}
-
-#elif defined(__WINNT__)
-
-#define DAEMON_CTL_NAME         "/proc/sys/lnet/daemon_file"
-#define SUBSYS_DEBUG_CTL_NAME   "/proc/sys/lnet/subsystem_debug"
-#define DEBUG_CTL_NAME          "/proc/sys/lnet/debug"
-#define DUMP_KERNEL_CTL_NAME    "/proc/sys/lnet/dump_kernel"
-
-static int
-dbg_open_ctlhandle(const char *str)
-{
-        int fd;
-        fd = cfs_proc_open((char *)str, (int)O_WRONLY);
-        if (fd < 0) {
-                fprintf(stderr, "open %s failed: %s\n", str,
-                        strerror(errno));
-                return -1;
-        }
-        return fd;
-}
-
-static void
-dbg_close_ctlhandle(int fd)
-{
-        cfs_proc_close(fd);
-}
-
-static int
-dbg_write_cmd(int fd, char *str, int len)
-{
-        int    rc  = cfs_proc_write(fd, str, len);
-
-        return (rc == len ? 0 : 1);
-}
-
-#else
-#error - Unknown sysctl convention.
-#endif
 
 static int do_debug_mask(char *name, int enable)
 {
@@ -562,8 +483,8 @@ print:
 
 int jt_dbg_debug_kernel(int argc, char **argv)
 {
-        char filename[4096];
-        struct stat st;
+       struct stat st;
+       char filename[PATH_MAX];
         int raw = 0;
         int save_errno;
         int fdin;
@@ -585,11 +506,21 @@ int jt_dbg_debug_kernel(int argc, char **argv)
         /* If we are dumping raw (which means no conversion step to ASCII)
          * then dump directly to any supplied filename, otherwise this is
          * just a temp file and we dump to the real file at convert time. */
-        if (argc > 1 && raw)
-                strcpy(filename, argv[1]);
-        else
-                sprintf(filename, "%s"CFS_TIME_T".%u",
-                       LIBCFS_DEBUG_FILE_PATH_DEFAULT, time(NULL), getpid());
+       if (argc > 1 && raw) {
+               if (strlen(argv[1]) >= sizeof(filename)) {
+                       fprintf(stderr, "File name too long: %s\n", argv[1]);
+                       return 1;
+               }
+               strncpy(filename, argv[1], sizeof(filename));
+       } else {
+               if (snprintf(filename, sizeof(filename), "%s"CFS_TIME_T".%u",
+                            LIBCFS_DEBUG_FILE_PATH_DEFAULT, time(NULL),
+                            getpid())
+                   >= sizeof(filename)) {
+                       fprintf(stderr, "File name too long\n");
+                       return 1;
+               }
+       }
 
         if (stat(filename, &st) == 0 && S_ISREG(st.st_mode))
                 unlink(filename);
@@ -796,41 +727,44 @@ int jt_dbg_clear_debug_buf(int argc, char **argv)
 
 int jt_dbg_mark_debug_buf(int argc, char **argv)
 {
-        static char scratch[MAX_MARK_SIZE] = { '\0' };
-        int rc, max_size = MAX_MARK_SIZE-1;
-        struct libcfs_ioctl_data data = { 0 };
-        char *text;
-        time_t now = time(NULL);
+       static char scratch[MAX_MARK_SIZE] = "";
+       struct libcfs_ioctl_data data = { 0 };
+       char *text;
+       int rc;
+
+       if (argc > 1) {
+               int count, max_size = sizeof(scratch) - 1;
+
+               strncpy(scratch, argv[1], max_size);
+               max_size -= strlen(argv[1]);
+               for (count = 2; (count < argc) && (max_size > 1); count++) {
+                       strncat(scratch, " ", max_size);
+                       max_size -= 1;
+                       strncat(scratch, argv[count], max_size);
+                       max_size -= strlen(argv[count]);
+               }
+               scratch[sizeof(scratch) - 1] = '\0';
+               text = scratch;
+       } else {
+               time_t now = time(NULL);
+               text = ctime(&now);
+       }
 
-        if (argc > 1) {
-                int count;
-                text = scratch;
-                strncpy(text, argv[1], max_size);
-                max_size-=strlen(argv[1]);
-                for (count = 2; (count < argc) && (max_size > 0); count++){
-                        strncat(text, " ", max_size);
-                        max_size -= 1;
-                        strncat(text, argv[count], max_size);
-                        max_size -= strlen(argv[count]);
-                }
-        } else {
-                text = ctime(&now);
-        }
+       data.ioc_inllen1 = strlen(text) + 1;
+       data.ioc_inlbuf1 = text;
 
-        data.ioc_inllen1 = strlen(text) + 1;
-        data.ioc_inlbuf1 = text;
-        if (libcfs_ioctl_pack(&data, &buf, max) != 0) {
-                fprintf(stderr, "libcfs_ioctl_pack failed.\n");
-                return -1;
-        }
+       if (libcfs_ioctl_pack(&data, &buf, max) != 0) {
+               fprintf(stderr, "libcfs_ioctl_pack failed.\n");
+               return -1;
+       }
 
-        rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_MARK_DEBUG, buf);
-        if (rc) {
-                fprintf(stderr, "IOC_LIBCFS_MARK_DEBUG failed: %s\n",
-                        strerror(errno));
-                return -1;
-        }
-        return 0;
+       rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_MARK_DEBUG, buf);
+       if (rc) {
+               fprintf(stderr, "IOC_LIBCFS_MARK_DEBUG failed: %s\n",
+                       strerror(errno));
+               return -1;
+       }
+       return 0;
 }
 
 static struct mod_paths {
@@ -840,13 +774,11 @@ static struct mod_paths {
        { "lnet", "lnet/lnet" },
        { "kmxlnd", "lnet/klnds/mxlnd" },
        { "ko2iblnd", "lnet/klnds/o2iblnd" },
-       { "kptllnd", "lnet/klnds/ptllnd" },
        { "kgnilnd", "lnet/klnds/gnilnd"},
        { "kqswlnd", "lnet/klnds/qswlnd" },
        { "kralnd", "lnet/klnds/ralnd" },
        { "ksocklnd", "lnet/klnds/socklnd" },
        { "ktdilnd", "lnet/klnds/tdilnd" },
-       { "lvfs", "lustre/lvfs" },
        { "obdclass", "lustre/obdclass" },
        { "llog_test", "lustre/obdclass" },
        { "ptlrpc_gss", "lustre/ptlrpc/gss" },
@@ -865,7 +797,6 @@ static struct mod_paths {
        { "obdfilter", "lustre/obdfilter" },
        { "lov", "lustre/lov" },
        { "lmv", "lustre/lmv" },
-       { "fsfilt_ldiskfs", "lustre/lvfs" },
        { "lquota", "lustre/quota" },
        { "mgs", "lustre/mgs" },
        { "mgc", "lustre/mgc" },
@@ -887,7 +818,7 @@ int jt_dbg_modules(int argc, char **argv)
         char *path = "";
         const char *proc = "/proc/modules";
         char modname[128], buf[4096];
-        long modaddr;
+       unsigned long modaddr;
         FILE *file;
 
         if (argc >= 2)