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