1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef BTRFS_MESSAGES_H
4 #define BTRFS_MESSAGES_H
6 #include <linux/types.h>
9 struct btrfs_trans_handle;
11 static inline __printf(2, 3) __cold
12 void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
18 #define btrfs_printk(fs_info, fmt, args...) \
19 _btrfs_printk(fs_info, fmt, ##args)
23 void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
27 #define btrfs_printk(fs_info, fmt, args...) \
28 btrfs_no_printk(fs_info, fmt, ##args)
31 #define btrfs_emerg(fs_info, fmt, args...) \
32 btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
33 #define btrfs_alert(fs_info, fmt, args...) \
34 btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
35 #define btrfs_crit(fs_info, fmt, args...) \
36 btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
37 #define btrfs_err(fs_info, fmt, args...) \
38 btrfs_printk(fs_info, KERN_ERR fmt, ##args)
39 #define btrfs_warn(fs_info, fmt, args...) \
40 btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
41 #define btrfs_notice(fs_info, fmt, args...) \
42 btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
43 #define btrfs_info(fs_info, fmt, args...) \
44 btrfs_printk(fs_info, KERN_INFO fmt, ##args)
47 * Wrappers that use printk_in_rcu
49 #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
50 btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
51 #define btrfs_alert_in_rcu(fs_info, fmt, args...) \
52 btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
53 #define btrfs_crit_in_rcu(fs_info, fmt, args...) \
54 btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
55 #define btrfs_err_in_rcu(fs_info, fmt, args...) \
56 btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
57 #define btrfs_warn_in_rcu(fs_info, fmt, args...) \
58 btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
59 #define btrfs_notice_in_rcu(fs_info, fmt, args...) \
60 btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
61 #define btrfs_info_in_rcu(fs_info, fmt, args...) \
62 btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
65 * Wrappers that use a ratelimited printk_in_rcu
67 #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
68 btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
69 #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
70 btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
71 #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
72 btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
73 #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
74 btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
75 #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
76 btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
77 #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
78 btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
79 #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
80 btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
83 * Wrappers that use a ratelimited printk
85 #define btrfs_emerg_rl(fs_info, fmt, args...) \
86 btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
87 #define btrfs_alert_rl(fs_info, fmt, args...) \
88 btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
89 #define btrfs_crit_rl(fs_info, fmt, args...) \
90 btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
91 #define btrfs_err_rl(fs_info, fmt, args...) \
92 btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
93 #define btrfs_warn_rl(fs_info, fmt, args...) \
94 btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
95 #define btrfs_notice_rl(fs_info, fmt, args...) \
96 btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
97 #define btrfs_info_rl(fs_info, fmt, args...) \
98 btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
100 #if defined(CONFIG_DYNAMIC_DEBUG)
101 #define btrfs_debug(fs_info, fmt, args...) \
102 _dynamic_func_call_no_desc(fmt, btrfs_printk, \
103 fs_info, KERN_DEBUG fmt, ##args)
104 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
105 _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \
106 fs_info, KERN_DEBUG fmt, ##args)
107 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
108 _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \
109 fs_info, KERN_DEBUG fmt, ##args)
110 #define btrfs_debug_rl(fs_info, fmt, args...) \
111 _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \
112 fs_info, KERN_DEBUG fmt, ##args)
114 #define btrfs_debug(fs_info, fmt, args...) \
115 btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
116 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
117 btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
118 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
119 btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
120 #define btrfs_debug_rl(fs_info, fmt, args...) \
121 btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
123 #define btrfs_debug(fs_info, fmt, args...) \
124 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
125 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
126 btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
127 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
128 btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
129 #define btrfs_debug_rl(fs_info, fmt, args...) \
130 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
133 #define btrfs_printk_in_rcu(fs_info, fmt, args...) \
136 btrfs_printk(fs_info, fmt, ##args); \
140 #define btrfs_no_printk_in_rcu(fs_info, fmt, args...) \
143 btrfs_no_printk(fs_info, fmt, ##args); \
147 #define btrfs_printk_ratelimited(fs_info, fmt, args...) \
149 static DEFINE_RATELIMIT_STATE(_rs, \
150 DEFAULT_RATELIMIT_INTERVAL, \
151 DEFAULT_RATELIMIT_BURST); \
152 if (__ratelimit(&_rs)) \
153 btrfs_printk(fs_info, fmt, ##args); \
156 #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \
159 btrfs_printk_ratelimited(fs_info, fmt, ##args); \
163 #ifdef CONFIG_BTRFS_ASSERT
164 void __cold btrfs_assertfail(const char *expr, const char *file, int line);
166 #define ASSERT(expr) \
167 (likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__))
169 #define ASSERT(expr) (void)(expr)
172 void __cold btrfs_print_v0_err(struct btrfs_fs_info *fs_info);
176 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
177 unsigned int line, int errno, const char *fmt, ...);
179 const char * __attribute_const__ btrfs_decode_error(int errno);
182 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
183 const char *function,
184 unsigned int line, int errno, bool first_hit);
186 bool __cold abort_should_print_stack(int errno);
189 * Call btrfs_abort_transaction as early as possible when an error condition is
190 * detected, that way the exact stack trace is reported for some errors.
192 #define btrfs_abort_transaction(trans, errno) \
194 bool first = false; \
195 /* Report first abort since mount */ \
196 if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \
197 &((trans)->fs_info->fs_state))) { \
199 if (WARN(abort_should_print_stack(errno), \
201 "BTRFS: Transaction aborted (error %d)\n", \
203 /* Stack trace printed. */ \
205 btrfs_debug((trans)->fs_info, \
206 "Transaction aborted (error %d)", \
210 __btrfs_abort_transaction((trans), __func__, \
211 __LINE__, (errno), first); \
214 #define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \
215 __btrfs_handle_fs_error((fs_info), __func__, __LINE__, \
216 (errno), fmt, ##args)
220 void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
221 unsigned int line, int errno, const char *fmt, ...);
223 * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
224 * will panic(). Otherwise we BUG() here.
226 #define btrfs_panic(fs_info, errno, fmt, args...) \
228 __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \
232 #if BITS_PER_LONG == 32
233 #define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT)
235 * The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical
236 * addresses of extents.
238 * For 4K page size it's about 10T, for 64K it's 160T.
240 #define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8)
241 void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info);
242 void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info);