Whamcloud - gitweb
Sync kernel's unification of jbd2 revoke and tag block checksum handling
authorTheodore Ts'o <tytso@mit.edu>
Sat, 9 Nov 2019 01:26:05 +0000 (20:26 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 9 Nov 2019 06:55:14 +0000 (01:55 -0500)
Commit 1101cd4d13ba ("jbd2: unify revoke and tag block checksum
handling") cleans up the fact that the jbd2_journal_revoke_tail and
jbd2_journal_block_tail structures are basically the same.  So it
drops the definition of struct jbd2_journal_revoke_tail and unifies
the functions which calculates and verifies the checksums for revoke
blocks and tag blocks.

Make the same changes in e2fsprogs so eliminate unnecessary
differences in e2fsck/recovery.c and e2fsck/revoke.c.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/do_journal.c
debugfs/journal.c
e2fsck/jfs_user.h
e2fsck/recovery.c
e2fsck/revoke.c
lib/ext2fs/kernel-jbd.h

index ee6d16b..48b2149 100644 (file)
@@ -181,7 +181,7 @@ static errcode_t journal_add_revoke_to_trans(journal_transaction_t *trans,
 
        /* Do we need to leave space at the end for a checksum? */
        if (jbd2_journal_has_csum_v2or3(trans->journal))
-               csum_size = sizeof(struct journal_revoke_tail);
+               csum_size = sizeof(struct jbd2_journal_block_tail);
 
        curr_blk = trans->block;
 
@@ -419,7 +419,7 @@ static blk64_t journal_guess_blocks(journal_t *journal, blk64_t data_blocks,
        /* Estimate # of revoke blocks */
        bs = journal->j_blocksize;
        if (jbd2_journal_has_csum_v2or3(journal))
-               bs -= sizeof(struct journal_revoke_tail);
+               bs -= sizeof(struct jbd2_journal_block_tail);
        sz = jbd2_has_feature_64bit(journal) ? sizeof(__u64) : sizeof(__u32);
        ret += revoke_blocks * sz / bs;
 
index fd4ccf2..7908e98 100644 (file)
@@ -889,17 +889,7 @@ void jbd2_commit_block_csum_set(journal_t *j, struct buffer_head *bh)
 
 void jbd2_revoke_csum_set(journal_t *j, struct buffer_head *bh)
 {
-       struct journal_revoke_tail *tail;
-       __u32 csum;
-
-       if (!jbd2_journal_has_csum_v2or3(j))
-               return;
-
-       tail = (struct journal_revoke_tail *)(bh->b_data + j->j_blocksize -
-                       sizeof(struct journal_revoke_tail));
-       tail->r_checksum = 0;
-       csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
-       tail->r_checksum = ext2fs_cpu_to_be32(csum);
+       jbd2_descr_block_csum_set(j, bh);
 }
 
 void jbd2_descr_block_csum_set(journal_t *j, struct buffer_head *bh)
index 46df997..239ac1d 100644 (file)
@@ -226,6 +226,22 @@ extern e2fsck_t e2fsck_global_ctx;  /* Try your very best not to use this! */
 #define EFSCORRUPTED   EXT2_ET_FILESYSTEM_CORRUPTED
 #endif
 
+static inline 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);
+}
+
 /* recovery.c */
 extern int     jbd2_journal_recover    (journal_t *journal);
 extern int     jbd2_journal_skip_recovery (journal_t *);
index a0e15e8..ddbb386 100644 (file)
@@ -192,8 +192,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;
        __u32 provided;
@@ -343,7 +342,7 @@ int jbd2_journal_skip_recovery(journal_t *journal)
                ++journal->j_transaction_sequence;
        } else {
 #ifdef CONFIG_JBD2_DEBUG
-               int dropped = info.end_transaction -
+               int dropped = info.end_transaction - 
                        ext2fs_be32_to_cpu(journal->j_superblock->s_sequence);
                jbd_debug(1,
                          "JBD2: ignoring %d transaction%s from the journal.\n",
@@ -540,8 +539,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)) {
                                err = -EFSBADCRC;
                                brelse(bh);
                                goto failed;
@@ -827,26 +826,6 @@ static int do_one_pass(journal_t *journal,
        return err;
 }
 
-static int jbd2_revoke_block_csum_verify(journal_t *j,
-                                        void *buf)
-{
-       struct journal_revoke_tail *tail;
-       __u32 provided;
-       __u32 calculated;
-
-       if (!jbd2_journal_has_csum_v2or3(j))
-               return 1;
-
-       tail = (struct journal_revoke_tail *)((char *)buf + j->j_blocksize -
-                       sizeof(struct 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 == ext2fs_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,
@@ -862,11 +841,11 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
        offset = sizeof(jbd2_journal_revoke_header_t);
        rcount = ext2fs_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 journal_revoke_tail);
+               csum_size = sizeof(struct jbd2_journal_block_tail);
        if (rcount > journal->j_blocksize - csum_size)
                return -EINVAL;
        max = rcount;
index 83b23fd..3fadf57 100644 (file)
@@ -588,7 +588,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 journal_revoke_tail);
+               csum_size = sizeof(struct jbd2_journal_block_tail);
 
        if (jbd2_has_feature_64bit(journal))
                sz = 8;
@@ -628,21 +628,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 journal_revoke_tail *tail;
-       __u32 csum;
-
-       if (!jbd2_journal_has_csum_v2or3(j))
-               return;
-
-       tail = (struct journal_revoke_tail *)(bh->b_data + j->j_blocksize -
-                       sizeof(struct journal_revoke_tail));
-       tail->r_checksum = 0;
-       csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
-       tail->r_checksum = ext2fs_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
@@ -661,7 +646,7 @@ static void flush_descriptor(journal_t *journal,
 
        header = (jbd2_journal_revoke_header_t *)descriptor->b_data;
        header->r_count = ext2fs_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 5e535b4..70a1206 100644 (file)
@@ -165,7 +165,7 @@ typedef struct journal_block_tag_s
        __u32           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;
 };
@@ -180,11 +180,6 @@ typedef struct journal_revoke_header_s
        int              r_count;       /* Count of bytes used in the block */
 } jbd2_journal_revoke_header_t;
 
-/* Tail of revoke block, for checksumming */
-struct journal_revoke_tail {
-       __be32          r_checksum;
-};
-
 /* 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 */