Whamcloud - gitweb
use special macro for print time_t, cleanup in includes.
[fs/lustre-release.git] / lnet / libcfs / debug.c
index baeaeac..4b275e6 100644 (file)
@@ -35,25 +35,44 @@ static char debug_file_name[1024];
 
 #ifdef __KERNEL__
 unsigned int libcfs_subsystem_debug = ~0;
+CFS_MODULE_PARM(libcfs_subsystem_debug, "i", int, 0644,
+                "Lustre kernel debug subsystem mask");
 EXPORT_SYMBOL(libcfs_subsystem_debug);
 
 unsigned int libcfs_debug = (D_EMERG | D_ERROR | D_WARNING | D_CONSOLE |
                              D_NETERROR | D_HA | D_CONFIG | D_IOCTL);
+CFS_MODULE_PARM(libcfs_debug, "i", int, 0644,
+                "Lustre kernel debug mask");
 EXPORT_SYMBOL(libcfs_debug);
 
-unsigned int libcfs_printk;
+int libcfs_debug_mb = -1;
+CFS_MODULE_PARM(libcfs_debug_mb, "i", int, 0644,
+                "Total debug buffer size.");
+EXPORT_SYMBOL(libcfs_debug_mb);
+
+unsigned int libcfs_printk = D_CANTMASK;
+CFS_MODULE_PARM(libcfs_printk, "i", uint, 0644,
+                "Lustre kernel debug console mask");
 EXPORT_SYMBOL(libcfs_printk);
 
 unsigned int libcfs_console_ratelimit = 1;
+CFS_MODULE_PARM(libcfs_console_ratelimit, "i", uint, 0644,
+                "Lustre kernel debug console ratelimit (0 to disable)");
 EXPORT_SYMBOL(libcfs_console_ratelimit);
 
 cfs_duration_t libcfs_console_max_delay;
+CFS_MODULE_PARM(libcfs_console_max_delay, "l", ulong, 0644,
+                "Lustre kernel debug console max delay (jiffies)");
 EXPORT_SYMBOL(libcfs_console_max_delay);
 
 cfs_duration_t libcfs_console_min_delay;
+CFS_MODULE_PARM(libcfs_console_min_delay, "l", ulong, 0644,
+                "Lustre kernel debug console min delay (jiffies)");
 EXPORT_SYMBOL(libcfs_console_min_delay);
 
 unsigned int libcfs_console_backoff = CDEBUG_DEFAULT_BACKOFF;
+CFS_MODULE_PARM(libcfs_console_backoff, "i", uint, 0644,
+                "Lustre kernel debug console backoff factor");
 EXPORT_SYMBOL(libcfs_console_backoff);
 
 unsigned int libcfs_debug_binary = 1;
@@ -69,6 +88,8 @@ unsigned int libcfs_catastrophe;
 EXPORT_SYMBOL(libcfs_catastrophe);
 
 unsigned int libcfs_panic_on_lbug = 0;
+CFS_MODULE_PARM(libcfs_panic_on_lbug, "i", uint, 0644,
+                "Lustre kernel panic on LBUG");
 EXPORT_SYMBOL(libcfs_panic_on_lbug);
 
 atomic_t libcfs_kmemory = ATOMIC_INIT(0);
@@ -81,6 +102,9 @@ char debug_file_path[1024] = "/r/tmp/lustre-log";
 #else
 char debug_file_path[1024] = "/tmp/lustre-log";
 #endif
+CFS_MODULE_PARM(debug_file_path, "s", charp, 0644,
+                "Path for dumping debug logs, "
+                "set 'NONE' to prevent log dumping");
 
 int libcfs_panic_in_progress;
 
@@ -381,11 +405,14 @@ void libcfs_debug_dumplog_internal(void *arg)
 
         CFS_PUSH_JOURNAL;
 
