public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v0 0/1] Add Btrfs messages to printk index
@ 2022-03-17  5:13 Jonathan Lassoff
  2022-03-17  5:13 ` [PATCH v0 1/1] " Jonathan Lassoff
  2022-03-17  7:20 ` [PATCH v0 0/1] " Nikolay Borisov
  0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Lassoff @ 2022-03-17  5:13 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Josef Bacik, Chris Mason, 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.

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

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index ebb2d109e8bb..cc768f71d0a5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3344,9 +3344,22 @@ void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 }
 
 #ifdef CONFIG_PRINTK
+#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, ...);
+void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
+#elif defined(CONFIG_PRINTK)
+#define btrfs_printk(fs_info, fmt, args...)                          \
+do {                                                                 \
+	_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, ...);
 #else
 #define btrfs_printk(fs_info, fmt, args...) \
 	btrfs_no_printk(fs_info, fmt, ##args)
@@ -3598,11 +3611,22 @@ do {								\
 				  __LINE__, (errno));		\
 } while (0)
 
+#ifdef CONFIG_PRINTK
+#define btrfs_handle_fs_error(fs_info, errno, fmt, args...)  \
+do {								                         \
+	printk_index_subsys_emit(                                \
+		"BTRFS: error (device %s) in %s:%d: errno=%d %s",    \
+		KERN_CRIT, fmt, ##args);                             \
+	__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 {								\
+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] 4+ messages in thread

end of thread, other threads:[~2022-03-17 17:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-17  5:13 [PATCH v0 0/1] Add Btrfs messages to printk index Jonathan Lassoff
2022-03-17  5:13 ` [PATCH v0 1/1] " Jonathan Lassoff
2022-03-17  7:20 ` [PATCH v0 0/1] " Nikolay Borisov
2022-03-17 17:44   ` Jonathan Lassoff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox