Whamcloud - gitweb
use special macro for print time_t, cleanup in includes.
[fs/lustre-release.git] / lnet / utils / debug.c
index 6dec5b8..39af760 100644 (file)
@@ -45,7 +45,6 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <sys/utsname.h>
@@ -69,17 +68,17 @@ static int debug_mask = ~0;
 static const char *libcfs_debug_subsystems[] =
         {"undefined", "mdc", "mds", "osc",
          "ost", "class", "log", "llite",
-         "rpc", "", "lnet", "lnd",
+         "rpc", "mgmt", "lnet", "lnd",
          "pinger", "filter", "", "echo",
          "ldlm", "lov", "", "",
          "", "", "", "lmv",
-         "", "sec", "gss", "", "mgc", "mgs",
-         "fid", "fld", NULL};
+         "", "sec", "gss", "", 
+         "mgc", "mgs", "fid", "fld", NULL};
 static const char *libcfs_debug_masks[] =
         {"trace", "inode", "super", "ext2",
          "malloc", "cache", "info", "ioctl",
-         "blocks", "net", "warning", "buffs",
-         "other", "dentry", "lnet", "page",
+         "neterror", "net", "warning", "buffs",
+         "other", "dentry", "nettrace", "page",
          "dlmtrace", "error", "emerg", "ha",
          "rpctrace", "vfstrace", "reada", "mmap",
          "config", "console", "quota", "sec", NULL};
@@ -321,42 +320,32 @@ struct dbg_line {
         char *file;
         char *fn;
         char *text;
-        struct list_head chain;
 };
 
-/* nurr. */
-static void list_add_ordered(struct dbg_line *new, struct list_head *head)
+static int cmp_rec(const void *p1, const void *p2)
 {
-        struct list_head *pos;
-        struct dbg_line *curr;
-
-        list_for_each(pos, head) {
-                curr = list_entry(pos, struct dbg_line, chain);
-
-                if (curr->hdr->ph_sec < new->hdr->ph_sec)
-                        continue;
-                if (curr->hdr->ph_sec == new->hdr->ph_sec &&
-                    curr->hdr->ph_usec < new->hdr->ph_usec)
-                        continue;
+        struct dbg_line *d1 = *(struct dbg_line **)p1;
+        struct dbg_line *d2 = *(struct dbg_line **)p2;
 
-                list_add(&new->chain, pos->prev);
-                return;
-        }
-        list_add_tail(&new->chain, head);
+        if (d1->hdr->ph_sec < d2->hdr->ph_sec)
+                return -1;
+        if (d1->hdr->ph_sec == d2->hdr->ph_sec &&
+            d1->hdr->ph_usec < d2->hdr->ph_usec)
+                return -1;
+        if (d1->hdr->ph_sec == d2->hdr->ph_sec &&
+            d1->hdr->ph_usec == d2->hdr->ph_usec)
+                return 0;
+        return 1;
 }
 
-static void print_saved_records(struct list_head *list, FILE *out)
+static void print_rec(struct dbg_line **linev, int used, FILE *out)
 {
-        struct list_head *pos, *tmp;
-
-        list_for_each_safe(pos, tmp, list) {
-                struct dbg_line *line;
-                struct ptldebug_header *hdr;
+        int i;
 
-                line = list_entry(pos, struct dbg_line, chain);
-                list_del(&line->chain);
+        for (i = 0; i < used; i++) {
+                struct dbg_line *line = linev[i];
+                struct ptldebug_header *hdr = line->hdr;
 
-                hdr = line->hdr;
                 fprintf(out, "%08x:%08x:%u:%u.%06llu:%u:%u:%u:(%s:%u:%s()) %s",
                         hdr->ph_subsys, hdr->ph_mask, hdr->ph_cpu_id,
                         hdr->ph_sec, (unsigned long long)hdr->ph_usec,
@@ -365,6 +354,26 @@ static void print_saved_records(struct list_head *list, FILE *out)
                 free(line->hdr);
                 free(line);
         }
+        free(linev);
+}
+
+static int add_rec(struct dbg_line *line, struct dbg_line ***linevp, int *lenp,
+                   int used)
+{
+        struct dbg_line **linev = *linevp;
+
+        if (used == *lenp) {
+                int nlen = *lenp + 512;
+                int nsize = nlen * sizeof(struct dbg_line *);
+
+                linev = *linevp ? realloc(*linevp, nsize) : malloc(nsize);
+                if (!linev)
+                        return 0;
+                *linevp = linev;
+                *lenp = nlen;
+        }
+        linev[used] = line; 
+        return 1;
 }
 
 static int parse_buffer(FILE *in, FILE *out)
@@ -374,9 +383,8 @@ static int parse_buffer(FILE *in, FILE *out)
         char buf[4097], *p;
         int rc;
         unsigned long dropped = 0, kept = 0;
-        struct list_head chunk_list;
-
-        CFS_INIT_LIST_HEAD(&chunk_list);
+        struct dbg_line **linev = NULL;
+        int linev_len = 0;
 
         while (1) {
                 rc = fread(buf, sizeof(hdr->ph_len) + sizeof(hdr->ph_flags), 1, in);
@@ -393,11 +401,6 @@ static int parse_buffer(FILE *in, FILE *out)
                         break;
                 }
 
-                if (hdr->ph_flags & PH_FLAG_FIRST_RECORD) {
-                        print_saved_records(&chunk_list, out);
-                        assert(list_empty(&chunk_list));
-                }
-
                 rc = fread(buf + sizeof(hdr->ph_len) + sizeof(hdr->ph_flags), 1,
                            hdr->ph_len - sizeof(hdr->ph_len) - sizeof(hdr->ph_flags), in);
                 if (rc <= 0)
@@ -436,11 +439,18 @@ static int parse_buffer(FILE *in, FILE *out)
                 p += strlen(line->fn) + 1;
                 line->text = p;
 
-                list_add_ordered(line, &chunk_list);
+                if (!add_rec(line, &linev, &linev_len, kept)) {
+                        fprintf(stderr, "malloc failed; printing accumulated " 
+                                "records and exiting.\n");
+                        break;
+                }        
                 kept++;
         }
 
-        print_saved_records(&chunk_list, out);
+        if (linev) {
+                qsort(linev, kept, sizeof(struct dbg_line *), cmp_rec);
+                print_rec(linev, kept, out);
+        }
 
         printf("Debug log: %lu lines, %lu kept, %lu dropped.\n",
                 dropped + kept, kept, dropped);
@@ -472,7 +482,8 @@ int jt_dbg_debug_kernel(int argc, char **argv)
         if (argc > 1 && raw)
                 strcpy(filename, argv[1]);
         else
-                sprintf(filename, "/tmp/lustre-log.%lu.%u",time(NULL),getpid());
+                sprintf(filename, "/tmp/lustre-log."CFS_TIME_T".%u",
+                       time(NULL),getpid());
 
         if (stat(filename, &st) == 0 && S_ISREG(st.st_mode))
                 unlink(filename);
@@ -758,7 +769,8 @@ static struct mod_paths {
         {"mdc", "lustre/mdc"},
         {"llite", "lustre/llite"},
         {"lustre", "lustre/llite"},
-        {"ldiskfs", "lustre/ldiskfs"},
+        {"llite_lloop", "lustre/llite"},
+        {"ldiskfs", "ldiskfs/ldiskfs"},
         {"smfs", "lustre/smfs"},
         {"obdecho", "lustre/obdecho"},
         {"ldlm", "lustre/ldlm"},