19 #include <linux/time.h>
22 #include <linux/errno.h>
41 static int do_one_pass(journal_t *journal,
43 static int scan_revoke_records(journal_t *,
struct buffer_head *,
49 static void journal_brelse_array(
struct buffer_head *
b[],
int n)
69 static int do_readahead(journal_t *journal,
unsigned int start)
74 struct buffer_head *bh;
76 struct buffer_head *
bufs[MAXBUF];
79 max = start + (128 * 1024 / journal->j_blocksize);
80 if (max > journal->j_maxlen)
81 max = journal->j_maxlen;
88 for (next = start; next <
max; next++) {
97 bh =
__getblk(journal->j_dev, blocknr, journal->j_blocksize);
103 if (!buffer_uptodate(bh) && !buffer_locked(bh)) {
105 if (nbufs == MAXBUF) {
107 journal_brelse_array(bufs, nbufs);
120 journal_brelse_array(bufs, nbufs);
131 static int jread(
struct buffer_head **bhp, journal_t *journal,
136 struct buffer_head *bh;
140 if (offset >= journal->j_maxlen) {
153 bh =
__getblk(journal->j_dev, blocknr, journal->j_blocksize);
157 if (!buffer_uptodate(bh)) {
161 do_readahead(journal, offset);
165 if (!buffer_uptodate(bh)) {
181 static int count_tags(
struct buffer_head *bh,
int size)
206 #define wrap(journal, var) \
208 if (var >= (journal)->j_last) \
209 var -= ((journal)->j_last - (journal)->j_first); \
231 memset(&info, 0,
sizeof(info));
232 sb = journal->j_superblock;
241 jbd_debug(1,
"No recovery required, last transaction %d\n",
247 err = do_one_pass(journal, &info,
PASS_SCAN);
253 jbd_debug(1,
"JBD: recovery, exit status %d, "
254 "recovered transactions %u to %u\n",
256 jbd_debug(1,
"JBD: Replayed %d and revoked %d/%d blocks\n",
268 if (journal->j_flags & JFS_BARRIER) {
295 memset (&info, 0,
sizeof(info));
297 err = do_one_pass(journal, &info,
PASS_SCAN);
301 ++journal->j_transaction_sequence;
303 #ifdef CONFIG_JBD_DEBUG
307 "JBD: ignoring %d transaction%s from the journal.\n",
308 dropped, (dropped == 1) ?
"" :
"s");
317 static int do_one_pass(journal_t *journal,
320 unsigned int first_commit_ID, next_commit_ID;
321 unsigned int next_log_block;
322 int err, success = 0;
325 struct buffer_head * bh;
335 sb = journal->j_superblock;
339 first_commit_ID = next_commit_ID;
343 jbd_debug(1,
"Starting recovery pass %d\n", pass);
356 struct buffer_head * obh;
357 struct buffer_head * nbh;
369 jbd_debug(2,
"Scanning for sequence ID %u at %u/%u\n",
370 next_commit_ID, next_log_block, journal->j_last);
376 jbd_debug(3,
"JBD: checking block %u\n", next_log_block);
377 err = jread(&bh, journal, next_log_block);
382 wrap(journal, next_log_block);
399 jbd_debug(3,
"Found magic %d, sequence %d\n",
400 blocktype, sequence);
402 if (sequence != next_commit_ID) {
418 count_tags(bh, journal->j_blocksize);
419 wrap(journal, next_log_block);
430 <= journal->j_blocksize) {
431 unsigned int io_block;
436 io_block = next_log_block++;
437 wrap(journal, next_log_block);
438 err = jread(&obh, journal, io_block);
444 "JBD: IO error %d recovering "
450 J_ASSERT(obh !=
NULL);
468 journal->j_blocksize);
471 "JBD: Out of memory "
472 "during recovery.\n");
480 memcpy(nbh->b_data, obh->b_data,
481 journal->j_blocksize);
483 *((
__be32 *)nbh->b_data) =
487 BUFFER_TRACE(nbh,
"marking dirty");
488 set_buffer_uptodate(nbh);
490 BUFFER_TRACE(nbh,
"marking uptodate");
526 err = scan_revoke_records(journal, bh,
527 next_commit_ID, info);
534 jbd_debug(3,
"Unrecognised magic %d, end of scan.\n",
556 "transaction %u, expected %u\n",
572 static int scan_revoke_records(journal_t *journal,
struct buffer_head *bh,
582 while (offset < max) {