Whamcloud - gitweb
Add superblock fields which track first and most recent fs errors
authorTheodore Ts'o <tytso@mit.edu>
Fri, 25 Jun 2010 14:53:13 +0000 (10:53 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 5 Jul 2010 18:45:55 +0000 (14:45 -0400)
Add superblock fields which track where and when the first and most
recent file system errors occured.  These fields are displayed by
dumpe2fs and cleared by e2fsck.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/unix.c
lib/e2p/ls.c
lib/ext2fs/ext2_fs.h

index be16501..34fa9b1 100644 (file)
@@ -1441,6 +1441,8 @@ no_journal:
                        sb->s_mnt_count = 0;
                        if (!(ctx->flags & E2F_FLAG_TIME_INSANE))
                                sb->s_lastcheck = ctx->now;
+                       memset(((char *) sb) + EXT4_S_ERR_START, 0,
+                              EXT4_S_ERR_LEN);
                        ext2fs_mark_super_dirty(fs);
                }
        }
index b208e66..f2a04ff 100644 (file)
@@ -341,6 +341,37 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
        if (sb->s_snapshot_list)
                fprintf(f, "Snapshot list head:       %u\n",
                        sb->s_snapshot_list);
+       if (sb->s_error_count)
+               fprintf(f, "FS Error count:           %u\n",
+                       sb->s_error_count);
+       if (sb->s_first_error_time) {
+               tm = sb->s_first_error_time;
+               fprintf(f, "First error time:         %s", ctime(&tm));
+               memset(buf, 0, sizeof(buf));
+               strncpy(buf, sb->s_first_error_func,
+                       sizeof(sb->s_first_error_func));
+               fprintf(f, "First error function:     %s\n", buf);
+               fprintf(f, "First error line #:       %u\n",
+                       sb->s_first_error_line);
+               fprintf(f, "First error inode #:      %u\n",
+                       sb->s_first_error_ino);
+               fprintf(f, "First error block #:      %llu\n",
+                       sb->s_first_error_block);
+       }
+       if (sb->s_last_error_time) {
+               tm = sb->s_last_error_time;
+               fprintf(f, "Last error time:          %s", ctime(&tm));
+               memset(buf, 0, sizeof(buf));
+               strncpy(buf, sb->s_last_error_func,
+                       sizeof(sb->s_last_error_func));
+               fprintf(f, "Last error function:      %s\n", buf);
+               fprintf(f, "Last error line #:        %u\n",
+                       sb->s_last_error_line);
+               fprintf(f, "Last error inode #:       %u\n",
+                       sb->s_last_error_ino);
+               fprintf(f, "Last error block #:       %llu\n",
+                       sb->s_last_error_block);
+       }
 }
 
 void list_super (struct ext2_super_block * s)
index 8735105..a2bca3d 100644 (file)
@@ -501,6 +501,12 @@ struct ext2_inode_large {
 #define EXT2_ERRORS_PANIC              3       /* Panic */
 #define EXT2_ERRORS_DEFAULT            EXT2_ERRORS_CONTINUE
 
+#if (__GNUC__ >= 4)
+#define ext4_offsetof(TYPE,MEMBER) __builtin_offsetof(TYPE,MEMBER)
+#else
+#define ext4_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
 /*
  * Structure of the super block
  */
@@ -594,9 +600,24 @@ struct ext2_super_block {
        __u64   s_snapshot_r_blocks_count; /* reserved blocks for active
                                              snapshot's future use */
        __u32   s_snapshot_list;        /* inode number of the head of the on-disk snapshot list */
-       __u32   s_reserved[155];        /* Padding to the end of the block */
+#define EXT4_S_ERR_START ext4_offsetof(struct ext2_super_block, s_error_count)
+       __u32   s_error_count;          /* number of fs errors */
+       __u32   s_first_error_time;     /* first time an error happened */
+       __u32   s_first_error_ino;      /* inode involved in first error */
+       __u64   s_first_error_block;    /* block involved of first error */
+       __u8    s_first_error_func[32]; /* function where the error happened */
+       __u32   s_first_error_line;     /* line number where error happened */
+       __u32   s_last_error_time;      /* most recent time of an error */
+       __u32   s_last_error_ino;       /* inode involved in last error */
+       __u32   s_last_error_line;      /* line number where error happened */
+       __u64   s_last_error_block;     /* block involved of last error */
+       __u8    s_last_error_func[32];  /* function where the error happened */
+#define EXT4_S_ERR_END ext4_offsetof(struct ext2_super_block, s_error_count)
+       __u32   s_reserved[128];        /* Padding to the end of the block */
 };
 
+#define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START)
+
 /*
  * Codes for operating systems
  */