btrfs: move the printk helpers out of ctree.h
authorJosef Bacik <josef@toxicpanda.com>
Wed, 19 Oct 2022 14:50:49 +0000 (10:50 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 5 Dec 2022 17:00:41 +0000 (18:00 +0100)
We have a bunch of printk helpers that are in ctree.h.  These have
nothing to do with ctree.c, so move them into their own header.
Subsequent patches will cleanup the printk helpers.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
36 files changed:
fs/btrfs/backref.h
fs/btrfs/check-integrity.c
fs/btrfs/ctree.c
fs/btrfs/ctree.h
fs/btrfs/delalloc-space.c
fs/btrfs/delayed-inode.c
fs/btrfs/delayed-ref.c
fs/btrfs/dir-item.c
fs/btrfs/extent-io-tree.c
fs/btrfs/extent_map.c
fs/btrfs/file-item.c
fs/btrfs/free-space-cache.c
fs/btrfs/free-space-tree.c
fs/btrfs/fs.c
fs/btrfs/inode-item.c
fs/btrfs/lzo.c
fs/btrfs/messages.h [new file with mode: 0644]
fs/btrfs/ordered-data.c
fs/btrfs/print-tree.c
fs/btrfs/props.c
fs/btrfs/raid56.c
fs/btrfs/ref-verify.c
fs/btrfs/reflink.c
fs/btrfs/root-tree.c
fs/btrfs/struct-funcs.c
fs/btrfs/subpage.c
fs/btrfs/super.c
fs/btrfs/sysfs.c
fs/btrfs/tree-checker.c
fs/btrfs/tree-log.h
fs/btrfs/tree-mod-log.c
fs/btrfs/ulist.c
fs/btrfs/uuid-tree.c
fs/btrfs/verity.c
fs/btrfs/xattr.c
fs/btrfs/zoned.h

index 6dac462430b052c2040d4f604688831346c1856f..fa3c9cbf9ae70a37b1eab63788d98c1698ea4295 100644 (file)
@@ -7,6 +7,7 @@
 #define BTRFS_BACKREF_H
 
 #include <linux/btrfs.h>
+#include "messages.h"
 #include "ulist.h"
 #include "disk-io.h"
 #include "extent_io.h"
index 98c6e5feab194f654e6891370d4dd295d353cbfa..e8e1a92b30ac4ca8c571367e3132c63644fee3d1 100644 (file)
@@ -82,6 +82,7 @@
 #include <linux/mm.h>
 #include <linux/string.h>
 #include <crypto/hash.h>
+#include "messages.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
index d645933ef135f2085e7dc108deee3542092e8c4d..f423b86f5262afe1dfb31c0ba01089fa092c4c27 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/rbtree.h>
 #include <linux/mm.h>
 #include <linux/error-injection.h>
+#include "messages.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
index e5e4079c92d400d17be3371c0d0b7e885fe07d0a..d27d059e4d5928bbf03e7e13a34fb11d30cf19ff 100644 (file)
@@ -3168,179 +3168,6 @@ int btrfs_sync_fs(struct super_block *sb, int wait);
 char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
                                          u64 subvol_objectid);
 
