recovery.c (c013d0af81f60cc7dbe357c4e2a925fb6738dbfe) recovery.c (cb3b3bf22cf33707d684e74207908ba0ef3b6467)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * linux/fs/jbd2/recovery.c
4 *
5 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
6 *
7 * Copyright 1999-2000 Red Hat Software --- All Rights Reserved
8 *

--- 86 unchanged lines hidden (view full) ---

95 if (!bh) {
96 err = -ENOMEM;
97 goto failed;
98 }
99
100 if (!buffer_uptodate(bh) && !buffer_locked(bh)) {
101 bufs[nbufs++] = bh;
102 if (nbufs == MAXBUF) {
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * linux/fs/jbd2/recovery.c
4 *
5 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
6 *
7 * Copyright 1999-2000 Red Hat Software --- All Rights Reserved
8 *

--- 86 unchanged lines hidden (view full) ---

95 if (!bh) {
96 err = -ENOMEM;
97 goto failed;
98 }
99
100 if (!buffer_uptodate(bh) && !buffer_locked(bh)) {
101 bufs[nbufs++] = bh;
102 if (nbufs == MAXBUF) {
103 ll_rw_block(REQ_OP_READ, nbufs, bufs);
103 ll_rw_block(REQ_OP_READ, 0, nbufs, bufs);
104 journal_brelse_array(bufs, nbufs);
105 nbufs = 0;
106 }
107 } else
108 brelse(bh);
109 }
110
111 if (nbufs)
104 journal_brelse_array(bufs, nbufs);
105 nbufs = 0;
106 }
107 } else
108 brelse(bh);
109 }
110
111 if (nbufs)
112 ll_rw_block(REQ_OP_READ, nbufs, bufs);
112 ll_rw_block(REQ_OP_READ, 0, nbufs, bufs);
113 err = 0;
114
115failed:
116 if (nbufs)
117 journal_brelse_array(bufs, nbufs);
118 return err;
119}
120

--- 119 unchanged lines hidden (view full) ---

240 struct buffer_head *bh;
241 int err = 0;
242
243 next_fc_block = journal->j_fc_first;
244 if (!journal->j_fc_replay_callback)
245 return 0;
246
247 while (next_fc_block <= journal->j_fc_last) {
113 err = 0;
114
115failed:
116 if (nbufs)
117 journal_brelse_array(bufs, nbufs);
118 return err;
119}
120

--- 119 unchanged lines hidden (view full) ---

