jbd2: unify revoke and tag block checksum handling
authorJan Kara <jack@suse.cz>
Tue, 23 Feb 2016 04:19:09 +0000 (23:19 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 23 Feb 2016 04:19:09 +0000 (23:19 -0500)
Revoke and tag descriptor blocks are just different kinds of descriptor
blocks and thus have checksum in the same place. Unify computation and
checking of checksums for these.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/jbd2/commit.c
fs/jbd2/journal.c
fs/jbd2/recovery.c
fs/jbd2/revoke.c
include/linux/jbd2.h

index cf221f3d955ab232a44b2b3c2d4a079498814e29..ae832cd44dd8ac22c8fc9d83523b2c819fb1727a 100644 (file)
@@ -317,22 +317,6 @@ static void write_tag_block(journal_t *j, journal_block_tag_t *tag,
                tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
 }
 
-static void jbd2_descr_block_csum_set(journal_t *j,
-                                     struct buffer_head *bh)
-{
-       struct jbd2_journal_block_tail *tail;
-       __u32 csum;
-
-       if (!jbd2_journal_has_csum_v2or3(j))
-               return;
-
-       tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
-                       sizeof(struct jbd2_journal_block_tail));
-       tail->t_checksum = 0;
-       csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
-       tail->t_checksum = cpu_to_be32(csum);
-}
-
 static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
                                    struct buffer_head *bh, __u32 sequence)
 {
@@ -714,7 +698,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
 
                        tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG);
 
-                       jbd2_descr_block_csum_set(journal, descriptor);
+                       jbd2_descriptor_block_csum_set(journal, descriptor);
 start_journal_io:
                        for (i = 0; i < bufs; i++) {
                                struct buffer_head *bh = wbuf[i];
index 28d05bd9a58816b0d809c8bdeb309cb065f7f00d..defa962a8e15ef51a950f96f04bb80289d1a0678 100644 (file)
@@ -834,6 +834,21 @@ jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type)
        return bh;
 }
 
+void jbd2_descriptor_block_csum_set(journal_t *j, struct buffer_head *bh)
+{
+       struct jbd2_journal_block_tail *tail;
+       __u32 csum;
+
+       if (!jbd2_journal_has_csum_v2or3(j))
+               return;
+
+       tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
+                       sizeof(struct jbd2_journal_block_tail));
+       tail->t_checksum = 0;
+       csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
+       tail->t_checksum = cpu_to_be32(csum);
+}
+
 /*
  * Return tid of the oldest transaction in the journal and block in the journal
  * where the transaction starts.
index 7f277e49fe8841edcf87c45a652b98c316c8b35e..08a456b96e4ef475d5212f136d69e8975aba86b4 100644 (file)
@@ -174,8 +174,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
        return 0;
 }
 
-static int jbd2_descr_block_csum_verify(journal_t *j,
-                                       void *buf)
+static int jbd2_descriptor_block_csum_verify(journal_t *j, void *buf)
 {
        struct jbd2_journal_block_tail *tail;
        __be32 provided;
@@ -522,8 +521,8 @@ static int do_one_pass(journal_t *journal,
                                descr_csum_size =
                                        sizeof(struct jbd2_journal_block_tail);
                        if (descr_csum_size > 0 &&
-                           !jbd2_descr_block_csum_verify(journal,
-                                                         bh->b_data)) {
+                           !jbd2_descriptor_block_csum_verify(journal,
+                                                              bh->b_data)) {
                                printk(KERN_ERR "JBD2: Invalid checksum "
                                       "recovering block %lu in log\n",
                                       next_log_block);
@@ -811,26 +810,6 @@ static int do_one_pass(journal_t *journal,
        return err;
 }
 
-static int jbd2_revoke_block_csum_verify(journal_t *j,
-                                        void *buf)
-{
-       struct jbd2_journal_revoke_tail *tail;
-       __be32 provided;
-       __u32 calculated;
-
-       if (!jbd2_journal_has_csum_v2or3(j))
-               return 1;
-
-       tail = (struct jbd2_journal_revoke_tail *)(buf + j->j_blocksize -
-                       sizeof(struct jbd2_journal_revoke_tail));
-       provided = tail->r_checksum;
-       tail->r_checksum = 0;
-       calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize);
-       tail->r_checksum = provided;
-
-       return provided == cpu_to_be32(calculated);
-}
-
 /* Scan a revoke record, marking all blocks mentioned as revoked. */
 
 static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
