1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef BTRFS_MESSAGES_H
4 #define BTRFS_MESSAGES_H
6 #include <linux/types.h>
7 #include <linux/printk.h>
13 * We want to be able to override this in btrfs-progs.
17 static inline __printf(2, 3) __cold
18 void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
26 #define btrfs_printk(fs_info, fmt, args...) \
27 _btrfs_printk(fs_info, fmt, ##args)
31 void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
35 #define btrfs_printk(fs_info, fmt, args...) \
36 btrfs_no_printk(fs_info, fmt, ##args)
39 #define btrfs_emerg(fs_info, fmt, args...) \
40 btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
41 #define btrfs_alert(fs_info, fmt, args...) \
42 btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
43 #define btrfs_crit(fs_info, fmt, args...) \
44 btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
45 #define btrfs_err(fs_info, fmt, args...) \
46 btrfs_printk(fs_info, KERN_ERR fmt, ##args)
47 #define btrfs_warn(fs_info, fmt, args...) \
48 btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
49 #define btrfs_notice(fs_info, fmt, args...) \
50 btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
51 #define btrfs_info(fs_info, fmt, args...) \
52 btrfs_printk(fs_info, KERN_INFO fmt, ##args)
55 * Wrappers that use printk_in_rcu
57 #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
58 btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
59 #define btrfs_alert_in_rcu(fs_info, fmt, args...) \
60 btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
61 #define btrfs_crit_in_rcu(fs_info, fmt, args...) \
62 btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
63 #define btrfs_err_in_rcu(fs_info, fmt, args...) \
64 btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
65 #define btrfs_warn_in_rcu(fs_info, fmt, args...) \
66 btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
67 #define btrfs_notice_in_rcu(fs_info, fmt, args...) \
68 btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
69 #define btrfs_info_in_rcu(fs_info, fmt, args...) \
70 btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
73 * Wrappers that use a ratelimited printk_in_rcu
75 #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
76 btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
77 #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
78 btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
79 #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
80 btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
81 #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
82 btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
83 #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
84 btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
85 #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
86 btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
87 #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
88 btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
91 * Wrappers that use a ratelimited printk
93 #define btrfs_emerg_rl(fs_info, fmt, args...) \
94 btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
95 #define btrfs_alert_rl(fs_info, fmt, args...) \
96 btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
97 #define btrfs_crit_rl(fs_info, fmt, args...) \
98 btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
99 #define btrfs_err_rl(fs_info, fmt, args...) \
100 btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
101 #define btrfs_warn_rl(fs_info, fmt, args...) \
102 btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
103 #define btrfs_notice_rl(fs_info, fmt, args...) \
104 btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
105 #define btrfs_info_rl(fs_info, fmt, args...) \
106 btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
108 #if defined(CONFIG_DYNAMIC_DEBUG)
109 #define btrfs_debug(fs_info, fmt, args...) \
110 _dynamic_func_call_no_desc(fmt, btrfs_printk, \
111 fs_info, KERN_DEBUG fmt, ##args)
112 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
113 _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \
114 fs_info, KERN_DEBUG fmt, ##args)
115 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
116 _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \
117 fs_info, KERN_DEBUG fmt, ##args)
118 #define btrfs_debug_rl(fs_info, fmt, args...) \
119 _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \
120 fs_info, KERN_DEBUG fmt, ##args)
122 #define btrfs_debug(fs_info, fmt, args...) \
123 btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
124 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
125 btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
126 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
127 btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
128 #define btrfs_debug_rl(fs_info, fmt, args...) \
129 btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
131 #define btrfs_debug(fs_info, fmt, args...) \
132 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
133 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
134 btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
135 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
136 btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
137 #define btrfs_debug_rl(fs_info, fmt, args...) \
138 btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
141 #define btrfs_printk_in_rcu(fs_info, fmt, args...) \
144 btrfs_printk(fs_info, fmt, ##args); \
148 #define btrfs_no_printk_in_rcu(fs_info, fmt, args...) \
151 btrfs_no_printk(fs_info, fmt, ##args); \
155 #define btrfs_printk_ratelimited(fs_info, fmt, args...) \
157 static DEFINE_RATELIMIT_STATE(_rs, \
158 DEFAULT_RATELIMIT_INTERVAL, \
159 DEFAULT_RATELIMIT_BURST); \
160 if (__ratelimit(&_rs)) \
161 btrfs_printk(fs_info, fmt, ##args); \
164 #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \
167 btrfs_printk_ratelimited(fs_info, fmt, ##args); \
171 #ifdef CONFIG_BTRFS_ASSERT
173 #define btrfs_assertfail(expr, file, line) ({ \
174 pr_err("assertion failed: %s, in %s:%d\n", (expr), (file), (line)); \
178 #define ASSERT(expr) \
179 (likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__))
181 #define ASSERT(expr) (void)(expr)
186 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
187 unsigned int line, int errno, const char *fmt, ...);
189 const char * __attribute_const__ btrfs_decode_error(int errno);
191 #define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \
192 __btrfs_handle_fs_error((fs_info), __func__, __LINE__, \
193 (errno), fmt, ##args)
197 void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
198 unsigned int line, int errno, const char *fmt, ...);
200 * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
201 * will panic(). Otherwise we BUG() here.
203 #define btrfs_panic(fs_info, errno, fmt, args...) \
205 __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \
209 #if BITS_PER_LONG == 32
210 #define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT)
212 * The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical
213 * addresses of extents.
215 * For 4K page size it's about 10T, for 64K it's 160T.
217 #define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8)
218 void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info);
219 void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info);