141
149
* extra_bblks is the number of blocks potentially verified on a previous
142
150
* call to this routine.
146
xlog_find_verify_log_record(xlog_t *log,
147
xfs_daddr_t start_blk,
148
xfs_daddr_t *last_blk,
153
xlog_find_verify_log_record(
155
xfs_daddr_t start_blk,
156
xfs_daddr_t *last_blk,
154
xlog_rec_header_t *head = NULL;
157
int num_blks = *last_blk - start_blk;
159
ASSERT(start_blk != 0 || *last_blk != start_blk);
161
if (!(bp = xlog_get_bp(num_blks, log->l_mp))) {
162
if (!(bp = xlog_get_bp(1, log->l_mp)))
165
buf = XFS_BUF_PTR(bp);
167
if ((error = xlog_bread(log, start_blk, num_blks, bp)))
169
buf = XFS_BUF_PTR(bp) + (num_blks - 1) * BBSIZE;
173
for (i=(*last_blk)-1; i>=0; i--) {
175
/* legal log record not found */
176
xlog_warn("XFS: Log inconsistent (didn't find previous header)");
180
error = XFS_ERROR(EIO);
184
if (smallmem && (error = xlog_bread(log, i, 1, bp)))
186
head = (xlog_rec_header_t*)buf;
188
if (INT_GET(head->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM)
196
* We hit the beginning of the physical log & still no header. Return
197
* to caller. If caller can handle a return of -1, then this routine
198
* will be called again for the end of the physical log.
205
/* we have the final block of the good log (the first block
206
* of the log record _before_ the head. So we check the uuid.
209
if ((error = xlog_header_check_mount(log->l_mp, head)))
213
* We may have found a log record header before we expected one.
214
* last_blk will be the 1st block # with a given cycle #. We may end
215
* up reading an entire log record. In this case, we don't want to
216
* reset last_blk. Only when last_blk points in the middle of a log
217
* record do we update last_blk.
219
if (*last_blk - i + extra_bblks
220
!= BTOBB(INT_GET(head->h_len, ARCH_CONVERT))+1)
161
xfs_caddr_t offset = NULL;
162
xlog_rec_header_t *head = NULL;
165
int num_blks = *last_blk - start_blk;
168
ASSERT(start_blk != 0 || *last_blk != start_blk);
170
if (!(bp = xlog_get_bp(log, num_blks))) {
171
if (!(bp = xlog_get_bp(log, 1)))
175
if ((error = xlog_bread(log, start_blk, num_blks, bp)))
177
offset = xlog_align(log, start_blk, num_blks, bp);
178
offset += ((num_blks - 1) << BBSHIFT);
181
for (i = (*last_blk) - 1; i >= 0; i--) {
183
/* valid log record not found */
185
"XFS: Log inconsistent (didn't find previous header)");
187
error = XFS_ERROR(EIO);
192
if ((error = xlog_bread(log, i, 1, bp)))
194
offset = xlog_align(log, i, 1, bp);
197
head = (xlog_rec_header_t *)offset;
199
if (XLOG_HEADER_MAGIC_NUM ==
200
INT_GET(head->h_magicno, ARCH_CONVERT))
208
* We hit the beginning of the physical log & still no header. Return
209
* to caller. If caller can handle a return of -1, then this routine
210
* will be called again for the end of the physical log.
218
* We have the final block of the good log (the first block
219
* of the log record _before_ the head. So we check the uuid.
221
if ((error = xlog_header_check_mount(log->l_mp, head)))
225
* We may have found a log record header before we expected one.
226
* last_blk will be the 1st block # with a given cycle #. We may end
227
* up reading an entire log record. In this case, we don't want to
228
* reset last_blk. Only when last_blk points in the middle of a log
229
* record do we update last_blk.
231
if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
232
uint h_size = INT_GET(head->h_size, ARCH_CONVERT);
234
xhdrs = h_size / XLOG_HEADER_CYCLE_SIZE;
235
if (h_size % XLOG_HEADER_CYCLE_SIZE)
241
if (*last_blk - i + extra_bblks
242
!= BTOBB(INT_GET(head->h_len, ARCH_CONVERT)) + xhdrs)
227
} /* xlog_find_verify_log_record */
230
251
* Head is defined to be the point of the log where the next log write
231
252
* write could go. This means that incomplete LR writes at the end are
232
253
* eliminated when calculating the head. We aren't guaranteed that previous
233
* LR have complete transactions. We only know that a cycle number of
254
* LR have complete transactions. We only know that a cycle number of
234
255
* current cycle number -1 won't be present in the log if we start writing
235
256
* from our current block number.
237
258
* last_blk contains the block number of the first block with a given
240
* Also called from xfs_log_print.c
242
261
* Return: zero if normal, non-zero if error.
245
xlog_find_head(xlog_t *log,
246
xfs_daddr_t *return_head_blk)
266
xfs_daddr_t *return_head_blk)
249
xfs_daddr_t new_blk, first_blk, start_blk, last_blk, head_blk;
251
uint first_half_cycle, last_half_cycle;
253
int error, log_bbnum = log->l_logBBsize;
255
/* Is the end of the log device zeroed? */
256
if ((error = xlog_find_zeroed(log, &first_blk)) == -1) {
257
*return_head_blk = first_blk;
259
/* is the whole lot zeroed? */
261
/* Linux XFS shouldn't generate totally zeroed logs -
262
* mkfs etc write a dummy unmount record to a fresh
263
* log so we can store the uuid in there
265
xlog_warn("XFS: totally zeroed log\n");
270
xfs_daddr_t new_blk, first_blk, start_blk, last_blk, head_blk;
272
uint first_half_cycle, last_half_cycle;
274
int error, log_bbnum = log->l_logBBsize;
276
/* Is the end of the log device zeroed? */
277
if ((error = xlog_find_zeroed(log, &first_blk)) == -1) {
278
*return_head_blk = first_blk;
280
/* Is the whole lot zeroed? */
282
/* Linux XFS shouldn't generate totally zeroed logs -
283
* mkfs etc write a dummy unmount record to a fresh
284
* log so we can store the uuid in there
286
xlog_warn("XFS: totally zeroed log");
291
xlog_warn("XFS: empty log check failed");
295
first_blk = 0; /* get cycle # of 1st block */
296
bp = xlog_get_bp(log, 1);
299
if ((error = xlog_bread(log, 0, 1, bp)))
301
offset = xlog_align(log, 0, 1, bp);
302
first_half_cycle = GET_CYCLE(offset, ARCH_CONVERT);
304
last_blk = head_blk = log_bbnum - 1; /* get cycle # of last block */
305
if ((error = xlog_bread(log, last_blk, 1, bp)))
307
offset = xlog_align(log, last_blk, 1, bp);
308
last_half_cycle = GET_CYCLE(offset, ARCH_CONVERT);
309
ASSERT(last_half_cycle != 0);
312
* If the 1st half cycle number is equal to the last half cycle number,
313
* then the entire log is stamped with the same cycle number. In this
314
* case, head_blk can't be set to zero (which makes sense). The below
315
* math doesn't work out properly with head_blk equal to zero. Instead,
316
* we set it to log_bbnum which is an invalid block number, but this
317
* value makes the math correct. If head_blk doesn't changed through
318
* all the tests below, *head_blk is set to zero at the very end rather
319
* than log_bbnum. In a sense, log_bbnum and zero are the same block
320
* in a circular file.
322
if (first_half_cycle == last_half_cycle) {
324
* In this case we believe that the entire log should have
325
* cycle number last_half_cycle. We need to scan backwards
326
* from the end verifying that there are no holes still
327
* containing last_half_cycle - 1. If we find such a hole,
328
* then the start of that hole will be the new head. The
329
* simple case looks like
330
* x | x ... | x - 1 | x
331
* Another case that fits this picture would be
332
* x | x + 1 | x ... | x
333
* In this case the head really is somwhere at the end of the
334
* log, as one of the latest writes at the beginning was
337
* x | x + 1 | x ... | x - 1 | x
338
* This is really the combination of the above two cases, and
339
* the head has to end up at the start of the x-1 hole at the
342
* In the 256k log case, we will read from the beginning to the
343
* end of the log and search for cycle numbers equal to x-1.
344
* We don't worry about the x+1 blocks that we encounter,
345
* because we know that they cannot be the head since the log
348
head_blk = log_bbnum;
349
stop_on_cycle = last_half_cycle - 1;
352
* In this case we want to find the first block with cycle
353
* number matching last_half_cycle. We expect the log to be
356
* The first block with cycle number x (last_half_cycle) will
357
* be where the new head belongs. First we do a binary search
358
* for the first occurrence of last_half_cycle. The binary
359
* search may not be totally accurate, so then we scan back
360
* from there looking for occurrences of last_half_cycle before
361
* us. If that backwards scan wraps around the beginning of
362
* the log, then we look for occurrences of last_half_cycle - 1
363
* at the end of the log. The cases we're looking for look
365
* x + 1 ... | x | x + 1 | x ...
366
* ^ binary search stopped here
368
* x + 1 ... | x ... | x - 1 | x
369
* <---------> less than scan distance
371
stop_on_cycle = last_half_cycle;
372
if ((error = xlog_find_cycle_start(log, bp, first_blk,
373
&head_blk, last_half_cycle)))
378
* Now validate the answer. Scan back some number of maximum possible
379
* blocks and make sure each one has the expected cycle number. The
380
* maximum is determined by the total possible amount of buffering
381
* in the in-core log. The following number can be made tighter if
382
* we actually look at the block size of the filesystem.
384
num_scan_bblks = XLOG_TOTAL_REC_SHIFT(log);
385
if (head_blk >= num_scan_bblks) {
387
* We are guaranteed that the entire check can be performed
390
start_blk = head_blk - num_scan_bblks;
391
if ((error = xlog_find_verify_cycle(log,
392
start_blk, num_scan_bblks,
393
stop_on_cycle, &new_blk)))
397
} else { /* need to read 2 parts of log */
399
* We are going to scan backwards in the log in two parts.
400
* First we scan the physical end of the log. In this part
401
* of the log, we are looking for blocks with cycle number
402
* last_half_cycle - 1.
403
* If we find one, then we know that the log starts there, as
404
* we've found a hole that didn't get written in going around
405
* the end of the physical log. The simple case for this is
406
* x + 1 ... | x ... | x - 1 | x
407
* <---------> less than scan distance
408
* If all of the blocks at the end of the log have cycle number
409
* last_half_cycle, then we check the blocks at the start of
410
* the log looking for occurrences of last_half_cycle. If we
411
* find one, then our current estimate for the location of the
412
* first occurrence of last_half_cycle is wrong and we move
413
* back to the hole we've found. This case looks like
414
* x + 1 ... | x | x + 1 | x ...
415
* ^ binary search stopped here
416
* Another case we need to handle that only occurs in 256k
418
* x + 1 ... | x ... | x+1 | x ...
419
* ^ binary search stops here
420
* In a 256k log, the scan at the end of the log will see the
421
* x + 1 blocks. We need to skip past those since that is
422
* certainly not the head of the log. By searching for
423
* last_half_cycle-1 we accomplish that.
425
start_blk = log_bbnum - num_scan_bblks + head_blk;
426
ASSERT(head_blk <= INT_MAX &&
427
(xfs_daddr_t) num_scan_bblks - head_blk >= 0);
428
if ((error = xlog_find_verify_cycle(log, start_blk,
429
num_scan_bblks - (int)head_blk,
430
(stop_on_cycle - 1), &new_blk)))
438
* Scan beginning of log now. The last part of the physical
439
* log is good. This scan needs to verify that it doesn't find
440
* the last_half_cycle.
443
ASSERT(head_blk <= INT_MAX);
444
if ((error = xlog_find_verify_cycle(log,
445
start_blk, (int)head_blk,
446
stop_on_cycle, &new_blk)))
454
* Now we need to make sure head_blk is not pointing to a block in
455
* the middle of a log record.
457
num_scan_bblks = XLOG_REC_SHIFT(log);
458
if (head_blk >= num_scan_bblks) {
459
start_blk = head_blk - num_scan_bblks; /* don't read head_blk */
461
/* start ptr at last block ptr before head_blk */
462
if ((error = xlog_find_verify_log_record(log, start_blk,
463
&head_blk, 0)) == -1) {
464
error = XFS_ERROR(EIO);
470
ASSERT(head_blk <= INT_MAX);
471
if ((error = xlog_find_verify_log_record(log, start_blk,
472
&head_blk, 0)) == -1) {
473
/* We hit the beginning of the log during our search */
474
start_blk = log_bbnum - num_scan_bblks + head_blk;
476
ASSERT(start_blk <= INT_MAX &&
477
(xfs_daddr_t) log_bbnum-start_blk >= 0);
478
ASSERT(head_blk <= INT_MAX);
479
if ((error = xlog_find_verify_log_record(log,
481
(int)head_blk)) == -1) {
482
error = XFS_ERROR(EIO);
486
if (new_blk != log_bbnum)
493
if (head_blk == log_bbnum)
494
*return_head_blk = 0;
496
*return_head_blk = head_blk;
498
* When returning here, we have a good block number. Bad block
499
* means that during a previous crash, we didn't have a clean break
500
* from cycle number N to cycle number N-1. In this case, we need
501
* to find the first block with cycle number N-1.
270
xlog_warn("XFS: empty log check failed");
274
first_blk = 0; /* get cycle # of 1st block */
275
bp = xlog_get_bp(1,log->l_mp);
278
if ((error = xlog_bread(log, 0, 1, bp)))
280
first_half_cycle = GET_CYCLE(XFS_BUF_PTR(bp), ARCH_CONVERT);
282
last_blk = head_blk = log_bbnum-1; /* get cycle # of last block */
283
if ((error = xlog_bread(log, last_blk, 1, bp)))
285
last_half_cycle = GET_CYCLE(XFS_BUF_PTR(bp), ARCH_CONVERT);
286
ASSERT(last_half_cycle != 0);
289
* If the 1st half cycle number is equal to the last half cycle number,
290
* then the entire log is stamped with the same cycle number. In this
291
* case, head_blk can't be set to zero (which makes sense). The below
292
* math doesn't work out properly with head_blk equal to zero. Instead,
293
* we set it to log_bbnum which is an illegal block number, but this
294
* value makes the math correct. If head_blk doesn't changed through
295
* all the tests below, *head_blk is set to zero at the very end rather
296
* than log_bbnum. In a sense, log_bbnum and zero are the same block
297
* in a circular file.
299
if (first_half_cycle == last_half_cycle) {
301
* In this case we believe that the entire log should have cycle
302
* number last_half_cycle. We need to scan backwards from the
303
* end verifying that there are no holes still containing
304
* last_half_cycle - 1. If we find such a hole, then the start
305
* of that hole will be the new head. The simple case looks like
306
* x | x ... | x - 1 | x
307
* Another case that fits this picture would be
308
* x | x + 1 | x ... | x
309
* In this case the head really is somwhere at the end of the
310
* log, as one of the latest writes at the beginning was incomplete.
312
* x | x + 1 | x ... | x - 1 | x
313
* This is really the combination of the above two cases, and the
314
* head has to end up at the start of the x-1 hole at the end of
317
* In the 256k log case, we will read from the beginning to the
318
* end of the log and search for cycle numbers equal to x-1. We
319
* don't worry about the x+1 blocks that we encounter, because
320
* we know that they cannot be the head since the log started with
323
head_blk = log_bbnum;
324
stop_on_cycle = last_half_cycle - 1;
327
* In this case we want to find the first block with cycle number
328
* matching last_half_cycle. We expect the log to be some
331
* The first block with cycle number x (last_half_cycle) will be
332
* where the new head belongs. First we do a binary search for
333
* the first occurrence of last_half_cycle. The binary search
334
* may not be totally accurate, so then we scan back from there
335
* looking for occurrences of last_half_cycle before us. If
336
* that backwards scan wraps around the beginning of the log,
337
* then we look for occurrences of last_half_cycle - 1 at the
338
* end of the log. The cases we're looking for look like
339
* x + 1 ... | x | x + 1 | x ...
340
* ^ binary search stopped here
342
* x + 1 ... | x ... | x - 1 | x
343
* <---------> less than scan distance
345
stop_on_cycle = last_half_cycle;
346
if ((error = xlog_find_cycle_start(log, bp, first_blk,
347
&head_blk, last_half_cycle)))
352
* Now validate the answer. Scan back some number of maximum possible
353
* blocks and make sure each one has the expected cycle number. The
354
* maximum is determined by the total possible amount of buffering
355
* in the in-core log. The following number can be made tighter if
356
* we actually look at the block size of the filesystem.
358
num_scan_bblks = BTOBB(XLOG_MAX_ICLOGS<<XLOG_MAX_RECORD_BSHIFT);
359
if (head_blk >= num_scan_bblks) {
361
* We are guaranteed that the entire check can be performed
364
start_blk = head_blk - num_scan_bblks;
365
new_blk = xlog_find_verify_cycle(log, start_blk, num_scan_bblks,
369
} else { /* need to read 2 parts of log */
371
* We are going to scan backwards in the log in two parts. First
372
* we scan the physical end of the log. In this part of the log,
373
* we are looking for blocks with cycle number last_half_cycle - 1.
374
* If we find one, then we know that the log starts there, as we've
375
* found a hole that didn't get written in going around the end
376
* of the physical log. The simple case for this is
377
* x + 1 ... | x ... | x - 1 | x
378
* <---------> less than scan distance
379
* If all of the blocks at the end of the log have cycle number
380
* last_half_cycle, then we check the blocks at the start of the
381
* log looking for occurrences of last_half_cycle. If we find one,
382
* then our current estimate for the location of the first
383
* occurrence of last_half_cycle is wrong and we move back to the
384
* hole we've found. This case looks like
385
* x + 1 ... | x | x + 1 | x ...
386
* ^ binary search stopped here
387
* Another case we need to handle that only occurs in 256k logs is
388
* x + 1 ... | x ... | x+1 | x ...
389
* ^ binary search stops here
390
* In a 256k log, the scan at the end of the log will see the x+1
391
* blocks. We need to skip past those since that is certainly not
392
* the head of the log. By searching for last_half_cycle-1 we
395
start_blk = log_bbnum - num_scan_bblks + head_blk;
396
ASSERT(head_blk <= INT_MAX && (xfs_daddr_t) num_scan_bblks-head_blk >= 0);
397
new_blk= xlog_find_verify_cycle(log, start_blk,
398
num_scan_bblks-(int)head_blk, (stop_on_cycle - 1));
405
* Scan beginning of log now. The last part of the physical log
406
* is good. This scan needs to verify that it doesn't find the
410
ASSERT(head_blk <= INT_MAX);
411
new_blk = xlog_find_verify_cycle(log, start_blk, (int) head_blk,
419
* Now we need to make sure head_blk is not pointing to a block in
420
* the middle of a log record.
422
num_scan_bblks = BTOBB(XLOG_MAX_RECORD_BSIZE);
423
if (head_blk >= num_scan_bblks) {
424
start_blk = head_blk - num_scan_bblks; /* don't read head_blk */
426
/* start ptr at last block ptr before head_blk */
427
if ((error = xlog_find_verify_log_record(log,
431
error = XFS_ERROR(EIO);
437
ASSERT(head_blk <= INT_MAX);
438
if ((error = xlog_find_verify_log_record(log,
442
/* We hit the beginning of the log during our search */
443
start_blk = log_bbnum - num_scan_bblks + head_blk;
445
ASSERT(start_blk <= INT_MAX && (xfs_daddr_t) log_bbnum-start_blk >= 0);
446
ASSERT(head_blk <= INT_MAX);
447
if ((error = xlog_find_verify_log_record(log,
450
(int)head_blk)) == -1) {
451
error = XFS_ERROR(EIO);
455
if (new_blk != log_bbnum)
462
if (head_blk == log_bbnum)
463
*return_head_blk = 0;
465
*return_head_blk = head_blk;
467
* When returning here, we have a good block number. Bad block
468
* means that during a previous crash, we didn't have a clean break
469
* from cycle number N to cycle number N-1. In this case, we need
470
* to find the first block with cycle number N-1.
478
xlog_warn("XFS: failed to find log head");
509
xlog_warn("XFS: failed to find log head");
481
} /* xlog_find_head */
484
514
* Find the sync block number or the tail of the log.
980
1079
item->ri_buf[item->ri_cnt].i_len = len;
983
} /* xlog_recover_add_to_trans */
986
xlog_recover_add_to_cont_trans(xlog_recover_t *trans,
990
xlog_recover_item_t *item;
991
xfs_caddr_t ptr, old_ptr;
994
item = trans->r_itemq;
996
/* finish copying rest of trans header */
997
xlog_recover_add_item(&trans->r_itemq);
998
ptr = (xfs_caddr_t)&trans->r_theader+sizeof(xfs_trans_header_t)-len;
999
bcopy(dp, ptr, len); /* s, d, l */
1002
item = item->ri_prev;
1004
old_ptr = item->ri_buf[item->ri_cnt-1].i_addr;
1005
old_len = item->ri_buf[item->ri_cnt-1].i_len;
1007
ptr = kmem_realloc(old_ptr, len+old_len, old_len, 0);
1008
bcopy(dp , &ptr[old_len], len); /* s, d, l */
1009
item->ri_buf[item->ri_cnt-1].i_len += len;
1010
item->ri_buf[item->ri_cnt-1].i_addr = ptr;
1012
} /* xlog_recover_add_to_cont_trans */
1015
xlog_recover_unmount_trans(xlog_recover_t *trans)
1085
xlog_recover_unmount_trans(
1086
xlog_recover_t *trans)
1017
1088
/* Do nothing now */
1018
1089
xlog_warn("XFS: xlog_recover_unmount_trans: Unmount LR");
1020
} /* xlog_recover_unmount_trans */
1024
xlog_recover_process_data(xlog_t *log,
1025
xlog_recover_t *rhash[],
1026
xlog_rec_header_t *rhead,
1030
xfs_caddr_t lp = dp+INT_GET(rhead->h_len, ARCH_CONVERT);
1031
int num_logops = INT_GET(rhead->h_num_logops, ARCH_CONVERT);
1032
xlog_op_header_t *ohead;
1033
xlog_recover_t *trans;
1039
/* check the log format matches our own - else we can't recover */
1040
if (xlog_header_check_recover(log->l_mp, rhead))
1041
return (XFS_ERROR(EIO));
1044
ASSERT(dp + sizeof(xlog_op_header_t) <= lp);
1045
ohead = (xlog_op_header_t *)dp;
1046
dp += sizeof(xlog_op_header_t);
1047
if (ohead->oh_clientid != XFS_TRANSACTION &&
1048
ohead->oh_clientid != XFS_LOG) {
1049
xlog_warn("XFS: xlog_recover_process_data: bad clientid");
1051
return (XFS_ERROR(EIO));
1053
tid = INT_GET(ohead->oh_tid, ARCH_CONVERT);
1054
hash = XLOG_RHASH(tid);
1055
trans = xlog_recover_find_tid(rhash[hash], tid);
1056
if (trans == NULL) { /* not found; add new tid */
1057
if (ohead->oh_flags & XLOG_START_TRANS)
1058
xlog_recover_new_tid(&rhash[hash], tid, INT_GET(rhead->h_lsn, ARCH_CONVERT));
1060
ASSERT(dp+INT_GET(ohead->oh_len, ARCH_CONVERT) <= lp);
1061
flags = ohead->oh_flags & ~XLOG_END_TRANS;
1062
if (flags & XLOG_WAS_CONT_TRANS)
1063
flags &= ~XLOG_CONTINUE_TRANS;
1065
case XLOG_COMMIT_TRANS: {
1066
error = xlog_recover_commit_trans(log, &rhash[hash],
1070
case XLOG_UNMOUNT_TRANS: {
1071
error = xlog_recover_unmount_trans(trans);
1074
case XLOG_WAS_CONT_TRANS: {
1075
error = xlog_recover_add_to_cont_trans(trans, dp,
1076
INT_GET(ohead->oh_len, ARCH_CONVERT));
1079
case XLOG_START_TRANS : {
1080
xlog_warn("XFS: xlog_recover_process_data: bad transaction");
1082
error = XFS_ERROR(EIO);
1086
case XLOG_CONTINUE_TRANS: {
1087
error = xlog_recover_add_to_trans(trans, dp,
1088
INT_GET(ohead->oh_len, ARCH_CONVERT));
1092
xlog_warn("XFS: xlog_recover_process_data: bad flag");
1094
error = XFS_ERROR(EIO);
1101
dp += INT_GET(ohead->oh_len, ARCH_CONVERT);
1105
} /* xlog_recover_process_data */
1094
* There are two valid states of the r_state field. 0 indicates that the
1095
* transaction structure is in a normal state. We have either seen the
1096
* start of the transaction or the last operation we added was not a partial
1097
* operation. If the last operation we added to the transaction was a
1098
* partial operation, we need to mark r_state with XLOG_WAS_CONT_TRANS.
1100
* NOTE: skip LRs with 0 data length.
1103
xlog_recover_process_data(
1105
xlog_recover_t *rhash[],
1106
xlog_rec_header_t *rhead,
1112
xlog_op_header_t *ohead;
1113
xlog_recover_t *trans;
1119
lp = dp + INT_GET(rhead->h_len, ARCH_CONVERT);
1120
num_logops = INT_GET(rhead->h_num_logops, ARCH_CONVERT);
1122
/* check the log format matches our own - else we can't recover */
1123
if (xlog_header_check_recover(log->l_mp, rhead))
1124
return (XFS_ERROR(EIO));
1126
while ((dp < lp) && num_logops) {
1127
ASSERT(dp + sizeof(xlog_op_header_t) <= lp);
1128
ohead = (xlog_op_header_t *)dp;
1129
dp += sizeof(xlog_op_header_t);
1130
if (ohead->oh_clientid != XFS_TRANSACTION &&
1131
ohead->oh_clientid != XFS_LOG) {
1133
"XFS: xlog_recover_process_data: bad clientid");
1135
return (XFS_ERROR(EIO));
1137
tid = INT_GET(ohead->oh_tid, ARCH_CONVERT);
1138
hash = XLOG_RHASH(tid);
1139
trans = xlog_recover_find_tid(rhash[hash], tid);
1140
if (trans == NULL) { /* not found; add new tid */
1141
if (ohead->oh_flags & XLOG_START_TRANS)
1142
xlog_recover_new_tid(&rhash[hash], tid,
1143
INT_GET(rhead->h_lsn, ARCH_CONVERT));
1145
ASSERT(dp+INT_GET(ohead->oh_len, ARCH_CONVERT) <= lp);
1146
flags = ohead->oh_flags & ~XLOG_END_TRANS;
1147
if (flags & XLOG_WAS_CONT_TRANS)
1148
flags &= ~XLOG_CONTINUE_TRANS;
1150
case XLOG_COMMIT_TRANS:
1151
error = xlog_recover_commit_trans(log,
1152
&rhash[hash], trans, pass);
1154
case XLOG_UNMOUNT_TRANS:
1155
error = xlog_recover_unmount_trans(trans);
1157
case XLOG_WAS_CONT_TRANS:
1158
error = xlog_recover_add_to_cont_trans(trans,
1159
dp, INT_GET(ohead->oh_len,
1162
case XLOG_START_TRANS:
1164
"XFS: xlog_recover_process_data: bad transaction");
1166
error = XFS_ERROR(EIO);
1169
case XLOG_CONTINUE_TRANS:
1170
error = xlog_recover_add_to_trans(trans,
1171
dp, INT_GET(ohead->oh_len,
1176
"XFS: xlog_recover_process_data: bad flag");
1178
error = XFS_ERROR(EIO);
1184
dp += INT_GET(ohead->oh_len, ARCH_CONVERT);
1191
xlog_valid_rec_header(
1193
xlog_rec_header_t *rhead,
1199
(INT_GET(rhead->h_magicno, ARCH_CONVERT) !=
1200
XLOG_HEADER_MAGIC_NUM))) {
1201
XFS_ERROR_REPORT("xlog_valid_rec_header(1)",
1202
XFS_ERRLEVEL_LOW, log->l_mp);
1203
return XFS_ERROR(EFSCORRUPTED);
1206
(INT_ISZERO(rhead->h_version, ARCH_CONVERT) ||
1207
(INT_GET(rhead->h_version, ARCH_CONVERT) &
1208
(~XLOG_VERSION_OKBITS)) != 0))) {
1209
xlog_warn("XFS: %s: unrecognised log version (%d).",
1210
__FUNCTION__, INT_GET(rhead->h_version, ARCH_CONVERT));
1211
return XFS_ERROR(EIO);
1214
/* LR body must have data or it wouldn't have been written */
1215
hlen = INT_GET(rhead->h_len, ARCH_CONVERT);
1216
if (unlikely( hlen <= 0 || hlen > INT_MAX )) {
1217
XFS_ERROR_REPORT("xlog_valid_rec_header(2)",
1218
XFS_ERRLEVEL_LOW, log->l_mp);
1219
return XFS_ERROR(EFSCORRUPTED);
1221
if (unlikely( blkno > log->l_logBBsize || blkno > INT_MAX )) {
1222
XFS_ERROR_REPORT("xlog_valid_rec_header(3)",
1223
XFS_ERRLEVEL_LOW, log->l_mp);
1224
return XFS_ERROR(EFSCORRUPTED);
1108
1230
* Read the log from tail to head and process the log records found.
1116
xlog_do_recovery_pass(xlog_t *log,
1117
xfs_daddr_t head_blk,
1118
xfs_daddr_t tail_blk,
1238
xlog_do_recovery_pass(
1240
xfs_daddr_t head_blk,
1241
xfs_daddr_t tail_blk,
1121
xlog_rec_header_t *rhead;
1123
xfs_caddr_t bufaddr;
1124
xfs_buf_t *hbp, *dbp;
1126
int bblks, split_bblks;
1127
xlog_recover_t *rhash[XLOG_RHASH_SIZE];
1130
hbp = xlog_get_bp(1,log->l_mp);
1133
dbp = xlog_get_bp(BTOBB(XLOG_MAX_RECORD_BSIZE),log->l_mp);
1244
xlog_rec_header_t *rhead;
1246
xfs_caddr_t bufaddr, offset;
1247
xfs_buf_t *hbp, *dbp;
1248
int error = 0, h_size;
1249
int bblks, split_bblks;
1250
int hblks, split_hblks, wrapped_hblks;
1251
xlog_recover_t *rhash[XLOG_RHASH_SIZE];
1253
ASSERT(head_blk != tail_blk);
1256
* Read the header of the tail block and get the iclog buffer size from
1257
* h_size. Use this to tell how many sectors make up the log header.
1259
if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
1261
* When using variable length iclogs, read first sector of
1262
* iclog header and extract the header size from it. Get a
1263
* new hbp that is the correct size.
1265
hbp = xlog_get_bp(log, 1);
1268
if ((error = xlog_bread(log, tail_blk, 1, hbp)))
1270
offset = xlog_align(log, tail_blk, 1, hbp);
1271
rhead = (xlog_rec_header_t *)offset;
1272
error = xlog_valid_rec_header(log, rhead, tail_blk);
1275
h_size = INT_GET(rhead->h_size, ARCH_CONVERT);
1276
if ((INT_GET(rhead->h_version, ARCH_CONVERT)
1277
& XLOG_VERSION_2) &&
1278
(h_size > XLOG_HEADER_CYCLE_SIZE)) {
1279
hblks = h_size / XLOG_HEADER_CYCLE_SIZE;
1280
if (h_size % XLOG_HEADER_CYCLE_SIZE)
1283
hbp = xlog_get_bp(log, hblks);
1288
ASSERT(log->l_sectbb_log == 0);
1290
hbp = xlog_get_bp(log, 1);
1291
h_size = XLOG_BIG_RECORD_BSIZE;
1296
dbp = xlog_get_bp(log, BTOBB(h_size));
1302
memset(rhash, 0, sizeof(rhash));
1303
if (tail_blk <= head_blk) {
1304
for (blk_no = tail_blk; blk_no < head_blk; ) {
1305
if ((error = xlog_bread(log, blk_no, hblks, hbp)))
1307
offset = xlog_align(log, blk_no, hblks, hbp);
1308
rhead = (xlog_rec_header_t *)offset;
1309
error = xlog_valid_rec_header(log, rhead, blk_no);
1313
/* blocks in data section */
1314
bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
1315
error = xlog_bread(log, blk_no + hblks, bblks, dbp);
1318
offset = xlog_align(log, blk_no + hblks, bblks, dbp);
1319
xlog_unpack_data(rhead, offset, log);
1320
if ((error = xlog_recover_process_data(log,
1321
rhash, rhead, offset, pass)))
1323
blk_no += bblks + hblks;
1327
* Perform recovery around the end of the physical log.
1328
* When the head is not on the same cycle number as the tail,
1329
* we can't do a sequential recovery as above.
1332
while (blk_no < log->l_logBBsize) {
1334
* Check for header wrapping around physical end-of-log
1339
if (blk_no + hblks <= log->l_logBBsize) {
1340
/* Read header in one read */
1341
error = xlog_bread(log, blk_no, hblks, hbp);
1344
offset = xlog_align(log, blk_no, hblks, hbp);
1346
/* This LR is split across physical log end */
1347
if (blk_no != log->l_logBBsize) {
1348
/* some data before physical log end */
1349
ASSERT(blk_no <= INT_MAX);
1350
split_hblks = log->l_logBBsize - (int)blk_no;
1351
ASSERT(split_hblks > 0);
1352
if ((error = xlog_bread(log, blk_no,
1355
offset = xlog_align(log, blk_no,
1359
* Note: this black magic still works with
1360
* large sector sizes (non-512) only because:
1361
* - we increased the buffer size originally
1362
* by 1 sector giving us enough extra space
1363
* for the second read;
1364
* - the log start is guaranteed to be sector
1366
* - we read the log end (LR header start)
1367
* _first_, then the log start (LR header end)
1368
* - order is important.
1370
bufaddr = XFS_BUF_PTR(hbp);
1371
XFS_BUF_SET_PTR(hbp,
1372
bufaddr + BBTOB(split_hblks),
1373
BBTOB(hblks - split_hblks));
1374
wrapped_hblks = hblks - split_hblks;
1375
error = xlog_bread(log, 0, wrapped_hblks, hbp);
1378
XFS_BUF_SET_PTR(hbp, bufaddr, BBTOB(hblks));
1380
offset = xlog_align(log, 0,
1381
wrapped_hblks, hbp);
1383
rhead = (xlog_rec_header_t *)offset;
1384
error = xlog_valid_rec_header(log, rhead,
1385
split_hblks ? blk_no : 0);
1389
bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
1392
/* Read in data for log record */
1393
if (blk_no + bblks <= log->l_logBBsize) {
1394
error = xlog_bread(log, blk_no, bblks, dbp);
1397
offset = xlog_align(log, blk_no, bblks, dbp);
1399
/* This log record is split across the
1400
* physical end of log */
1403
if (blk_no != log->l_logBBsize) {
1404
/* some data is before the physical
1406
ASSERT(!wrapped_hblks);
1407
ASSERT(blk_no <= INT_MAX);
1409
log->l_logBBsize - (int)blk_no;
1410
ASSERT(split_bblks > 0);
1411
if ((error = xlog_bread(log, blk_no,
1414
offset = xlog_align(log, blk_no,
1418
* Note: this black magic still works with
1419
* large sector sizes (non-512) only because:
1420
* - we increased the buffer size originally
1421
* by 1 sector giving us enough extra space
1422
* for the second read;
1423
* - the log start is guaranteed to be sector
1425
* - we read the log end (LR header start)
1426
* _first_, then the log start (LR header end)
1427
* - order is important.
1429
bufaddr = XFS_BUF_PTR(dbp);
1430
XFS_BUF_SET_PTR(dbp,
1431
bufaddr + BBTOB(split_bblks),
1432
BBTOB(bblks - split_bblks));
1433
if ((error = xlog_bread(log, wrapped_hblks,
1434
bblks - split_bblks, dbp)))
1436
XFS_BUF_SET_PTR(dbp, bufaddr, h_size);
1438
offset = xlog_align(log, wrapped_hblks,
1439
bblks - split_bblks, dbp);
1441
xlog_unpack_data(rhead, offset, log);
1442
if ((error = xlog_recover_process_data(log, rhash,
1443
rhead, offset, pass)))
1448
ASSERT(blk_no >= log->l_logBBsize);
1449
blk_no -= log->l_logBBsize;
1451
/* read first part of physical log */
1452
while (blk_no < head_blk) {
1453
if ((error = xlog_bread(log, blk_no, hblks, hbp)))
1455
offset = xlog_align(log, blk_no, hblks, hbp);
1456
rhead = (xlog_rec_header_t *)offset;
1457
error = xlog_valid_rec_header(log, rhead, blk_no);
1460
bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
1461
if ((error = xlog_bread(log, blk_no+hblks, bblks, dbp)))
1463
offset = xlog_align(log, blk_no+hblks, bblks, dbp);
1464
xlog_unpack_data(rhead, offset, log);
1465
if ((error = xlog_recover_process_data(log, rhash,
1466
rhead, offset, pass)))
1468
blk_no += bblks + hblks;
1135
1475
xlog_put_bp(hbp);
1138
bzero(rhash, sizeof(rhash));
1139
if (tail_blk <= head_blk) {
1140
for (blk_no = tail_blk; blk_no < head_blk; ) {
1141
if ((error = xlog_bread(log, blk_no, 1, hbp)))
1143
rhead = (xlog_rec_header_t *)XFS_BUF_PTR(hbp);
1144
ASSERT(INT_GET(rhead->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM);
1145
ASSERT(BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT) <= INT_MAX));
1146
bblks = (int) BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)); /* blocks in data section */
1148
if ((error = xlog_bread(log, blk_no+1, bblks, dbp)))
1150
xlog_unpack_data(rhead, XFS_BUF_PTR(dbp), log);
1151
if ((error = xlog_recover_process_data(log, rhash,
1152
rhead, XFS_BUF_PTR(dbp),
1156
blk_no += (bblks+1);
1160
* Perform recovery around the end of the physical log. When the head
1161
* is not on the same cycle number as the tail, we can't do a sequential
1162
* recovery as above.
1165
while (blk_no < log->l_logBBsize) {
1167
/* Read header of one block */
1168
if ((error = xlog_bread(log, blk_no, 1, hbp)))
1170
rhead = (xlog_rec_header_t *)XFS_BUF_PTR(hbp);
1171
ASSERT(INT_GET(rhead->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM);
1172
ASSERT(BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT) <= INT_MAX));
1173
bblks = (int) BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
1175
/* LR body must have data or it wouldn't have been written */
1177
blk_no++; /* successfully read header */
1178
ASSERT(blk_no <= log->l_logBBsize);
1180
if ((INT_GET(rhead->h_magicno, ARCH_CONVERT) != XLOG_HEADER_MAGIC_NUM) ||
1181
(BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT) > INT_MAX)) ||
1183
(blk_no > log->l_logBBsize)) {
1184
error = EFSCORRUPTED;
1188
/* Read in data for log record */
1189
if (blk_no+bblks <= log->l_logBBsize) {
1190
if ((error = xlog_bread(log, blk_no, bblks, dbp)))
1193
/* This log record is split across physical end of log */
1195
if (blk_no != log->l_logBBsize) {
1197
/* some data is before physical end of log */
1198
ASSERT(blk_no <= INT_MAX);
1199
split_bblks = log->l_logBBsize - (int)blk_no;
1200
ASSERT(split_bblks > 0);
1201
if ((error = xlog_bread(log, blk_no, split_bblks, dbp)))
1204
bufaddr = XFS_BUF_PTR(dbp);
1205
XFS_BUF_SET_PTR(dbp, bufaddr + BBTOB(split_bblks),
1206
BBTOB(bblks - split_bblks));
1207
if ((error = xlog_bread(log, 0, bblks - split_bblks, dbp)))
1209
XFS_BUF_SET_PTR(dbp, bufaddr, XLOG_MAX_RECORD_BSIZE);
1211
xlog_unpack_data(rhead, XFS_BUF_PTR(dbp), log);
1212
if ((error = xlog_recover_process_data(log, rhash,
1213
rhead, XFS_BUF_PTR(dbp),
1219
ASSERT(blk_no >= log->l_logBBsize);
1220
blk_no -= log->l_logBBsize;
1222
/* read first part of physical log */
1223
while (blk_no < head_blk) {
1224
if ((error = xlog_bread(log, blk_no, 1, hbp)))
1226
rhead = (xlog_rec_header_t *)XFS_BUF_PTR(hbp);
1227
ASSERT(INT_GET(rhead->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM);
1228
ASSERT(BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT) <= INT_MAX));
1229
bblks = (int) BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
1231
if ((error = xlog_bread(log, blk_no+1, bblks, dbp)))
1233
xlog_unpack_data(rhead, XFS_BUF_PTR(dbp), log);
1234
if ((error = xlog_recover_process_data(log, rhash,
1235
rhead, XFS_BUF_PTR(dbp),
1238
blk_no += (bblks+1);