@@ -846,11 +825,11 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
        offset = sizeof(jbd2_journal_revoke_header_t);
        rcount = be32_to_cpu(header->r_count);
 
-       if (!jbd2_revoke_block_csum_verify(journal, header))
+       if (!jbd2_descriptor_block_csum_verify(journal, header))
                return -EFSBADCRC;
 
        if (jbd2_journal_has_csum_v2or3(journal))
-               csum_size = sizeof(struct jbd2_journal_revoke_tail);
+               csum_size = sizeof(struct jbd2_journal_block_tail);
        if (rcount > journal->j_blocksize - csum_size)
                return -EINVAL;
        max = rcount;
index d1ebb1d41d1703f39a47e0d7be48d6bede3d110f..91171dc352cbd10d7a0bc8120f6e8bffcf19d139 100644 (file)
@@ -583,7 +583,7 @@ static void write_one_revoke_record(transaction_t *transaction,
 
        /* Do we need to leave space at the end for a checksum? */
        if (jbd2_journal_has_csum_v2or3(journal))
-               csum_size = sizeof(struct jbd2_journal_revoke_tail);
+               csum_size = sizeof(struct jbd2_journal_block_tail);
 
        if (jbd2_has_feature_64bit(journal))
                sz = 8;
@@ -623,21 +623,6 @@ static void write_one_revoke_record(transaction_t *transaction,
        *offsetp = offset;
 }
 
-static void jbd2_revoke_csum_set(journal_t *j, struct buffer_head *bh)
-{
-       struct jbd2_journal_revoke_tail *tail;
-       __u32 csum;
-
-       if (!jbd2_journal_has_csum_v2or3(j))
-               return;
-
-       tail = (struct jbd2_journal_revoke_tail *)(bh->b_data + j->j_blocksize -
-                       sizeof(struct jbd2_journal_revoke_tail));
-       tail->r_checksum = 0;
-       csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
-       tail->r_checksum = cpu_to_be32(csum);
-}
-
 /*
  * Flush a revoke descriptor out to the journal.  If we are aborting,
  * this is a noop; otherwise we are generating a buffer which needs to
@@ -658,7 +643,7 @@ static void flush_descriptor(journal_t *journal,
 
        header = (jbd2_journal_revoke_header_t *)descriptor->b_data;
        header->r_count = cpu_to_be32(offset);
-       jbd2_revoke_csum_set(journal, descriptor);
+       jbd2_descriptor_block_csum_set(journal, descriptor);
 
        set_buffer_jwrite(descriptor);
        BUFFER_TRACE(descriptor, "write");
index 3649cb8d3a41356698757374536cedca359224e9..fd1083c46c61f0f2163287f4b873968d4778aa07 100644 (file)
@@ -200,7 +200,7 @@ typedef struct journal_block_tag_s
        __be32          t_blocknr_high; /* most-significant high 32bits. */
 } journal_block_tag_t;
 
-/* Tail of descriptor block, for checksumming */
+/* Tail of descriptor or revoke block, for checksumming */
 struct jbd2_journal_block_tail {
        __be32          t_checksum;     /* crc32c(uuid+descr_block) */
 };
@@ -215,11 +215,6 @@ typedef struct jbd2_journal_revoke_header_s
        __be32           r_count;       /* Count of bytes used in the block */
 } jbd2_journal_revoke_header_t;
 
-/* Tail of revoke block, for checksumming */
-struct jbd2_journal_revoke_tail {
-       __be32          r_checksum;     /* crc32c(uuid+revoke_block) */
-};
-
 /* Definitions for the journal tag flags word: */
 #define JBD2_FLAG_ESCAPE               1       /* on-disk block is escaped */
 #define JBD2_FLAG_SAME_UUID    2       /* block has same uuid as previous */
@@ -1138,6 +1133,7 @@ static inline void jbd2_unfile_log_bh(struct buffer_head *bh)
 
 /* Log buffer allocation */
 struct buffer_head *jbd2_journal_get_descriptor_buffer(transaction_t *, int);
+void jbd2_descriptor_block_csum_set(journal_t *, struct buffer_head *);
 int jbd2_journal_next_log_block(journal_t *, unsigned long long *);
 int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid,
                              unsigned long *block);