Add Jan Kara's jbd2 cleanup patches
[ext4-patch-queue.git] / unify-revoke-and-tag-block-checksum-handling
blob27aa8b9b95212d6f4784b38be037f4a644ee9504
1 jbd2: unify revoke and tag block checksum handling
3 From: Jan Kara <jack@suse.cz>
5 Revoke and tag descriptor blocks are just different kinds of descriptor
6 blocks and thus have checksum in the same place. Unify computation and
7 checking of checksums for these.
9 Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
10 Signed-off-by: Jan Kara <jack@suse.cz>
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 ---
13  fs/jbd2/commit.c     | 18 +-----------------
14  fs/jbd2/journal.c    | 15 +++++++++++++++
15  fs/jbd2/recovery.c   | 31 +++++--------------------------
16  fs/jbd2/revoke.c     | 19 ++-----------------
17  include/linux/jbd2.h |  8 ++------
18  5 files changed, 25 insertions(+), 66 deletions(-)
20 diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
21 index cf221f3d955a..ae832cd44dd8 100644
22 --- a/fs/jbd2/commit.c
23 +++ b/fs/jbd2/commit.c
24 @@ -317,22 +317,6 @@ static void write_tag_block(journal_t *j, journal_block_tag_t *tag,
25                 tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
26  }
28 -static void jbd2_descr_block_csum_set(journal_t *j,
29 -                                     struct buffer_head *bh)
31 -       struct jbd2_journal_block_tail *tail;
32 -       __u32 csum;
34 -       if (!jbd2_journal_has_csum_v2or3(j))
35 -               return;
37 -       tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
38 -                       sizeof(struct jbd2_journal_block_tail));
39 -       tail->t_checksum = 0;
40 -       csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
41 -       tail->t_checksum = cpu_to_be32(csum);
44  static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
45                                     struct buffer_head *bh, __u32 sequence)
46  {
47 @@ -714,7 +698,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
49                         tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG);
51 -                       jbd2_descr_block_csum_set(journal, descriptor);
52 +                       jbd2_descriptor_block_csum_set(journal, descriptor);
53  start_journal_io:
54                         for (i = 0; i < bufs; i++) {
55                                 struct buffer_head *bh = wbuf[i];
56 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
57 index 28d05bd9a588..defa962a8e15 100644
58 --- a/fs/jbd2/journal.c
59 +++ b/fs/jbd2/journal.c
60 @@ -834,6 +834,21 @@ jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type)
61         return bh;
62  }
64 +void jbd2_descriptor_block_csum_set(journal_t *j, struct buffer_head *bh)
66 +       struct jbd2_journal_block_tail *tail;
67 +       __u32 csum;
69 +       if (!jbd2_journal_has_csum_v2or3(j))
70 +               return;
72 +       tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
73 +                       sizeof(struct jbd2_journal_block_tail));
74 +       tail->t_checksum = 0;
75 +       csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
76 +       tail->t_checksum = cpu_to_be32(csum);
79  /*
80   * Return tid of the oldest transaction in the journal and block in the journal
81   * where the transaction starts.
82 diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
83 index 7f277e49fe88..08a456b96e4e 100644
84 --- a/fs/jbd2/recovery.c
85 +++ b/fs/jbd2/recovery.c
86 @@ -174,8 +174,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
87         return 0;
88  }
90 -static int jbd2_descr_block_csum_verify(journal_t *j,
91 -                                       void *buf)
92 +static int jbd2_descriptor_block_csum_verify(journal_t *j, void *buf)
93  {
94         struct jbd2_journal_block_tail *tail;
95         __be32 provided;
96 @@ -522,8 +521,8 @@ static int do_one_pass(journal_t *journal,
97                                 descr_csum_size =
98                                         sizeof(struct jbd2_journal_block_tail);
99                         if (descr_csum_size > 0 &&
100 -                           !jbd2_descr_block_csum_verify(journal,
101 -                                                         bh->b_data)) {
102 +                           !jbd2_descriptor_block_csum_verify(journal,
103 +                                                              bh->b_data)) {
104                                 printk(KERN_ERR "JBD2: Invalid checksum "
105                                        "recovering block %lu in log\n",
106                                        next_log_block);
107 @@ -811,26 +810,6 @@ static int do_one_pass(journal_t *journal,
108         return err;
111 -static int jbd2_revoke_block_csum_verify(journal_t *j,
112 -                                        void *buf)
114 -       struct jbd2_journal_revoke_tail *tail;
115 -       __be32 provided;
116 -       __u32 calculated;
118 -       if (!jbd2_journal_has_csum_v2or3(j))
119 -               return 1;
121 -       tail = (struct jbd2_journal_revoke_tail *)(buf + j->j_blocksize -
122 -                       sizeof(struct jbd2_journal_revoke_tail));
123 -       provided = tail->r_checksum;
124 -       tail->r_checksum = 0;
125 -       calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize);
126 -       tail->r_checksum = provided;
128 -       return provided == cpu_to_be32(calculated);
131  /* Scan a revoke record, marking all blocks mentioned as revoked. */
133  static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
134 @@ -846,11 +825,11 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
135         offset = sizeof(jbd2_journal_revoke_header_t);
136         rcount = be32_to_cpu(header->r_count);
138 -       if (!jbd2_revoke_block_csum_verify(journal, header))
139 +       if (!jbd2_descriptor_block_csum_verify(journal, header))
140                 return -EFSBADCRC;
142         if (jbd2_journal_has_csum_v2or3(journal))
143 -               csum_size = sizeof(struct jbd2_journal_revoke_tail);
144 +               csum_size = sizeof(struct jbd2_journal_block_tail);
145         if (rcount > journal->j_blocksize - csum_size)
146                 return -EINVAL;
147         max = rcount;
148 diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
149 index d1ebb1d41d17..91171dc352cb 100644
150 --- a/fs/jbd2/revoke.c
151 +++ b/fs/jbd2/revoke.c
152 @@ -583,7 +583,7 @@ static void write_one_revoke_record(transaction_t *transaction,
154         /* Do we need to leave space at the end for a checksum? */
155         if (jbd2_journal_has_csum_v2or3(journal))
156 -               csum_size = sizeof(struct jbd2_journal_revoke_tail);
157 +               csum_size = sizeof(struct jbd2_journal_block_tail);
159         if (jbd2_has_feature_64bit(journal))
160                 sz = 8;
161 @@ -623,21 +623,6 @@ static void write_one_revoke_record(transaction_t *transaction,
162         *offsetp = offset;
165 -static void jbd2_revoke_csum_set(journal_t *j, struct buffer_head *bh)
167 -       struct jbd2_journal_revoke_tail *tail;
168 -       __u32 csum;
170 -       if (!jbd2_journal_has_csum_v2or3(j))
171 -               return;
173 -       tail = (struct jbd2_journal_revoke_tail *)(bh->b_data + j->j_blocksize -
174 -                       sizeof(struct jbd2_journal_revoke_tail));
175 -       tail->r_checksum = 0;
176 -       csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
177 -       tail->r_checksum = cpu_to_be32(csum);
180  /*
181   * Flush a revoke descriptor out to the journal.  If we are aborting,
182   * this is a noop; otherwise we are generating a buffer which needs to
183 @@ -658,7 +643,7 @@ static void flush_descriptor(journal_t *journal,
185         header = (jbd2_journal_revoke_header_t *)descriptor->b_data;
186         header->r_count = cpu_to_be32(offset);
187 -       jbd2_revoke_csum_set(journal, descriptor);
188 +       jbd2_descriptor_block_csum_set(journal, descriptor);
190         set_buffer_jwrite(descriptor);
191         BUFFER_TRACE(descriptor, "write");
192 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
193 index 3649cb8d3a41..fd1083c46c61 100644
194 --- a/include/linux/jbd2.h
195 +++ b/include/linux/jbd2.h
196 @@ -200,7 +200,7 @@ typedef struct journal_block_tag_s
197         __be32          t_blocknr_high; /* most-significant high 32bits. */
198  } journal_block_tag_t;
200 -/* Tail of descriptor block, for checksumming */
201 +/* Tail of descriptor or revoke block, for checksumming */
202  struct jbd2_journal_block_tail {
203         __be32          t_checksum;     /* crc32c(uuid+descr_block) */
204  };
205 @@ -215,11 +215,6 @@ typedef struct jbd2_journal_revoke_header_s
206         __be32           r_count;       /* Count of bytes used in the block */
207  } jbd2_journal_revoke_header_t;
209 -/* Tail of revoke block, for checksumming */
210 -struct jbd2_journal_revoke_tail {
211 -       __be32          r_checksum;     /* crc32c(uuid+revoke_block) */
214  /* Definitions for the journal tag flags word: */
215  #define JBD2_FLAG_ESCAPE               1       /* on-disk block is escaped */
216  #define JBD2_FLAG_SAME_UUID    2       /* block has same uuid as previous */
217 @@ -1138,6 +1133,7 @@ static inline void jbd2_unfile_log_bh(struct buffer_head *bh)
219  /* Log buffer allocation */
220  struct buffer_head *jbd2_journal_get_descriptor_buffer(transaction_t *, int);
221 +void jbd2_descriptor_block_csum_set(journal_t *, struct buffer_head *);
222  int jbd2_journal_next_log_block(journal_t *, unsigned long long *);
223  int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid,
224                               unsigned long *block);
225 -- 
226 2.6.2