]> git.proxmox.com Git - mirror_spl.git/blobdiff - module/spl/spl-err.c
Retire legacy debugging infrastructure
[mirror_spl.git] / module / spl / spl-err.c
index 2706f9bd13996fc0955d0f69aeb85538fcd905ec..14ff8a3373f533cb539099ef81af16bbcdd1a5e2 100644 (file)
 
 #include <sys/sysmacros.h>
 #include <sys/cmn_err.h>
-#include <spl-debug.h>
+#include <linux/ratelimit.h>
 
-#ifdef SS_DEBUG_SUBSYS
-#undef SS_DEBUG_SUBSYS
-#endif
+/*
+ * Limit the number of stack traces dumped to not more than 5 every
+ * 60 seconds to prevent denial-of-service attacks from debug code.
+ */
+DEFINE_RATELIMIT_STATE(dumpstack_ratelimit_state, 60 * HZ, 5);
 
-#define SS_DEBUG_SUBSYS SS_GENERIC
-
-#ifdef DEBUG_LOG
-static char ce_prefix[CE_IGNORE][10] = { "", "NOTICE: ", "WARNING: ", "" };
-static char ce_suffix[CE_IGNORE][2] = { "", "\n", "\n", "" };
-#endif
+void
+spl_dumpstack(void)
+{
+       if (__ratelimit(&dumpstack_ratelimit_state)) {
+               printk("Showing stack for process %d\n", current->pid);
+               dump_stack();
+       }
+}
+EXPORT_SYMBOL(spl_dumpstack);
 
 int
-spl_PANIC(char *filename, const char *functionname,
-    int lineno, const char *fmt, ...) {
+spl_panic(const char *file, const char *func, int line, const char *fmt, ...) {
+       const char *newfile;
        char msg[MAXMSGLEN];
        va_list ap;
 
+       newfile = strrchr(file, '/');
+       if (newfile != NULL)
+               newfile = newfile + 1;
+       else
+               newfile = file;
+
        va_start(ap, fmt);
-       if (vsnprintf(msg, sizeof (msg), fmt, ap) == sizeof (msg))
-               msg[sizeof (msg) - 1] = '\0';
+       (void) vsnprintf(msg, sizeof (msg), fmt, ap);
        va_end(ap);
-#ifdef NDEBUG
+
        printk(KERN_EMERG "%s", msg);
-#else
-       spl_debug_msg(NULL, 0, 0,
-            filename, functionname, lineno, "%s", msg);
-#endif
-       spl_debug_bug(filename, functionname, lineno, 0);
-       return 1;
-}
-EXPORT_SYMBOL(spl_PANIC);
+       printk(KERN_EMERG "PANIC at %s:%d:%s()\n", newfile, line, func);
+       spl_dumpstack();
 
-void
-vpanic(const char *fmt, va_list ap)
-{
-       char msg[MAXMSGLEN];
+       /* Halt the thread to facilitate further debugging */
+       set_task_state(current, TASK_UNINTERRUPTIBLE);
+       while (1)
+               schedule();
 
-       vsnprintf(msg, MAXMSGLEN - 1, fmt, ap);
-       PANIC("%s", msg);
-} /* vpanic() */
-EXPORT_SYMBOL(vpanic);
+       /* Unreachable */
+       return (1);
+}
+EXPORT_SYMBOL(spl_panic);
 
 void
 vcmn_err(int ce, const char *fmt, va_list ap)
 {
        char msg[MAXMSGLEN];
 
-       if (ce == CE_PANIC)
-               vpanic(fmt, ap);
+       vsnprintf(msg, MAXMSGLEN - 1, fmt, ap);
 
-       if (ce != CE_NOTE) {
-               vsnprintf(msg, MAXMSGLEN - 1, fmt, ap);
+       switch (ce) {
+       case CE_IGNORE:
+               break;
+       case CE_CONT:
+               printk("%s", msg);
+               break;
+       case CE_NOTE:
+               printk(KERN_NOTICE "NOTICE: %s\n", msg);
+               break;
+       case CE_WARN:
+               printk(KERN_WARNING "WARNING: %s\n", msg);
+               break;
+       case CE_PANIC:
+               printk(KERN_EMERG "PANIC: %s\n", msg);
+               spl_dumpstack();
 
-               if (fmt[0] == '!')
-                       SDEBUG(SD_INFO, "%s%s%s",
-                              ce_prefix[ce], msg, ce_suffix[ce]);
-               else
-                       SERROR("%s%s%s", ce_prefix[ce], msg, ce_suffix[ce]);
+               /* Halt the thread to facilitate further debugging */
+               set_task_state(current, TASK_UNINTERRUPTIBLE);
+               while (1)
+                       schedule();
        }
 } /* vcmn_err() */
 EXPORT_SYMBOL(vcmn_err);
@@ -100,4 +115,3 @@ cmn_err(int ce, const char *fmt, ...)
        va_end(ap);
 } /* cmn_err() */
 EXPORT_SYMBOL(cmn_err);
-