Path: blob/main/sys/contrib/openzfs/module/os/linux/spl/spl-err.c
48775 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.3* Copyright (C) 2007 The Regents of the University of California.4* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).5* Written by Brian Behlendorf <[email protected]>.6* UCRL-CODE-2351977*8* This file is part of the SPL, Solaris Porting Layer.9*10* The SPL is free software; you can redistribute it and/or modify it11* under the terms of the GNU General Public License as published by the12* Free Software Foundation; either version 2 of the License, or (at your13* option) any later version.14*15* The SPL is distributed in the hope that it will be useful, but WITHOUT16* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or17* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License18* for more details.19*20* You should have received a copy of the GNU General Public License along21* with the SPL. If not, see <http://www.gnu.org/licenses/>.22*23* Solaris Porting Layer (SPL) Error Implementation.24*/2526#include <sys/sysmacros.h>27#include <sys/cmn_err.h>2829/*30* It is often useful to actually have the panic crash the node so you31* can then get notified of the event, get the crashdump for later32* analysis and other such goodies.33* But we would still default to the current default of not to do that.34*/35static unsigned int spl_panic_halt;36module_param(spl_panic_halt, uint, 0644);37MODULE_PARM_DESC(spl_panic_halt, "Cause kernel panic on assertion failures");3839void40spl_dumpstack(void)41{42printk("Showing stack for process %d\n", current->pid);43dump_stack();44}45EXPORT_SYMBOL(spl_dumpstack);4647void48spl_panic(const char *file, const char *func, int line, const char *fmt, ...)49{50const char *newfile;51char msg[MAXMSGLEN];52va_list ap;5354newfile = strrchr(file, '/');55if (newfile != NULL)56newfile = newfile + 1;57else58newfile = file;5960va_start(ap, fmt);61(void) vsnprintf(msg, sizeof (msg), fmt, ap);62va_end(ap);6364printk(KERN_EMERG "%s", msg);65printk(KERN_EMERG "PANIC at %s:%d:%s()\n", newfile, line, func);66if (spl_panic_halt)67panic("%s", msg);6869spl_dumpstack();7071/* Halt the thread to facilitate further debugging */72set_current_state(TASK_UNINTERRUPTIBLE);73while (1)74schedule();7576/* Unreachable */77}78EXPORT_SYMBOL(spl_panic);7980void81vcmn_err(int ce, const char *fmt, va_list ap)82{83char msg[MAXMSGLEN];8485vsnprintf(msg, MAXMSGLEN, fmt, ap);8687switch (ce) {88case CE_IGNORE:89break;90case CE_CONT:91printk("%s", msg);92break;93case CE_NOTE:94printk(KERN_NOTICE "NOTICE: %s\n", msg);95break;96case CE_WARN:97printk(KERN_WARNING "WARNING: %s\n", msg);98break;99case CE_PANIC:100printk(KERN_EMERG "PANIC: %s\n", msg);101if (spl_panic_halt)102panic("%s", msg);103104spl_dumpstack();105106/* Halt the thread to facilitate further debugging */107set_current_state(TASK_UNINTERRUPTIBLE);108while (1)109schedule();110}111} /* vcmn_err() */112EXPORT_SYMBOL(vcmn_err);113114void115cmn_err(int ce, const char *fmt, ...)116{117va_list ap;118119va_start(ap, fmt);120vcmn_err(ce, fmt, ap);121va_end(ap);122} /* cmn_err() */123EXPORT_SYMBOL(cmn_err);124125126