+ if (in_interrupt()) {
+ cfs_trace_debug_print();
+ } else {
+ libcfs_debug_dumplog_internal((void *)(long)current->pid);
+ }
+#endif
+ return 0;
+}
+
+static struct notifier_block libcfs_panic_notifier = {
+ .notifier_call = panic_notifier,
+ .next = NULL,
+ .priority = 10000,
+};
+
+static void libcfs_register_panic_notifier(void)
+{
+ atomic_notifier_chain_register(&panic_notifier_list,
+ &libcfs_panic_notifier);
+}
+
+static void libcfs_unregister_panic_notifier(void)
+{
+ atomic_notifier_chain_unregister(&panic_notifier_list,
+ &libcfs_panic_notifier);
+}
+
+int libcfs_debug_init(unsigned long bufsize)
+{
+ unsigned int max = libcfs_debug_mb;
+ int rc = 0;
+
+ if (libcfs_console_max_delay <= 0 || /* not set by user or */
+ libcfs_console_min_delay <= 0 || /* set to invalid values */
+ libcfs_console_min_delay >= libcfs_console_max_delay) {
+ libcfs_console_max_delay = CDEBUG_DEFAULT_MAX_DELAY;
+ libcfs_console_min_delay = CDEBUG_DEFAULT_MIN_DELAY;
+ }
+
+ /* If libcfs_debug_mb is uninitialized then just make the
+ * total buffers smp_num_cpus * TCD_MAX_PAGES
+ */
+ if (max < num_possible_cpus()) {
+ max = TCD_MAX_PAGES;
+ } else {
+ max = (max / num_possible_cpus());
+ max <<= (20 - PAGE_SHIFT);
+ }
+
+ rc = cfs_tracefile_init(max);
+ if (rc)
+ return rc;
+
+ libcfs_register_panic_notifier();
+ kernel_param_lock(THIS_MODULE);
+ if (libcfs_debug_mb == 0)
+ libcfs_debug_mb = cfs_trace_get_debug_mb();
+ kernel_param_unlock(THIS_MODULE);
+ return rc;