[PATCH v2] ext4: add sysfs entry showing whether the fs contains errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently there is no easy way to tell that the mounted file system
contains errors other than checking for log messages, or reading the
information directly from superblock.

This patch adds new sysfs entry "errors" for each ext4 file
system so user can simply check

cat /sys/fs/ext4/sda/errors

If the file system is not marked as containing errors then the file
returns just 0. Otherwise it would print out the following information:

<error count> first <first_error_time> <first_error_func>:<first_error_line> \
last <last_error_time> <last_error_func>:<last_error_line>

For example:

2 first 1399305407 trigger_test_error:2630 last 1399463224 trigger_test_error:2601

Signed-off-by: Lukas Czerner <lczerner@xxxxxxxxxx>
---
v2: Change the name of the file to errors and change the output format

 fs/ext4/super.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 6f9e6fa..9d49ec1 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2502,6 +2502,27 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
 			  EXT4_SB(sb)->s_sectors_written_start) >> 1)));
 }
 
+static ssize_t errors_show(struct ext4_attr *a,
+			   struct ext4_sb_info *sbi, char *buf)
+{
+	struct ext4_super_block *es = sbi->s_es;
+
+	if (es->s_error_count)
+		return snprintf(buf, PAGE_SIZE,
+				"%u first %u %.*s:%d last %u %.*s:%d\n",
+				le32_to_cpu(es->s_error_count),
+				le32_to_cpu(es->s_first_error_time),
+				(int) sizeof(es->s_first_error_func),
+				es->s_first_error_func,
+				le32_to_cpu(es->s_first_error_line),
+				le32_to_cpu(es->s_last_error_time),
+				(int) sizeof(es->s_last_error_func),
+				es->s_last_error_func,
+				le32_to_cpu(es->s_last_error_line));
+	else
+		return snprintf(buf, PAGE_SIZE, "0\n");
+}
+
 static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
 					  struct ext4_sb_info *sbi,
 					  const char *buf, size_t count)
@@ -2617,6 +2638,7 @@ static struct ext4_attr ext4_attr_##_name = {			\
 EXT4_RO_ATTR(delayed_allocation_blocks);
 EXT4_RO_ATTR(session_write_kbytes);
 EXT4_RO_ATTR(lifetime_write_kbytes);
+EXT4_RO_ATTR(errors);
 EXT4_RW_ATTR(reserved_clusters);
 EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
 		 inode_readahead_blks_store, s_inode_readahead_blks);
@@ -2641,6 +2663,7 @@ static struct attribute *ext4_attrs[] = {
 	ATTR_LIST(delayed_allocation_blocks),
 	ATTR_LIST(session_write_kbytes),
 	ATTR_LIST(lifetime_write_kbytes),
+	ATTR_LIST(errors),
 	ATTR_LIST(reserved_clusters),
 	ATTR_LIST(inode_readahead_blks),
 	ATTR_LIST(inode_goal),
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux