Add Jan Kara's ext4 data corruption bugs for blocksize < pagesize
[ext4-patch-queue.git] / add-sysfs-entry-showing-whether-the-fs-contains-errors
blobac10b530c2646e1d33d55259ccbd36b42f04e45f
1 ext4: add sysfs entry showing whether the fs contains errors
3 From: Lukas Czerner <lczerner@redhat.com>
5 Currently there is no easy way to tell that the mounted file system
6 contains errors other than checking for log messages, or reading the
7 information directly from superblock.
9 This patch adds new sysfs entries:
11 errors_count            (number of fs errors we encounter)
12 first_error_time        (unix timestamp for the first error we see)
13 last_error_time         (unix timestamp for the last error we see)
15 If the file system is not marked as containing errors then any of the
16 file will return 0. Otherwise it will contain valid information. More
17 details about the errors should as always be found in the logs.
19 Signed-off-by: Lukas Czerner <lczerner@redhat.com>
20 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 ---
22  fs/ext4/super.c | 31 +++++++++++++++++++++++++++++++
23  1 file changed, 31 insertions(+)
25 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
26 index 0b28b36..8e55ae1 100644
27 --- a/fs/ext4/super.c
28 +++ b/fs/ext4/super.c
29 @@ -2548,6 +2548,16 @@ static ssize_t sbi_ui_store(struct ext4_attr *a,
30         return count;
31  }
33 +static ssize_t es_ui_show(struct ext4_attr *a,
34 +                          struct ext4_sb_info *sbi, char *buf)
37 +       unsigned int *ui = (unsigned int *) (((char *) sbi->s_es) +
38 +                          a->u.offset);
40 +       return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
43  static ssize_t reserved_clusters_show(struct ext4_attr *a,
44                                   struct ext4_sb_info *sbi, char *buf)
45  {
46 @@ -2601,14 +2611,29 @@ static struct ext4_attr ext4_attr_##_name = {                   \
47                 .offset = offsetof(struct ext4_sb_info, _elname),\
48         },                                                      \
49  }
51 +#define EXT4_ATTR_OFFSET_ES(_name,_mode,_show,_store,_elname)          \
52 +static struct ext4_attr ext4_attr_##_name = {                          \
53 +       .attr = {.name = __stringify(_name), .mode = _mode },           \
54 +       .show   = _show,                                                \
55 +       .store  = _store,                                               \
56 +       .u = {                                                          \
57 +               .offset = offsetof(struct ext4_super_block, _elname),   \
58 +       },                                                              \
61  #define EXT4_ATTR(name, mode, show, store) \
62  static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
64  #define EXT4_INFO_ATTR(name) EXT4_ATTR(name, 0444, NULL, NULL)
65  #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL)
66  #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store)
68 +#define EXT4_RO_ATTR_ES_UI(name, elname)       \
69 +       EXT4_ATTR_OFFSET_ES(name, 0444, es_ui_show, NULL, elname)
70  #define EXT4_RW_ATTR_SBI_UI(name, elname)      \
71         EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname)
73  #define ATTR_LIST(name) &ext4_attr_##name.attr
74  #define EXT4_DEPRECATED_ATTR(_name, _val)      \
75  static struct ext4_attr ext4_attr_##_name = {                  \
76 @@ -2641,6 +2666,9 @@ EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.int
77  EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
78  EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
79  EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
80 +EXT4_RO_ATTR_ES_UI(errors_count, s_error_count);
81 +EXT4_RO_ATTR_ES_UI(first_error_time, s_first_error_time);
82 +EXT4_RO_ATTR_ES_UI(last_error_time, s_last_error_time);
84  static struct attribute *ext4_attrs[] = {
85         ATTR_LIST(delayed_allocation_blocks),
86 @@ -2664,6 +2692,9 @@ static struct attribute *ext4_attrs[] = {
87         ATTR_LIST(warning_ratelimit_burst),
88         ATTR_LIST(msg_ratelimit_interval_ms),
89         ATTR_LIST(msg_ratelimit_burst),
90 +       ATTR_LIST(errors_count),
91 +       ATTR_LIST(first_error_time),
92 +       ATTR_LIST(last_error_time),
93         NULL,
94  };
96 -- 
97 1.8.3.1
100 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
101 the body of a message to majordomo@vger.kernel.org
102 More majordomo info at  http://vger.kernel.org/majordomo-info.html