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 struct btrfs_trans_handle; 109b569ea0SJosef Bacik 119b569ea0SJosef Bacik static inline __printf(2, 3) __cold 129b569ea0SJosef Bacik void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) 139b569ea0SJosef Bacik { 149b569ea0SJosef Bacik } 159b569ea0SJosef Bacik 16bbde07a4SJosef Bacik #ifdef CONFIG_PRINTK 179b569ea0SJosef Bacik 189b569ea0SJosef Bacik #define btrfs_printk(fs_info, fmt, args...) \ 199b569ea0SJosef Bacik _btrfs_printk(fs_info, fmt, ##args) 209b569ea0SJosef Bacik 219b569ea0SJosef Bacik __printf(2, 3) 229b569ea0SJosef Bacik __cold 239b569ea0SJosef Bacik void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...); 249b569ea0SJosef Bacik 259b569ea0SJosef Bacik #else 269b569ea0SJosef Bacik 279b569ea0SJosef Bacik #define btrfs_printk(fs_info, fmt, args...) \ 289b569ea0SJosef Bacik btrfs_no_printk(fs_info, fmt, ##args) 299b569ea0SJosef Bacik #endif 309b569ea0SJosef Bacik 319b569ea0SJosef Bacik #define btrfs_emerg(fs_info, fmt, args...) \ 329b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_EMERG fmt, ##args) 339b569ea0SJosef Bacik #define btrfs_alert(fs_info, fmt, args...) \ 349b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_ALERT fmt, ##args) 359b569ea0SJosef Bacik #define btrfs_crit(fs_info, fmt, args...) \ 369b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_CRIT fmt, ##args) 379b569ea0SJosef Bacik #define btrfs_err(fs_info, fmt, args...) \ 389b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_ERR fmt, ##args) 399b569ea0SJosef Bacik #define btrfs_warn(fs_info, fmt, args...) \ 409b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_WARNING fmt, ##args) 419b569ea0SJosef Bacik #define btrfs_notice(fs_info, fmt, args...) \ 429b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_NOTICE fmt, ##args) 439b569ea0SJosef Bacik #define btrfs_info(fs_info, fmt, args...) \ 449b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_INFO fmt, ##args) 459b569ea0SJosef Bacik 469b569ea0SJosef Bacik /* 479b569ea0SJosef Bacik * Wrappers that use printk_in_rcu 489b569ea0SJosef Bacik */ 499b569ea0SJosef Bacik #define btrfs_emerg_in_rcu(fs_info, fmt, args...) \ 509b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args) 519b569ea0SJosef Bacik #define btrfs_alert_in_rcu(fs_info, fmt, args...) \ 529b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args) 539b569ea0SJosef Bacik #define btrfs_crit_in_rcu(fs_info, fmt, args...) \ 549b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args) 559b569ea0SJosef Bacik #define btrfs_err_in_rcu(fs_info, fmt, args...) \ 569b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args) 579b569ea0SJosef Bacik #define btrfs_warn_in_rcu(fs_info, fmt, args...) \ 589b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args) 599b569ea0SJosef Bacik #define btrfs_notice_in_rcu(fs_info, fmt, args...) \ 609b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args) 619b569ea0SJosef Bacik #define btrfs_info_in_rcu(fs_info, fmt, args...) \ 629b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args) 639b569ea0SJosef Bacik 649b569ea0SJosef Bacik /* 659b569ea0SJosef Bacik * Wrappers that use a ratelimited printk_in_rcu 669b569ea0SJosef Bacik */ 679b569ea0SJosef Bacik #define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \ 689b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args) 699b569ea0SJosef Bacik #define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \ 709b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args) 719b569ea0SJosef Bacik #define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \ 729b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args) 739b569ea0SJosef Bacik #define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \ 749b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args) 759b569ea0SJosef Bacik #define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \ 769b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args) 779b569ea0SJosef Bacik #define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \ 789b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args) 799b569ea0SJosef Bacik #define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \ 809b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args) 819b569ea0SJosef Bacik 829b569ea0SJosef Bacik /* 839b569ea0SJosef Bacik * Wrappers that use a ratelimited printk 849b569ea0SJosef Bacik */ 859b569ea0SJosef Bacik #define btrfs_emerg_rl(fs_info, fmt, args...) \ 869b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args) 879b569ea0SJosef Bacik #define btrfs_alert_rl(fs_info, fmt, args...) \ 889b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args) 899b569ea0SJosef Bacik #define btrfs_crit_rl(fs_info, fmt, args...) \ 909b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args) 919b569ea0SJosef Bacik #define btrfs_err_rl(fs_info, fmt, args...) \ 929b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args) 939b569ea0SJosef Bacik #define btrfs_warn_rl(fs_info, fmt, args...) \ 949b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args) 959b569ea0SJosef Bacik #define btrfs_notice_rl(fs_info, fmt, args...) \ 969b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args) 979b569ea0SJosef Bacik #define btrfs_info_rl(fs_info, fmt, args...) \ 989b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args) 999b569ea0SJosef Bacik 1009b569ea0SJosef Bacik #if defined(CONFIG_DYNAMIC_DEBUG) 1019b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...) \ 1029b569ea0SJosef Bacik _dynamic_func_call_no_desc(fmt, btrfs_printk, \ 1039b569ea0SJosef Bacik fs_info, KERN_DEBUG fmt, ##args) 1049b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ 1059b569ea0SJosef Bacik _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \ 1069b569ea0SJosef Bacik fs_info, KERN_DEBUG fmt, ##args) 1079b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ 1089b569ea0SJosef Bacik _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \ 1099b569ea0SJosef Bacik fs_info, KERN_DEBUG fmt, ##args) 1109b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...) \ 1119b569ea0SJosef Bacik _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \ 1129b569ea0SJosef Bacik fs_info, KERN_DEBUG fmt, ##args) 1139b569ea0SJosef Bacik #elif defined(DEBUG) 1149b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...) \ 1159b569ea0SJosef Bacik btrfs_printk(fs_info, KERN_DEBUG fmt, ##args) 1169b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ 1179b569ea0SJosef Bacik btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) 1189b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ 1199b569ea0SJosef Bacik btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args) 1209b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...) \ 1219b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args) 1229b569ea0SJosef Bacik #else 1239b569ea0SJosef Bacik #define btrfs_debug(fs_info, fmt, args...) \ 1249b569ea0SJosef Bacik btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) 1259b569ea0SJosef Bacik #define btrfs_debug_in_rcu(fs_info, fmt, args...) \ 1269b569ea0SJosef Bacik btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) 1279b569ea0SJosef Bacik #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ 1289b569ea0SJosef Bacik btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args) 1299b569ea0SJosef Bacik #define btrfs_debug_rl(fs_info, fmt, args...) \ 1309b569ea0SJosef Bacik btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args) 1319b569ea0SJosef Bacik #endif 1329b569ea0SJosef Bacik 1339b569ea0SJosef Bacik #define btrfs_printk_in_rcu(fs_info, fmt, args...) \ 1349b569ea0SJosef Bacik do { \ 1359b569ea0SJosef Bacik rcu_read_lock(); \ 1369b569ea0SJosef Bacik btrfs_printk(fs_info, fmt, ##args); \ 1379b569ea0SJosef Bacik rcu_read_unlock(); \ 1389b569ea0SJosef Bacik } while (0) 1399b569ea0SJosef Bacik 1409b569ea0SJosef Bacik #define btrfs_no_printk_in_rcu(fs_info, fmt, args...) \ 1419b569ea0SJosef Bacik do { \ 1429b569ea0SJosef Bacik rcu_read_lock(); \ 1439b569ea0SJosef Bacik btrfs_no_printk(fs_info, fmt, ##args); \ 1449b569ea0SJosef Bacik rcu_read_unlock(); \ 1459b569ea0SJosef Bacik } while (0) 1469b569ea0SJosef Bacik 1479b569ea0SJosef Bacik #define btrfs_printk_ratelimited(fs_info, fmt, args...) \ 1489b569ea0SJosef Bacik do { \ 1499b569ea0SJosef Bacik static DEFINE_RATELIMIT_STATE(_rs, \ 1509b569ea0SJosef Bacik DEFAULT_RATELIMIT_INTERVAL, \ 1519b569ea0SJosef Bacik DEFAULT_RATELIMIT_BURST); \ 1529b569ea0SJosef Bacik if (__ratelimit(&_rs)) \ 1539b569ea0SJosef Bacik btrfs_printk(fs_info, fmt, ##args); \ 1549b569ea0SJosef Bacik } while (0) 1559b569ea0SJosef Bacik 1569b569ea0SJosef Bacik #define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \ 1579b569ea0SJosef Bacik do { \ 1589b569ea0SJosef Bacik rcu_read_lock(); \ 1599b569ea0SJosef Bacik btrfs_printk_ratelimited(fs_info, fmt, ##args); \ 1609b569ea0SJosef Bacik rcu_read_unlock(); \ 1619b569ea0SJosef Bacik } while (0) 1629b569ea0SJosef Bacik 1639b569ea0SJosef Bacik #ifdef CONFIG_BTRFS_ASSERT 1649b569ea0SJosef Bacik void __cold btrfs_assertfail(const char *expr, const char *file, int line); 1659b569ea0SJosef Bacik 1669b569ea0SJosef Bacik #define ASSERT(expr) \ 1679b569ea0SJosef Bacik (likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__)) 1689b569ea0SJosef Bacik #else 1699b569ea0SJosef Bacik #define ASSERT(expr) (void)(expr) 1709b569ea0SJosef Bacik #endif 1719b569ea0SJosef Bacik 1729b569ea0SJosef Bacik void __cold btrfs_print_v0_err(struct btrfs_fs_info *fs_info); 1739b569ea0SJosef Bacik 1749b569ea0SJosef Bacik __printf(5, 6) 1759b569ea0SJosef Bacik __cold 1769b569ea0SJosef Bacik void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function, 1779b569ea0SJosef Bacik unsigned int line, int errno, const char *fmt, ...); 1789b569ea0SJosef Bacik 1799b569ea0SJosef Bacik const char * __attribute_const__ btrfs_decode_error(int errno); 1809b569ea0SJosef Bacik 1819b569ea0SJosef Bacik __cold 1829b569ea0SJosef Bacik void __btrfs_abort_transaction(struct btrfs_trans_handle *trans, 1839b569ea0SJosef Bacik const char *function, 1849b569ea0SJosef Bacik unsigned int line, int errno, bool first_hit); 1859b569ea0SJosef Bacik 1869b569ea0SJosef Bacik bool __cold abort_should_print_stack(int errno); 1879b569ea0SJosef Bacik 1889b569ea0SJosef Bacik /* 1899b569ea0SJosef Bacik * Call btrfs_abort_transaction as early as possible when an error condition is 1909b569ea0SJosef Bacik * detected, that way the exact stack trace is reported for some errors. 1919b569ea0SJosef Bacik */ 1929b569ea0SJosef Bacik #define btrfs_abort_transaction(trans, errno) \ 1939b569ea0SJosef Bacik do { \ 1949b569ea0SJosef Bacik bool first = false; \ 1959b569ea0SJosef Bacik /* Report first abort since mount */ \ 1969b569ea0SJosef Bacik if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED, \ 1979b569ea0SJosef Bacik &((trans)->fs_info->fs_state))) { \ 1989b569ea0SJosef Bacik first = true; \ 1999b569ea0SJosef Bacik if (WARN(abort_should_print_stack(errno), \ 2009b569ea0SJosef Bacik KERN_DEBUG \ 2019b569ea0SJosef Bacik "BTRFS: Transaction aborted (error %d)\n", \ 2029b569ea0SJosef Bacik (errno))) { \ 2039b569ea0SJosef Bacik /* Stack trace printed. */ \ 2049b569ea0SJosef Bacik } else { \ 2059b569ea0SJosef Bacik btrfs_debug((trans)->fs_info, \ 2069b569ea0SJosef Bacik "Transaction aborted (error %d)", \ 2079b569ea0SJosef Bacik (errno)); \ 2089b569ea0SJosef Bacik } \ 2099b569ea0SJosef Bacik } \ 2109b569ea0SJosef Bacik __btrfs_abort_transaction((trans), __func__, \ 2119b569ea0SJosef Bacik __LINE__, (errno), first); \ 2129b569ea0SJosef Bacik } while (0) 2139b569ea0SJosef Bacik 2149b569ea0SJosef Bacik #define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \ 2159b569ea0SJosef Bacik __btrfs_handle_fs_error((fs_info), __func__, __LINE__, \ 2169b569ea0SJosef Bacik (errno), fmt, ##args) 2179b569ea0SJosef Bacik 2189b569ea0SJosef Bacik __printf(5, 6) 2199b569ea0SJosef Bacik __cold 2209b569ea0SJosef Bacik void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function, 2219b569ea0SJosef Bacik unsigned int line, int errno, const char *fmt, ...); 2229b569ea0SJosef Bacik /* 2239b569ea0SJosef Bacik * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic 2249b569ea0SJosef Bacik * will panic(). Otherwise we BUG() here. 2259b569ea0SJosef Bacik */ 2269b569ea0SJosef Bacik #define btrfs_panic(fs_info, errno, fmt, args...) \ 2279b569ea0SJosef Bacik do { \ 2289b569ea0SJosef Bacik __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \ 2299b569ea0SJosef Bacik BUG(); \ 2309b569ea0SJosef Bacik } while (0) 2319b569ea0SJosef Bacik 232*b538a271SJosef Bacik #if BITS_PER_LONG == 32 233*b538a271SJosef Bacik #define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT) 234*b538a271SJosef Bacik /* 235*b538a271SJosef Bacik * The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical 236*b538a271SJosef Bacik * addresses of extents. 237*b538a271SJosef Bacik * 238*b538a271SJosef Bacik * For 4K page size it's about 10T, for 64K it's 160T. 239*b538a271SJosef Bacik */ 240*b538a271SJosef Bacik #define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8) 241*b538a271SJosef Bacik void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info); 242*b538a271SJosef Bacik void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info); 243*b538a271SJosef Bacik #endif 244*b538a271SJosef Bacik 2459b569ea0SJosef Bacik #endif 246