summaryrefslogtreecommitdiffstats
path: root/module/spl/spl-err.c
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2014-11-05 17:30:35 -0500
committerBrian Behlendorf <[email protected]>2014-11-19 10:35:07 -0800
commit8d9a23e82cea5d897e9357d569ef364106703d5a (patch)
treee49678dab2f5b419d630d388aca924a3c6e4fc72 /module/spl/spl-err.c
parent917fef273295616c563bbb0a5f6986cfce543d2f (diff)
Retire legacy debugging infrastructure
When the SPL was originally written Linux tracepoints were still in their infancy. Therefore, an entire debugging subsystem was added to facilite tracing which served us well for many years. Now that Linux tracepoints have matured they provide all the functionality of the previous tracing subsystem. Rather than maintain parallel functionality it makes sense to fully adopt tracepoints. Therefore, this patch retires the legacy debugging infrastructure. See zfsonlinux/zfs@bc9f413 for the tracepoint changes. Signed-off-by: Ned Bass <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #408
Diffstat (limited to 'module/spl/spl-err.c')
-rw-r--r--module/spl/spl-err.c96
1 files changed, 55 insertions, 41 deletions
diff --git a/module/spl/spl-err.c b/module/spl/spl-err.c
index 2706f9bd1..14ff8a337 100644
--- a/module/spl/spl-err.c
+++ b/module/spl/spl-err.c
@@ -26,66 +26,81 @@
#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);
-