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