Whamcloud - gitweb
Land b1_2 onto HEAD (20040304_171022)
[fs/lustre-release.git] / lustre / portals / utils / debug.c
index 9ab1c73..01e690f 100644 (file)
@@ -23,6 +23,8 @@
  *
  */
 
+#define __USE_FILE_OFFSET64
+
 #include <stdio.h>
 #include <netdb.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
 #include <time.h>
-#include <syscall.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>
+
 #define BUG()                            /* workaround for module.h includes */
 #include <linux/version.h>
 
@@ -53,17 +58,21 @@ static char rawbuf[8192];
 static char *buf = rawbuf;
 static int max = 8192;
 //static int g_pfd = -1;
-static int subsystem_array[1 << 8];
+static int subsystem_mask = ~0;
 static int debug_mask = ~0;
 
+#define MAX_MARK_SIZE 100
+
 static const char *portal_debug_subsystems[] =
-        {"undefined", "mdc", "mds", "osc", "ost", "class", "obdfs", "llite",
-         "rpc", "ext2obd", "portals", "socknal", "qswnal", "pinger", "filter",
-         "obdtrace", "echo", "ldlm", "lov", "gmnal", "router", "ptldb", NULL};
+        {"undefined", "mdc", "mds", "osc", "ost", "class", "log", "llite",
+         "rpc", "mgmt", "portals", "socknal", "qswnal", "pinger", "filter",
+         "ptlbd", "echo", "ldlm", "lov", "gmnal", "router", "cobd", "ibnal",
+         NULL};
 static const char *portal_debug_masks[] =
         {"trace", "inode", "super", "ext2", "malloc", "cache", "info", "ioctl",
          "blocks", "net", "warning", "buffs", "other", "dentry", "portals",
-         "page", "dlmtrace", "error", "emerg", "ha", "rpctrace", "vfstrace", NULL};
+         "page", "dlmtrace", "error", "emerg", "ha", "rpctrace", "vfstrace",
+         "reada", NULL};
 
 struct debug_daemon_cmd {
         char *cmd;
@@ -88,7 +97,10 @@ static int do_debug_mask(char *name, int enable)
                         printf("%s output from subsystem \"%s\"\n",
                                 enable ? "Enabling" : "Disabling",
                                 portal_debug_subsystems[i]);
-                        subsystem_array[i] = enable;
+                        if (enable)
+                                subsystem_mask |= (1 << i);
+                        else
+                                subsystem_mask &= ~(1 << i);
                         found = 1;
                 }
         }
@@ -111,7 +123,6 @@ static int do_debug_mask(char *name, int enable)
 
 int dbg_initialize(int argc, char **argv)
 {
-        memset(subsystem_array, 1, sizeof(subsystem_array));
         return 0;
 }
 
@@ -213,12 +224,7 @@ int jt_dbg_list(int argc, char **argv)
                 for (i = 0; portal_debug_masks[i] != NULL; i++)
                         printf(", %s", portal_debug_masks[i]);
                 printf("\n");
-        }
-        else if (strcasecmp(argv[1], "applymasks") == 0) {
-                unsigned int subsystem_mask = 0;
-                for (i = 0; portal_debug_subsystems[i] != NULL; i++) {
-                        if (subsystem_array[i]) subsystem_mask |= (1 << i);
-                }
+        } else if (strcasecmp(argv[1], "applymasks") == 0) {
                 applymask_all(subsystem_mask, debug_mask);
         }
         return 0;
