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