110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner/* 210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * Copyright (c) 2011 Red Hat, Inc. All Rights Reserved. 310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * 410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * This program is free software; you can redistribute it and/or 510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * modify it under the terms of the GNU General Public License as 610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * published by the Free Software Foundation. 710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * 810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * This program is distributed in the hope that it would be useful, 910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * but WITHOUT ANY WARRANTY; without even the implied warranty of 1010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * GNU General Public License for more details. 1210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * 1310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * You should have received a copy of the GNU General Public License 1410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * along with this program; if not, write the Free Software Foundation, 1510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 1610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner */ 1710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 1810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs.h" 1910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_fs.h" 20239880ef6454ccff2ba8d762c3f86e8278f0ce1cDave Chinner#include "xfs_log_format.h" 21239880ef6454ccff2ba8d762c3f86e8278f0ce1cDave Chinner#include "xfs_trans_resv.h" 2210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_sb.h" 2310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_ag.h" 2410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#include "xfs_mount.h" 2510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 2610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner/* 2710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner * XFS logging functions 2810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner */ 29957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigstatic void 3010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner__xfs_printk( 3110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner const char *level, 3210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner const struct xfs_mount *mp, 3310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner struct va_format *vaf) 3410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{ 353eff1268994f72266b660782e87f215720c29639Dave Chinner if (mp && mp->m_fsname) { 36957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig printk("%sXFS (%s): %pV\n", level, mp->m_fsname, vaf); 373eff1268994f72266b660782e87f215720c29639Dave Chinner return; 383eff1268994f72266b660782e87f215720c29639Dave Chinner } 39957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig printk("%sXFS: %pV\n", level, vaf); 4010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner} 4110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 4210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#define define_xfs_printk_level(func, kern_level) \ 43957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigvoid func(const struct xfs_mount *mp, const char *fmt, ...) \ 4410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{ \ 4510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner struct va_format vaf; \ 4610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner va_list args; \ 4710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner \ 4810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner va_start(args, fmt); \ 4910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner \ 5010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner vaf.fmt = fmt; \ 5110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner vaf.va = &args; \ 5210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner \ 53957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig __xfs_printk(kern_level, mp, &vaf); \ 5410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner va_end(args); \ 5510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner} \ 5610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 5710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_emerg, KERN_EMERG); 5810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_alert, KERN_ALERT); 5910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_crit, KERN_CRIT); 6010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_err, KERN_ERR); 6110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_warn, KERN_WARNING); 6210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_notice, KERN_NOTICE); 6310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_info, KERN_INFO); 6410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#ifdef DEBUG 6510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerdefine_xfs_printk_level(xfs_debug, KERN_DEBUG); 6610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner#endif 6710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 68957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwigvoid 6910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinnerxfs_alert_tag( 7010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner const struct xfs_mount *mp, 7110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner int panic_tag, 7210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner const char *fmt, ...) 7310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner{ 7410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner struct va_format vaf; 7510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner va_list args; 760c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder int do_panic = 0; 7710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 7810e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) { 79e69522a8cc51fbefbfe9d178ad177f7b6ca00ebdJoe Perches xfs_alert(mp, "Transforming an alert into a BUG."); 800c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder do_panic = 1; 8110e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner } 8210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 8310e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner va_start(args, fmt); 8410e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 8510e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner vaf.fmt = fmt; 8610e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner vaf.va = &args; 8710e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 88957935dcd8e11d6f789b4ed769b376040e15565bChristoph Hellwig __xfs_printk(KERN_ALERT, mp, &vaf); 8910e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner va_end(args); 9010e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner 910c9ba97318fc9a905bcc1419b6966de061203a70Alex Elder BUG_ON(do_panic); 9210e38391c0e242e53e30094f6c00553418ab2f2eDave Chinner} 939130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner 949130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnervoid 95742ae1e35b038ed65ddd86182723441ea74db765Dave Chinnerasswarn(char *expr, char *file, int line) 96742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner{ 97742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner xfs_warn(NULL, "Assertion failed: %s, file: %s, line: %d", 98742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner expr, file, line); 99742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner WARN_ON(1); 100742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner} 101742ae1e35b038ed65ddd86182723441ea74db765Dave Chinner 102742ae1e35b038ed65ddd86182723441ea74db765Dave Chinnervoid 1039130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnerassfail(char *expr, char *file, int line) 1049130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner{ 1059130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner xfs_emerg(NULL, "Assertion failed: %s, file: %s, line: %d", 1069130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner expr, file, line); 1079130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner BUG(); 1089130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner} 1099130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner 1109130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnervoid 1119130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinnerxfs_hex_dump(void *p, int length) 1129130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner{ 1139130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_ADDRESS, 16, 1, p, length, 1); 1149130090b5f04f7e7bc29b944e0b1ba494fff3f98Dave Chinner} 115