recovery.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*
  2. * linux/fs/jbd2/recovery.c
  3. *
  4. * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
  5. *
  6. * Copyright 1999-2000 Red Hat Software --- All Rights Reserved
  7. *
  8. * This file is part of the Linux kernel and is made available under
  9. * the terms of the GNU General Public License, version 2, or at your
  10. * option, any later version, incorporated herein by reference.
  11. *
  12. * Journal recovery routines for the generic filesystem journaling code;
  13. * part of the ext2fs journaling system.
  14. */
  15. #ifndef __KERNEL__
  16. #include "jfs_user.h"
  17. #else
  18. #include <linux/time.h>
  19. #include <linux/fs.h>
  20. #include <linux/jbd2.h>
  21. #include <linux/errno.h>
  22. #include <linux/crc32.h>
  23. #endif
  24. /*
  25. * Maintain information about the progress of the recovery job, so that
  26. * the different passes can carry information between them.
  27. */
  28. struct recovery_info
  29. {
  30. tid_t start_transaction;
  31. tid_t end_transaction;
  32. int nr_replays;
  33. int nr_revokes;
  34. int nr_revoke_hits;
  35. };
  36. enum passtype {PASS_SCAN, PASS_REVOKE, PASS_REPLAY};
  37. static int do_one_pass(journal_t *journal,
  38. struct recovery_info *info, enum passtype pass);
  39. static int scan_revoke_records(journal_t *, struct buffer_head *,
  40. tid_t, struct recovery_info *);
  41. #ifdef __KERNEL__
  42. /* Release readahead buffers after use */
  43. static void journal_brelse_array(struct buffer_head *b[], int n)
  44. {
  45. while (--n >= 0)
  46. brelse (b[n]);
  47. }
  48. /*
  49. * When reading from the journal, we are going through the block device
  50. * layer directly and so there is no readahead being done for us. We
  51. * need to implement any readahead ourselves if we want it to happen at
  52. * all. Recovery is basically one long sequential read, so make sure we
  53. * do the IO in reasonably large chunks.
  54. *
  55. * This is not so critical that we need to be enormously clever about
  56. * the readahead size, though. 128K is a purely arbitrary, good-enough
  57. * fixed value.
  58. */
  59. #define MAXBUF 8
  60. static int do_readahead(journal_t *journal, unsigned int start)
  61. {
  62. int err;
  63. unsigned int max, nbufs, next;
  64. unsigned long long blocknr;
  65. struct buffer_head *bh;
  66. struct buffer_head * bufs[MAXBUF];
  67. /* Do up to 128K of readahead */
  68. max = start + (128 * 1024 / journal->j_blocksize);
  69. if (max > journal->j_maxlen)
  70. max = journal->j_maxlen;
  71. /* Do the readahead itself. We'll submit MAXBUF buffer_heads at
  72. * a time to the block device IO layer. */
  73. nbufs = 0;
  74. for (next = start; next < max; next++) {
  75. err = jbd2_journal_bmap(journal, next, &blocknr);
  76. if (err) {
  77. printk (KERN_ERR "JBD: bad block at offset %u\n",
  78. next);
  79. goto failed;
  80. }
  81. bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
  82. if (!bh) {
  83. err = -ENOMEM;
  84. goto failed;
  85. }
  86. if (!buffer_uptodate(bh) && !buffer_locked(bh)) {
  87. bufs[nbufs++] = bh;
  88. if (nbufs == MAXBUF) {
  89. ll_rw_block(READ, nbufs, bufs);
  90. journal_brelse_array(bufs, nbufs);
  91. nbufs = 0;
  92. }
  93. } else
  94. brelse(bh);
  95. }
  96. if (nbufs)
  97. ll_rw_block(READ, nbufs, bufs);
  98. err = 0;
  99. failed:
  100. if (nbufs)
  101. journal_brelse_array(bufs, nbufs);
  102. return err;
  103. }
  104. #endif /* __KERNEL__ */
  105. /*
  106. * Read a block from the journal
  107. */
  108. static int jread(struct buffer_head **bhp, journal_t *journal,
  109. unsigned int offset)
  110. {
  111. int err;
  112. unsigned long long blocknr;
  113. struct buffer_head *bh;
  114. *bhp = NULL;
  115. if (offset >= journal->j_maxlen) {
  116. printk(KERN_ERR "JBD: corrupted journal superblock\n");
  117. return -EIO;
  118. }
  119. err = jbd2_journal_bmap(journal, offset, &blocknr);
  120. if (err) {
  121. printk (KERN_ERR "JBD: bad block at offset %u\n",
  122. offset);
  123. return err;
  124. }
  125. bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
  126. if (!bh)
  127. return -ENOMEM;
  128. if (!buffer_uptodate(bh)) {
  129. /* If this is a brand new buffer, start readahead.
  130. Otherwise, we assume we are already reading it. */
  131. if (!buffer_req(bh))
  132. do_readahead(journal, offset);
  133. wait_on_buffer(bh);
  134. }
  135. if (!buffer_uptodate(bh)) {
  136. printk (KERN_ERR "JBD: Failed to read block at offset %u\n",
  137. offset);
  138. brelse(bh);
  139. return -EIO;
  140. }
  141. *bhp = bh;
  142. return 0;
  143. }
  144. /*
  145. * Count the number of in-use tags in a journal descriptor block.
  146. */
  147. static int count_tags(journal_t *journal, struct buffer_head *bh)
  148. {
  149. char * tagp;
  150. journal_block_tag_t * tag;
  151. int nr = 0, size = journal->j_blocksize;
  152. int tag_bytes = journal_tag_bytes(journal);
  153. tagp = &bh->b_data[sizeof(journal_header_t)];
  154. while ((tagp - bh->b_data + tag_bytes) <= size) {
  155. tag = (journal_block_tag_t *) tagp;
  156. nr++;
  157. tagp += tag_bytes;
  158. if (!(tag->t_flags & cpu_to_be32(JBD2_FLAG_SAME_UUID)))
  159. tagp += 16;
  160. if (tag->t_flags & cpu_to_be32(JBD2_FLAG_LAST_TAG))
  161. break;
  162. }
  163. return nr;
  164. }
  165. /* Make sure we wrap around the log correctly! */
  166. #define wrap(journal, var) \
  167. do { \
  168. if (var >= (journal)->j_last) \
  169. var -= ((journal)->j_last - (journal)->j_first); \
  170. } while (0)
  171. /**
  172. * jbd2_journal_recover - recovers a on-disk journal
  173. * @journal: the journal to recover
  174. *
  175. * The primary function for recovering the log contents when mounting a
  176. * journaled device.
  177. *
  178. * Recovery is done in three passes. In the first pass, we look for the
  179. * end of the log. In the second, we assemble the list of revoke
  180. * blocks. In the third and final pass, we replay any un-revoked blocks
  181. * in the log.
  182. */
  183. int jbd2_journal_recover(journal_t *journal)
  184. {
  185. int err, err2;
  186. journal_superblock_t * sb;
  187. struct recovery_info info;
  188. memset(&info, 0, sizeof(info));
  189. sb = journal->j_superblock;
  190. /*
  191. * The journal superblock's s_start field (the current log head)
  192. * is always zero if, and only if, the journal was cleanly
  193. * unmounted.
  194. */
  195. if (!sb->s_start) {
  196. jbd_debug(1, "No recovery required, last transaction %d\n",
  197. be32_to_cpu(sb->s_sequence));
  198. journal->j_transaction_sequence = be32_to_cpu(sb->s_sequence) + 1;
  199. return 0;
  200. }
  201. err = do_one_pass(journal, &info, PASS_SCAN);
  202. if (!err)
  203. err = do_one_pass(journal, &info, PASS_REVOKE);
  204. if (!err)
  205. err = do_one_pass(journal, &info, PASS_REPLAY);
  206. jbd_debug(1, "JBD: recovery, exit status %d, "
  207. "recovered transactions %u to %u\n",
  208. err, info.start_transaction, info.end_transaction);
  209. jbd_debug(1, "JBD: Replayed %d and revoked %d/%d blocks\n",
  210. info.nr_replays, info.nr_revoke_hits, info.nr_revokes);
  211. /* Restart the log at the next transaction ID, thus invalidating
  212. * any existing commit records in the log. */
  213. journal->j_transaction_sequence = ++info.end_transaction;
  214. jbd2_journal_clear_revoke(journal);
  215. err2 = sync_blockdev(journal->j_fs_dev);
  216. if (!err)
  217. err = err2;
  218. return err;
  219. }
  220. /**
  221. * jbd2_journal_skip_recovery - Start journal and wipe exiting records
  222. * @journal: journal to startup
  223. *
  224. * Locate any valid recovery information from the journal and set up the
  225. * journal structures in memory to ignore it (presumably because the
  226. * caller has evidence that it is out of date).
  227. * This function does'nt appear to be exorted..
  228. *
  229. * We perform one pass over the journal to allow us to tell the user how
  230. * much recovery information is being erased, and to let us initialise
  231. * the journal transaction sequence numbers to the next unused ID.
  232. */
  233. int jbd2_journal_skip_recovery(journal_t *journal)
  234. {
  235. int err;
  236. journal_superblock_t * sb;
  237. struct recovery_info info;
  238. memset (&info, 0, sizeof(info));
  239. sb = journal->j_superblock;
  240. err = do_one_pass(journal, &info, PASS_SCAN);
  241. if (err) {
  242. printk(KERN_ERR "JBD: error %d scanning journal\n", err);
  243. ++journal->j_transaction_sequence;
  244. } else {
  245. #ifdef CONFIG_JBD2_DEBUG
  246. int dropped = info.end_transaction - be32_to_cpu(sb->s_sequence);
  247. #endif
  248. jbd_debug(1,
  249. "JBD: ignoring %d transaction%s from the journal.\n",
  250. dropped, (dropped == 1) ? "" : "s");
  251. journal->j_transaction_sequence = ++info.end_transaction;
  252. }
  253. journal->j_tail = 0;
  254. return err;
  255. }
  256. static inline unsigned long long read_tag_block(int tag_bytes, journal_block_tag_t *tag)
  257. {
  258. unsigned long long block = be32_to_cpu(tag->t_blocknr);
  259. if (tag_bytes > JBD2_TAG_SIZE32)
  260. block |= (u64)be32_to_cpu(tag->t_blocknr_high) << 32;
  261. return block;
  262. }
  263. /*
  264. * calc_chksums calculates the checksums for the blocks described in the
  265. * descriptor block.
  266. */
  267. static int calc_chksums(journal_t *journal, struct buffer_head *bh,
  268. unsigned long *next_log_block, __u32 *crc32_sum)
  269. {
  270. int i, num_blks, err;
  271. unsigned long io_block;
  272. struct buffer_head *obh;
  273. num_blks = count_tags(journal, bh);
  274. /* Calculate checksum of the descriptor block. */
  275. *crc32_sum = crc32_be(*crc32_sum, (void *)bh->b_data, bh->b_size);
  276. for (i = 0; i < num_blks; i++) {
  277. io_block = (*next_log_block)++;
  278. wrap(journal, *next_log_block);
  279. err = jread(&obh, journal, io_block);
  280. if (err) {
  281. printk(KERN_ERR "JBD: IO error %d recovering block "
  282. "%lu in log\n", err, io_block);
  283. return 1;
  284. } else {
  285. *crc32_sum = crc32_be(*crc32_sum, (void *)obh->b_data,
  286. obh->b_size);
  287. }
  288. put_bh(obh);
  289. }
  290. return 0;
  291. }
  292. static int do_one_pass(journal_t *journal,
  293. struct recovery_info *info, enum passtype pass)
  294. {
  295. unsigned int first_commit_ID, next_commit_ID;
  296. unsigned long next_log_block;
  297. int err, success = 0;
  298. journal_superblock_t * sb;
  299. journal_header_t * tmp;
  300. struct buffer_head * bh;
  301. unsigned int sequence;
  302. int blocktype;
  303. int tag_bytes = journal_tag_bytes(journal);
  304. __u32 crc32_sum = ~0; /* Transactional Checksums */
  305. /* Precompute the maximum metadata descriptors in a descriptor block */
  306. int MAX_BLOCKS_PER_DESC;
  307. MAX_BLOCKS_PER_DESC = ((journal->j_blocksize-sizeof(journal_header_t))
  308. / tag_bytes);
  309. /*
  310. * First thing is to establish what we expect to find in the log
  311. * (in terms of transaction IDs), and where (in terms of log
  312. * block offsets): query the superblock.
  313. */
  314. sb = journal->j_superblock;
  315. next_commit_ID = be32_to_cpu(sb->s_sequence);
  316. next_log_block = be32_to_cpu(sb->s_start);
  317. first_commit_ID = next_commit_ID;
  318. if (pass == PASS_SCAN)
  319. info->start_transaction = first_commit_ID;
  320. jbd_debug(1, "Starting recovery pass %d\n", pass);
  321. /*
  322. * Now we walk through the log, transaction by transaction,
  323. * making sure that each transaction has a commit block in the
  324. * expected place. Each complete transaction gets replayed back
  325. * into the main filesystem.
  326. */
  327. while (1) {
  328. int flags;
  329. char * tagp;
  330. journal_block_tag_t * tag;
  331. struct buffer_head * obh;
  332. struct buffer_head * nbh;
  333. cond_resched();
  334. /* If we already know where to stop the log traversal,
  335. * check right now that we haven't gone past the end of
  336. * the log. */
  337. if (pass != PASS_SCAN)
  338. if (tid_geq(next_commit_ID, info->end_transaction))
  339. break;
  340. jbd_debug(2, "Scanning for sequence ID %u at %lu/%lu\n",
  341. next_commit_ID, next_log_block, journal->j_last);
  342. /* Skip over each chunk of the transaction looking
  343. * either the next descriptor block or the final commit
  344. * record. */
  345. jbd_debug(3, "JBD: checking block %ld\n", next_log_block);
  346. err = jread(&bh, journal, next_log_block);
  347. if (err)
  348. goto failed;
  349. next_log_block++;
  350. wrap(journal, next_log_block);
  351. /* What kind of buffer is it?
  352. *
  353. * If it is a descriptor block, check that it has the
  354. * expected sequence number. Otherwise, we're all done
  355. * here. */
  356. tmp = (journal_header_t *)bh->b_data;
  357. if (tmp->h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER)) {
  358. brelse(bh);
  359. break;
  360. }
  361. blocktype = be32_to_cpu(tmp->h_blocktype);
  362. sequence = be32_to_cpu(tmp->h_sequence);
  363. jbd_debug(3, "Found magic %d, sequence %d\n",
  364. blocktype, sequence);
  365. if (sequence != next_commit_ID) {
  366. brelse(bh);
  367. break;
  368. }
  369. /* OK, we have a valid descriptor block which matches
  370. * all of the sequence number checks. What are we going
  371. * to do with it? That depends on the pass... */
  372. switch(blocktype) {
  373. case JBD2_DESCRIPTOR_BLOCK:
  374. /* If it is a valid descriptor block, replay it
  375. * in pass REPLAY; if journal_checksums enabled, then
  376. * calculate checksums in PASS_SCAN, otherwise,
  377. * just skip over the blocks it describes. */
  378. if (pass != PASS_REPLAY) {
  379. if (pass == PASS_SCAN &&
  380. JBD2_HAS_COMPAT_FEATURE(journal,
  381. JBD2_FEATURE_COMPAT_CHECKSUM) &&
  382. !info->end_transaction) {
  383. if (calc_chksums(journal, bh,
  384. &next_log_block,
  385. &crc32_sum)) {
  386. put_bh(bh);
  387. break;
  388. }
  389. put_bh(bh);
  390. continue;
  391. }
  392. next_log_block += count_tags(journal, bh);
  393. wrap(journal, next_log_block);
  394. put_bh(bh);
  395. continue;
  396. }
  397. /* A descriptor block: we can now write all of
  398. * the data blocks. Yay, useful work is finally
  399. * getting done here! */
  400. tagp = &bh->b_data[sizeof(journal_header_t)];
  401. while ((tagp - bh->b_data + tag_bytes)
  402. <= journal->j_blocksize) {
  403. unsigned long io_block;
  404. tag = (journal_block_tag_t *) tagp;
  405. flags = be32_to_cpu(tag->t_flags);
  406. io_block = next_log_block++;
  407. wrap(journal, next_log_block);
  408. err = jread(&obh, journal, io_block);
  409. if (err) {
  410. /* Recover what we can, but
  411. * report failure at the end. */
  412. success = err;
  413. printk (KERN_ERR
  414. "JBD: IO error %d recovering "
  415. "block %ld in log\n",
  416. err, io_block);
  417. } else {
  418. unsigned long long blocknr;
  419. J_ASSERT(obh != NULL);
  420. blocknr = read_tag_block(tag_bytes,
  421. tag);
  422. /* If the block has been
  423. * revoked, then we're all done
  424. * here. */
  425. if (jbd2_journal_test_revoke
  426. (journal, blocknr,
  427. next_commit_ID)) {
  428. brelse(obh);
  429. ++info->nr_revoke_hits;
  430. goto skip_write;
  431. }
  432. /* Find a buffer for the new
  433. * data being restored */
  434. nbh = __getblk(journal->j_fs_dev,
  435. blocknr,
  436. journal->j_blocksize);
  437. if (nbh == NULL) {
  438. printk(KERN_ERR
  439. "JBD: Out of memory "
  440. "during recovery.\n");
  441. err = -ENOMEM;
  442. brelse(bh);
  443. brelse(obh);
  444. goto failed;
  445. }
  446. lock_buffer(nbh);
  447. memcpy(nbh->b_data, obh->b_data,
  448. journal->j_blocksize);
  449. if (flags & JBD2_FLAG_ESCAPE) {
  450. *((__be32 *)nbh->b_data) =
  451. cpu_to_be32(JBD2_MAGIC_NUMBER);
  452. }
  453. BUFFER_TRACE(nbh, "marking dirty");
  454. set_buffer_uptodate(nbh);
  455. mark_buffer_dirty(nbh);
  456. BUFFER_TRACE(nbh, "marking uptodate");
  457. ++info->nr_replays;
  458. /* ll_rw_block(WRITE, 1, &nbh); */
  459. unlock_buffer(nbh);
  460. brelse(obh);
  461. brelse(nbh);
  462. }
  463. skip_write:
  464. tagp += tag_bytes;
  465. if (!(flags & JBD2_FLAG_SAME_UUID))
  466. tagp += 16;
  467. if (flags & JBD2_FLAG_LAST_TAG)
  468. break;
  469. }
  470. brelse(bh);
  471. continue;
  472. case JBD2_COMMIT_BLOCK:
  473. /* How to differentiate between interrupted commit
  474. * and journal corruption ?
  475. *
  476. * {nth transaction}
  477. * Checksum Verification Failed
  478. * |
  479. * ____________________
  480. * | |
  481. * async_commit sync_commit
  482. * | |
  483. * | GO TO NEXT "Journal Corruption"
  484. * | TRANSACTION
  485. * |
  486. * {(n+1)th transanction}
  487. * |
  488. * _______|______________
  489. * | |
  490. * Commit block found Commit block not found
  491. * | |
  492. * "Journal Corruption" |
  493. * _____________|_________
  494. * | |
  495. * nth trans corrupt OR nth trans
  496. * and (n+1)th interrupted interrupted
  497. * before commit block
  498. * could reach the disk.
  499. * (Cannot find the difference in above
  500. * mentioned conditions. Hence assume
  501. * "Interrupted Commit".)
  502. */
  503. /* Found an expected commit block: if checksums
  504. * are present verify them in PASS_SCAN; else not
  505. * much to do other than move on to the next sequence
  506. * number. */
  507. if (pass == PASS_SCAN &&
  508. JBD2_HAS_COMPAT_FEATURE(journal,
  509. JBD2_FEATURE_COMPAT_CHECKSUM)) {
  510. int chksum_err, chksum_seen;
  511. struct commit_header *cbh =
  512. (struct commit_header *)bh->b_data;
  513. unsigned found_chksum =
  514. be32_to_cpu(cbh->h_chksum[0]);
  515. chksum_err = chksum_seen = 0;
  516. if (info->end_transaction) {
  517. journal->j_failed_commit =
  518. info->end_transaction;
  519. brelse(bh);
  520. break;
  521. }
  522. if (crc32_sum == found_chksum &&
  523. cbh->h_chksum_type == JBD2_CRC32_CHKSUM &&
  524. cbh->h_chksum_size ==
  525. JBD2_CRC32_CHKSUM_SIZE)
  526. chksum_seen = 1;
  527. else if (!(cbh->h_chksum_type == 0 &&
  528. cbh->h_chksum_size == 0 &&
  529. found_chksum == 0 &&
  530. !chksum_seen))
  531. /*
  532. * If fs is mounted using an old kernel and then
  533. * kernel with journal_chksum is used then we
  534. * get a situation where the journal flag has
  535. * checksum flag set but checksums are not
  536. * present i.e chksum = 0, in the individual
  537. * commit blocks.
  538. * Hence to avoid checksum failures, in this
  539. * situation, this extra check is added.
  540. */
  541. chksum_err = 1;
  542. if (chksum_err) {
  543. info->end_transaction = next_commit_ID;
  544. if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
  545. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)){
  546. journal->j_failed_commit =
  547. next_commit_ID;
  548. brelse(bh);
  549. break;
  550. }
  551. }
  552. crc32_sum = ~0;
  553. }
  554. brelse(bh);
  555. next_commit_ID++;
  556. continue;
  557. case JBD2_REVOKE_BLOCK:
  558. /* If we aren't in the REVOKE pass, then we can
  559. * just skip over this block. */
  560. if (pass != PASS_REVOKE) {
  561. brelse(bh);
  562. continue;
  563. }
  564. err = scan_revoke_records(journal, bh,
  565. next_commit_ID, info);
  566. brelse(bh);
  567. if (err)
  568. goto failed;
  569. continue;
  570. default:
  571. jbd_debug(3, "Unrecognised magic %d, end of scan.\n",
  572. blocktype);
  573. brelse(bh);
  574. goto done;
  575. }
  576. }
  577. done:
  578. /*
  579. * We broke out of the log scan loop: either we came to the
  580. * known end of the log or we found an unexpected block in the
  581. * log. If the latter happened, then we know that the "current"
  582. * transaction marks the end of the valid log.
  583. */
  584. if (pass == PASS_SCAN) {
  585. if (!info->end_transaction)
  586. info->end_transaction = next_commit_ID;
  587. } else {
  588. /* It's really bad news if different passes end up at
  589. * different places (but possible due to IO errors). */
  590. if (info->end_transaction != next_commit_ID) {
  591. printk (KERN_ERR "JBD: recovery pass %d ended at "
  592. "transaction %u, expected %u\n",
  593. pass, next_commit_ID, info->end_transaction);
  594. if (!success)
  595. success = -EIO;
  596. }
  597. }
  598. return success;
  599. failed:
  600. return err;
  601. }
  602. /* Scan a revoke record, marking all blocks mentioned as revoked. */
  603. static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
  604. tid_t sequence, struct recovery_info *info)
  605. {
  606. jbd2_journal_revoke_header_t *header;
  607. int offset, max;
  608. int record_len = 4;
  609. header = (jbd2_journal_revoke_header_t *) bh->b_data;
  610. offset = sizeof(jbd2_journal_revoke_header_t);
  611. max = be32_to_cpu(header->r_count);
  612. if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
  613. record_len = 8;
  614. while (offset + record_len <= max) {
  615. unsigned long long blocknr;
  616. int err;
  617. if (record_len == 4)
  618. blocknr = be32_to_cpu(* ((__be32 *) (bh->b_data+offset)));
  619. else
  620. blocknr = be64_to_cpu(* ((__be64 *) (bh->b_data+offset)));
  621. offset += record_len;
  622. err = jbd2_journal_set_revoke(journal, blocknr, sequence);
  623. if (err)
  624. return err;
  625. ++info->nr_revokes;
  626. }
  627. return 0;
  628. }