240 struct buffer_head *bh;
241 int err = 0;
242
243 next_fc_block = journal->j_fc_first;
244 if (!journal->j_fc_replay_callback)
245 return 0;
246
247 while (next_fc_block <= journal->j_fc_last) {
248 jbd_debug(3, "Fast commit replay: next block %ld\n",
248 jbd2_debug(3, "Fast commit replay: next block %ld\n",
249 next_fc_block);
250 err = jread(&bh, journal, next_fc_block);
251 if (err) {
249 next_fc_block);
250 err = jread(&bh, journal, next_fc_block);
251 if (err) {
252 jbd_debug(3, "Fast commit replay: read error\n");
252 jbd2_debug(3, "Fast commit replay: read error\n");
253 break;
254 }
255
256 err = journal->j_fc_replay_callback(journal, bh, pass,
257 next_fc_block - journal->j_fc_first,
258 expected_commit_id);
259 next_fc_block++;
260 if (err < 0 || err == JBD2_FC_REPLAY_STOP)
261 break;
262 err = 0;
263 }
264
265 if (err)
253 break;
254 }
255
256 err = journal->j_fc_replay_callback(journal, bh, pass,
257 next_fc_block - journal->j_fc_first,
258 expected_commit_id);
259 next_fc_block++;
260 if (err < 0 || err == JBD2_FC_REPLAY_STOP)
261 break;
262 err = 0;
263 }
264
265 if (err)
266 jbd_debug(3, "Fast commit replay failed, err = %d\n", err);
266 jbd2_debug(3, "Fast commit replay failed, err = %d\n", err);
267
268 return err;
269}
270
271/**
272 * jbd2_journal_recover - recovers a on-disk journal
273 * @journal: the journal to recover
274 *

--- 17 unchanged lines hidden (view full) ---

292
293 /*
294 * The journal superblock's s_start field (the current log head)
295 * is always zero if, and only if, the journal was cleanly
296 * unmounted.
297 */
298
299 if (!sb->s_start) {
267
268 return err;
269}
270
271/**
272 * jbd2_journal_recover - recovers a on-disk journal
273 * @journal: the journal to recover
274 *

--- 17 unchanged lines hidden (view full) ---

292
293 /*
294 * The journal superblock's s_start field (the current log head)
295 * is always zero if, and only if, the journal was cleanly
296 * unmounted.
297 */
298
299 if (!sb->s_start) {
300 jbd_debug(1, "No recovery required, last transaction %d\n",
300 jbd2_debug(1, "No recovery required, last transaction %d\n",
301 be32_to_cpu(sb->s_sequence));
302 journal->j_transaction_sequence = be32_to_cpu(sb->s_sequence) + 1;
303 return 0;
304 }
305
306 err = do_one_pass(journal, &info, PASS_SCAN);
307 if (!err)
308 err = do_one_pass(journal, &info, PASS_REVOKE);
309 if (!err)
310 err = do_one_pass(journal, &info, PASS_REPLAY);
311
301 be32_to_cpu(sb->s_sequence));
302 journal->j_transaction_sequence = be32_to_cpu(sb->s_sequence) + 1;
303 return 0;
304 }
305
306 err = do_one_pass(journal, &info, PASS_SCAN);
307 if (!err)
308 err = do_one_pass(journal, &info, PASS_REVOKE);
309 if (!err)
310 err = do_one_pass(journal, &info, PASS_REPLAY);
311
312 jbd_debug(1, "JBD2: recovery, exit status %d, "
312 jbd2_debug(1, "JBD2: recovery, exit status %d, "
313 "recovered transactions %u to %u\n",
314 err, info.start_transaction, info.end_transaction);
313 "recovered transactions %u to %u\n",
314 err, info.start_transaction, info.end_transaction);
315 jbd_debug(1, "JBD2: Replayed %d and revoked %d/%d blocks\n",
315 jbd2_debug(1, "JBD2: Replayed %d and revoked %d/%d blocks\n",
316 info.nr_replays, info.nr_revoke_hits, info.nr_revokes);
317
318 /* Restart the log at the next transaction ID, thus invalidating
319 * any existing commit records in the log. */
320 journal->j_transaction_sequence = ++info.end_transaction;
321
322 jbd2_journal_clear_revoke(journal);
323 err2 = sync_blockdev(journal->j_fs_dev);

--- 33 unchanged lines hidden (view full) ---

357
358 if (err) {
359 printk(KERN_ERR "JBD2: error %d scanning journal\n", err);
360 ++journal->j_transaction_sequence;
361 } else {
362#ifdef CONFIG_JBD2_DEBUG
363 int dropped = info.end_transaction -
364 be32_to_cpu(journal->j_superblock->s_sequence);
316 info.nr_replays, info.nr_revoke_hits, info.nr_revokes);
317
318 /* Restart the log at the next transaction ID, thus invalidating
319 * any existing commit records in the log. */
320 journal->j_transaction_sequence = ++info.end_transaction;
321
322 jbd2_journal_clear_revoke(journal);
323 err2 = sync_blockdev(journal->j_fs_dev);

--- 33 unchanged lines hidden (view full) ---

357
358 if (err) {
359 printk(KERN_ERR "JBD2: error %d scanning journal\n", err);
360 ++journal->j_transaction_sequence;
361 } else {
362#ifdef CONFIG_JBD2_DEBUG
363 int dropped = info.end_transaction -
364 be32_to_cpu(journal->j_superblock->s_sequence);
365 jbd_debug(1,
365 jbd2_debug(1,
366 "JBD2: ignoring %d transaction%s from the journal.\n",
367 dropped, (dropped == 1) ? "" : "s");
368#endif
369 journal->j_transaction_sequence = ++info.end_transaction;
370 }
371
372 journal->j_tail = 0;
373 return err;

--- 105 unchanged lines hidden (view full) ---

479 sb = journal->j_superblock;
480 next_commit_ID = be32_to_cpu(sb->s_sequence);
481 next_log_block = be32_to_cpu(sb->s_start);
482
483 first_commit_ID = next_commit_ID;
484 if (pass == PASS_SCAN)
485 info->start_transaction = first_commit_ID;
486
366 "JBD2: ignoring %d transaction%s from the journal.\n",
367 dropped, (dropped == 1) ? "" : "s");
368#endif
369 journal->j_transaction_sequence = ++info.end_transaction;
370 }
371
372 journal->j_tail = 0;
373 return err;

