Blame view

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

f7f4bccb7   Mingming Cao   [PATCH] jbd2: ren...
592
593
  	header = (jbd2_journal_revoke_header_t *) bh->b_data;
  	offset = sizeof(jbd2_journal_revoke_header_t);
470decc61   Dave Kleikamp   [PATCH] jbd2: ini...
594
  	max = be32_to_cpu(header->r_count);
b517bea1c   Zach Brown   [PATCH] 64-bit jb...
595
596
597
598
  	if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
  		record_len = 8;
  
  	while (offset + record_len <= max) {
18eba7aae   Mingming Cao   [PATCH] jbd2: swi...
599
  		unsigned long long blocknr;
470decc61   Dave Kleikamp   [PATCH] jbd2: ini...
600
  		int err;
b517bea1c   Zach Brown   [PATCH] 64-bit jb...
601
602
603
604
605
  		if (record_len == 4)
  			blocknr = be32_to_cpu(* ((__be32 *) (bh->b_data+offset)));
  		else
  			blocknr = be64_to_cpu(* ((__be64 *) (bh->b_data+offset)));
  		offset += record_len;
f7f4bccb7   Mingming Cao   [PATCH] jbd2: ren...
606
  		err = jbd2_journal_set_revoke(journal, blocknr, sequence);
470decc61   Dave Kleikamp   [PATCH] jbd2: ini...
607
608
609
610
611
612
  		if (err)
  			return err;
  		++info->nr_revokes;
  	}
  	return 0;
  }