Whamcloud - gitweb
b=15977 analyse only consistent part of the log
[fs/lustre-release.git] / lnet / utils / debug.c
index 7079a2e..ca17a3d 100644 (file)
@@ -352,7 +352,7 @@ static int cmp_rec(const void *p1, const void *p2)
                 return 0;
         return 1;
 }
-  
+
 static void print_rec(struct dbg_line ***linevp, int used, int fdout)
 {
         struct dbg_line **linev = *linevp;
@@ -363,15 +363,24 @@ static void print_rec(struct dbg_line ***linevp, int used, int fdout)
                 struct dbg_line *line = linev[i];
                 struct ptldebug_header *hdr = line->hdr;
                 char out[4097];
+                char *buf = out;
                 int bytes;
+                ssize_t bytes_written;
 
-                bytes = sprintf(out, "%08x:%08x:%u:%u.%06llu:%u:%u:%u:(%s:%u:%s()) %s",
-                                hdr->ph_subsys, hdr->ph_mask, hdr->ph_cpu_id,
+                bytes = sprintf(out, "%08x:%08x:%u.%u%s:%u.%06llu:%u:%u:%u:(%s:%u:%s()) %s",
+                                hdr->ph_subsys, hdr->ph_mask,
+                                hdr->ph_cpu_id, hdr->ph_type,
+                                hdr->ph_flags & PH_FLAG_FIRST_RECORD ? "F" : "",
                                 hdr->ph_sec, (unsigned long long)hdr->ph_usec,
                                 hdr->ph_stack, hdr->ph_pid, hdr->ph_extern_pid,
                                 line->file, hdr->ph_line_num, line->fn, line->text);
-
-                write(fdout, out, bytes);
+                while (bytes > 0) {
+                        bytes_written = write(fdout, buf, bytes);
+                        if (bytes_written <= 0)
+                                break;
+                        bytes -= bytes_written;
+                        buf += bytes_written;
+                }
                 free(line->hdr);
                 free(line);
         }
@@ -408,6 +417,7 @@ static void dump_hdr(unsigned long long offset, struct ptldebug_header *hdr)
         fprintf(stderr, "  subsystem = %x\n", hdr->ph_subsys);
         fprintf(stderr, "  mask = %x\n", hdr->ph_mask);
         fprintf(stderr, "  cpu_id = %u\n", hdr->ph_cpu_id);
+        fprintf(stderr, "  type = %u\n", hdr->ph_type);
         fprintf(stderr, "  seconds = %u\n", hdr->ph_sec);
         fprintf(stderr, "  microseconds = %lu\n", (long)hdr->ph_usec);
         fprintf(stderr, "  stack = %u\n", hdr->ph_stack);
@@ -447,7 +457,7 @@ static int parse_buffer(int fdin, int fdout)
                         goto readhdr;
                 
                 if (hdr->ph_len > 4094 ||       /* is this header bogus? */
-                    hdr->ph_cpu_id > 65536 ||
+                    hdr->ph_type >= CFS_TCD_TYPE_MAX ||
                     hdr->ph_stack > 65536 ||
                     hdr->ph_sec < (1 << 30) ||
                     hdr->ph_usec > 1000000000 ||
@@ -502,13 +512,13 @@ static int parse_buffer(int fdin, int fdout)
                          if (linev) {
                                 fprintf(stderr, "error: line malloc(%u): "
                                         "printing accumulated records\n",
-                                        sizeof(*line));
+                                        (unsigned int)sizeof(*line));
                                 print_rec(&linev, kept, fdout);
 
                                 goto retry_alloc;
                         }
                         fprintf(stderr, "error: line malloc(%u): exiting\n",
-                                sizeof(*line));
+                                (unsigned int)sizeof(*line));
                         break;
                 }
 
@@ -561,7 +571,7 @@ print:
 
         printf("Debug log: %lu lines, %lu kept, %lu dropped, %lu bad.\n",
                 dropped + kept + bad, kept, dropped, bad);
-  
+
         return 0;
 }
 
@@ -594,11 +604,11 @@ int jt_dbg_debug_kernel(int argc, char **argv)
                 strcpy(filename, argv[1]);
         else
                 sprintf(filename, "%s"CFS_TIME_T".%u",
-                       DEBUG_FILE_PATH_DEFAULT, time(NULL), getpid());
+                       LIBCFS_DEBUG_FILE_PATH_DEFAULT, time(NULL), getpid());
 
         if (stat(filename, &st) == 0 && S_ISREG(st.st_mode))
                 unlink(filename);
-  
+
         fdin = dbg_open_ctlhandle(DUMP_KERNEL_CTL_NAME);
         if (fdin < 0) {
                 fprintf(stderr, "open(dump_kernel) failed: %s\n",
@@ -617,7 +627,7 @@ int jt_dbg_debug_kernel(int argc, char **argv)
 
         if (raw)
                 return 0;
-  
+
         fdin = open(filename, O_RDONLY);
         if (fdin < 0) {
                 if (errno == ENOENT) /* no dump file created */
@@ -627,7 +637,8 @@ int jt_dbg_debug_kernel(int argc, char **argv)
                 return 1;
         }
         if (argc > 1) {
-                fdout = open(argv[1], O_WRONLY|O_CREAT);
+                fdout = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC,
+                             S_IRUSR | S_IWUSR);
                 if (fdout < 0) {
                         fprintf(stderr, "fopen(%s) failed: %s\n", argv[1],
                                 strerror(errno));