xref: /openbmc/linux/fs/btrfs/messages.h (revision 724ba675)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef BTRFS_MESSAGES_H
4 #define BTRFS_MESSAGES_H
5 
6 #include <linux/types.h>
7 
8 struct btrfs_fs_info;
9 
10 static inline __printf(2, 3) __cold
11 void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
12 {
13 }
14 
15 #ifdef CONFIG_PRINTK
16 
17 #define btrfs_printk(fs_info, fmt, args...)				\
18 	_btrfs_printk(fs_info, fmt, ##args)
19 
20 __printf(2, 3)
21 __cold
22 void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
23 
24 #else
25 
26 #define btrfs_printk(fs_info, fmt, args...) \
27 	btrfs_no_printk(fs_info, fmt, ##args)
28 #endif
29 
30 #define btrfs_emerg(fs_info, fmt, args...) \
31 	btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
32 #define btrfs_alert(fs_info, fmt, args...) \
33 	btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
34 #define btrfs_crit(fs_info, fmt, args...) \
35 	btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
36 #define btrfs_err(fs_info, fmt, args...) \
37 	btrfs_printk(fs_info, KERN_ERR fmt, ##args)
38 #define btrfs_warn(fs_info, fmt, args...) \
39 	btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
40 #define btrfs_notice(fs_info, fmt, args...) \
41 	btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
42 #define btrfs_info(fs_info, fmt, args...) \
43 	btrfs_printk(fs_info, KERN_INFO fmt, ##args)
44 
45 /*
46  * Wrappers that use printk_in_rcu
47  */
48 #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
49 	btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
50 #define btrfs_alert_in_rcu(fs_info, fmt, args...) \
51 	btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
52 #define btrfs_crit_in_rcu(fs_info, fmt, args...) \
53 	btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
54 #define btrfs_err_in_rcu(fs_info, fmt, args...) \
55 	btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
56 #define btrfs_warn_in_rcu(fs_info, fmt, args...) \
57 	btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
58 #define btrfs_notice_in_rcu(fs_info, fmt, args...) \
59 	btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
60 #define btrfs_info_in_rcu(fs_info, fmt, args...) \
61 	btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
62 
63 /*
64  * Wrappers that use a ratelimited printk_in_rcu
65  */
66 #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
67 	btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
68 #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
69 	btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
70 #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
71 	btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
72 #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
73 	btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
74 #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
75 	btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
76 #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
77 	btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
78 #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
79 	btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
80 
81 /*
82  * Wrappers that use a ratelimited printk
83  */
84 #define btrfs_emerg_rl(fs_info, fmt, args...) \
85 	btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
86 #define btrfs_alert_rl(fs_info, fmt, args...) \
87 	btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
88 #define btrfs_crit_rl(fs_info, fmt, args...) \
89 	btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
90 #define btrfs_err_rl(fs_info, fmt, args...) \
91 	btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
92 #define btrfs_warn_rl(fs_info, fmt, args...) \
93 	btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
94 #define btrfs_notice_rl(fs_info, fmt, args...) \
95 	btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
96 #define btrfs_info_rl(fs_info, fmt, args...) \
97 	btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
98 
99 #if defined(CONFIG_DYNAMIC_DEBUG)
100 #define btrfs_debug(fs_info, fmt, args...)				\
101 	_dynamic_func_call_no_desc(fmt, btrfs_printk,			\
102 				   fs_info, KERN_DEBUG fmt, ##args)
103 #define btrfs_debug_in_rcu(fs_info, fmt, args...)			\
104 	_dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu,		\
105 				   fs_info, KERN_DEBUG fmt, ##args)
106 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...)			\
107 	_dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu,		\
108 				   fs_info, KERN_DEBUG fmt, ##args)
109 #define btrfs_debug_rl(fs_info, fmt, args...)				\
110 	_dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited,	\
111 				   fs_info, KERN_DEBUG fmt, ##args)
112 #elif defined(DEBUG)
113 #define btrfs_debug(fs_info, fmt, args...) \
114 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
115 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
116 	btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
117 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
118 	btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
119 #define btrfs_debug_rl(fs_info, fmt, args...) \
120 	btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
121 #else
122 #define btrfs_debug(fs_info, fmt, args...) \
123 	btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
124 #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
125 	btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
126 #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
127 	btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
128 #define btrfs_debug_rl(fs_info, fmt, args...) \
129 	btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
130 #endif
131 
132 #define btrfs_printk_in_rcu(fs_info, fmt, args...)	\
133 do {							\
134 	rcu_read_lock();				\
135 	btrfs_printk(fs_info, fmt, ##args);		\
136 	rcu_read_unlock();				\
137 } while (0)
138 
139 #define btrfs_no_printk_in_rcu(fs_info, fmt, args...)	\
140 do {							\
141 	rcu_read_lock();				\
142 	btrfs_no_printk(fs_info, fmt, ##args);		\
143 	rcu_read_unlock();				\
144 } while (0)
145 
146 #define btrfs_printk_ratelimited(fs_info, fmt, args...)		\
147 do {								\
148 	static DEFINE_RATELIMIT_STATE(_rs,			\
149 		DEFAULT_RATELIMIT_INTERVAL,			\
150 		DEFAULT_RATELIMIT_BURST);			\
151 	if (__ratelimit(&_rs))					\
152 		btrfs_printk(fs_info, fmt, ##args);		\
153 } while (0)
154 
155 #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...)		\
156 do {								\
157 	rcu_read_lock();					\
158 	btrfs_printk_ratelimited(fs_info, fmt, ##args);		\
159 	rcu_read_unlock();					\
160 } while (0)
161 
162 #ifdef CONFIG_BTRFS_ASSERT
163 void __cold __noreturn btrfs_assertfail(const char *expr, const char *file, int line);
164 
165 #define ASSERT(expr)						\
166 	(likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__))
167 #else
168 #define ASSERT(expr)	(void)(expr)
169 #endif
170 
171 void __cold btrfs_print_v0_err(struct btrfs_fs_info *fs_info);
172 
173 __printf(5, 6)
174 __cold
175 void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
176 		     unsigned int line, int errno, const char *fmt, ...);
177 
178 const char * __attribute_const__ btrfs_decode_error(int errno);
179 
180 #define btrfs_handle_fs_error(fs_info, errno, fmt, args...)		\
181 	__btrfs_handle_fs_error((fs_info), __func__, __LINE__,		\
182 				(errno), fmt, ##args)
183 
184 __printf(5, 6)
185 __cold
186 void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
187 		   unsigned int line, int errno, const char *fmt, ...);
188 /*
189  * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
190  * will panic().  Otherwise we BUG() here.
191  */
192 #define btrfs_panic(fs_info, errno, fmt, args...)			\
193 do {									\
194 	__btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args);	\
195 	BUG();								\
196 } while (0)
197 
198 #if BITS_PER_LONG == 32
199 #define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT)
200 /*
201  * The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical
202  * addresses of extents.
203  *
204  * For 4K page size it's about 10T, for 64K it's 160T.
205  */
206 #define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8)
207 void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info);
208 void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info);
209 #endif
210 
211 #endif
212