1 jbd2: load jmap from journal
3 If the lazy journal feature is enabled, instead of replaying the
4 journal, read the journal into journal map.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 fs/jbd2/jmap.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
9 fs/jbd2/recovery.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
10 include/linux/jmap.h | 4 ++++
11 3 files changed, 127 insertions(+), 23 deletions(-)
13 diff --git a/fs/jbd2/jmap.c b/fs/jbd2/jmap.c
14 index ea1bb25e2d5d..7cfc6f6eb9d3 100644
17 @@ -100,7 +100,7 @@ static int process_existing_mappings(journal_t *journal,
18 if (je == journal->j_cleaner_ctx->pos) {
19 journal->j_cleaner_ctx->pos = list_next_entry(je, list);
20 trace_jbd2_jmap_printf1("updating pos to",
21 - (unsigned long long) journal->j_cleaner_ctx->pos);
22 + (unsigned long long) (unsigned long) journal->j_cleaner_ctx->pos);
25 spin_unlock(&journal->j_cleaner_ctx->pos_lock);
26 @@ -179,6 +179,61 @@ static void add_new_mappings(journal_t *journal, struct transaction_info *ti,
30 +void jbd2_add_new_transaction_infos(journal_t *journal, tid_t tid,
31 + unsigned long log_start)
33 + struct transaction_infos *tis = journal->j_transaction_infos;
34 + int t_idx = tis->head;
35 + struct transaction_info *ti = &tis->buf[t_idx];
38 + * We are possibly reusing space of an old transaction_info. The old
39 + * transaction should not have any live blocks in it.
41 + BUG_ON(!list_empty(&ti->live_blks));
43 + write_lock(&journal->j_jmap_lock);
45 + ti->offset = log_start;
46 + write_unlock(&journal->j_jmap_lock);
49 +int jbd2_add_mapping(journal_t *journal, struct blk_mapping *mapping)
51 + struct transaction_infos *tis = journal->j_transaction_infos;
52 + int t_idx = tis->head;
53 + struct transaction_info *ti = &tis->buf[t_idx];
54 + struct jmap_entry *new_entry;
57 + write_lock(&journal->j_jmap_lock);
58 + nr_new = process_existing_mappings(journal, ti, t_idx, mapping, 1);
59 + write_unlock(&journal->j_jmap_lock);
64 + new_entry = kmem_cache_zalloc(jbd2_jmap_cache, GFP_NOFS);
68 + write_lock(&journal->j_jmap_lock);
69 + add_new_mappings(journal, ti, t_idx, mapping, &new_entry, 1);
70 + write_unlock(&journal->j_jmap_lock);
74 +void jbd2_finish_transaction_infos(journal_t *journal)
76 + struct transaction_infos *tis = journal->j_transaction_infos;
78 + atomic_inc(&journal->j_cleaner_ctx->nr_txns_committed);
80 + write_lock(&journal->j_jmap_lock);
81 + tis->head = (tis->head + 1) & (MAX_LIVE_TRANSACTIONS - 1);
82 + write_unlock(&journal->j_jmap_lock);
86 * This function is called after a transaction commits. It adds new
87 * transaction_info structure to transaction_infos and populates jmap map with
88 diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
89 index da100044566c..fc02a2eb837c 100644
90 --- a/fs/jbd2/recovery.c
91 +++ b/fs/jbd2/recovery.c
92 @@ -32,17 +32,18 @@ struct recovery_info
94 tid_t start_transaction;
95 tid_t end_transaction;
103 -enum passtype {PASS_SCAN, PASS_REVOKE, PASS_REPLAY};
104 +enum passtype {PASS_SCAN, PASS_REVOKE, PASS_REPLAY, PASS_JMAP};
105 static int do_one_pass(journal_t *journal,
106 struct recovery_info *info, enum passtype pass);
107 -static int scan_revoke_records(journal_t *, struct buffer_head *,
108 - tid_t, struct recovery_info *);
109 +static int scan_revoke_records(journal_t *, struct buffer_head *, enum passtype,
110 + tid_t, struct recovery_info *);
114 @@ -267,11 +268,15 @@ int jbd2_journal_recover(journal_t *journal)
118 - err = do_one_pass(journal, &info, PASS_SCAN);
120 - err = do_one_pass(journal, &info, PASS_REVOKE);
122 - err = do_one_pass(journal, &info, PASS_REPLAY);
123 + if (journal->j_flags & JBD2_LAZY)
124 + err = do_one_pass(journal, &info, PASS_JMAP);
126 + err = do_one_pass(journal, &info, PASS_SCAN);
128 + err = do_one_pass(journal, &info, PASS_REVOKE);
130 + err = do_one_pass(journal, &info, PASS_REPLAY);
133 jbd_debug(1, "JBD2: recovery, exit status %d, "
134 "recovered transactions %u to %u\n",
135 @@ -279,6 +284,14 @@ int jbd2_journal_recover(journal_t *journal)
136 jbd_debug(1, "JBD2: Replayed %d and revoked %d/%d blocks\n",
137 info.nr_replays, info.nr_revoke_hits, info.nr_revokes);
139 + if (journal->j_flags & JBD2_LAZY) {
142 + journal->j_head = be32_to_cpu(sb->s_start);
143 + journal->j_tail = info.tail_block;
147 /* Restart the log at the next transaction ID, thus invalidating
148 * any existing commit records in the log. */
149 journal->j_transaction_sequence = info.end_transaction;
150 @@ -431,6 +444,7 @@ static int do_one_pass(journal_t *journal,
151 __u32 crc32_sum = ~0; /* Transactional Checksums */
152 int descr_csum_size = 0;
157 * First thing is to establish what we expect to find in the log
158 @@ -443,7 +457,7 @@ static int do_one_pass(journal_t *journal,
159 next_log_block = be32_to_cpu(sb->s_start);
161 first_commit_ID = next_commit_ID;
162 - if (pass == PASS_SCAN)
163 + if (pass == PASS_SCAN || pass == PASS_JMAP)
164 info->start_transaction = first_commit_ID;
166 jbd_debug(1, "Starting recovery pass %d\n", pass);
167 @@ -468,7 +482,7 @@ static int do_one_pass(journal_t *journal,
168 * check right now that we haven't gone past the end of
171 - if (pass != PASS_SCAN)
172 + if (pass != PASS_SCAN && pass != PASS_JMAP)
173 if (tid_geq(next_commit_ID, info->end_transaction))
176 @@ -484,9 +498,6 @@ static int do_one_pass(journal_t *journal,
181 - wrap(journal, next_log_block);
183 /* What kind of buffer is it?
185 * If it is a descriptor block, check that it has the
186 @@ -510,6 +521,14 @@ static int do_one_pass(journal_t *journal,
190 + if ((pass == PASS_JMAP) && new_txn) {
191 + jbd2_add_new_transaction_infos(journal, sequence, next_log_block);
196 + wrap(journal, next_log_block);
198 /* OK, we have a valid descriptor block which matches
199 * all of the sequence number checks. What are we going
200 * to do with it? That depends on the pass... */
201 @@ -535,7 +554,7 @@ static int do_one_pass(journal_t *journal,
202 * in pass REPLAY; if journal_checksums enabled, then
203 * calculate checksums in PASS_SCAN, otherwise,
204 * just skip over the blocks it describes. */
205 - if (pass != PASS_REPLAY) {
206 + if ((pass != PASS_REPLAY) && (pass != PASS_JMAP)) {
207 if (pass == PASS_SCAN &&
208 jbd2_has_feature_checksum(journal) &&
209 !info->end_transaction) {
210 @@ -562,12 +581,28 @@ static int do_one_pass(journal_t *journal,
211 while ((tagp - bh->b_data + tag_bytes)
212 <= journal->j_blocksize - descr_csum_size) {
213 unsigned long io_block;
214 + unsigned long long log_block;
216 tag = (journal_block_tag_t *) tagp;
217 flags = be16_to_cpu(tag->t_flags);
219 io_block = next_log_block++;
220 wrap(journal, next_log_block);
221 + if (pass == PASS_JMAP) {
222 + struct blk_mapping map;
224 + err = jbd2_journal_bmap(journal,
229 + map.fsblk = read_tag_block(journal, tag);
230 + map.logblk = log_block;
231 + err = jbd2_add_mapping(journal, &map);
236 err = jread(&obh, journal, io_block);
238 /* Recover what we can, but
239 @@ -753,6 +788,10 @@ static int do_one_pass(journal_t *journal,
243 + if (pass == PASS_JMAP) {
244 + jbd2_finish_transaction_infos(journal);
250 @@ -760,12 +799,12 @@ static int do_one_pass(journal_t *journal,
251 case JBD2_REVOKE_BLOCK:
252 /* If we aren't in the REVOKE pass, then we can
253 * just skip over this block. */
254 - if (pass != PASS_REVOKE) {
255 + if (pass != PASS_REVOKE && pass != PASS_JMAP) {
260 - err = scan_revoke_records(journal, bh,
261 + err = scan_revoke_records(journal, bh, pass,
262 next_commit_ID, info);
265 @@ -788,9 +827,10 @@ static int do_one_pass(journal_t *journal,
266 * transaction marks the end of the valid log.
269 - if (pass == PASS_SCAN) {
270 + if (pass == PASS_SCAN || pass == PASS_JMAP) {
271 if (!info->end_transaction)
272 info->end_transaction = next_commit_ID;
273 + info->tail_block = next_log_block;
275 /* It's really bad news if different passes end up at
276 * different places (but possible due to IO errors). */
277 @@ -813,7 +853,8 @@ static int do_one_pass(journal_t *journal,
278 /* Scan a revoke record, marking all blocks mentioned as revoked. */
280 static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
281 - tid_t sequence, struct recovery_info *info)
282 + enum passtype pass, tid_t sequence,
283 + struct recovery_info *info)
285 jbd2_journal_revoke_header_t *header;
287 @@ -839,16 +880,20 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
289 while (offset + record_len <= max) {
290 unsigned long long blocknr;
294 blocknr = be32_to_cpu(* ((__be32 *) (bh->b_data+offset)));
296 blocknr = be64_to_cpu(* ((__be64 *) (bh->b_data+offset)));
297 offset += record_len;
298 - err = jbd2_journal_set_revoke(journal, blocknr, sequence);
301 + if (pass == PASS_JMAP)
302 + jbd2_jmap_revoke(journal, blocknr);
304 + int err = jbd2_journal_set_revoke(journal, blocknr,
312 diff --git a/include/linux/jmap.h b/include/linux/jmap.h
313 index acd588b4c68b..0d258cbeb603 100644
314 --- a/include/linux/jmap.h
315 +++ b/include/linux/jmap.h
316 @@ -109,6 +109,10 @@ extern void jbd2_journal_destroy_jmap_cache(void);
318 extern int jbd2_init_transaction_infos(journal_t *journal);
319 extern void jbd2_free_transaction_infos(journal_t *journal);
320 +extern void jbd2_add_new_transaction_infos(journal_t *journal, tid_t t_tid,
321 + unsigned long log_start);
322 +extern int jbd2_add_mapping(journal_t *journal, struct blk_mapping *mapping);
323 +extern void jbd2_finish_transaction_infos(journal_t *journal);
324 extern int jbd2_transaction_infos_add(journal_t *journal,
325 transaction_t *transaction,
326 struct blk_mapping *mappings,