aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@us.ibm.com>2012-05-22 22:43:41 -0400
committerTheodore Ts'o <tytso@mit.edu>2012-05-22 22:43:41 -0400
commit8f888ef846d4481e24c74b4a91ece771d2bcbcb5 (patch)
treebd037514671c52cea95426ba417a6c1b4b59f96a
parentf32aaf2d2b996b14e993da1c23f7ee22ea7333a3 (diff)
jbd2: change disk layout for metadata checksumming
Define flags and allocate space in on-disk journal structures to support checksumming of journal metadata. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--fs/jbd2/commit.c4
-rw-r--r--fs/jbd2/recovery.c6
-rw-r--r--include/linux/jbd2.h30
3 files changed, 33 insertions, 7 deletions
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 840f70f5079..69d780310ae 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -627,7 +627,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
627 627
628 tag = (journal_block_tag_t *) tagp; 628 tag = (journal_block_tag_t *) tagp;
629 write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr); 629 write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr);
630 tag->t_flags = cpu_to_be32(tag_flag); 630 tag->t_flags = cpu_to_be16(tag_flag);
631 tagp += tag_bytes; 631 tagp += tag_bytes;
632 space_left -= tag_bytes; 632 space_left -= tag_bytes;
633 633
@@ -651,7 +651,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
651 submitting the IOs. "tag" still points to 651 submitting the IOs. "tag" still points to
652 the last tag we set up. */ 652 the last tag we set up. */
653 653
654 tag->t_flags |= cpu_to_be32(JBD2_FLAG_LAST_TAG); 654 tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG);
655 655
656start_journal_io: 656start_journal_io:
657 for (i = 0; i < bufs; i++) { 657 for (i = 0; i < bufs; i++) {
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index c1a03354a22..980f3d6b5f8 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -193,10 +193,10 @@ static int count_tags(journal_t *journal, struct buffer_head *bh)
193 193
194 nr++; 194 nr++;
195 tagp += tag_bytes; 195 tagp += tag_bytes;
196 if (!(tag->t_flags & cpu_to_be32(JBD2_FLAG_SAME_UUID))) 196 if (!(tag->t_flags & cpu_to_be16(JBD2_FLAG_SAME_UUID)))
197 tagp += 16; 197 tagp += 16;
198 198
199 if (tag->t_flags & cpu_to_be32(JBD2_FLAG_LAST_TAG)) 199 if (tag->t_flags & cpu_to_be16(JBD2_FLAG_LAST_TAG))
200 break; 200 break;
201 } 201 }
202 202
@@ -485,7 +485,7 @@ static int do_one_pass(journal_t *journal,
485 unsigned long io_block; 485 unsigned long io_block;
486 486
487 tag = (journal_block_tag_t *) tagp; 487 tag = (journal_block_tag_t *) tagp;
488 flags = be32_to_cpu(tag->t_flags); 488 flags = be16_to_cpu(tag->t_flags);
489 489
490 io_block = next_log_block++; 490 io_block = next_log_block++;
491 wrap(journal, next_log_block); 491 wrap(journal, next_log_block);
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 912c30a8ddb..809c439066c 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -147,12 +147,24 @@ typedef struct journal_header_s
147#define JBD2_CRC32_CHKSUM 1 147#define JBD2_CRC32_CHKSUM 1
148#define JBD2_MD5_CHKSUM 2 148#define JBD2_MD5_CHKSUM 2
149#define JBD2_SHA1_CHKSUM 3 149#define JBD2_SHA1_CHKSUM 3
150#define JBD2_CRC32C_CHKSUM 4
150 151
151#define JBD2_CRC32_CHKSUM_SIZE 4 152#define JBD2_CRC32_CHKSUM_SIZE 4
152 153
153#define JBD2_CHECKSUM_BYTES (32 / sizeof(u32)) 154#define JBD2_CHECKSUM_BYTES (32 / sizeof(u32))
154/* 155/*
155 * Commit block header for storing transactional checksums: 156 * Commit block header for storing transactional checksums:
157 *
158 * NOTE: If FEATURE_COMPAT_CHECKSUM (checksum v1) is set, the h_chksum*
159 * fields are used to store a checksum of the descriptor and data blocks.
160 *
161 * If FEATURE_INCOMPAT_CSUM_V2 (checksum v2) is set, then the h_chksum
162 * field is used to store crc32c(uuid+commit_block). Each journal metadata
163 * block gets its own checksum, and data block checksums are stored in
164 * journal_block_tag (in the descriptor). The other h_chksum* fields are
165 * not used.
166 *
167 * Checksum v1 and v2 are mutually exclusive features.
156 */ 168 */
157struct commit_header { 169struct commit_header {
158 __be32 h_magic; 170 __be32 h_magic;
@@ -175,13 +187,19 @@ struct commit_header {
175typedef struct journal_block_tag_s 187typedef struct journal_block_tag_s
176{ 188{
177 __be32 t_blocknr; /* The on-disk block number */ 189 __be32 t_blocknr; /* The on-disk block number */
178 __be32 t_flags; /* See below */ 190 __be16 t_checksum; /* truncated crc32c(uuid+seq+block) */
191 __be16 t_flags; /* See below */
179 __be32 t_blocknr_high; /* most-significant high 32bits. */ 192 __be32 t_blocknr_high; /* most-significant high 32bits. */
180} journal_block_tag_t; 193} journal_block_tag_t;
181 194
182#define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high)) 195#define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high))
183#define JBD2_TAG_SIZE64 (sizeof(journal_block_tag_t)) 196#define JBD2_TAG_SIZE64 (sizeof(journal_block_tag_t))
184 197
198/* Tail of descriptor block, for checksumming */
199struct jbd2_journal_block_tail {
200 __be32 t_checksum; /* crc32c(uuid+descr_block) */
201};
202
185/* 203/*
186 * The revoke descriptor: used on disk to describe a series of blocks to 204 * The revoke descriptor: used on disk to describe a series of blocks to
187 * be revoked from the log 205 * be revoked from the log
@@ -192,6 +210,10 @@ typedef struct jbd2_journal_revoke_header_s
192 __be32 r_count; /* Count of bytes used in the block */ 210 __be32 r_count; /* Count of bytes used in the block */
193} jbd2_journal_revoke_header_t; 211} jbd2_journal_revoke_header_t;
194 212
213/* Tail of revoke block, for checksumming */
214struct jbd2_journal_revoke_tail {
215 __be32 r_checksum; /* crc32c(uuid+revoke_block) */
216};
195 217
196/* Definitions for the journal tag flags word: */ 218/* Definitions for the journal tag flags word: */
197#define JBD2_FLAG_ESCAPE 1 /* on-disk block is escaped */ 219#define JBD2_FLAG_ESCAPE 1 /* on-disk block is escaped */
@@ -241,7 +263,10 @@ typedef struct journal_superblock_s
241 __be32 s_max_trans_data; /* Limit of data blocks per trans. */ 263 __be32 s_max_trans_data; /* Limit of data blocks per trans. */
242 264
243/* 0x0050 */ 265/* 0x0050 */
244 __u32 s_padding[44]; 266 __u8 s_checksum_type; /* checksum type */
267 __u8 s_padding2[3];
268 __u32 s_padding[42];
269 __be32 s_checksum; /* crc32c(superblock) */
245 270
246/* 0x0100 */ 271/* 0x0100 */
247 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */ 272 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
@@ -263,6 +288,7 @@ typedef struct journal_superblock_s
263#define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 288#define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001
264#define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 289#define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002
265#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004 290#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004
291#define JBD2_FEATURE_INCOMPAT_CSUM_V2 0x00000008
266 292
267/* Features known to this kernel version: */ 293/* Features known to this kernel version: */
268#define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM 294#define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM