All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Add Btrfs messages to printk index
@ 2022-03-24 23:04 Jonathan Lassoff
  2022-03-25 20:12 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Lassoff @ 2022-03-24 23:04 UTC (permalink / raw)
  To: linux-btrfs
  Cc: Josef Bacik, Chris Mason, Nikolay Borisov, David Sterba,
	Jonathan Lassoff

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 changable
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.

PATCH v1
  - Fix conditional: CONFIG_PRINTK should be CONFIG_PRINTK_INDEX
  - Fix whitespace
PATCH v2 -- Minimize the btrfs ctree.h changes

Signed-off-by: Jonathan Lassoff <jof@thejof.com>
---
 fs/btrfs/ctree.h | 32 +++++++++++++++++++++++++++-----
 fs/btrfs/super.c |  6 +++---
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index ebb2d109e8bb..2d5c14003a2f 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3343,10 +3343,21 @@ 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)
 __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
 #define btrfs_printk(fs_info, fmt, args...) \
 	btrfs_no_printk(fs_info, fmt, ##args)
@@ -3598,11 +3609,22 @@ do {								\
 				  __LINE__, (errno));		\
 } while (0)
 
+#ifdef CONFIG_PRINTK_INDEX
 #define btrfs_handle_fs_error(fs_info, errno, fmt, args...)		\
-do {								\
-	__btrfs_handle_fs_error((fs_info), __func__, __LINE__,	\
-			  (errno), fmt, ##args);		\
+do {									\
+	printk_index_subsys_emit(					\
+		"BTRFS: error (device %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...)		\
+do {									\
+	__btrfs_handle_fs_error((fs_info), __func__, __LINE__,		\
+			  (errno), fmt, ##args);			\
 } while (0)
+#endif
 
 #define BTRFS_FS_ERROR(fs_info)	(unlikely(test_bit(BTRFS_FS_STATE_ERROR, \
 						   &(fs_info)->fs_state)))
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 4d947ba32da9..4eff3e20f55a 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -213,7 +213,7 @@ 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, ...)
+void __cold _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 {
 	char lvl[PRINTK_MAX_SINGLE_HEADER_LEN + 1] = "\0";
 	struct va_format vaf;
@@ -241,10 +241,10 @@ void __cold btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, .
 
 	if (__ratelimit(ratelimit)) {
 		if (fs_info)
-			printk("%sBTRFS %s (device %s): %pV\n", lvl, type,
+			_printk("%sBTRFS %s (device %s): %pV\n", lvl, type,
 				fs_info->sb->s_id, &vaf);
 		else
-			printk("%sBTRFS %s: %pV\n", lvl, type, &vaf);
+			_printk("%sBTRFS %s: %pV\n", lvl, type, &vaf);
 	}
 
 	va_end(args);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] Add Btrfs messages to printk index
  2022-03-24 23:04 [PATCH v2] Add Btrfs messages to printk index Jonathan Lassoff
@ 2022-03-25 20:12 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2022-03-25 20:12 UTC (permalink / raw)
  To: Jonathan Lassoff
  Cc: linux-btrfs, Josef Bacik, Chris Mason, Nikolay Borisov, David Sterba

On Thu, Mar 24, 2022 at 04:04:17PM -0700, Jonathan Lassoff wrote:
> 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 changable
> 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.
> 
> PATCH v1
>   - Fix conditional: CONFIG_PRINTK should be CONFIG_PRINTK_INDEX
>   - Fix whitespace
> PATCH v2 -- Minimize the btrfs ctree.h changes
> 
> Signed-off-by: Jonathan Lassoff <jof@thejof.com>

Added to misc-next, with some fixups, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-25 20:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 23:04 [PATCH v2] Add Btrfs messages to printk index Jonathan Lassoff
2022-03-25 20:12 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.