1*eda14cbcSMatt Macy /* 2*eda14cbcSMatt Macy * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3*eda14cbcSMatt Macy * Copyright (C) 2007 The Regents of the University of California. 4*eda14cbcSMatt Macy * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5*eda14cbcSMatt Macy * Written by Brian Behlendorf <behlendorf1@llnl.gov>. 6*eda14cbcSMatt Macy * UCRL-CODE-235197 7*eda14cbcSMatt Macy * 8*eda14cbcSMatt Macy * This file is part of the SPL, Solaris Porting Layer. 9*eda14cbcSMatt Macy * For details, see <http://zfsonlinux.org/>. 10*eda14cbcSMatt Macy * 11*eda14cbcSMatt Macy * The SPL is free software; you can redistribute it and/or modify it 12*eda14cbcSMatt Macy * under the terms of the GNU General Public License as published by the 13*eda14cbcSMatt Macy * Free Software Foundation; either version 2 of the License, or (at your 14*eda14cbcSMatt Macy * option) any later version. 15*eda14cbcSMatt Macy * 16*eda14cbcSMatt Macy * The SPL is distributed in the hope that it will be useful, but WITHOUT 17*eda14cbcSMatt Macy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18*eda14cbcSMatt Macy * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19*eda14cbcSMatt Macy * for more details. 20*eda14cbcSMatt Macy * 21*eda14cbcSMatt Macy * You should have received a copy of the GNU General Public License along 22*eda14cbcSMatt Macy * with the SPL. If not, see <http://www.gnu.org/licenses/>. 23*eda14cbcSMatt Macy * 24*eda14cbcSMatt Macy * Solaris Porting Layer (SPL) Error Implementation. 25*eda14cbcSMatt Macy */ 26*eda14cbcSMatt Macy 27*eda14cbcSMatt Macy #include <sys/sysmacros.h> 28*eda14cbcSMatt Macy #include <sys/cmn_err.h> 29*eda14cbcSMatt Macy 30*eda14cbcSMatt Macy /* 31*eda14cbcSMatt Macy * It is often useful to actually have the panic crash the node so you 32*eda14cbcSMatt Macy * can then get notified of the event, get the crashdump for later 33*eda14cbcSMatt Macy * analysis and other such goodies. 34*eda14cbcSMatt Macy * But we would still default to the current default of not to do that. 35*eda14cbcSMatt Macy */ 36*eda14cbcSMatt Macy /* BEGIN CSTYLED */ 37*eda14cbcSMatt Macy unsigned int spl_panic_halt; 38*eda14cbcSMatt Macy module_param(spl_panic_halt, uint, 0644); 39*eda14cbcSMatt Macy MODULE_PARM_DESC(spl_panic_halt, "Cause kernel panic on assertion failures"); 40*eda14cbcSMatt Macy /* END CSTYLED */ 41*eda14cbcSMatt Macy 42*eda14cbcSMatt Macy void 43*eda14cbcSMatt Macy spl_dumpstack(void) 44*eda14cbcSMatt Macy { 45*eda14cbcSMatt Macy printk("Showing stack for process %d\n", current->pid); 46*eda14cbcSMatt Macy dump_stack(); 47*eda14cbcSMatt Macy } 48*eda14cbcSMatt Macy EXPORT_SYMBOL(spl_dumpstack); 49*eda14cbcSMatt Macy 50*eda14cbcSMatt Macy int 51*eda14cbcSMatt Macy spl_panic(const char *file, const char *func, int line, const char *fmt, ...) 52*eda14cbcSMatt Macy { 53*eda14cbcSMatt Macy const char *newfile; 54*eda14cbcSMatt Macy char msg[MAXMSGLEN]; 55*eda14cbcSMatt Macy va_list ap; 56*eda14cbcSMatt Macy 57*eda14cbcSMatt Macy newfile = strrchr(file, '/'); 58*eda14cbcSMatt Macy if (newfile != NULL) 59*eda14cbcSMatt Macy newfile = newfile + 1; 60*eda14cbcSMatt Macy else 61*eda14cbcSMatt Macy newfile = file; 62*eda14cbcSMatt Macy 63*eda14cbcSMatt Macy va_start(ap, fmt); 64*eda14cbcSMatt Macy (void) vsnprintf(msg, sizeof (msg), fmt, ap); 65*eda14cbcSMatt Macy va_end(ap); 66*eda14cbcSMatt Macy 67*eda14cbcSMatt Macy printk(KERN_EMERG "%s", msg); 68*eda14cbcSMatt Macy printk(KERN_EMERG "PANIC at %s:%d:%s()\n", newfile, line, func); 69*eda14cbcSMatt Macy if (spl_panic_halt) 70*eda14cbcSMatt Macy panic("%s", msg); 71*eda14cbcSMatt Macy 72*eda14cbcSMatt Macy spl_dumpstack(); 73*eda14cbcSMatt Macy 74*eda14cbcSMatt Macy /* Halt the thread to facilitate further debugging */ 75*eda14cbcSMatt Macy set_current_state(TASK_UNINTERRUPTIBLE); 76*eda14cbcSMatt Macy while (1) 77*eda14cbcSMatt Macy schedule(); 78*eda14cbcSMatt Macy 79*eda14cbcSMatt Macy /* Unreachable */ 80*eda14cbcSMatt Macy return (1); 81*eda14cbcSMatt Macy } 82*eda14cbcSMatt Macy EXPORT_SYMBOL(spl_panic); 83*eda14cbcSMatt Macy 84*eda14cbcSMatt Macy void 85*eda14cbcSMatt Macy vcmn_err(int ce, const char *fmt, va_list ap) 86*eda14cbcSMatt Macy { 87*eda14cbcSMatt Macy char msg[MAXMSGLEN]; 88*eda14cbcSMatt Macy 89*eda14cbcSMatt Macy vsnprintf(msg, MAXMSGLEN, fmt, ap); 90*eda14cbcSMatt Macy 91*eda14cbcSMatt Macy switch (ce) { 92*eda14cbcSMatt Macy case CE_IGNORE: 93*eda14cbcSMatt Macy break; 94*eda14cbcSMatt Macy case CE_CONT: 95*eda14cbcSMatt Macy printk("%s", msg); 96*eda14cbcSMatt Macy break; 97*eda14cbcSMatt Macy case CE_NOTE: 98*eda14cbcSMatt Macy printk(KERN_NOTICE "NOTICE: %s\n", msg); 99*eda14cbcSMatt Macy break; 100*eda14cbcSMatt Macy case CE_WARN: 101*eda14cbcSMatt Macy printk(KERN_WARNING "WARNING: %s\n", msg); 102*eda14cbcSMatt Macy break; 103*eda14cbcSMatt Macy case CE_PANIC: 104*eda14cbcSMatt Macy printk(KERN_EMERG "PANIC: %s\n", msg); 105*eda14cbcSMatt Macy spl_dumpstack(); 106*eda14cbcSMatt Macy 107*eda14cbcSMatt Macy /* Halt the thread to facilitate further debugging */ 108*eda14cbcSMatt Macy set_current_state(TASK_UNINTERRUPTIBLE); 109*eda14cbcSMatt Macy while (1) 110*eda14cbcSMatt Macy schedule(); 111*eda14cbcSMatt Macy } 112*eda14cbcSMatt Macy } /* vcmn_err() */ 113*eda14cbcSMatt Macy EXPORT_SYMBOL(vcmn_err); 114*eda14cbcSMatt Macy 115*eda14cbcSMatt Macy void 116*eda14cbcSMatt Macy cmn_err(int ce, const char *fmt, ...) 117*eda14cbcSMatt Macy { 118*eda14cbcSMatt Macy va_list ap; 119*eda14cbcSMatt Macy 120*eda14cbcSMatt Macy va_start(ap, fmt); 121*eda14cbcSMatt Macy vcmn_err(ce, fmt, ap); 122*eda14cbcSMatt Macy va_end(ap); 123*eda14cbcSMatt Macy } /* cmn_err() */ 124*eda14cbcSMatt Macy EXPORT_SYMBOL(cmn_err); 125