@@ -230,12 +236,6 @@ static void dump_buffer(FILE *fd, char *buf, int size, int raw)
 {
         char *p, *z;
         unsigned long subsystem, debug, dropped = 0, kept = 0;
-        int max_sub, max_type;
-
-        for (max_sub = 0; portal_debug_subsystems[max_sub] != NULL; max_sub++)
-                ;
-        for (max_type = 0; portal_debug_masks[max_type] != NULL; max_type++)
-                ;
 
         while (size) {
                 p = memchr(buf, '\n', size);
@@ -247,8 +247,7 @@ static void dump_buffer(FILE *fd, char *buf, int size, int raw)
                 z++;
                 /* for some reason %*s isn't working. */
                 *p = '\0';
-                if (subsystem < max_sub &&
-                    subsystem_array[subsystem] &&
+                if ((subsystem_mask & subsystem) &&
                     (!debug || (debug_mask & debug))) {
                         if (raw)
                                 fprintf(fd, "%s\n", buf);
@@ -419,13 +418,8 @@ int jt_dbg_debug_file(int argc, char **argv)
                         strerror(errno));
                 return -1;
         }
-#warning FIXME: cleanup fstat issue here
-#ifndef SYS_fstat64
-#define __SYS_fstat__ SYS_fstat
-#else
-#define __SYS_fstat__ SYS_fstat64
-#endif
-        rc = syscall(__SYS_fstat__, fd, &statbuf);
+
+        rc = fstat(fd, &statbuf);
         if (rc < 0) {
                 fprintf(stderr, "fstat failed: %s\n", strerror(errno));
                 goto out;
@@ -489,22 +483,29 @@ int jt_dbg_clear_debug_buf(int argc, char **argv)
 
 int jt_dbg_mark_debug_buf(int argc, char **argv)
 {
-        int rc;
+        int rc, max_size = MAX_MARK_SIZE-1;
         struct portal_ioctl_data data;
         char *text;
         time_t now = time(NULL);
 
-        if (argc > 2) {
-                fprintf(stderr, "usage: %s [marker text]\n", argv[0]);
-                return 0;
-        }
-
-        if (argc == 2) {
-                text = argv[1];
+        if (argc > 1) {
+                int counter;
+                text = malloc(MAX_MARK_SIZE);
+                strncpy(text, argv[1], max_size);
+                max_size-=strlen(argv[1]);
+                for(counter = 2; (counter < argc) && (max_size > 0) ; counter++){
+                        strncat(text, " ", 1);
+                        max_size-=1;
+                        strncat(text, argv[counter], max_size);
+                        max_size-=strlen(argv[counter]);
+                }
         } else {
                 text = ctime(&now);
                 text[strlen(text) - 1] = '\0'; /* stupid \n */
         }
+        if (!max_size) {
+                text[MAX_MARK_SIZE - 1] = '\0';
+        }
 
         memset(&data, 0, sizeof(data));
         data.ioc_inllen1 = strlen(text) + 1;
@@ -523,7 +524,6 @@ int jt_dbg_mark_debug_buf(int argc, char **argv)
         return 0;
 }
 
-
 int jt_dbg_modules(int argc, char **argv)
 {
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
@@ -532,7 +532,10 @@ int jt_dbg_modules(int argc, char **argv)
         } *mp, mod_paths[] = {
                 {"portals", "lustre/portals/libcfs"},
                 {"ksocknal", "lustre/portals/knals/socknal"},
+                {"kptlrouter", "lustre/portals/router"},
+                {"lvfs", "lustre/lvfs"},
                 {"obdclass", "lustre/obdclass"},
+                {"llog_test", "lustre/obdclass"},
                 {"ptlrpc", "lustre/ptlrpc"},
                 {"obdext2", "lustre/obdext2"},
                 {"ost", "lustre/ost"},
@@ -545,12 +548,15 @@ int jt_dbg_modules(int argc, char **argv)
                 {"obdfilter", "lustre/obdfilter"},
                 {"extN", "lustre/extN"},
                 {"lov", "lustre/lov"},
-                {"fsfilt_ext3", "lustre/obdclass"},
-                {"fsfilt_extN", "lustre/obdclass"},
+                {"fsfilt_ext3", "lustre/lvfs"},
+                {"fsfilt_extN", "lustre/lvfs"},
+                {"fsfilt_reiserfs", "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"},
                 {NULL, NULL}
         };
         char *path = "..";