xref: /openbmc/linux/fs/btrfs/messages.h (revision 182741d2)
19b569ea0SJosef Bacik /* SPDX-License-Identifier: GPL-2.0 */
29b569ea0SJosef Bacik 
39b569ea0SJosef Bacik #ifndef BTRFS_MESSAGES_H
49b569ea0SJosef Bacik #define BTRFS_MESSAGES_H
59b569ea0SJosef Bacik 
69b569ea0SJosef Bacik #include <linux/types.h>
7*b831306bSDavid Sterba #include <linux/printk.h>
8*b831306bSDavid Sterba #include <linux/bug.h>
99b569ea0SJosef Bacik 
109b569ea0SJosef Bacik struct btrfs_fs_info;
119b569ea0SJosef Bacik 
12a95b7f93SJosef Bacik /*
13a95b7f93SJosef Bacik  * We want to be able to override this in btrfs-progs.
14a95b7f93SJosef Bacik  */
15a95b7f93SJosef Bacik #ifdef __KERNEL__
16a95b7f93SJosef Bacik 
179b569ea0SJosef Bacik static inline __printf(2, 3) __cold
btrfs_no_printk(const struct btrfs_fs_info * fs_info,const char * fmt,...)189b569ea0SJosef Bacik void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
199b569ea0SJosef Bacik {
209b569ea0SJosef Bacik }
219b569ea0SJosef Bacik 
22a95b7f93SJosef Bacik #endif
23a95b7f93SJosef Bacik 
24bbde07a4SJosef Bacik #ifdef CONFIG_PRINTK
259b569ea0SJosef Bacik 
269b569ea0SJosef Bacik #define btrfs_printk(fs_info, fmt, args...)				\
279b569ea0SJosef Bacik 	_btrfs_printk(fs_info, fmt, ##args)
289b569ea0SJosef Bacik 
299b569ea0SJosef Bacik __printf(2, 3)
309b569ea0SJosef Bacik __cold
319b569ea0SJosef Bacik void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
329b569ea0SJosef Bacik 
339b569ea0SJosef Bacik #else
349b569ea0SJosef Bacik 
359b569ea0SJosef Bacik #define btrfs_printk(fs_info, fmt, args...) \
369b569ea0SJosef Bacik 	btrfs_no_printk(fs_info, fmt, ##args)
379b569ea0SJosef Bacik #endif
389b569ea0SJosef Bacik 
399b569ea0SJosef Bacik #define btrfs_emerg(fs_info, fmt, args...) \
409b569ea0SJosef Bacik 	btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
419b569ea0SJosef Bacik #define btrfs_alert(fs_info, fmt, args...) \
429b569ea0SJosef Bacik 	btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
439b569ea0SJosef Bacik #define btrfs_crit(fs_info, fmt, args...) \
449b569ea0SJosef Bacik 	btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
459b569ea0SJosef Bacik #define btrfs_err(fs_info, fmt, args...) \
469b569ea0SJosef Bacik 	btrfs_printk(fs_info, KERN_ERR fmt, ##args)
479b569ea0SJosef Bacik #define btrfs_warn(fs_info, fmt, args...) \
489b569ea0SJosef Bacik 	btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
499b569ea0SJosef Bacik #define btrfs_notice(fs_info, fmt, args...) \
509b569ea0SJosef Bacik 	btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
519b569ea0SJosef Bacik #define btrfs_info(fs_info, fmt, args...) \
529b569ea0SJosef Bacik 	btrfs_printk(fs_info, KERN_INFO fmt, ##args)
539b569ea0SJosef Bacik 
549b569ea0SJosef Bacik /*
559b569ea0SJosef Bacik  * Wrappers that use printk_in_rcu
569b569ea0SJosef Bacik  */
579b569ea0SJosef Bacik #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
589b569ea0SJosef Bacik 	btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
599b569ea0SJosef Bacik #define btrfs_alert_in_rcu(fs_info, fmt, args...) \
609b569ea0SJosef Bacik 	btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
619b569ea0SJosef Bacik #define btrfs_crit_in_rcu(fs_info, fmt, args...) \
629b569ea0SJosef Bacik 	btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
639b569ea0SJosef Bacik #define btrfs_err_in_rcu(fs_info, fmt, args...) \
649b569ea0SJosef Bacik 	btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
659b569ea0SJosef Bacik #define btrfs_warn_in_rcu(fs_info, fmt, args...) \
669b569ea0SJosef Bacik 	btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
679b569ea0SJosef Bacik #define btrfs_notice_in_rcu(fs_info, fmt, args...) \
689b569ea0SJosef Bacik 	btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
699b569ea0SJosef Bacik #define btrfs_info_in_rcu(fs_info, fmt, args...) \
709b569ea0SJosef Bacik 	btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
719b569ea0SJosef Bacik 
729b569ea0SJosef Bacik /*
739b569ea0SJosef Bacik  * Wrappers that use a ratelimited printk_in_rcu
749b569ea0SJosef Bacik  */
759b569ea0SJosef Bacik #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
769b569ea0SJosef Bacik 	btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
779b569ea0SJosef Bacik #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
789b569ea0SJosef Bacik 	btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
799b569ea0SJosef Bacik #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
809b569ea0SJosef Bacik 	btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
819b569ea0SJosef Bacik #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
829b569ea0SJosef Bacik 	btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
839b569ea0SJosef Bacik #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
849b569ea0SJosef Bacik 	btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
859b569ea0SJosef Bacik #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
869b569ea0SJosef Bacik 	btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
879b569ea0SJosef Bacik #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
889b569ea0SJosef Bacik 	btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
899b569ea0SJosef Bacik 
909b569ea0SJosef Bacik /*
919b569ea0SJosef Bacik  * Wrappers that use a ratelimited printk
929b569ea0SJosef Bacik  */
939b569ea0SJosef Bacik #define btrfs_emerg_rl(fs_info, fmt, args...) \
949b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
959b569ea0SJosef Bacik #define btrfs_alert_rl(fs_info, fmt, args...) \
969b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
979b569ea0SJosef Bacik #define btrfs_crit_rl(fs_info, fmt, args...) \
989b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
999b569ea0SJosef Bacik #define btrfs_err_rl(fs_info, fmt, args...) \
1009b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
1019b569ea0SJosef Bacik #define btrfs_warn_rl(fs_info, fmt, args...) \
1029b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
1039b569ea0SJosef Bacik #define btrfs_notice_rl(fs_info, fmt, args...) \
1049b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
1059b569ea0SJosef Bacik #define btrfs_info_rl(fs_info, fmt, args...) \
1069b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
1079b569ea0SJosef Bacik 
1089b569ea0SJosef Bacik #if defined(CONFIG_DYNAMIC_DEBUG)
1099b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...)				\
1109b569ea0SJosef Bacik 	_dynamic_func_call_no_desc(fmt, btrfs_printk,			\
1119b569ea0SJosef Bacik 				   fs_info, KERN_DEBUG fmt, ##args)
1129b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...)			\
1139b569ea0SJosef Bacik 	_dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu,		\
1149b569ea0SJosef Bacik 				   fs_info, KERN_DEBUG fmt, ##args)
1159b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...)			\
1169b569ea0SJosef Bacik 	_dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu,		\
1179b569ea0SJosef Bacik 				   fs_info, KERN_DEBUG fmt, ##args)
1189b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...)				\
1199b569ea0SJosef Bacik 	_dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited,	\
1209b569ea0SJosef Bacik 				   fs_info, KERN_DEBUG fmt, ##args)
1219b569ea0SJosef Bacik #elif defined(DEBUG)
1229b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...) \
1239b569ea0SJosef Bacik 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
1249b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
1259b569ea0SJosef Bacik 	btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
1269b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
1279b569ea0SJosef Bacik 	btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
1289b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...) \
1299b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
1309b569ea0SJosef Bacik #else
1319b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...) \
1329b569ea0SJosef Bacik 	btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
1339b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...) \
1349b569ea0SJosef Bacik 	btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
1359b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
1369b569ea0SJosef Bacik 	btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
1379b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...) \
1389b569ea0SJosef Bacik 	btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
1399b569ea0SJosef Bacik #endif
1409b569ea0SJosef Bacik 
1419b569ea0SJosef Bacik #define btrfs_printk_in_rcu(fs_info, fmt, args...)	\
1429b569ea0SJosef Bacik do {							\
1439b569ea0SJosef Bacik 	rcu_read_lock();				\
1449b569ea0SJosef Bacik 	btrfs_printk(fs_info, fmt, ##args);		\
1459b569ea0SJosef Bacik 	rcu_read_unlock();				\
1469b569ea0SJosef Bacik } while (0)
1479b569ea0SJosef Bacik 
1489b569ea0SJosef Bacik #define btrfs_no_printk_in_rcu(fs_info, fmt, args...)	\
1499b569ea0SJosef Bacik do {							\
1509b569ea0SJosef Bacik 	rcu_read_lock();				\
1519b569ea0SJosef Bacik 	btrfs_no_printk(fs_info, fmt, ##args);		\
1529b569ea0SJosef Bacik 	rcu_read_unlock();				\
1539b569ea0SJosef Bacik } while (0)
1549b569ea0SJosef Bacik 
1559b569ea0SJosef Bacik #define btrfs_printk_ratelimited(fs_info, fmt, args...)		\
1569b569ea0SJosef Bacik do {								\
1579b569ea0SJosef Bacik 	static DEFINE_RATELIMIT_STATE(_rs,			\
1589b569ea0SJosef Bacik 		DEFAULT_RATELIMIT_INTERVAL,			\
1599b569ea0SJosef Bacik 		DEFAULT_RATELIMIT_BURST);			\
1609b569ea0SJosef Bacik 	if (__ratelimit(&_rs))					\
1619b569ea0SJosef Bacik 		btrfs_printk(fs_info, fmt, ##args);		\
1629b569ea0SJosef Bacik } while (0)
1639b569ea0SJosef Bacik 
1649b569ea0SJosef Bacik #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...)		\
1659b569ea0SJosef Bacik do {								\
1669b569ea0SJosef Bacik 	rcu_read_lock();					\
1679b569ea0SJosef Bacik 	btrfs_printk_ratelimited(fs_info, fmt, ##args);		\
1689b569ea0SJosef Bacik 	rcu_read_unlock();					\
1699b569ea0SJosef Bacik } while (0)
1709b569ea0SJosef Bacik 
1719b569ea0SJosef Bacik #ifdef CONFIG_BTRFS_ASSERT
172*b831306bSDavid Sterba 
173*b831306bSDavid Sterba #define btrfs_assertfail(expr, file, line)	({				\
174*b831306bSDavid Sterba 	pr_err("assertion failed: %s, in %s:%d\n", (expr), (file), (line));	\
175*b831306bSDavid Sterba 	BUG();								\
176*b831306bSDavid Sterba })
1779b569ea0SJosef Bacik 
1789b569ea0SJosef Bacik #define ASSERT(expr)						\
1799b569ea0SJosef Bacik 	(likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__))
1809b569ea0SJosef Bacik #else
1819b569ea0SJosef Bacik #define ASSERT(expr)	(void)(expr)
1829b569ea0SJosef Bacik #endif
1839b569ea0SJosef Bacik 
1849b569ea0SJosef Bacik __printf(5, 6)
1859b569ea0SJosef Bacik __cold
1869b569ea0SJosef Bacik void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
1879b569ea0SJosef Bacik 		     unsigned int line, int errno, const char *fmt, ...);
1889b569ea0SJosef Bacik 
1899b569ea0SJosef Bacik const char * __attribute_const__ btrfs_decode_error(int errno);
1909b569ea0SJosef Bacik 
1919b569ea0SJosef Bacik #define btrfs_handle_fs_error(fs_info, errno, fmt, args...)		\
1929b569ea0SJosef Bacik 	__btrfs_handle_fs_error((fs_info), __func__, __LINE__,		\
1939b569ea0SJosef Bacik 				(errno), fmt, ##args)
1949b569ea0SJosef Bacik 
1959b569ea0SJosef Bacik __printf(5, 6)
1969b569ea0SJosef Bacik __cold
1979b569ea0SJosef Bacik void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
1989b569ea0SJosef Bacik 		   unsigned int line, int errno, const char *fmt, ...);
1999b569ea0SJosef Bacik /*
2009b569ea0SJosef Bacik  * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
2019b569ea0SJosef Bacik  * will panic().  Otherwise we BUG() here.
2029b569ea0SJosef Bacik  */
2039b569ea0SJosef Bacik #define btrfs_panic(fs_info, errno, fmt, args...)			\
2049b569ea0SJosef Bacik do {									\
2059b569ea0SJosef Bacik 	__btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args);	\
2069b569ea0SJosef Bacik 	BUG();								\
2079b569ea0SJosef Bacik } while (0)
2089b569ea0SJosef Bacik 
209b538a271SJosef Bacik #if BITS_PER_LONG == 32
210b538a271SJosef Bacik #define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT)
211b538a271SJosef Bacik /*
212b538a271SJosef Bacik  * The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical
213b538a271SJosef Bacik  * addresses of extents.
214b538a271SJosef Bacik  *
215b538a271SJosef Bacik  * For 4K page size it's about 10T, for 64K it's 160T.
216b538a271SJosef Bacik  */
217b538a271SJosef Bacik #define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8)
218b538a271SJosef Bacik void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info);
219b538a271SJosef Bacik void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info);
220b538a271SJosef Bacik #endif
221b538a271SJosef Bacik 
2229b569ea0SJosef Bacik #endif
223