-        snprintf(debug_file_name, sizeof(debug_file_path) - 1, "%s.%ld.%ld",
-                 debug_file_path, cfs_time_current_sec(), (long)arg);
-        printk(KERN_ALERT "LustreError: dumping log to %s\n", debug_file_name);
-        tracefile_dump_all_pages(debug_file_name);
-
+        if (strncmp(debug_file_path, "NONE", 4) != 0) {
+                snprintf(debug_file_name, sizeof(debug_file_path) - 1,
+                         "%s.%ld.%ld", debug_file_path, cfs_time_current_sec(),
+                         (long)arg);
+                printk(KERN_ALERT "LustreError: dumping log to %s\n",
+                       debug_file_name);
+                tracefile_dump_all_pages(debug_file_name);
+        }
         CFS_POP_JOURNAL;
 }
 
@@ -426,12 +453,21 @@ void libcfs_debug_dumplog(void)
 
 int libcfs_debug_init(unsigned long bufsize)
 {
-        int    rc;
+        int    rc = 0;
+        int    max = libcfs_debug_mb;
 
         cfs_waitq_init(&debug_ctlwq);
         libcfs_console_max_delay = CDEBUG_DEFAULT_MAX_DELAY;
         libcfs_console_min_delay = CDEBUG_DEFAULT_MIN_DELAY;
-        rc = tracefile_init();
+        /* If libcfs_debug_mb is set to an invalid value or uninitialized
+         * then just make the total buffers smp_num_cpus * TCD_MAX_PAGES */
+        if (max > trace_max_debug_mb() || max < num_possible_cpus()) {
+                max = TCD_MAX_PAGES;
+        } else {
+                max = (max / num_possible_cpus());
+                max = (max << (20 - CFS_PAGE_SHIFT));
+        }
+        rc = tracefile_init(max);
 
         if (rc == 0)
                 libcfs_register_panic_notifier();
@@ -621,7 +657,7 @@ int libcfs_debug_init(unsigned long bufsize)
 
         if (debug_file_name[0] == '\0' && debug_file_path[0] != '\0')
                 snprintf(debug_file_name, sizeof(debug_file_name) - 1,
-                         "%s-%s-%lu.log", debug_file_path, source_nid, time(0));
+                         "%s-%s-"CFS_TIME_T".log", debug_file_path, source_nid, time(0));
 
         if (strcmp(debug_file_name, "stdout") == 0 ||
             strcmp(debug_file_name, "-") == 0) {
@@ -689,8 +725,9 @@ libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls,
         int            nob;
         int            remain;
         va_list        ap;
-        char           buf[PAGE_SIZE]; /* size 4096 used for compatimble with linux,
-                                        * where message can`t be exceed PAGE_SIZE */
+        char           buf[CFS_PAGE_SIZE]; /* size 4096 used for compatimble
+                                            * with linux, where message can`t
+                                            * be exceed PAGE_SIZE */
         int            console = 0;
         char *prefix = "Lustre";
 
@@ -698,10 +735,8 @@ libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls,
         /* toconsole == 0 - all messages to debug_file_fd
          * toconsole == 1 - warnings to console, all to debug_file_fd
          * toconsole >  1 - all debug to console */
-        if ( ((mask & D_CANTMASK) &&
-             (toconsole == 1)) || (toconsole > 1)) {
+        if (((mask & libcfs_printk) && toconsole == 1) || toconsole > 1)
                 console = 1;
-        }
 #endif
 
         if ((!console) && (!debug_file_fd)) {
@@ -785,7 +820,7 @@ out_file:
 
         gettimeofday(&tv, NULL);
 
-        fprintf(debug_file_fd, "%lu.%06lu:%u:%s:(%s:%d:%s()): %s",
+        fprintf(debug_file_fd, CFS_TIME_T".%06lu:%u:%s:(%s:%d:%s()): %s",
                 tv.tv_sec, tv.tv_usec, source_pid, source_nid,
                 file, line, fn, buf);