Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Guo Xuenan <guoxuenan@huawei.com>
Cc: dchinner@redhat.com, linux-xfs@vger.kernel.org,
	sandeen@redhat.com, guoxuenan@huaweicloud.com,
	houtao1@huawei.com, fangwei1@huawei.com, jack.qiu@huawei.com,
	yi.zhang@huawei.com
Subject: Re: [PATCH v2 1/2] xfs: fix xfs print level wrong parsing
Date: Fri, 21 Apr 2023 20:55:12 -0700	[thread overview]
Message-ID: <20230422035512.GM360889@frogsfrogsfrogs> (raw)
In-Reply-To: <20230421113716.1890274-2-guoxuenan@huawei.com>

On Fri, Apr 21, 2023 at 07:37:15PM +0800, Guo Xuenan wrote:
> Recently, during my xfs bugfix work, notice a bug that makes
> xfs_stack_trace never take effect. This has been around here at xfs
> debug framework for a long time.
> 
> The root cause is misuse of `kstrtoint` which always return -EINVAL,
> because KERN_<LEVEL> with KERN_SOH prefix will always parse failed.
> Directly set loglevel in xfs print definition to make it work properly.
> 
> Fixes: 847f9f6875fb ("xfs: more info from kmem deadlocks and high-level error msgs")
> Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
> ---
>  fs/xfs/xfs_message.c |  5 ++---
>  fs/xfs/xfs_message.h | 28 ++++++++++++++--------------
>  2 files changed, 16 insertions(+), 17 deletions(-)
> 
> diff --git a/fs/xfs/xfs_message.c b/fs/xfs/xfs_message.c
> index 8f495cc23903..1cfa21d62514 100644
> --- a/fs/xfs/xfs_message.c
> +++ b/fs/xfs/xfs_message.c
> @@ -30,12 +30,12 @@ __xfs_printk(
>  void
>  xfs_printk_level(
>  	const char *kern_level,
> +	const int log_level,
>  	const struct xfs_mount *mp,
>  	const char *fmt, ...)
>  {
>  	struct va_format	vaf;
>  	va_list			args;
> -	int			level;
>  
>  	va_start(args, fmt);
>  	vaf.fmt = fmt;
> @@ -45,8 +45,7 @@ xfs_printk_level(
>  
>  	va_end(args);
>  
> -	if (!kstrtoint(kern_level, 0, &level) &&
> -	    level <= LOGLEVEL_ERR &&
> +	if (log_level <= LOGLEVEL_ERR &&

Ok, this resolves my occasional squinting at this and wondering "how in
the h*** does this work?" after I set the log level, fail to get any
messages, and then decide to just do it with ftrace so I can concentrate
on finishing the problem I'm working on.

IOWs, thank you for sorting this out finally.

>  	    xfs_error_level >= XFS_ERRLEVEL_HIGH)
>  		xfs_stack_trace();
>  }
> diff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h
> index cc323775a12c..666a549eb989 100644
> --- a/fs/xfs/xfs_message.h
> +++ b/fs/xfs/xfs_message.h
> @@ -6,32 +6,32 @@
>  
>  struct xfs_mount;
>  
> -extern __printf(3, 4)
> -void xfs_printk_level(const char *kern_level, const struct xfs_mount *mp,
> -			const char *fmt, ...);
> +extern __printf(4, 5)
> +void xfs_printk_level(const char *kern_level, const int log_level,
> +		const struct xfs_mount *mp, const char *fmt, ...);
>  
> -#define xfs_printk_index_wrap(kern_level, mp, fmt, ...)		\
> +#define xfs_printk_index_wrap(level, mp, fmt, ...)		\
>  ({								\
> -	printk_index_subsys_emit("%sXFS%s: ", kern_level, fmt);	\
> -	xfs_printk_level(kern_level, mp, fmt, ##__VA_ARGS__);	\
> +	printk_index_subsys_emit("%sXFS%s: ", KERN_##level, fmt);	\
> +	xfs_printk_level(KERN_##level, LOGLEVEL_##level, mp, fmt, ##__VA_ARGS__); \

Not in love with the macro mess, but it seems to get the job done.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

>  })
>  #define xfs_emerg(mp, fmt, ...) \
> -	xfs_printk_index_wrap(KERN_EMERG, mp, fmt, ##__VA_ARGS__)
> +	xfs_printk_index_wrap(EMERG, mp, fmt, ##__VA_ARGS__)
>  #define xfs_alert(mp, fmt, ...) \
> -	xfs_printk_index_wrap(KERN_ALERT, mp, fmt, ##__VA_ARGS__)
> +	xfs_printk_index_wrap(ALERT, mp, fmt, ##__VA_ARGS__)
>  #define xfs_crit(mp, fmt, ...) \
> -	xfs_printk_index_wrap(KERN_CRIT, mp, fmt, ##__VA_ARGS__)
> +	xfs_printk_index_wrap(CRIT, mp, fmt, ##__VA_ARGS__)
>  #define xfs_err(mp, fmt, ...) \
> -	xfs_printk_index_wrap(KERN_ERR, mp, fmt, ##__VA_ARGS__)
> +	xfs_printk_index_wrap(ERR, mp, fmt, ##__VA_ARGS__)
>  #define xfs_warn(mp, fmt, ...) \
> -	xfs_printk_index_wrap(KERN_WARNING, mp, fmt, ##__VA_ARGS__)
> +	xfs_printk_index_wrap(WARNING, mp, fmt, ##__VA_ARGS__)
>  #define xfs_notice(mp, fmt, ...) \
> -	xfs_printk_index_wrap(KERN_NOTICE, mp, fmt, ##__VA_ARGS__)
> +	xfs_printk_index_wrap(NOTICE, mp, fmt, ##__VA_ARGS__)
>  #define xfs_info(mp, fmt, ...) \
> -	xfs_printk_index_wrap(KERN_INFO, mp, fmt, ##__VA_ARGS__)
> +	xfs_printk_index_wrap(INFO, mp, fmt, ##__VA_ARGS__)
>  #ifdef DEBUG
>  #define xfs_debug(mp, fmt, ...) \
> -	xfs_printk_index_wrap(KERN_DEBUG, mp, fmt, ##__VA_ARGS__)
> +	xfs_printk_index_wrap(DEBUG, mp, fmt, ##__VA_ARGS__)
>  #else
>  #define xfs_debug(mp, fmt, ...) do {} while (0)
>  #endif
> -- 
> 2.31.1
> 

  reply	other threads:[~2023-04-22  3:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-21 11:37 [PATCH v2 0/2] xfs fix and clean up Guo Xuenan
2023-04-21 11:37 ` [PATCH v2 1/2] xfs: fix xfs print level wrong parsing Guo Xuenan
2023-04-22  3:55   ` Darrick J. Wong [this message]
2023-04-21 11:37 ` [PATCH v2 2/2] xfs: clean up some unnecessary xfs_stack_trace Guo Xuenan
2023-04-22  3:57   ` Darrick J. Wong
2023-04-23  1:44     ` Guo Xuenan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230422035512.GM360889@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=dchinner@redhat.com \
    --cc=fangwei1@huawei.com \
    --cc=guoxuenan@huawei.com \
    --cc=guoxuenan@huaweicloud.com \
    --cc=houtao1@huawei.com \
    --cc=jack.qiu@huawei.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox