Skip to content

Commit 1cf006e

Browse files
Dmitry Monakhovtytso
authored andcommitted
ext4: export msg_count and warning_count via sysfs
This numbers can be analized by system automation similar to errors_count. In ideal world it would be nice to have separate counters for different log-levels, but this makes this patch too intrusive. Signed-off-by: Dmitry Monakhov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 6dbd300 commit 1cf006e

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

fs/ext4/ext4.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,8 @@ struct ext4_sb_info {
15911591
struct ratelimit_state s_err_ratelimit_state;
15921592
struct ratelimit_state s_warning_ratelimit_state;
15931593
struct ratelimit_state s_msg_ratelimit_state;
1594+
atomic_t s_warning_count;
1595+
atomic_t s_msg_count;
15941596

15951597
/* Encryption context for '-o test_dummy_encryption' */
15961598
struct fscrypt_dummy_context s_dummy_enc_ctx;

fs/ext4/super.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ void __ext4_msg(struct super_block *sb,
744744
struct va_format vaf;
745745
va_list args;
746746

747+
atomic_inc(&EXT4_SB(sb)->s_msg_count);
747748
if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), "EXT4-fs"))
748749
return;
749750

@@ -754,9 +755,12 @@ void __ext4_msg(struct super_block *sb,
754755
va_end(args);
755756
}
756757

757-
#define ext4_warning_ratelimit(sb) \
758-
___ratelimit(&(EXT4_SB(sb)->s_warning_ratelimit_state), \
759-
"EXT4-fs warning")
758+
static int ext4_warning_ratelimit(struct super_block *sb)
759+
{
760+
atomic_inc(&EXT4_SB(sb)->s_warning_count);
761+
return ___ratelimit(&(EXT4_SB(sb)->s_warning_ratelimit_state),
762+
"EXT4-fs warning");
763+
}
760764

761765
void __ext4_warning(struct super_block *sb, const char *function,
762766
unsigned int line, const char *fmt, ...)
@@ -4840,6 +4844,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
48404844
ratelimit_state_init(&sbi->s_err_ratelimit_state, 5 * HZ, 10);
48414845
ratelimit_state_init(&sbi->s_warning_ratelimit_state, 5 * HZ, 10);
48424846
ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10);
4847+
atomic_set(&sbi->s_warning_count, 0);
4848+
atomic_set(&sbi->s_msg_count, 0);
48434849

48444850
kfree(orig_data);
48454851
return 0;

fs/ext4/sysfs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ static struct ext4_attr ext4_attr_##_name = { \
189189
#define EXT4_RW_ATTR_SBI_UL(_name,_elname) \
190190
EXT4_ATTR_OFFSET(_name, 0644, pointer_ul, ext4_sb_info, _elname)
191191

192+
#define EXT4_RO_ATTR_SBI_ATOMIC(_name,_elname) \
193+
EXT4_ATTR_OFFSET(_name, 0444, pointer_atomic, ext4_sb_info, _elname)
194+
192195
#define EXT4_ATTR_PTR(_name,_mode,_id,_ptr) \
193196
static struct ext4_attr ext4_attr_##_name = { \
194197
.attr = {.name = __stringify(_name), .mode = _mode }, \
@@ -226,6 +229,8 @@ EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
226229
#ifdef CONFIG_EXT4_DEBUG
227230
EXT4_RW_ATTR_SBI_UL(simulate_fail, s_simulate_fail);
228231
#endif
232+
EXT4_RO_ATTR_SBI_ATOMIC(warning_count, s_warning_count);
233+
EXT4_RO_ATTR_SBI_ATOMIC(msg_count, s_msg_count);
229234
EXT4_RO_ATTR_ES_UI(errors_count, s_error_count);
230235
EXT4_RO_ATTR_ES_U8(first_error_errcode, s_first_error_errcode);
231236
EXT4_RO_ATTR_ES_U8(last_error_errcode, s_last_error_errcode);
@@ -269,6 +274,8 @@ static struct attribute *ext4_attrs[] = {
269274
ATTR_LIST(msg_ratelimit_interval_ms),
270275
ATTR_LIST(msg_ratelimit_burst),
271276
ATTR_LIST(errors_count),
277+
ATTR_LIST(warning_count),
278+
ATTR_LIST(msg_count),
272279
ATTR_LIST(first_error_ino),
273280
ATTR_LIST(last_error_ino),
274281
ATTR_LIST(first_error_block),

0 commit comments

Comments
 (0)