--- 105 unchanged lines hidden (view full) ---

479 sb = journal->j_superblock;
480 next_commit_ID = be32_to_cpu(sb->s_sequence);
481 next_log_block = be32_to_cpu(sb->s_start);
482
483 first_commit_ID = next_commit_ID;
484 if (pass == PASS_SCAN)
485 info->start_transaction = first_commit_ID;
486
487 jbd_debug(1, "Starting recovery pass %d\n", pass);
487 jbd2_debug(1, "Starting recovery pass %d\n", pass);
488
489 /*
490 * Now we walk through the log, transaction by transaction,
491 * making sure that each transaction has a commit block in the
492 * expected place. Each complete transaction gets replayed back
493 * into the main filesystem.
494 */
495

--- 9 unchanged lines hidden (view full) ---

505 /* If we already know where to stop the log traversal,
506 * check right now that we haven't gone past the end of
507 * the log. */
508
509 if (pass != PASS_SCAN)
510 if (tid_geq(next_commit_ID, info->end_transaction))
511 break;
512
488
489 /*
490 * Now we walk through the log, transaction by transaction,
491 * making sure that each transaction has a commit block in the
492 * expected place. Each complete transaction gets replayed back
493 * into the main filesystem.
494 */
495

--- 9 unchanged lines hidden (view full) ---

505 /* If we already know where to stop the log traversal,
506 * check right now that we haven't gone past the end of
507 * the log. */
508
509 if (pass != PASS_SCAN)
510 if (tid_geq(next_commit_ID, info->end_transaction))
511 break;
512
513 jbd_debug(2, "Scanning for sequence ID %u at %lu/%lu\n",
513 jbd2_debug(2, "Scanning for sequence ID %u at %lu/%lu\n",
514 next_commit_ID, next_log_block,
515 jbd2_has_feature_fast_commit(journal) ?
516 journal->j_fc_last : journal->j_last);
517
518 /* Skip over each chunk of the transaction looking
519 * either the next descriptor block or the final commit
520 * record. */
521
514 next_commit_ID, next_log_block,
515 jbd2_has_feature_fast_commit(journal) ?
516 journal->j_fc_last : journal->j_last);
517
518 /* Skip over each chunk of the transaction looking
519 * either the next descriptor block or the final commit
520 * record. */
521
522 jbd_debug(3, "JBD2: checking block %ld\n", next_log_block);
522 jbd2_debug(3, "JBD2: checking block %ld\n", next_log_block);
523 err = jread(&bh, journal, next_log_block);
524 if (err)
525 goto failed;
526
527 next_log_block++;
528 wrap(journal, next_log_block);
529
530 /* What kind of buffer is it?

--- 6 unchanged lines hidden (view full) ---

537
538 if (tmp->h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER)) {
539 brelse(bh);
540 break;
541 }
542
543 blocktype = be32_to_cpu(tmp->h_blocktype);
544 sequence = be32_to_cpu(tmp->h_sequence);
523 err = jread(&bh, journal, next_log_block);
524 if (err)
525 goto failed;
526
527 next_log_block++;
528 wrap(journal, next_log_block);
529
530 /* What kind of buffer is it?

--- 6 unchanged lines hidden (view full) ---

537
538 if (tmp->h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER)) {
539 brelse(bh);
540 break;
541 }
542
543 blocktype = be32_to_cpu(tmp->h_blocktype);
544 sequence = be32_to_cpu(tmp->h_sequence);
545 jbd_debug(3, "Found magic %d, sequence %d\n",
545 jbd2_debug(3, "Found magic %d, sequence %d\n",
546 blocktype, sequence);
547
548 if (sequence != next_commit_ID) {
549 brelse(bh);
550 break;
551 }
552
553 /* OK, we have a valid descriptor block which matches

--- 16 unchanged lines hidden (view full) ---

570 if (pass != PASS_SCAN) {
571 pr_err("JBD2: Invalid checksum recovering block %lu in log\n",
572 next_log_block);
573 err = -EFSBADCRC;
574 brelse(bh);
575 goto failed;
576 }
577 need_check_commit_time = true;
546 blocktype, sequence);
547
548 if (sequence != next_commit_ID) {
549 brelse(bh);
550 break;
551 }
552
553 /* OK, we have a valid descriptor block which matches

--- 16 unchanged lines hidden (view full) ---

570 if (pass != PASS_SCAN) {
571 pr_err("JBD2: Invalid checksum recovering block %lu in log\n",
572 next_log_block);
573 err = -EFSBADCRC;
574 brelse(bh);
575 goto failed;
576 }
577 need_check_commit_time = true;
578 jbd_debug(1,
578 jbd2_debug(1,
579 "invalid descriptor block found in %lu\n",
580 next_log_block);
581 }
582
583 /* If it is a valid descriptor block, replay it
584 * in pass REPLAY; if journal_checksums enabled, then
585 * calculate checksums in PASS_SCAN, otherwise,
586 * just skip over the blocks it describes. */

