提交 b0a66a31 编写于 作者: J Jonathan Lassoff 提交者: David Sterba

btrfs: add messages to printk index

In order for end users to quickly react to new issues that come up in
production, it is proving useful to leverage this printk indexing
system. This printk index enables kernel developers to use calls to
printk() with changeable ad-hoc format strings, while still enabling end
users to detect changes and develop a semi-stable interface for
detecting and parsing these messages.

So that detailed Btrfs messages are captured by this printk index, this
patch wraps btrfs_printk and btrfs_handle_fs_error with macros.

Example of the generated list:
https://lore.kernel.org/lkml/12588e13d51a9c3bf59467d3fc1ac2162f1275c1.1647539056.git.jof@thejof.comSigned-off-by: NJonathan Lassoff <jof@thejof.com>
Reviewed-by: NDavid Sterba <dsterba@suse.com>
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 88c602ab
...@@ -3451,11 +3451,29 @@ void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) ...@@ -3451,11 +3451,29 @@ void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
{ {
} }
#ifdef CONFIG_PRINTK #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) __printf(2, 3)
__cold __cold
void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...); void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
#else #else
#define btrfs_printk(fs_info, fmt, args...) \ #define btrfs_printk(fs_info, fmt, args...) \
btrfs_no_printk(fs_info, fmt, ##args) btrfs_no_printk(fs_info, fmt, ##args)
#endif #endif
...@@ -3706,12 +3724,25 @@ do { \ ...@@ -3706,12 +3724,25 @@ do { \
__LINE__, (errno)); \ __LINE__, (errno)); \
} while (0) } while (0)
#ifdef CONFIG_PRINTK_INDEX
#define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \ #define btrfs_handle_fs_error(fs_info, errno, fmt, args...) \
do { \ do { \
__btrfs_handle_fs_error((fs_info), __func__, __LINE__, \ printk_index_subsys_emit( \
(errno), fmt, ##args); \ "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) } 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, \ #define BTRFS_FS_ERROR(fs_info) (unlikely(test_bit(BTRFS_FS_STATE_ERROR, \
&(fs_info)->fs_state))) &(fs_info)->fs_state)))
#define BTRFS_FS_LOG_CLEANUP_ERROR(fs_info) \ #define BTRFS_FS_LOG_CLEANUP_ERROR(fs_info) \
......
...@@ -261,7 +261,7 @@ static struct ratelimit_state printk_limits[] = { ...@@ -261,7 +261,7 @@ static struct ratelimit_state printk_limits[] = {
RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100), RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100),
}; };
void __cold btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) void __cold _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
{ {
char lvl[PRINTK_MAX_SINGLE_HEADER_LEN + 1] = "\0"; char lvl[PRINTK_MAX_SINGLE_HEADER_LEN + 1] = "\0";
struct va_format vaf; struct va_format vaf;
...@@ -292,10 +292,10 @@ void __cold btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, . ...@@ -292,10 +292,10 @@ void __cold btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, .
char statestr[STATE_STRING_BUF_LEN]; char statestr[STATE_STRING_BUF_LEN];
btrfs_state_to_string(fs_info, statestr); btrfs_state_to_string(fs_info, statestr);
printk("%sBTRFS %s (device %s%s): %pV\n", lvl, type, _printk("%sBTRFS %s (device %s%s): %pV\n", lvl, type,
fs_info->sb->s_id, statestr, &vaf); fs_info->sb->s_id, statestr, &vaf);
} else { } else {
printk("%sBTRFS %s: %pV\n", lvl, type, &vaf); _printk("%sBTRFS %s: %pV\n", lvl, type, &vaf);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册