mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-02 00:24:12 +08:00
b831306b3b
Assertions reports are split into two parts, the exact file and location of the condition and then the stack trace printed from btrfs_assertfail(). This means all the stack traces report the same line and this is what's typically reported by various tools, making it harder to distinguish the reports. [403.2467] assertion failed: refcount_read(&block_group->refs) == 1, in fs/btrfs/block-group.c:4259 [403.2479] ------------[ cut here ]------------ [403.2484] kernel BUG at fs/btrfs/messages.c:259! [403.2488] invalid opcode: 0000 [#1] PREEMPT SMP KASAN [403.2493] CPU: 2 PID: 23202 Comm: umount Not tainted 6.2.0-rc4-default+ #67 [403.2499] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552-rebuilt.opensuse.org 04/01/2014 [403.2509] RIP: 0010:btrfs_assertfail+0x19/0x1b [btrfs] ... [403.2595] Call Trace: [403.2598] <TASK> [403.2601] btrfs_free_block_groups.cold+0x52/0xae [btrfs] [403.2608] close_ctree+0x6c2/0x761 [btrfs] [403.2613] ? __wait_for_common+0x2b8/0x360 [403.2618] ? btrfs_cleanup_one_transaction.cold+0x7a/0x7a [btrfs] [403.2626] ? mark_held_locks+0x6b/0x90 [403.2630] ? lockdep_hardirqs_on_prepare+0x13d/0x200 [403.2636] ? __call_rcu_common.constprop.0+0x1ea/0x3d0 [403.2642] ? trace_hardirqs_on+0x2d/0x110 [403.2646] ? __call_rcu_common.constprop.0+0x1ea/0x3d0 [403.2652] generic_shutdown_super+0xb0/0x1c0 [403.2657] kill_anon_super+0x1e/0x40 [403.2662] btrfs_kill_super+0x25/0x30 [btrfs] [403.2668] deactivate_locked_super+0x4c/0xc0 By making btrfs_assertfail a macro we'll get the same line number for the BUG output: [63.5736] assertion failed: 0, in fs/btrfs/super.c:1572 [63.5758] ------------[ cut here ]------------ [63.5782] kernel BUG at fs/btrfs/super.c:1572! [63.5807] invalid opcode: 0000 [#2] PREEMPT SMP KASAN [63.5831] CPU: 0 PID: 859 Comm: mount Tainted: G D 6.3.0-rc7-default+ #2062 [63.5868] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a-rebuilt.opensuse.org 04/01/2014 [63.5905] RIP: 0010:btrfs_mount+0x24/0x30 [btrfs] [63.5964] RSP: 0018:ffff88800e69fcd8 EFLAGS: 00010246 [63.5982] RAX: 000000000000002d RBX: ffff888008fc1400 RCX: 0000000000000000 [63.6004] RDX: 0000000000000000 RSI: ffffffffb90fd868 RDI: ffffffffbcc3ff20 [63.6026] RBP: ffffffffc081b200 R08: 0000000000000001 R09: ffff88800e69fa27 [63.6046] R10: ffffed1001cd3f44 R11: 0000000000000001 R12: ffff888005a3c370 [63.6062] R13: ffffffffc058e830 R14: 0000000000000000 R15: 00000000ffffffff [63.6081] FS: 00007f7b3561f800(0000) GS:ffff88806c600000(0000) knlGS:0000000000000000 [63.6105] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [63.6120] CR2: 00007fff83726e10 CR3: 0000000002a9e000 CR4: 00000000000006b0 [63.6137] Call Trace: [63.6143] <TASK> [63.6148] legacy_get_tree+0x80/0xd0 [63.6158] vfs_get_tree+0x43/0x120 [63.6166] do_new_mount+0x1f3/0x3d0 [63.6176] ? do_add_mount+0x140/0x140 [63.6187] ? cap_capable+0xa4/0xe0 [63.6197] path_mount+0x223/0xc10 This comes at a cost of bloating the final btrfs.ko module due all the inlining, as long as assertions are compiled in. This is a must for debugging builds but this is often enabled on release builds too. Release build: text data bss dec hex filename 1251676 20317 16088 1288081 13a791 pre/btrfs.ko 1260612 29473 16088 1306173 13ee3d post/btrfs.ko DELTA: +8936 CC: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: David Sterba <dsterba@suse.com>
225 lines
7.5 KiB
C
225 lines
7.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef BTRFS_MESSAGES_H
|
|
#define BTRFS_MESSAGES_H
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/printk.h>
|
|
#include <linux/bug.h>
|
|
|
|
struct btrfs_fs_info;
|
|
|
|
/*
|
|
* We want to be able to override this in btrfs-progs.
|
|
*/
|
|
#ifdef __KERNEL__
|
|
|
|
static inline __printf(2, 3) __cold
|
|
void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
|
|
{
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PRINTK
|
|
|
|
#define btrfs_printk(fs_info, fmt, args...) \
|
|
_btrfs_printk(fs_info, fmt, ##args)
|
|
|
|
__printf(2, 3)
|
|
__cold
|
|
void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
|
|
|
|
#else
|
|
|
|
#define btrfs_printk(fs_info, fmt, args...) \
|
|
btrfs_no_printk(fs_info, fmt, ##args)
|
|
#endif
|
|
|
|
#define btrfs_emerg(fs_info, fmt, args...) \
|
|
btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
|
|
#define btrfs_alert(fs_info, fmt, args...) \
|
|
btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
|
|
#define btrfs_crit(fs_info, fmt, args...) \
|
|
btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
|
|
#define btrfs_err(fs_info, fmt, args...) \
|
|
btrfs_printk(fs_info, KERN_ERR fmt, ##args)
|
|
#define btrfs_warn(fs_info, fmt, args...) \
|
|
btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
|
|
#define btrfs_notice(fs_info, fmt, args...) \
|
|
btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
|
|
#define btrfs_info(fs_info, fmt, args...) \
|
|
btrfs_printk(fs_info, KERN_INFO fmt, ##args)
|
|
|
|
/*
|
|
* Wrappers that use printk_in_rcu
|
|
*/
|
|
#define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
|
|
#define btrfs_alert_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
|
|
#define btrfs_crit_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
|
|
#define btrfs_err_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
|
|
#define btrfs_warn_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
|
|
#define btrfs_notice_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
|
|
#define btrfs_info_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
|
|
|
|
/*
|
|
* Wrappers that use a ratelimited printk_in_rcu
|
|
*/
|
|
#define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
|
|
#define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
|
|
#define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
|
|
#define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
|
|
#define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
|
|
#define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
|
|
#define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
|
|
|
|
/*
|
|
* Wrappers that use a ratelimited printk
|
|
*/
|
|
#define btrfs_emerg_rl(fs_info, fmt, args...) \
|
|
btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
|
|
#define btrfs_alert_rl(fs_info, fmt, args...) \
|
|
btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
|
|
#define btrfs_crit_rl(fs_info, fmt, args...) \
|
|
btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
|
|
#define btrfs_err_rl(fs_info, fmt, args...) \
|
|
btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
|
|
#define btrfs_warn_rl(fs_info, fmt, args...) \
|
|
btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
|
|
#define btrfs_notice_rl(fs_info, fmt, args...) \
|
|
btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
|
|
#define btrfs_info_rl(fs_info, fmt, args...) \
|
|
btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
|
|
|
|
#if defined(CONFIG_DYNAMIC_DEBUG)
|
|
#define btrfs_debug(fs_info, fmt, args...) \
|
|
_dynamic_func_call_no_desc(fmt, btrfs_printk, \
|
|
fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
|
|
_dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \
|
|
fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
|
|
_dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \
|
|
fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_rl(fs_info, fmt, args...) \
|
|
_dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \
|
|
fs_info, KERN_DEBUG fmt, ##args)
|
|
#elif defined(DEBUG)
|
|
#define btrfs_debug(fs_info, fmt, args...) \
|
|
btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_rl(fs_info, fmt, args...) \
|
|
btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
|
|
#else
|
|
#define btrfs_debug(fs_info, fmt, args...) \
|
|
btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
|
|
btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
|
|
#define btrfs_debug_rl(fs_info, fmt, args...) \
|
|
btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
|
|
#endif
|
|
|
|
#define btrfs_printk_in_rcu(fs_info, fmt, args...) \
|
|
do { \
|
|
rcu_read_lock(); \
|
|
btrfs_printk(fs_info, fmt, ##args); \
|
|
rcu_read_unlock(); \
|
|
} while (0)
|
|
|
|
#define btrfs_no_printk_in_rcu(fs_info, fmt, args...) \
|
|
do { \
|
|
rcu_read_lock(); \
|
|
btrfs_no_printk(fs_info, fmt, ##args); \
|
|
rcu_read_unlock(); \
|
|
} while (0)
|
|
|
|
#define btrfs_printk_ratelimited(fs_info, fmt, args...) \
|
|
do { \
|
|
static DEFINE_RATELIMIT_STATE(_rs, \
|
|
DEFAULT_RATELIMIT_INTERVAL, \
|
|
DEFAULT_RATELIMIT_BURST); \
|
|
if (__ratelimit(&_rs)) \
|
|
btrfs_printk(fs_info, fmt, ##args); \
|
|
} while (0)
|
|
|
|
#define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \
|
|
do { \
|
|
rcu_read_lock(); \
|
|
btrfs_printk_ratelimited(fs_info, fmt, ##args); \
|
|
rcu_read_unlock(); \
|
|
} while (0)
|
|
|
|
#ifdef CONFIG_BTRFS_ASSERT
|
|
|
|
#define btrfs_assertfail(expr, file, line) ({ \
|
|
pr_err("assertion failed: %s, in %s:%d\n", (expr), (file), (line)); \
|
|
BUG(); \
|
|
})
|
|
|
|
#define ASSERT(expr) \
|
|
(likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__))
|
|
#else
|
|
#define ASSERT(expr) (void)(expr)
|
|
#endif
|
|
|
|
void __cold btrfs_print_v0_err(struct btrfs_fs_info *fs_info);
|
|
|
|
__printf(5, 6)
|
|
__cold
|
|
void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
|
|
unsigned int line, int errno, const char *fmt, ...);
|
|
|
|
const char * __attribute_const__ btrfs_decode_error(int errno);
|
|
|
|
#define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \
|
|
__btrfs_handle_fs_error((fs_info), __func__, __LINE__, \
|
|
(errno), fmt, ##args)
|
|
|
|
__printf(5, 6)
|
|
__cold
|
|
void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
|
|
unsigned int line, int errno, const char *fmt, ...);
|
|
/*
|
|
* If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
|
|
* will panic(). Otherwise we BUG() here.
|
|
*/
|
|
#define btrfs_panic(fs_info, errno, fmt, args...) \
|
|
do { \
|
|
__btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \
|
|
BUG(); \
|
|
} while (0)
|
|
|
|
#if BITS_PER_LONG == 32
|
|
#define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT)
|
|
/*
|
|
* The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical
|
|
* addresses of extents.
|
|
*
|
|
* For 4K page size it's about 10T, for 64K it's 160T.
|
|
*/
|
|
#define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8)
|
|
void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info);
|
|
void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info);
|
|
#endif
|
|
|
|
#endif
|