--- 166 unchanged lines hidden (view full) ---

753 brelse(bh);
754 goto failed;
755 }
756 ignore_crc_mismatch:
757 /*
758 * It likely does not belong to same journal,
759 * just end this recovery with success.
760 */
579 "invalid descriptor block found in %lu\n",
580 next_log_block);
581 }
582
583 /* If it is a valid descriptor block, replay it
584 * in pass REPLAY; if journal_checksums enabled, then
585 * calculate checksums in PASS_SCAN, otherwise,
586 * just skip over the blocks it describes. */

--- 166 unchanged lines hidden (view full) ---

753 brelse(bh);
754 goto failed;
755 }
756 ignore_crc_mismatch:
757 /*
758 * It likely does not belong to same journal,
759 * just end this recovery with success.
760 */
761 jbd_debug(1, "JBD2: Invalid checksum ignored in transaction %u, likely stale data\n",
761 jbd2_debug(1, "JBD2: Invalid checksum ignored in transaction %u, likely stale data\n",
762 next_commit_ID);
763 brelse(bh);
764 goto done;
765 }
766
767 /*
768 * Found an expected commit block: if checksums
769 * are present, verify them in PASS_SCAN; else not

--- 51 unchanged lines hidden (view full) ---

821 case JBD2_REVOKE_BLOCK:
822 /*
823 * Check revoke block crc in pass_scan, if csum verify
824 * failed, check commit block time later.
825 */
826 if (pass == PASS_SCAN &&
827 !jbd2_descriptor_block_csum_verify(journal,
828 bh->b_data)) {
762 next_commit_ID);
763 brelse(bh);
764 goto done;
765 }
766
767 /*
768 * Found an expected commit block: if checksums
769 * are present, verify them in PASS_SCAN; else not

--- 51 unchanged lines hidden (view full) ---

821 case JBD2_REVOKE_BLOCK:
822 /*
823 * Check revoke block crc in pass_scan, if csum verify
824 * failed, check commit block time later.
825 */
826 if (pass == PASS_SCAN &&
827 !jbd2_descriptor_block_csum_verify(journal,
828 bh->b_data)) {
829 jbd_debug(1, "JBD2: invalid revoke block found in %lu\n",
829 jbd2_debug(1, "JBD2: invalid revoke block found in %lu\n",
830 next_log_block);
831 need_check_commit_time = true;
832 }
833 /* If we aren't in the REVOKE pass, then we can
834 * just skip over this block. */
835 if (pass != PASS_REVOKE) {
836 brelse(bh);
837 continue;
838 }
839
840 err = scan_revoke_records(journal, bh,
841 next_commit_ID, info);
842 brelse(bh);
843 if (err)
844 goto failed;
845 continue;
846
847 default:
830 next_log_block);
831 need_check_commit_time = true;
832 }
833 /* If we aren't in the REVOKE pass, then we can
834 * just skip over this block. */
835 if (pass != PASS_REVOKE) {
836 brelse(bh);
837 continue;
838 }
839
840 err = scan_revoke_records(journal, bh,
841 next_commit_ID, info);
842 brelse(bh);
843 if (err)
844 goto failed;
845 continue;
846
847 default:
848 jbd_debug(3, "Unrecognised magic %d, end of scan.\n",
848 jbd2_debug(3, "Unrecognised magic %d, end of scan.\n",
849 blocktype);
850 brelse(bh);
851 goto done;
852 }
853 }
854
855 done:
856 /*

--- 75 unchanged lines hidden ---
849 blocktype);
850 brelse(bh);
851 goto done;
852 }
853 }
854
855 done:
856 /*

--- 75 unchanged lines hidden ---