]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: change on-disk journal layout to support metadata checksumming
authorDarrick J. Wong <djwong@us.ibm.com>
Fri, 3 Aug 2012 00:47:45 +0000 (20:47 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 3 Aug 2012 00:47:45 +0000 (20:47 -0400)
Define flags and change journal structure definitions to support v2 journal
checksumming.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/logdump.c
e2fsck/recovery.c
lib/ext2fs/jfs_compat.h
lib/ext2fs/kernel-jbd.h

index 6e39b74cab9a01c9bfc7fd5e2765fc20ea469d5a..4a09bdb95e2455468cc8f87fb39eae0898b8015a 100644 (file)
@@ -501,7 +501,7 @@ static void dump_descriptor_block(FILE *out_file,
                        break;
 
                tag_block = be32_to_cpu(tag->t_blocknr);
-               tag_flags = be32_to_cpu(tag->t_flags);
+               tag_flags = be16_to_cpu(tag->t_flags);
 
                if (!(tag_flags & JFS_FLAG_SAME_UUID))
                        offset += 16;
index e94ef4e18c640d30c549df738f63fdeba1f444d9..a9fc3f7ae5b3a9c762d0ce21d25121c7746ef9eb 100644 (file)
@@ -193,10 +193,10 @@ static int count_tags(journal_t *journal, struct buffer_head *bh)
 
                nr++;
                tagp += tag_bytes;
-               if (!(tag->t_flags & cpu_to_be32(JFS_FLAG_SAME_UUID)))
+               if (!(tag->t_flags & cpu_to_be16(JFS_FLAG_SAME_UUID)))
                        tagp += 16;
 
-               if (tag->t_flags & cpu_to_be32(JFS_FLAG_LAST_TAG))
+               if (tag->t_flags & cpu_to_be16(JFS_FLAG_LAST_TAG))
                        break;
        }
 
@@ -486,7 +486,7 @@ static int do_one_pass(journal_t *journal,
                                unsigned long long io_block;
 
                                tag = (journal_block_tag_t *) tagp;
-                               flags = be32_to_cpu(tag->t_flags);
+                               flags = be16_to_cpu(tag->t_flags);
 
                                io_block = next_log_block++;
                                wrap(journal, next_log_block);
index 7b8aafd755a21efb9cd0f325544f1aa86c9695ae..7947ef5aefb35887a52f48bb3fa1aa5d028e10ba 100644 (file)
@@ -17,6 +17,8 @@
 
 #define cpu_to_be32(n) htonl(n)
 #define be32_to_cpu(n) ntohl(n)
+#define cpu_to_be16(n) htons(n)
+#define be16_to_cpu(n) ntohs(n)
 
 typedef unsigned int tid_t;
 typedef struct journal_s journal_t;
index 066c031ed4c9e3b89e08eefcf3c2a34570f65ff7..accd29c74cc9b70abed7859d16c5c71774ab75f5 100644 (file)
@@ -114,12 +114,24 @@ typedef struct journal_header_s
 #define JBD2_CRC32_CHKSUM   1
 #define JBD2_MD5_CHKSUM     2
 #define JBD2_SHA1_CHKSUM    3
+#define JBD2_CRC32C_CHKSUM  4
 
 #define JBD2_CRC32_CHKSUM_SIZE 4
 
 #define JBD2_CHECKSUM_BYTES (32 / sizeof(__u32))
 /*
  * Commit block header for storing transactional checksums:
+ *
+ * NOTE: If FEATURE_COMPAT_CHECKSUM (checksum v1) is set, the h_chksum*
+ * fields are used to store a checksum of the descriptor and data blocks.
+ *
+ * If FEATURE_INCOMPAT_CSUM_V2 (checksum v2) is set, then the h_chksum
+ * field is used to store crc32c(uuid+commit_block).  Each journal metadata
+ * block gets its own checksum, and data block checksums are stored in
+ * journal_block_tag (in the descriptor).  The other h_chksum* fields are
+ * not used.
+ *
+ * Checksum v1 and v2 are mutually exclusive features.
  */
 struct commit_header {
        __u32           h_magic;
@@ -139,13 +151,19 @@ struct commit_header {
 typedef struct journal_block_tag_s
 {
        __u32           t_blocknr;      /* The on-disk block number */
-       __u32           t_flags;        /* See below */
+       __u16           t_checksum;     /* truncated crc32c(uuid+seq+block) */
+       __u16           t_flags;        /* See below */
        __u32           t_blocknr_high; /* most-significant high 32bits. */
 } journal_block_tag_t;
 
 #define JBD_TAG_SIZE64 (sizeof(journal_block_tag_t))
 #define JBD_TAG_SIZE32 (8)
 
+/* Tail of descriptor block, for checksumming */
+struct journal_block_tail {
+       __u32           t_checksum;
+};
+
 /*
  * The revoke descriptor: used on disk to describe a series of blocks to
  * be revoked from the log
@@ -156,6 +174,10 @@ typedef struct journal_revoke_header_s
        int              r_count;       /* Count of bytes used in the block */
 } journal_revoke_header_t;
 
+/* Tail of revoke block, for checksumming */
+struct journal_revoke_tail {
+       __u32           r_checksum;
+};
 
 /* Definitions for the journal tag flags word: */
 #define JFS_FLAG_ESCAPE                1       /* on-disk block is escaped */
@@ -205,7 +227,10 @@ typedef struct journal_superblock_s
        __u32   s_max_trans_data;       /* Limit of data blocks per trans. */
 
 /* 0x0050 */
-       __u32   s_padding[44];
+       __u8    s_checksum_type;        /* checksum type */
+       __u8    s_padding2[3];
+       __u32   s_padding[42];
+       __u32   s_checksum;             /* crc32c(superblock) */
 
 /* 0x0100 */
        __u8    s_users[16*48];         /* ids of all fs'es sharing the log */
@@ -224,11 +249,10 @@ typedef struct journal_superblock_s
 
 #define JFS_FEATURE_COMPAT_CHECKSUM    0x00000001
 
-#define JFS_FEATURE_INCOMPAT_REVOKE    0x00000001
-
 #define JFS_FEATURE_INCOMPAT_REVOKE            0x00000001
 #define JFS_FEATURE_INCOMPAT_64BIT             0x00000002
 #define JFS_FEATURE_INCOMPAT_ASYNC_COMMIT      0x00000004
+#define JFS_FEATURE_INCOMPAT_CSUM_V2           0x00000008
 
 /* Features known to this kernel version: */
 #define JFS_KNOWN_COMPAT_FEATURES      0