From c9573d13bb19ed7f228a8c259487e49c21acb2b4 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 26 Apr 2018 10:32:21 -0700 Subject: [PATCH] scoutfs: add scoutfs_corruption() Add a helper for printing a message warning about corruption. Signed-off-by: Zach Brown --- kmod/src/format.h | 9 +++++++++ kmod/src/msg.h | 22 ++++++++++++++++++++++ kmod/src/super.h | 2 ++ 3 files changed, 33 insertions(+) diff --git a/kmod/src/format.h b/kmod/src/format.h index b935d033..8022f36a 100644 --- a/kmod/src/format.h +++ b/kmod/src/format.h @@ -645,4 +645,13 @@ struct scoutfs_fid { #define FILEID_SCOUTFS 0x81 #define FILEID_SCOUTFS_WITH_PARENT 0x82 +/* + * Identifiers for sources of corruption that can generate messages. + */ +enum { + SC_NR_SOURCES, +}; + +#define SC_NR_LONGS DIV_ROUND_UP(SC_NR_SOURCES, BITS_PER_LONG) + #endif diff --git a/kmod/src/msg.h b/kmod/src/msg.h index 0586f75c..75791309 100644 --- a/kmod/src/msg.h +++ b/kmod/src/msg.h @@ -1,6 +1,7 @@ #ifndef _SCOUTFS_MSG_H_ #define _SCOUTFS_MSG_H_ +#include #include "key.h" void __printf(4, 5) scoutfs_msg(struct super_block *sb, const char *prefix, @@ -23,4 +24,25 @@ do { \ } \ } while (0) \ +/* + * Each message is only generated once per volume. Remounting resets + * the messages. + */ +#define scoutfs_corruption(sb, which, counter, fmt, args...) \ +do { \ + __typeof__(sb) _sb = (sb); \ + struct scoutfs_sb_info *_sbi = SCOUTFS_SB(_sb); \ + unsigned int _bit = (which); \ + \ + if (WARN_ON_ONCE(_bit >= SC_NR_SOURCES)) \ + break; \ + \ + scoutfs_inc_counter(_sb, counter); \ + if (!test_and_set_bit(_bit, _sbi->corruption_messages_once)) { \ + scoutfs_err(_sb, "corruption (see scoutfs-corruption(5)): " \ + #which ": " fmt, ##args); \ + dump_stack(); \ + } \ +} while (0) \ + #endif diff --git a/kmod/src/super.h b/kmod/src/super.h index 195e54d0..fdc15efc 100644 --- a/kmod/src/super.h +++ b/kmod/src/super.h @@ -70,6 +70,8 @@ struct scoutfs_sb_info { struct dentry *debug_root; bool shutdown; + + unsigned long corruption_messages_once[SC_NR_LONGS]; }; static inline struct scoutfs_sb_info *SCOUTFS_SB(struct super_block *sb)