All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Lassoff <jof@thejof.com>
To: linux-btrfs@vger.kernel.org
Cc: Josef Bacik <josef@toxicpanda.com>, Chris Mason <clm@fb.com>,
	Nikolay Borisov <nborisov@suse.com>,
	David Sterba <dsterba@suse.cz>, Jonathan Lassoff <jof@thejof.com>
Subject: [PATCH v2] Add Btrfs messages to printk index
Date: Thu, 24 Mar 2022 16:04:17 -0700	[thread overview]
Message-ID: <b16ccc0d48d9a25fd001f57eaeb3066055ac17a4.1648162972.git.jof@thejof.com> (raw)

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


             reply	other threads:[~2022-03-24 23:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24 23:04 Jonathan Lassoff [this message]
2022-03-25 20:12 ` [PATCH v2] Add Btrfs messages to printk index David Sterba

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=b16ccc0d48d9a25fd001f57eaeb3066055ac17a4.1648162972.git.jof@thejof.com \
    --to=jof@thejof.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.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 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.