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> 79b569ea0SJosef Bacik 89b569ea0SJosef Bacik struct btrfs_fs_info; 99b569ea0SJosef Bacik 109b569ea0SJosef Bacik static inline __printf(2, 3) __cold 119b569ea0SJosef Bacik void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) 129b569ea0SJosef Bacik { 139b569ea0SJosef Bacik } 149b569ea0SJosef Bacik 15bbde07a4SJosef Bacik #ifdef CONFIG_PRINTK 169b569ea0SJosef Bacik 179b569ea0SJosef Bacik #define btrfs_printk(fs_info, fmt, args...) \ 189b569ea0SJosef Bacik _btrfs_printk(fs_info, fmt, ##args) 199b569ea0SJosef Bacik 209b569ea0SJosef Bacik __printf(2, 3) 219b569ea0SJosef Bacik __cold 229b569ea0SJosef Bacik void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...); 239b569ea0SJosef Bacik 249b569ea0SJosef Bacik #else 259b569ea0SJosef Bacik 269b569ea0SJosef Bacik #define btrfs_printk(fs_info, fmt, args...) \ 279b569ea0SJosef Bacik btrfs_no_printk(fs_info, fmt, ##args) 289b569ea0SJosef Bacik #endif 299b569ea0SJosef Bacik 309b569ea0SJosef Bacik #define btrfs_emerg(fs_info, fmt, args...) \ 319b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_EMERG fmt, ##args) 329b569ea0SJosef Bacik #define btrfs_alert(fs_info, fmt, args...) \ 339b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_ALERT fmt, ##args) 349b569ea0SJosef Bacik #define btrfs_crit(fs_info, fmt, args...) \ 359b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_CRIT fmt, ##args) 369b569ea0SJosef Bacik #define btrfs_err(fs_info, fmt, args...) \ 379b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_ERR fmt, ##args) 389b569ea0SJosef Bacik #define btrfs_warn(fs_info, fmt, args...) \ 399b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_WARNING fmt, ##args) 409b569ea0SJosef Bacik #define btrfs_notice(fs_info, fmt, args...) \ 419b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_NOTICE fmt, ##args) 429b569ea0SJosef Bacik #define btrfs_info(fs_info, fmt, args...) \ 439b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_INFO fmt, ##args) 449b569ea0SJosef Bacik 459b569ea0SJosef Bacik /* 469b569ea0SJosef Bacik * Wrappers that use printk_in_rcu 479b569ea0SJosef Bacik */ 489b569ea0SJosef Bacik #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \ 499b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args) 509b569ea0SJosef Bacik #define btrfs_alert_in_rcu(fs_info, fmt, args...) \ 519b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args) 529b569ea0SJosef Bacik #define btrfs_crit_in_rcu(fs_info, fmt, args...) \ 539b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args) 549b569ea0SJosef Bacik #define btrfs_err_in_rcu(fs_info, fmt, args...) \ 559b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args) 569b569ea0SJosef Bacik #define btrfs_warn_in_rcu(fs_info, fmt, args...) \ 579b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args) 589b569ea0SJosef Bacik #define btrfs_notice_in_rcu(fs_info, fmt, args...) \ 599b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args) 609b569ea0SJosef Bacik #define btrfs_info_in_rcu(fs_info, fmt, args...) \ 619b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args) 629b569ea0SJosef Bacik 639b569ea0SJosef Bacik /* 649b569ea0SJosef Bacik * Wrappers that use a ratelimited printk_in_rcu 659b569ea0SJosef Bacik */ 669b569ea0SJosef Bacik #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \ 679b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args) 689b569ea0SJosef Bacik #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \ 699b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args) 709b569ea0SJosef Bacik #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \ 719b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args) 729b569ea0SJosef Bacik #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \ 739b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args) 749b569ea0SJosef Bacik #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \ 759b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args) 769b569ea0SJosef Bacik #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \ 779b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args) 789b569ea0SJosef Bacik #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \ 799b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args) 809b569ea0SJosef Bacik 819b569ea0SJosef Bacik /* 829b569ea0SJosef Bacik * Wrappers that use a ratelimited printk 839b569ea0SJosef Bacik */ 849b569ea0SJosef Bacik #define btrfs_emerg_rl(fs_info, fmt, args...) \ 859b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args) 869b569ea0SJosef Bacik #define btrfs_alert_rl(fs_info, fmt, args...) \ 879b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args) 889b569ea0SJosef Bacik #define btrfs_crit_rl(fs_info, fmt, args...) \ 899b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args) 909b569ea0SJosef Bacik #define btrfs_err_rl(fs_info, fmt, args...) \ 919b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args) 929b569ea0SJosef Bacik #define btrfs_warn_rl(fs_info, fmt, args...) \ 939b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args) 949b569ea0SJosef Bacik #define btrfs_notice_rl(fs_info, fmt, args...) \ 959b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args) 969b569ea0SJosef Bacik #define btrfs_info_rl(fs_info, fmt, args...) \ 979b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args) 989b569ea0SJosef Bacik 999b569ea0SJosef Bacik #if defined(CONFIG_DYNAMIC_DEBUG) 1009b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...) \ 1019b569ea0SJosef Bacik _dynamic_func_call_no_desc(fmt, btrfs_printk, \ 1029b569ea0SJosef Bacik fs_info, KERN_DEBUG fmt, ##args) 1039b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ 1049b569ea0SJosef Bacik _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \ 1059b569ea0SJosef Bacik fs_info, KERN_DEBUG fmt, ##args) 1069b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ 1079b569ea0SJosef Bacik _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \ 1089b569ea0SJosef Bacik fs_info, KERN_DEBUG fmt, ##args) 1099b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...) \ 1109b569ea0SJosef Bacik _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \ 1119b569ea0SJosef Bacik fs_info, KERN_DEBUG fmt, ##args) 1129b569ea0SJosef Bacik #elif defined(DEBUG) 1139b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...) \ 1149b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_DEBUG fmt, ##args) 1159b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ 1169b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) 1179b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ 1189b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args) 1199b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...) \ 1209b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args) 1219b569ea0SJosef Bacik #else 1229b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...) \ 1239b569ea0SJosef Bacik btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) 1249b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ 1259b569ea0SJosef Bacik btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) 1269b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ 1279b569ea0SJosef Bacik btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) 1289b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...) \ 1299b569ea0SJosef Bacik btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) 1309b569ea0SJosef Bacik #endif 1319b569ea0SJosef Bacik 1329b569ea0SJosef Bacik #define btrfs_printk_in_rcu(fs_info, fmt, args...) \ 1339b569ea0SJosef Bacik do { \ 1349b569ea0SJosef Bacik rcu_read_lock(); \ 1359b569ea0SJosef Bacik btrfs_printk(fs_info, fmt, ##args); \ 1369b569ea0SJosef Bacik rcu_read_unlock(); \ 1379b569ea0SJosef Bacik } while (0) 1389b569ea0SJosef Bacik 1399b569ea0SJosef Bacik #define btrfs_no_printk_in_rcu(fs_info, fmt, args...) \ 1409b569ea0SJosef Bacik do { \ 1419b569ea0SJosef Bacik rcu_read_lock(); \ 1429b569ea0SJosef Bacik btrfs_no_printk(fs_info, fmt, ##args); \ 1439b569ea0SJosef Bacik rcu_read_unlock(); \ 1449b569ea0SJosef Bacik } while (0) 1459b569ea0SJosef Bacik 1469b569ea0SJosef Bacik #define btrfs_printk_ratelimited(fs_info, fmt, args...) \ 1479b569ea0SJosef Bacik do { \ 1489b569ea0SJosef Bacik static DEFINE_RATELIMIT_STATE(_rs, \ 1499b569ea0SJosef Bacik DEFAULT_RATELIMIT_INTERVAL, \ 1509b569ea0SJosef Bacik DEFAULT_RATELIMIT_BURST); \ 1519b569ea0SJosef Bacik if (__ratelimit(&_rs)) \ 1529b569ea0SJosef Bacik btrfs_printk(fs_info, fmt, ##args); \ 1539b569ea0SJosef Bacik } while (0) 1549b569ea0SJosef Bacik 1559b569ea0SJosef Bacik #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \ 1569b569ea0SJosef Bacik do { \ 1579b569ea0SJosef Bacik rcu_read_lock(); \ 1589b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, fmt, ##args); \ 1599b569ea0SJosef Bacik rcu_read_unlock(); \ 1609b569ea0SJosef Bacik } while (0) 1619b569ea0SJosef Bacik 1629b569ea0SJosef Bacik #ifdef CONFIG_BTRFS_ASSERT 163*f3724631SJosh Poimboeuf void __cold __noreturn btrfs_assertfail(const char *expr, const char *file, int line); 1649b569ea0SJosef Bacik 1659b569ea0SJosef Bacik #define ASSERT(expr) \ 1669b569ea0SJosef Bacik (likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__)) 1679b569ea0SJosef Bacik #else 1689b569ea0SJosef Bacik #define ASSERT(expr) (void)(expr) 1699b569ea0SJosef Bacik #endif 1709b569ea0SJosef Bacik 1719b569ea0SJosef Bacik void __cold btrfs_print_v0_err(struct btrfs_fs_info *fs_info); 1729b569ea0SJosef Bacik 1739b569ea0SJosef Bacik __printf(5, 6) 1749b569ea0SJosef Bacik __cold 1759b569ea0SJosef Bacik void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function, 1769b569ea0SJosef Bacik unsigned int line, int errno, const char *fmt, ...); 1779b569ea0SJosef Bacik 1789b569ea0SJosef Bacik const char * __attribute_const__ btrfs_decode_error(int errno); 1799b569ea0SJosef Bacik 1809b569ea0SJosef Bacik #define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \ 1819b569ea0SJosef Bacik __btrfs_handle_fs_error((fs_info), __func__, __LINE__, \ 1829b569ea0SJosef Bacik (errno), fmt, ##args) 1839b569ea0SJosef Bacik 1849b569ea0SJosef Bacik __printf(5, 6) 1859b569ea0SJosef Bacik __cold 1869b569ea0SJosef Bacik void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function, 1879b569ea0SJosef Bacik unsigned int line, int errno, const char *fmt, ...); 1889b569ea0SJosef Bacik /* 1899b569ea0SJosef Bacik * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic 1909b569ea0SJosef Bacik * will panic(). Otherwise we BUG() here. 1919b569ea0SJosef Bacik */ 1929b569ea0SJosef Bacik #define btrfs_panic(fs_info, errno, fmt, args...) \ 1939b569ea0SJosef Bacik do { \ 1949b569ea0SJosef Bacik __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \ 1959b569ea0SJosef Bacik BUG(); \ 1969b569ea0SJosef Bacik } while (0) 1979b569ea0SJosef Bacik 198b538a271SJosef Bacik #if BITS_PER_LONG == 32 199b538a271SJosef Bacik #define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT) 200b538a271SJosef Bacik /* 201b538a271SJosef Bacik * The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical 202b538a271SJosef Bacik * addresses of extents. 203b538a271SJosef Bacik * 204b538a271SJosef Bacik * For 4K page size it's about 10T, for 64K it's 160T. 205b538a271SJosef Bacik */ 206b538a271SJosef Bacik #define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8) 207b538a271SJosef Bacik void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info); 208b538a271SJosef Bacik void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info); 209b538a271SJosef Bacik #endif 210b538a271SJosef Bacik 2119b569ea0SJosef Bacik #endif 212