-static inline __printf(2, 3) __cold
-void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
-{
-}
-
-#ifdef CONFIG_PRINTK_INDEX
-
-#define btrfs_printk(fs_info, fmt, args...)                                    \
-do {                                                                           \
-       printk_index_subsys_emit("%sBTRFS %s (device %s): ", NULL, fmt);        \
-       _btrfs_printk(fs_info, fmt, ##args);                                    \
-} while (0)
-
-__printf(2, 3)
-__cold
-void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
-
-#elif defined(CONFIG_PRINTK)
-
-#define btrfs_printk(fs_info, fmt, args...)                            \
-       _btrfs_printk(fs_info, fmt, ##args)
-
-__printf(2, 3)
-__cold
-void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
-
-#else
-
-#define btrfs_printk(fs_info, fmt, args...) \
-       btrfs_no_printk(fs_info, fmt, ##args)
-#endif
-
-#define btrfs_emerg(fs_info, fmt, args...) \
-       btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
-#define btrfs_alert(fs_info, fmt, args...) \
-       btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
-#define btrfs_crit(fs_info, fmt, args...) \
-       btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
-#define btrfs_err(fs_info, fmt, args...) \
-       btrfs_printk(fs_info, KERN_ERR fmt, ##args)
-#define btrfs_warn(fs_info, fmt, args...) \
-       btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
-#define btrfs_notice(fs_info, fmt, args...) \
-       btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
-#define btrfs_info(fs_info, fmt, args...) \
-       btrfs_printk(fs_info, KERN_INFO fmt, ##args)
-
-/*
- * Wrappers that use printk_in_rcu
- */
-#define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
-#define btrfs_alert_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
-#define btrfs_crit_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
-#define btrfs_err_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
-#define btrfs_warn_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
-#define btrfs_notice_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
-#define btrfs_info_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
-
-/*
- * Wrappers that use a ratelimited printk_in_rcu
- */
-#define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
-#define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
-#define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
-#define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
-#define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
-#define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
-#define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
-
-/*
- * Wrappers that use a ratelimited printk
- */
-#define btrfs_emerg_rl(fs_info, fmt, args...) \
-       btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
-#define btrfs_alert_rl(fs_info, fmt, args...) \
-       btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
-#define btrfs_crit_rl(fs_info, fmt, args...) \
-       btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
-#define btrfs_err_rl(fs_info, fmt, args...) \
-       btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
-#define btrfs_warn_rl(fs_info, fmt, args...) \
-       btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
-#define btrfs_notice_rl(fs_info, fmt, args...) \
-       btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
-#define btrfs_info_rl(fs_info, fmt, args...) \
-       btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
-
-#if defined(CONFIG_DYNAMIC_DEBUG)
-#define btrfs_debug(fs_info, fmt, args...)                             \
-       _dynamic_func_call_no_desc(fmt, btrfs_printk,                   \
-                                  fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_in_rcu(fs_info, fmt, args...)                      \
-       _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu,            \
-                                  fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...)                   \
-       _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu,         \
-                                  fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_rl(fs_info, fmt, args...)                          \
-       _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited,       \
-                                  fs_info, KERN_DEBUG fmt, ##args)
-#elif defined(DEBUG)
-#define btrfs_debug(fs_info, fmt, args...) \
-       btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_rl(fs_info, fmt, args...) \
-       btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
-#else
-#define btrfs_debug(fs_info, fmt, args...) \
-       btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
-       btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
-       btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
-#define btrfs_debug_rl(fs_info, fmt, args...) \
-       btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
-#endif
-
-#define btrfs_printk_in_rcu(fs_info, fmt, args...)     \
-do {                                                   \
-       rcu_read_lock();                                \
-       btrfs_printk(fs_info, fmt, ##args);             \
-       rcu_read_unlock();                              \
-} while (0)
-
-#define btrfs_no_printk_in_rcu(fs_info, fmt, args...)  \
-do {                                                   \
-       rcu_read_lock();                                \
-       btrfs_no_printk(fs_info, fmt, ##args);          \
-       rcu_read_unlock();                              \
-} while (0)
-
-#define btrfs_printk_ratelimited(fs_info, fmt, args...)                \
-do {                                                           \
-       static DEFINE_RATELIMIT_STATE(_rs,                      \
-               DEFAULT_RATELIMIT_INTERVAL,                     \
-               DEFAULT_RATELIMIT_BURST);                       \
-       if (__ratelimit(&_rs))                                  \
-               btrfs_printk(fs_info, fmt, ##args);             \
-} while (0)
-
-#define btrfs_printk_rl_in_rcu(fs_info, fmt, args...)          \
-do {                                                           \
-       rcu_read_lock();                                        \
-       btrfs_printk_ratelimited(fs_info, fmt, ##args);         \
-       rcu_read_unlock();                                      \
-} while (0)
-
-#ifdef CONFIG_BTRFS_ASSERT
-void __cold btrfs_assertfail(const char *expr, const char *file, int line);
-
-#define ASSERT(expr)                                           \
-       (likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__))
-#else
-#define ASSERT(expr)   (void)(expr)
-#endif
-
 #if BITS_PER_LONG == 32
 #define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT)
 /*
@@ -3397,88 +3224,12 @@ static inline unsigned long get_eb_page_index(unsigned long offset)
 #define EXPORT_FOR_TESTS
 #endif
 
-void __cold btrfs_print_v0_err(struct btrfs_fs_info *fs_info);
-
-__printf(5, 6)
-__cold
-void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
-                    unsigned int line, int errno, const char *fmt, ...);
-
-const char * __attribute_const__ btrfs_decode_error(int errno);
-
-__cold
-void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
-                              const char *function,
-                              unsigned int line, int errno, bool first_hit);
-
-bool __cold abort_should_print_stack(int errno);
-
-/*
- * Call btrfs_abort_transaction as early as possible when an error condition is
- * detected, that way the exact stack trace is reported for some errors.
- */
-#define btrfs_abort_transaction(trans, errno)          \
-do {                                                           \
-       bool first = false;                                     \
-       /* Report first abort since mount */                    \
-       if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,     \
-                       &((trans)->fs_info->fs_state))) {       \
-               first = true;                                   \
-               if (WARN(abort_should_print_stack(errno),       \
-                       KERN_DEBUG                              \
-                       "BTRFS: Transaction aborted (error %d)\n",      \
-                       (errno))) {                                     \
-                       /* Stack trace printed. */                      \
-               } else {                                                \
-                       btrfs_debug((trans)->fs_info,                   \
-                                   "Transaction aborted (error %d)", \
-                                 (errno));                     \
-               }                                               \
-       }                                                       \
-       __btrfs_abort_transaction((trans), __func__,            \
-                                 __LINE__, (errno), first);    \
-} while (0)
-
-#ifdef CONFIG_PRINTK_INDEX
-
-#define btrfs_handle_fs_error(fs_info, errno, fmt, args...)            \
-do {                                                                   \
-       printk_index_subsys_emit(                                       \
-               "BTRFS: error (device %s%s) in %s:%d: errno=%d %s",     \
-               KERN_CRIT, fmt);                                        \
-       __btrfs_handle_fs_error((fs_info), __func__, __LINE__,          \
-                               (errno), fmt, ##args);                  \
-} while (0)
-
-#else
-
-#define btrfs_handle_fs_error(fs_info, errno, fmt, args...)            \
-       __btrfs_handle_fs_error((fs_info), __func__, __LINE__,          \
-                               (errno), fmt, ##args)
-
-#endif
-
 #define BTRFS_FS_ERROR(fs_info)        (unlikely(test_bit(BTRFS_FS_STATE_ERROR, \
                                                   &(fs_info)->fs_state)))
 #define BTRFS_FS_LOG_CLEANUP_ERROR(fs_info)                            \
        (unlikely(test_bit(BTRFS_FS_STATE_LOG_CLEANUP_ERROR,            \
                           &(fs_info)->fs_state)))
 
-__printf(5, 6)
-__cold
-void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
-                  unsigned int line, int errno, const char *fmt, ...);
-/*
- * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
- * will panic().  Otherwise we BUG() here.
- */
-#define btrfs_panic(fs_info, errno, fmt, args...)                      \
-do {                                                                   \
-       __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \
-       BUG();                                                          \
-} while (0)
-
-
 /* acl.c */
 #ifdef CONFIG_BTRFS_FS_POSIX_ACL
 struct posix_acl *btrfs_get_acl(struct inode *inode, int type, bool rcu);
index 118b2e20b2e192b12f5a6fb9ca5848e826ef3b3c..045545145a2b8513d05ecba97ac54cc8d5fe52b3 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#include "messages.h"
 #include "ctree.h"
 #include "delalloc-space.h"
 #include "block-rsv.h"
index a411f04a7b9772594ea4e216f16743d8397ff98c..8cf5ee64614759fe980444db7ada607eed1872a6 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <linux/slab.h>
 #include <linux/iversion.h>
+#include "messages.h"
 #include "misc.h"
 #include "delayed-inode.h"
 #include "disk-io.h"
index 36a3debe94930e7b0e5b832116a4bc160f1d98e8..c775ff4f1cb1526aa9bf20c02b6b3b75ad3fae49 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/sort.h>
+#include "messages.h"
 #include "ctree.h"
 #include "delayed-ref.h"
 #include "transaction.h"
index 72fb2c518a2b4eb74e593abfe769959d79538c8b..be5c1c2a8da56b05d431190db504b0ded18bde05 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright (C) 2007 Oracle.  All rights reserved.
  */
 
+#include "messages.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
index 599db7b15574330493862bc138c4063ce779447f..2cdff74ff0334e05531a510bef72e9471260457c 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <linux/slab.h>
 #include <trace/events/btrfs.h>
+#include "messages.h"
 #include "ctree.h"
 #include "extent-io-tree.h"
 #include "btrfs_inode.h"
index 715979807ae137aac71d88fe0671ee9fff555afd..f97508afb65943721e7bb3b07714466bbdff6ad2 100644 (file)
@@ -3,6 +3,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
+#include "messages.h"
 #include "ctree.h"
 #include "volumes.h"
 #include "extent_map.h"
index 824ff54d8155eeb89ef6575052db643ae8a23d90..675987e2d652aa13b78223c278e398f8291b16dd 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/highmem.h>
 #include <linux/sched/mm.h>
 #include <crypto/hash.h>
+#include "messages.h"
 #include "misc.h"
 #include "ctree.h"
 #include "disk-io.h"
index bd68fafcccc7316546aea3b1e4f344be87a4ce7c..83d866f5ab6cdbf42a535ffe483aa8f5ee1e1c0c 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/ratelimit.h>
 #include <linux/error-injection.h>
 #include <linux/sched/mm.h>
+#include "messages.h"
 #include "misc.h"
 #include "ctree.h"
 #include "free-space-cache.h"
index bfc21eb8ec63b47d2ae9e1397f7c73ab4f2e0cf6..026214d74a02bb0517e715b31fec6c5fbd681393 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <linux/kernel.h>
 #include <linux/sched/mm.h>
+#include "messages.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "locking.h"
index d4ba948eba56a7b83aba8487cb46e79f4bb40a5e..a59504b59435015a1d3f8b768f62a380a82a569f 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#include "messages.h"
 #include "ctree.h"
 #include "fs.h"
 
index 366f3a788c6a9c930f19f0e6b4c6280a8f96dab9..b301d8e3df8771d4ecf17e2719814a64f0e55f86 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright (C) 2007 Oracle.  All rights reserved.
  */
 
+#include "messages.h"
 #include "ctree.h"
 #include "inode-item.h"
 #include "disk-io.h"
index 89bc5f825e0a6a99128e29b2f6b82ccb3d86b81a..6751874a3e699f7b05ae422ac2441d06057d3644 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/bio.h>
 #include <linux/lzo.h>
 #include <linux/refcount.h>
+#include "messages.h"
 #include "compression.h"
 #include "ctree.h"
 
diff --git a/fs/btrfs/messages.h b/fs/btrfs/messages.h
new file mode 100644 (file)
index 0000000..ace5bb0
--- /dev/null
@@ -0,0 +1,259 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef BTRFS_MESSAGES_H
+#define BTRFS_MESSAGES_H
+
+#include <linux/types.h>
+
+struct btrfs_fs_info;
+struct btrfs_trans_handle;
+
+static inline __printf(2, 3) __cold
+void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
+{
+}
+
+#ifdef CONFIG_PRINTK_INDEX
+
+#define btrfs_printk(fs_info, fmt, args...)                                    \
+do {                                                                           \
+       printk_index_subsys_emit("%sBTRFS %s (device %s): ", NULL, fmt);        \
+       _btrfs_printk(fs_info, fmt, ##args);                                    \
+} while (0)
+
+__printf(2, 3)
+__cold
+void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
+
+#elif defined(CONFIG_PRINTK)
+
+#define btrfs_printk(fs_info, fmt, args...)                            \
+       _btrfs_printk(fs_info, fmt, ##args)
+
+__printf(2, 3)
+__cold
+void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
+
+#else
+
+#define btrfs_printk(fs_info, fmt, args...) \
+       btrfs_no_printk(fs_info, fmt, ##args)
+#endif
+
+#define btrfs_emerg(fs_info, fmt, args...) \
+       btrfs_printk(fs_info, KERN_EMERG fmt, ##args)
+#define btrfs_alert(fs_info, fmt, args...) \
+       btrfs_printk(fs_info, KERN_ALERT fmt, ##args)
+#define btrfs_crit(fs_info, fmt, args...) \
+       btrfs_printk(fs_info, KERN_CRIT fmt, ##args)
+#define btrfs_err(fs_info, fmt, args...) \
+       btrfs_printk(fs_info, KERN_ERR fmt, ##args)
+#define btrfs_warn(fs_info, fmt, args...) \
+       btrfs_printk(fs_info, KERN_WARNING fmt, ##args)
+#define btrfs_notice(fs_info, fmt, args...) \
+       btrfs_printk(fs_info, KERN_NOTICE fmt, ##args)
+#define btrfs_info(fs_info, fmt, args...) \
+       btrfs_printk(fs_info, KERN_INFO fmt, ##args)
+
+/*
+ * Wrappers that use printk_in_rcu
+ */
+#define btrfs_emerg_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_in_rcu(fs_info, KERN_EMERG fmt, ##args)
+#define btrfs_alert_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_in_rcu(fs_info, KERN_ALERT fmt, ##args)
+#define btrfs_crit_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
+#define btrfs_err_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
+#define btrfs_warn_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
+#define btrfs_notice_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
+#define btrfs_info_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
+
+/*
+ * Wrappers that use a ratelimited printk_in_rcu
+ */
+#define btrfs_emerg_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_rl_in_rcu(fs_info, KERN_EMERG fmt, ##args)
+#define btrfs_alert_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_rl_in_rcu(fs_info, KERN_ALERT fmt, ##args)
+#define btrfs_crit_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
+#define btrfs_err_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
+#define btrfs_warn_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
+#define btrfs_notice_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_rl_in_rcu(fs_info, KERN_NOTICE fmt, ##args)
+#define btrfs_info_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
+
+/*
+ * Wrappers that use a ratelimited printk
+ */
+#define btrfs_emerg_rl(fs_info, fmt, args...) \
+       btrfs_printk_ratelimited(fs_info, KERN_EMERG fmt, ##args)
+#define btrfs_alert_rl(fs_info, fmt, args...) \
+       btrfs_printk_ratelimited(fs_info, KERN_ALERT fmt, ##args)
+#define btrfs_crit_rl(fs_info, fmt, args...) \
+       btrfs_printk_ratelimited(fs_info, KERN_CRIT fmt, ##args)
+#define btrfs_err_rl(fs_info, fmt, args...) \
+       btrfs_printk_ratelimited(fs_info, KERN_ERR fmt, ##args)
+#define btrfs_warn_rl(fs_info, fmt, args...) \
+       btrfs_printk_ratelimited(fs_info, KERN_WARNING fmt, ##args)
+#define btrfs_notice_rl(fs_info, fmt, args...) \
+       btrfs_printk_ratelimited(fs_info, KERN_NOTICE fmt, ##args)
+#define btrfs_info_rl(fs_info, fmt, args...) \
+       btrfs_printk_ratelimited(fs_info, KERN_INFO fmt, ##args)
+
+#if defined(CONFIG_DYNAMIC_DEBUG)
+#define btrfs_debug(fs_info, fmt, args...)                             \
+       _dynamic_func_call_no_desc(fmt, btrfs_printk,                   \
+                                  fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_in_rcu(fs_info, fmt, args...)                      \
+       _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu,            \
+                                  fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...)                   \
+       _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu,         \
+                                  fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_rl(fs_info, fmt, args...)                          \
+       _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited,       \
+                                  fs_info, KERN_DEBUG fmt, ##args)
+#elif defined(DEBUG)
+#define btrfs_debug(fs_info, fmt, args...) \
+       btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_rl(fs_info, fmt, args...) \
+       btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, ##args)
+#else
+#define btrfs_debug(fs_info, fmt, args...) \
+       btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_in_rcu(fs_info, fmt, args...) \
+       btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \
+       btrfs_no_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
+#define btrfs_debug_rl(fs_info, fmt, args...) \
+       btrfs_no_printk(fs_info, KERN_DEBUG fmt, ##args)
+#endif
+
+#define btrfs_printk_in_rcu(fs_info, fmt, args...)     \
+do {                                                   \
+       rcu_read_lock();                                \
+       btrfs_printk(fs_info, fmt, ##args);             \
+       rcu_read_unlock();                              \
+} while (0)
+
+#define btrfs_no_printk_in_rcu(fs_info, fmt, args...)  \
+do {                                                   \
+       rcu_read_lock();                                \
+       btrfs_no_printk(fs_info, fmt, ##args);          \
+       rcu_read_unlock();                              \
+} while (0)
+
+#define btrfs_printk_ratelimited(fs_info, fmt, args...)                \
+do {                                                           \
+       static DEFINE_RATELIMIT_STATE(_rs,                      \
+               DEFAULT_RATELIMIT_INTERVAL,                     \
+               DEFAULT_RATELIMIT_BURST);                       \
+       if (__ratelimit(&_rs))                                  \
+               btrfs_printk(fs_info, fmt, ##args);             \
+} while (0)
+
+#define btrfs_printk_rl_in_rcu(fs_info, fmt, args...)          \
+do {                                                           \
+       rcu_read_lock();                                        \
+       btrfs_printk_ratelimited(fs_info, fmt, ##args);         \
+       rcu_read_unlock();                                      \
+} while (0)
+
+#ifdef CONFIG_BTRFS_ASSERT
+void __cold btrfs_assertfail(const char *expr, const char *file, int line);
+
+#define ASSERT(expr)                                           \
+       (likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__))
+#else
+#define ASSERT(expr)   (void)(expr)
+#endif
+
+void __cold btrfs_print_v0_err(struct btrfs_fs_info *fs_info);
+
+__printf(5, 6)
+__cold
+void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
+                    unsigned int line, int errno, const char *fmt, ...);
+
+const char * __attribute_const__ btrfs_decode_error(int errno);
+
+__cold
+void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
+                              const char *function,
+                              unsigned int line, int errno, bool first_hit);
+
+bool __cold abort_should_print_stack(int errno);
+
+/*
+ * Call btrfs_abort_transaction as early as possible when an error condition is
+ * detected, that way the exact stack trace is reported for some errors.
+ */
+#define btrfs_abort_transaction(trans, errno)                  \
+do {                                                           \
+       bool first = false;                                     \
+       /* Report first abort since mount */                    \
+       if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,     \
+                             &((trans)->fs_info->fs_state))) { \
+               first = true;                                   \
+               if (WARN(abort_should_print_stack(errno),       \
+                       KERN_DEBUG                              \
+                       "BTRFS: Transaction aborted (error %d)\n",      \
+                       (errno))) {                                     \
+                       /* Stack trace printed. */                      \
+               } else {                                                \
+                       btrfs_debug((trans)->fs_info,                   \
+                                   "Transaction aborted (error %d)", \
+                                 (errno));                     \
+               }                                               \
+       }                                                       \
+       __btrfs_abort_transaction((trans), __func__,            \
+                                 __LINE__, (errno), first);    \
+} while (0)
+
+#ifdef CONFIG_PRINTK_INDEX
+
+#define btrfs_handle_fs_error(fs_info, errno, fmt, args...)            \
+do {                                                                   \
+       printk_index_subsys_emit(                                       \
+               "BTRFS: error (device %s%s) in %s:%d: errno=%d %s",     \
+               KERN_CRIT, fmt);                                        \
+       __btrfs_handle_fs_error((fs_info), __func__, __LINE__,          \
+                               (errno), fmt, ##args);                  \
+} while (0)
+
+#else
+
+#define btrfs_handle_fs_error(fs_info, errno, fmt, args...)            \
+       __btrfs_handle_fs_error((fs_info), __func__, __LINE__,          \
+                               (errno), fmt, ##args)
+
+#endif
+
+__printf(5, 6)
+__cold
+void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
+                  unsigned int line, int errno, const char *fmt, ...);
+/*
+ * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
+ * will panic().  Otherwise we BUG() here.
+ */
+#define btrfs_panic(fs_info, errno, fmt, args...)                      \
+do {                                                                   \
+       __btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args); \
+       BUG();                                                          \
+} while (0)
+
+#endif
index de2b716d3e7bd4876f01019a09015322996fd600..1cbaacdc50da3141bdd443598e63e57af6ab1e49 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/blkdev.h>
 #include <linux/writeback.h>
 #include <linux/sched/mm.h>
+#include "messages.h"
 #include "misc.h"
 #include "ctree.h"
 #include "transaction.h"
index dd8777872143a487d7059caca5b10186e5286cc1..708facaede2cdfe5e206d09782a78bf99125448d 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright (C) 2007 Oracle.  All rights reserved.
  */
 
+#include "messages.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "print-tree.h"
index d2c699c9aa5128de99e0404d42d51b28596983ec..6d88bf0a9b1739736e8a063c856fd0a6aa056557 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/hashtable.h>
+#include "messages.h"
 #include "props.h"
 #include "btrfs_inode.h"
 #include "transaction.h"
index c009c0a2081e16b46dc7c3eebf42892b8ad2dd5a..349270537c2ef17a745a5c2232082943cd9eb8a4 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/list_sort.h>
 #include <linux/raid/xor.h>
 #include <linux/mm.h>
+#include "messages.h"
 #include "misc.h"
 #include "ctree.h"
 #include "disk-io.h"
index a248f46cfe728cfe0e2a7d6b965e7db51f98b786..f7535b8b62f56573313cfab2e0d9599395fc250b 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <linux/sched.h>
 #include <linux/stacktrace.h>
+#include "messages.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "locking.h"
index f50586ff85c84258c74d31aabc73fe24270854b9..6179864de6e7aed5636b905ed565028a554c6dbf 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <linux/blkdev.h>
 #include <linux/iversion.h>
+#include "messages.h"
 #include "compression.h"
 #include "ctree.h"
 #include "delalloc-space.h"
index e1f599d7a9164b7973515afc9de35a9df524040c..44c8c8ad0a16c3d9f7e97a0d8ff0701143f85376 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <linux/err.h>
 #include <linux/uuid.h>
+#include "messages.h"
 #include "ctree.h"
 #include "transaction.h"
 #include "disk-io.h"
index 12455b2b41de8978e1b5814f3b3b75607174ecd8..6ba16c018d7f21ab8e362e5baa79aec5cc4c0b18 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <asm/unaligned.h>
 
+#include "messages.h"
 #include "ctree.h"
 
 static bool check_setget_bounds(const struct extent_buffer *eb,
index 9a176af847d7f013ad031a03bfcd063b16962f6b..dd46b978ac2cfcb5b713e589115cd8798f783934 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <linux/slab.h>
+#include "messages.h"
 #include "ctree.h"
 #include "subpage.h"
 #include "btrfs_inode.h"
index 06661bcb991bac1117d7e45876a7266f48d64e79..7debbcfc5d471454ecadc8f389f3157355a75660 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/ratelimit.h>
 #include <linux/crc32c.h>
 #include <linux/btrfs.h>
+#include "messages.h"
 #include "delayed-inode.h"
 #include "ctree.h"
 #include "disk-io.h"
index 910702df7767e944119ec190cb8f718a765b55f9..0b6bea00742c2ef405dd300c915b1a433710d137 100644 (file)
@@ -10,7 +10,7 @@
 #include <linux/completion.h>
 #include <linux/bug.h>
 #include <crypto/hash.h>
-
+#include "messages.h"
 #include "ctree.h"
 #include "discard.h"
 #include "disk-io.h"
index 862d67798de59350e2be1a6a7d583ae33226a666..fa9536110d69d62df59c64229437498c62f39841 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/types.h>
 #include <linux/stddef.h>
 #include <linux/error-injection.h>
+#include "messages.h"
 #include "ctree.h"
 #include "tree-checker.h"
 #include "disk-io.h"
index aed1e05e9879e6cae9d0d1fb0d8cfaea4118cf5f..f5770829d0756e31817413b9b9107a9190890ff4 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef BTRFS_TREE_LOG_H
 #define BTRFS_TREE_LOG_H
 
+#include "messages.h"
 #include "ctree.h"
 #include "transaction.h"
 
index 18b4699bcb1132151fc49a8e98f22e8de0d296db..41e5d9f789dce812c517f5451e8ae67d400823c3 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#include "messages.h"
 #include "tree-mod-log.h"
 #include "disk-io.h"
 
index 3374c9e9be672bcb25fe95a90747ca0fbf67f466..f2f20c8d84aa97bab5488039e110235a8baf8f5b 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <linux/slab.h>
+#include "messages.h"
 #include "ulist.h"
 #include "ctree.h"
 
index 2d7eb290fb9caa075b16e7206b04d05bc2f0b23d..190f752a2e107fbdf93c8bc5960eab89de05ca81 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <linux/uuid.h>
 #include <asm/unaligned.h>
+#include "messages.h"
 #include "ctree.h"
 #include "transaction.h"
 #include "disk-io.h"
index ab0b39badbbe3b8e636a17813e8cd67874b6de30..35445855df4de33eb32e2173e7536ab31fe67e08 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/iversion.h>
 #include <linux/fsverity.h>
 #include <linux/sched/mm.h>
+#include "messages.h"
 #include "ctree.h"
 #include "btrfs_inode.h"
 #include "transaction.h"
index 5bb8d8c86311902ea8065862e66b35ec652f6c85..d12903f01f835e2d6f61857fa9f2443cb200317e 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/posix_acl_xattr.h>
 #include <linux/iversion.h>
 #include <linux/sched/mm.h>
+#include "messages.h"
 #include "ctree.h"
 #include "btrfs_inode.h"
 #include "transaction.h"
index 8bd16d40b7c65befa495df76860ff4da619b944e..f43990985d802cf36f3578fc928204206707b4d8 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <linux/types.h>
 #include <linux/blkdev.h>
+#include "messages.h"
 #include "volumes.h"
 #include "disk-io.h"
 #include "block-group.h"