mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 02:44:41 +01:00
btrfs: pass level to _btrfs_printk() to avoid parsing level from string
There's code in _btrfs_printk() to parse the message level from the input string so we can augment the message with the level description for better visibility in the logs. The parsing code has evolved over time, see commits: -40f7828b36("btrfs: better handle btrfs_printk() defaults") -262c5e86fe("printk/btrfs: handle more message headers") -533574c6bc("btrfs: use printk_get_level and printk_skip_level, add __printf, fix fallout") -4da3511342("btrfs: add varargs to btrfs_error") As we are using the specific level helpers everywhere we can simply pass the message level so we don't have to parse it. The proper printk() message header is created as KERN_SOH + "level". Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
c53d61e240
commit
01c8634c69
2 changed files with 30 additions and 45 deletions
|
|
@ -211,33 +211,19 @@ static struct ratelimit_state printk_limits[] = {
|
|||
RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100),
|
||||
};
|
||||
|
||||
void __cold _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
|
||||
__printf(3, 4) __cold
|
||||
void _btrfs_printk(const struct btrfs_fs_info *fs_info, unsigned int level, const char *fmt, ...)
|
||||
{
|
||||
char lvl[PRINTK_MAX_SINGLE_HEADER_LEN + 1] = "\0";
|
||||
struct va_format vaf;
|
||||
va_list args;
|
||||
int kern_level;
|
||||
const char *type = logtypes[4];
|
||||
struct ratelimit_state *ratelimit = &printk_limits[4];
|
||||
const char *type = logtypes[level];
|
||||
struct ratelimit_state *ratelimit = &printk_limits[level];
|
||||
|
||||
#ifdef CONFIG_PRINTK_INDEX
|
||||
printk_index_subsys_emit("%sBTRFS %s (device %s): ", NULL, fmt);
|
||||
#endif
|
||||
|
||||
va_start(args, fmt);
|
||||
|
||||
while ((kern_level = printk_get_level(fmt)) != 0) {
|
||||
size_t size = printk_skip_level(fmt) - fmt;
|
||||
|
||||
if (kern_level >= '0' && kern_level <= '7') {
|
||||
memcpy(lvl, fmt, size);
|
||||
lvl[size] = '\0';
|
||||
type = logtypes[kern_level - '0'];
|
||||
ratelimit = &printk_limits[kern_level - '0'];
|
||||
}
|
||||
fmt += size;
|
||||
}
|
||||
|
||||
vaf.fmt = fmt;
|
||||
vaf.va = &args;
|
||||
|
||||
|
|
@ -247,10 +233,10 @@ void __cold _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt,
|
|||
char statestr[STATE_STRING_BUF_LEN];
|
||||
|
||||
btrfs_state_to_string(fs_info, statestr);
|
||||
_printk("%sBTRFS %s (device %s%s): %pV\n", lvl, type,
|
||||
_printk(KERN_SOH "%dBTRFS %s (device %s%s): %pV\n", level, type,
|
||||
fs_info->sb->s_id, statestr, &vaf);
|
||||
} else {
|
||||
_printk("%sBTRFS %s: %pV\n", lvl, type, &vaf);
|
||||
_printk(KERN_SOH "%dBTRFS %s: %pV\n", level, type, &vaf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,19 +23,18 @@ void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
|
|||
|
||||
#ifdef CONFIG_PRINTK
|
||||
|
||||
__printf(2, 3)
|
||||
__cold
|
||||
void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
|
||||
__printf(3, 4) __cold
|
||||
void _btrfs_printk(const struct btrfs_fs_info *fs_info, unsigned int level, const char *fmt, ...);
|
||||
|
||||
#else
|
||||
|
||||
#define btrfs_printk(fs_info, fmt, args...) \
|
||||
#define btrfs_printk_in_rcu(fs_info, level, fmt, args...) \
|
||||
btrfs_no_printk(fs_info, fmt, ##args)
|
||||
|
||||
#define btrfs_printk_in_rcu(fs_info, fmt, args...) \
|
||||
#define btrfs_printk_in_rcu(fs_info, level, fmt, args...) \
|
||||
btrfs_no_printk(fs_info, fmt, ##args)
|
||||
|
||||
#define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \
|
||||
#define btrfs_printk_rl_in_rcu(fs_info, level, fmt, args...) \
|
||||
btrfs_no_printk(fs_info, fmt, ##args)
|
||||
|
||||
#endif
|
||||
|
|
@ -44,38 +43,38 @@ void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
|
|||
* Print a message with filesystem info, enclosed in RCU protection.
|
||||
*/
|
||||
#define btrfs_crit(fs_info, fmt, args...) \
|
||||
btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
|
||||
btrfs_printk_in_rcu(fs_info, LOGLEVEL_CRIT, fmt, ##args)
|
||||
#define btrfs_err(fs_info, fmt, args...) \
|
||||
btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
|
||||
btrfs_printk_in_rcu(fs_info, LOGLEVEL_ERR, fmt, ##args)
|
||||
#define btrfs_warn(fs_info, fmt, args...) \
|
||||
btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
|
||||
btrfs_printk_in_rcu(fs_info, LOGLEVEL_WARNING, fmt, ##args)
|
||||
#define btrfs_info(fs_info, fmt, args...) \
|
||||
btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
|
||||
btrfs_printk_in_rcu(fs_info, LOGLEVEL_INFO, fmt, ##args)
|
||||
|
||||
/*
|
||||
* Wrappers that use a ratelimited printk
|
||||
*/
|
||||
#define btrfs_crit_rl(fs_info, fmt, args...) \
|
||||
btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
|
||||
btrfs_printk_rl_in_rcu(fs_info, LOGLEVEL_CRIT, fmt, ##args)
|
||||
#define btrfs_err_rl(fs_info, fmt, args...) \
|
||||
btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
|
||||
btrfs_printk_rl_in_rcu(fs_info, LOGLEVEL_ERR, fmt, ##args)
|
||||
#define btrfs_warn_rl(fs_info, fmt, args...) \
|
||||
btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
|
||||
btrfs_printk_rl_in_rcu(fs_info, LOGLEVEL_WARNING, fmt, ##args)
|
||||
#define btrfs_info_rl(fs_info, fmt, args...) \
|
||||
btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
|
||||
btrfs_printk_rl_in_rcu(fs_info, LOGLEVEL_INFO, fmt, ##args)
|
||||
|
||||
#if defined(CONFIG_DYNAMIC_DEBUG)
|
||||
#define btrfs_debug(fs_info, fmt, args...) \
|
||||
_dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \
|
||||
fs_info, KERN_DEBUG fmt, ##args)
|
||||
fs_info, LOGLEVEL_DEBUG, fmt, ##args)
|
||||
#define btrfs_debug_rl(fs_info, fmt, args...) \
|
||||
_dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \
|
||||
fs_info, KERN_DEBUG fmt, ##args)
|
||||
fs_info, LOGLEVEL_DEBUG, fmt, ##args)
|
||||
#elif defined(DEBUG)
|
||||
#define btrfs_debug(fs_info, fmt, args...) \
|
||||
btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
|
||||
btrfs_printk_in_rcu(fs_info, LOGLEVEL_DEBUG, fmt, ##args)
|
||||
#define btrfs_debug_rl(fs_info, fmt, args...) \
|
||||
btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
|
||||
btrfs_printk_rl_in_rcu(fs_info, LOGLEVEl_DEBUG, fmt, ##args)
|
||||
#else
|
||||
/* When printk() is no_printk(), expand to no-op. */
|
||||
#define btrfs_debug(fs_info, fmt, args...) do { (void)(fs_info); } while(0)
|
||||
|
|
@ -84,14 +83,14 @@ void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
|
|||
|
||||
#ifdef CONFIG_PRINTK
|
||||
|
||||
#define btrfs_printk_in_rcu(fs_info, fmt, args...) \
|
||||
do { \
|
||||
rcu_read_lock(); \
|
||||
_btrfs_printk(fs_info, fmt, ##args); \
|
||||
rcu_read_unlock(); \
|
||||
#define btrfs_printk_in_rcu(fs_info, level, fmt, args...) \
|
||||
do { \
|
||||
rcu_read_lock(); \
|
||||
_btrfs_printk(fs_info, level, fmt, ##args); \
|
||||
rcu_read_unlock(); \
|
||||
} while (0)
|
||||
|
||||
#define btrfs_printk_rl_in_rcu(fs_info, fmt, args...) \
|
||||
#define btrfs_printk_rl_in_rcu(fs_info, level, fmt, args...) \
|
||||
do { \
|
||||
static DEFINE_RATELIMIT_STATE(_rs, \
|
||||
DEFAULT_RATELIMIT_INTERVAL, \
|
||||
|
|
@ -99,7 +98,7 @@ do { \
|
|||
\
|
||||
rcu_read_lock(); \
|
||||
if (__ratelimit(&_rs)) \
|
||||
_btrfs_printk(fs_info, fmt, ##args); \
|
||||
_btrfs_printk(fs_info, level, fmt, ##args); \
|
||||
rcu_read_unlock(); \
|
||||
} while (0)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue