1
2
3
4
5
6#include "xfs.h"
7#include "xfs_fs.h"
8#include "xfs_shared.h"
9#include "xfs_format.h"
10#include "xfs_log_format.h"
11#include "xfs_trans_resv.h"
12#include "xfs_bit.h"
13#include "xfs_mount.h"
14#include "xfs_trans.h"
15#include "xfs_buf_item.h"
16#include "xfs_trans_priv.h"
17#include "xfs_trace.h"
18#include "xfs_log.h"
19#include "xfs_log_priv.h"
20#include "xfs_log_recover.h"
21#include "xfs_error.h"
22#include "xfs_inode.h"
23#include "xfs_dir2.h"
24#include "xfs_quota.h"
25
26
27
28
29
30struct xfs_buf_cancel {
31 xfs_daddr_t bc_blkno;
32 uint bc_len;
33 int bc_refcount;
34 struct list_head bc_list;
35};
36
37static struct xfs_buf_cancel *
38xlog_find_buffer_cancelled(
39 struct xlog *log,
40 xfs_daddr_t blkno,
41 uint len)
42{
43 struct list_head *bucket;
44 struct xfs_buf_cancel *bcp;
45
46 if (!log->l_buf_cancel_table)
47 return NULL;
48
49 bucket = XLOG_BUF_CANCEL_BUCKET(log, blkno);
50 list_for_each_entry(bcp, bucket, bc_list) {
51 if (bcp->bc_blkno == blkno && bcp->bc_len == len)
52 return bcp;
53 }
54
55 return NULL;
56}
57
58static bool
59xlog_add_buffer_cancelled(
60 struct xlog *log,
61 xfs_daddr_t blkno,
62 uint len)
63{
64 struct xfs_buf_cancel *bcp;
65
66
67
68
69
70
71
72
73 bcp = xlog_find_buffer_cancelled(log, blkno, len);
74 if (bcp) {
75 bcp->bc_refcount++;
76 return false;
77 }
78
79 bcp = kmem_alloc(sizeof(struct xfs_buf_cancel), 0);
80 bcp->bc_blkno = blkno;
81 bcp->bc_len = len;
82 bcp->bc_refcount = 1;
83 list_add_tail(&bcp->bc_list, XLOG_BUF_CANCEL_BUCKET(log, blkno));
84 return true;
85}
86
87
88
89
90bool
91xlog_is_buffer_cancelled(
92 struct xlog *log,
93 xfs_daddr_t blkno,
94 uint len)
95{
96 return xlog_find_buffer_cancelled(log, blkno, len) != NULL;
97}
98
99
100
101
102
103
104
105
106
107static bool
108xlog_put_buffer_cancelled(
109 struct xlog *log,
110 xfs_daddr_t blkno,
111 uint len)
112{
113 struct xfs_buf_cancel *bcp;
114
115 bcp = xlog_find_buffer_cancelled(log, blkno, len);
116 if (!bcp) {
117 ASSERT(0);
118 return false;
119 }
120
121 if (--bcp->bc_refcount == 0) {
122 list_del(&bcp->bc_list);
123 kmem_free(bcp);
124 }
125 return true;
126}
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144STATIC enum xlog_recover_reorder
145xlog_recover_buf_reorder(
146 struct xlog_recover_item *item)
147{
148 struct xfs_buf_log_format *buf_f = item->ri_buf[0].i_addr;
149
150 if (buf_f->blf_flags & XFS_BLF_CANCEL)
151 return XLOG_REORDER_CANCEL_LIST;
152 if (buf_f->blf_flags & XFS_BLF_INODE_BUF)
153 return XLOG_REORDER_INODE_BUFFER_LIST;
154 return XLOG_REORDER_BUFFER_LIST;
155}
156
157STATIC void
158xlog_recover_buf_ra_pass2(
159 struct xlog *log,
160 struct xlog_recover_item *item)
161{
162 struct xfs_buf_log_format *buf_f = item->ri_buf[0].i_addr;
163
164 xlog_buf_readahead(log, buf_f->blf_blkno, buf_f->blf_len, NULL);
165}
166
167
168
169
170
171static int
172xlog_recover_buf_commit_pass1(
173 struct xlog *log,
174 struct xlog_recover_item *item)
175{
176 struct xfs_buf_log_format *bf = item->ri_buf[0].i_addr;
177
178 if (!xfs_buf_log_check_iovec(&item->ri_buf[0])) {
179 xfs_err(log->l_mp, "bad buffer log item size (%d)",
180 item->ri_buf[0].i_len);
181 return -EFSCORRUPTED;
182 }
183
184 if (!(bf->blf_flags & XFS_BLF_CANCEL))
185 trace_xfs_log_recover_buf_not_cancel(log, bf);
186 else if (xlog_add_buffer_cancelled(log, bf->blf_blkno, bf->blf_len))
187 trace_xfs_log_recover_buf_cancel_add(log, bf);
188 else
189 trace_xfs_log_recover_buf_cancel_ref_inc(log, bf);
190 return 0;
191}
192
193
194
195
196
197
198
199
200
201static void
202xlog_recover_validate_buf_type(
203 struct xfs_mount *mp,
204 struct xfs_buf *bp,
205 struct xfs_buf_log_format *buf_f,
206 xfs_lsn_t current_lsn)
207{
208 struct xfs_da_blkinfo *info = bp->b_addr;
209 uint32_t magic32;
210 uint16_t magic16;
211 uint16_t magicda;
212 char *warnmsg = NULL;
213
214
215
216
217
218
219
220
221
222 if (!xfs_sb_version_hascrc(&mp->m_sb))
223 return;
224
225 magic32 = be32_to_cpu(*(__be32 *)bp->b_addr);
226 magic16 = be16_to_cpu(*(__be16*)bp->b_addr);
227 magicda = be16_to_cpu(info->magic);
228 switch (xfs_blft_from_flags(buf_f)) {
229 case XFS_BLFT_BTREE_BUF:
230 switch (magic32) {
231 case XFS_ABTB_CRC_MAGIC:
232 case XFS_ABTB_MAGIC:
233 bp->b_ops = &xfs_bnobt_buf_ops;
234 break;
235 case XFS_ABTC_CRC_MAGIC:
236 case XFS_ABTC_MAGIC:
237 bp->b_ops = &xfs_cntbt_buf_ops;
238 break;
239 case XFS_IBT_CRC_MAGIC:
240 case XFS_IBT_MAGIC:
241 bp->b_ops = &xfs_inobt_buf_ops;
242 break;
243 case XFS_FIBT_CRC_MAGIC:
244 case XFS_FIBT_MAGIC:
245 bp->b_ops = &xfs_finobt_buf_ops;
246 break;
247 case XFS_BMAP_CRC_MAGIC:
248 case XFS_BMAP_MAGIC:
249 bp->b_ops = &xfs_bmbt_buf_ops;
250 break;
251 case XFS_RMAP_CRC_MAGIC:
252 bp->b_ops = &xfs_rmapbt_buf_ops;
253 break;
254 case XFS_REFC_CRC_MAGIC:
255 bp->b_ops = &xfs_refcountbt_buf_ops;
256 break;
257 default:
258 warnmsg = "Bad btree block magic!";
259 break;
260 }
261 break;
262 case XFS_BLFT_AGF_BUF:
263 if (magic32 != XFS_AGF_MAGIC) {
264 warnmsg = "Bad AGF block magic!";
265 break;
266 }
267 bp->b_ops = &xfs_agf_buf_ops;
268 break;
269 case XFS_BLFT_AGFL_BUF:
270 if (magic32 != XFS_AGFL_MAGIC) {
271 warnmsg = "Bad AGFL block magic!";
272 break;
273 }
274 bp->b_ops = &xfs_agfl_buf_ops;
275 break;
276 case XFS_BLFT_AGI_BUF:
277 if (magic32 != XFS_AGI_MAGIC) {
278 warnmsg = "Bad AGI block magic!";
279 break;
280 }
281 bp->b_ops = &xfs_agi_buf_ops;
282 break;
283 case XFS_BLFT_UDQUOT_BUF:
284 case XFS_BLFT_PDQUOT_BUF:
285 case XFS_BLFT_GDQUOT_BUF:
286#ifdef CONFIG_XFS_QUOTA
287 if (magic16 != XFS_DQUOT_MAGIC) {
288 warnmsg = "Bad DQUOT block magic!";
289 break;
290 }
291 bp->b_ops = &xfs_dquot_buf_ops;
292#else
293 xfs_alert(mp,
294 "Trying to recover dquots without QUOTA support built in!");
295 ASSERT(0);
296#endif
297 break;
298 case XFS_BLFT_DINO_BUF:
299 if (magic16 != XFS_DINODE_MAGIC) {
300 warnmsg = "Bad INODE block magic!";
301 break;
302 }
303 bp->b_ops = &xfs_inode_buf_ops;
304 break;
305 case XFS_BLFT_SYMLINK_BUF:
306 if (magic32 != XFS_SYMLINK_MAGIC) {
307 warnmsg = "Bad symlink block magic!";
308 break;
309 }
310 bp->b_ops = &xfs_symlink_buf_ops;
311 break;
312 case XFS_BLFT_DIR_BLOCK_BUF:
313 if (magic32 != XFS_DIR2_BLOCK_MAGIC &&
314 magic32 != XFS_DIR3_BLOCK_MAGIC) {
315 warnmsg = "Bad dir block magic!";
316 break;
317 }
318 bp->b_ops = &xfs_dir3_block_buf_ops;
319 break;
320 case XFS_BLFT_DIR_DATA_BUF:
321 if (magic32 != XFS_DIR2_DATA_MAGIC &&
322 magic32 != XFS_DIR3_DATA_MAGIC) {
323 warnmsg = "Bad dir data magic!";
324 break;
325 }
326 bp->b_ops = &xfs_dir3_data_buf_ops;
327 break;
328 case XFS_BLFT_DIR_FREE_BUF:
329 if (magic32 != XFS_DIR2_FREE_MAGIC &&
330 magic32 != XFS_DIR3_FREE_MAGIC) {
331 warnmsg = "Bad dir3 free magic!";
332 break;
333 }
334 bp->b_ops = &xfs_dir3_free_buf_ops;
335 break;
336 case XFS_BLFT_DIR_LEAF1_BUF:
337 if (magicda != XFS_DIR2_LEAF1_MAGIC &&
338 magicda != XFS_DIR3_LEAF1_MAGIC) {
339 warnmsg = "Bad dir leaf1 magic!";
340 break;
341 }
342 bp->b_ops = &xfs_dir3_leaf1_buf_ops;
343 break;
344 case XFS_BLFT_DIR_LEAFN_BUF:
345 if (magicda != XFS_DIR2_LEAFN_MAGIC &&
346 magicda != XFS_DIR3_LEAFN_MAGIC) {
347 warnmsg = "Bad dir leafn magic!";
348 break;
349 }
350 bp->b_ops = &xfs_dir3_leafn_buf_ops;
351 break;
352 case XFS_BLFT_DA_NODE_BUF:
353 if (magicda != XFS_DA_NODE_MAGIC &&
354 magicda != XFS_DA3_NODE_MAGIC) {
355 warnmsg = "Bad da node magic!";
356 break;
357 }
358 bp->b_ops = &xfs_da3_node_buf_ops;
359 break;
360 case XFS_BLFT_ATTR_LEAF_BUF:
361 if (magicda != XFS_ATTR_LEAF_MAGIC &&
362 magicda != XFS_ATTR3_LEAF_MAGIC) {
363 warnmsg = "Bad attr leaf magic!";
364 break;
365 }
366 bp->b_ops = &xfs_attr3_leaf_buf_ops;
367 break;
368 case XFS_BLFT_ATTR_RMT_BUF:
369 if (magic32 != XFS_ATTR3_RMT_MAGIC) {
370 warnmsg = "Bad attr remote magic!";
371 break;
372 }
373 bp->b_ops = &xfs_attr3_rmt_buf_ops;
374 break;
375 case XFS_BLFT_SB_BUF:
376 if (magic32 != XFS_SB_MAGIC) {
377 warnmsg = "Bad SB block magic!";
378 break;
379 }
380 bp->b_ops = &xfs_sb_buf_ops;
381 break;
382#ifdef CONFIG_XFS_RT
383 case XFS_BLFT_RTBITMAP_BUF:
384 case XFS_BLFT_RTSUMMARY_BUF:
385
386 bp->b_ops = &xfs_rtbuf_ops;
387 break;
388#endif
389 default:
390 xfs_warn(mp, "Unknown buffer type %d!",
391 xfs_blft_from_flags(buf_f));
392 break;
393 }
394
395
396
397
398
399
400 if (current_lsn == NULLCOMMITLSN)
401 return;
402
403 if (warnmsg) {
404 xfs_warn(mp, warnmsg);
405 ASSERT(0);
406 }
407
408
409
410
411
412
413
414
415
416
417
418
419 if (bp->b_ops) {
420 struct xfs_buf_log_item *bip;
421
422 bp->b_flags |= _XBF_LOGRECOVERY;
423 xfs_buf_item_init(bp, mp);
424 bip = bp->b_log_item;
425 bip->bli_item.li_lsn = current_lsn;
426 }
427}
428
429
430
431
432
433
434
435STATIC void
436xlog_recover_do_reg_buffer(
437 struct xfs_mount *mp,
438 struct xlog_recover_item *item,
439 struct xfs_buf *bp,
440 struct xfs_buf_log_format *buf_f,
441 xfs_lsn_t current_lsn)
442{
443 int i;
444 int bit;
445 int nbits;
446 xfs_failaddr_t fa;
447 const size_t size_disk_dquot = sizeof(struct xfs_disk_dquot);
448
449 trace_xfs_log_recover_buf_reg_buf(mp->m_log, buf_f);
450
451 bit = 0;
452 i = 1;
453 while (1) {
454 bit = xfs_next_bit(buf_f->blf_data_map,
455 buf_f->blf_map_size, bit);
456 if (bit == -1)
457 break;
458 nbits = xfs_contig_bits(buf_f->blf_data_map,
459 buf_f->blf_map_size, bit);
460 ASSERT(nbits > 0);
461 ASSERT(item->ri_buf[i].i_addr != NULL);
462 ASSERT(item->ri_buf[i].i_len % XFS_BLF_CHUNK == 0);
463 ASSERT(BBTOB(bp->b_length) >=
464 ((uint)bit << XFS_BLF_SHIFT) + (nbits << XFS_BLF_SHIFT));
465
466
467
468
469
470
471
472
473
474 if (item->ri_buf[i].i_len < (nbits << XFS_BLF_SHIFT))
475 nbits = item->ri_buf[i].i_len >> XFS_BLF_SHIFT;
476
477
478
479
480
481
482 fa = NULL;
483 if (buf_f->blf_flags &
484 (XFS_BLF_UDQUOT_BUF|XFS_BLF_PDQUOT_BUF|XFS_BLF_GDQUOT_BUF)) {
485 if (item->ri_buf[i].i_addr == NULL) {
486 xfs_alert(mp,
487 "XFS: NULL dquot in %s.", __func__);
488 goto next;
489 }
490 if (item->ri_buf[i].i_len < size_disk_dquot) {
491 xfs_alert(mp,
492 "XFS: dquot too small (%d) in %s.",
493 item->ri_buf[i].i_len, __func__);
494 goto next;
495 }
496 fa = xfs_dquot_verify(mp, item->ri_buf[i].i_addr, -1);
497 if (fa) {
498 xfs_alert(mp,
499 "dquot corrupt at %pS trying to replay into block 0x%llx",
500 fa, bp->b_bn);
501 goto next;
502 }
503 }
504
505 memcpy(xfs_buf_offset(bp,
506 (uint)bit << XFS_BLF_SHIFT),
507 item->ri_buf[i].i_addr,
508 nbits<<XFS_BLF_SHIFT);
509 next:
510 i++;
511 bit += nbits;
512 }
513
514
515 ASSERT(i == item->ri_total);
516
517 xlog_recover_validate_buf_type(mp, bp, buf_f, current_lsn);
518}
519
520
521
522
523
524
525
526
527
528
529STATIC bool
530xlog_recover_do_dquot_buffer(
531 struct xfs_mount *mp,
532 struct xlog *log,
533 struct xlog_recover_item *item,
534 struct xfs_buf *bp,
535 struct xfs_buf_log_format *buf_f)
536{
537 uint type;
538
539 trace_xfs_log_recover_buf_dquot_buf(log, buf_f);
540
541
542
543
544 if (!mp->m_qflags)
545 return false;
546
547 type = 0;
548 if (buf_f->blf_flags & XFS_BLF_UDQUOT_BUF)
549 type |= XFS_DQTYPE_USER;
550 if (buf_f->blf_flags & XFS_BLF_PDQUOT_BUF)
551 type |= XFS_DQTYPE_PROJ;
552 if (buf_f->blf_flags & XFS_BLF_GDQUOT_BUF)
553 type |= XFS_DQTYPE_GROUP;
554
555
556
557 if (log->l_quotaoffs_flag & type)
558 return false;
559
560 xlog_recover_do_reg_buffer(mp, item, bp, buf_f, NULLCOMMITLSN);
561 return true;
562}
563
564
565
566
567
568
569
570
571
572
573
574
575
576STATIC int
577xlog_recover_do_inode_buffer(
578 struct xfs_mount *mp,
579 struct xlog_recover_item *item,
580 struct xfs_buf *bp,
581 struct xfs_buf_log_format *buf_f)
582{
583 int i;
584 int item_index = 0;
585 int bit = 0;
586 int nbits = 0;
587 int reg_buf_offset = 0;
588 int reg_buf_bytes = 0;
589 int next_unlinked_offset;
590 int inodes_per_buf;
591 xfs_agino_t *logged_nextp;
592 xfs_agino_t *buffer_nextp;
593
594 trace_xfs_log_recover_buf_inode_buf(mp->m_log, buf_f);
595
596
597
598
599
600 if (xfs_sb_version_hascrc(&mp->m_sb))
601 bp->b_ops = &xfs_inode_buf_ops;
602
603 inodes_per_buf = BBTOB(bp->b_length) >> mp->m_sb.sb_inodelog;
604 for (i = 0; i < inodes_per_buf; i++) {
605 next_unlinked_offset = (i * mp->m_sb.sb_inodesize) +
606 offsetof(xfs_dinode_t, di_next_unlinked);
607
608 while (next_unlinked_offset >=
609 (reg_buf_offset + reg_buf_bytes)) {
610
611
612
613
614
615
616 bit += nbits;
617 bit = xfs_next_bit(buf_f->blf_data_map,
618 buf_f->blf_map_size, bit);
619
620
621
622
623
624 if (bit == -1)
625 return 0;
626
627 nbits = xfs_contig_bits(buf_f->blf_data_map,
628 buf_f->blf_map_size, bit);
629 ASSERT(nbits > 0);
630 reg_buf_offset = bit << XFS_BLF_SHIFT;
631 reg_buf_bytes = nbits << XFS_BLF_SHIFT;
632 item_index++;
633 }
634
635
636
637
638
639
640 if (next_unlinked_offset < reg_buf_offset)
641 continue;
642
643 ASSERT(item->ri_buf[item_index].i_addr != NULL);
644 ASSERT((item->ri_buf[item_index].i_len % XFS_BLF_CHUNK) == 0);
645 ASSERT((reg_buf_offset + reg_buf_bytes) <= BBTOB(bp->b_length));
646
647
648
649
650
651
652 logged_nextp = item->ri_buf[item_index].i_addr +
653 next_unlinked_offset - reg_buf_offset;
654 if (XFS_IS_CORRUPT(mp, *logged_nextp == 0)) {
655 xfs_alert(mp,
656 "Bad inode buffer log record (ptr = "PTR_FMT", bp = "PTR_FMT"). "
657 "Trying to replay bad (0) inode di_next_unlinked field.",
658 item, bp);
659 return -EFSCORRUPTED;
660 }
661
662 buffer_nextp = xfs_buf_offset(bp, next_unlinked_offset);
663 *buffer_nextp = *logged_nextp;
664
665
666
667
668
669
670 xfs_dinode_calc_crc(mp,
671 xfs_buf_offset(bp, i * mp->m_sb.sb_inodesize));
672
673 }
674
675 return 0;
676}
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698static xfs_lsn_t
699xlog_recover_get_buf_lsn(
700 struct xfs_mount *mp,
701 struct xfs_buf *bp)
702{
703 uint32_t magic32;
704 uint16_t magic16;
705 uint16_t magicda;
706 void *blk = bp->b_addr;
707 uuid_t *uuid;
708 xfs_lsn_t lsn = -1;
709
710
711 if (!xfs_sb_version_hascrc(&mp->m_sb))
712 goto recover_immediately;
713
714 magic32 = be32_to_cpu(*(__be32 *)blk);
715 switch (magic32) {
716 case XFS_ABTB_CRC_MAGIC:
717 case XFS_ABTC_CRC_MAGIC:
718 case XFS_ABTB_MAGIC:
719 case XFS_ABTC_MAGIC:
720 case XFS_RMAP_CRC_MAGIC:
721 case XFS_REFC_CRC_MAGIC:
722 case XFS_FIBT_CRC_MAGIC:
723 case XFS_FIBT_MAGIC:
724 case XFS_IBT_CRC_MAGIC:
725 case XFS_IBT_MAGIC: {
726 struct xfs_btree_block *btb = blk;
727
728 lsn = be64_to_cpu(btb->bb_u.s.bb_lsn);
729 uuid = &btb->bb_u.s.bb_uuid;
730 break;
731 }
732 case XFS_BMAP_CRC_MAGIC:
733 case XFS_BMAP_MAGIC: {
734 struct xfs_btree_block *btb = blk;
735
736 lsn = be64_to_cpu(btb->bb_u.l.bb_lsn);
737 uuid = &btb->bb_u.l.bb_uuid;
738 break;
739 }
740 case XFS_AGF_MAGIC:
741 lsn = be64_to_cpu(((struct xfs_agf *)blk)->agf_lsn);
742 uuid = &((struct xfs_agf *)blk)->agf_uuid;
743 break;
744 case XFS_AGFL_MAGIC:
745 lsn = be64_to_cpu(((struct xfs_agfl *)blk)->agfl_lsn);
746 uuid = &((struct xfs_agfl *)blk)->agfl_uuid;
747 break;
748 case XFS_AGI_MAGIC:
749 lsn = be64_to_cpu(((struct xfs_agi *)blk)->agi_lsn);
750 uuid = &((struct xfs_agi *)blk)->agi_uuid;
751 break;
752 case XFS_SYMLINK_MAGIC:
753 lsn = be64_to_cpu(((struct xfs_dsymlink_hdr *)blk)->sl_lsn);
754 uuid = &((struct xfs_dsymlink_hdr *)blk)->sl_uuid;
755 break;
756 case XFS_DIR3_BLOCK_MAGIC:
757 case XFS_DIR3_DATA_MAGIC:
758 case XFS_DIR3_FREE_MAGIC:
759 lsn = be64_to_cpu(((struct xfs_dir3_blk_hdr *)blk)->lsn);
760 uuid = &((struct xfs_dir3_blk_hdr *)blk)->uuid;
761 break;
762 case XFS_ATTR3_RMT_MAGIC:
763
764
765
766
767
768
769
770 goto recover_immediately;
771 case XFS_SB_MAGIC:
772
773
774
775
776
777
778
779 lsn = be64_to_cpu(((struct xfs_dsb *)blk)->sb_lsn);
780 if (xfs_sb_version_hasmetauuid(&mp->m_sb))
781 uuid = &((struct xfs_dsb *)blk)->sb_meta_uuid;
782 else
783 uuid = &((struct xfs_dsb *)blk)->sb_uuid;
784 break;
785 default:
786 break;
787 }
788
789 if (lsn != (xfs_lsn_t)-1) {
790 if (!uuid_equal(&mp->m_sb.sb_meta_uuid, uuid))
791 goto recover_immediately;
792 return lsn;
793 }
794
795 magicda = be16_to_cpu(((struct xfs_da_blkinfo *)blk)->magic);
796 switch (magicda) {
797 case XFS_DIR3_LEAF1_MAGIC:
798 case XFS_DIR3_LEAFN_MAGIC:
799 case XFS_DA3_NODE_MAGIC:
800 lsn = be64_to_cpu(((struct xfs_da3_blkinfo *)blk)->lsn);
801 uuid = &((struct xfs_da3_blkinfo *)blk)->uuid;
802 break;
803 default:
804 break;
805 }
806
807 if (lsn != (xfs_lsn_t)-1) {
808 if (!uuid_equal(&mp->m_sb.sb_uuid, uuid))
809 goto recover_immediately;
810 return lsn;
811 }
812
813
814
815
816
817
818
819
820
821
822
823
824 magic16 = be16_to_cpu(*(__be16 *)blk);
825 switch (magic16) {
826 case XFS_DQUOT_MAGIC:
827 case XFS_DINODE_MAGIC:
828 goto recover_immediately;
829 default:
830 break;
831 }
832
833
834
835recover_immediately:
836 return (xfs_lsn_t)-1;
837
838}
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863STATIC int
864xlog_recover_buf_commit_pass2(
865 struct xlog *log,
866 struct list_head *buffer_list,
867 struct xlog_recover_item *item,
868 xfs_lsn_t current_lsn)
869{
870 struct xfs_buf_log_format *buf_f = item->ri_buf[0].i_addr;
871 struct xfs_mount *mp = log->l_mp;
872 struct xfs_buf *bp;
873 int error;
874 uint buf_flags;
875 xfs_lsn_t lsn;
876
877
878
879
880
881 if (buf_f->blf_flags & XFS_BLF_CANCEL) {
882 if (xlog_put_buffer_cancelled(log, buf_f->blf_blkno,
883 buf_f->blf_len))
884 goto cancelled;
885 } else {
886
887 if (xlog_is_buffer_cancelled(log, buf_f->blf_blkno,
888 buf_f->blf_len))
889 goto cancelled;
890 }
891
892 trace_xfs_log_recover_buf_recover(log, buf_f);
893
894 buf_flags = 0;
895 if (buf_f->blf_flags & XFS_BLF_INODE_BUF)
896 buf_flags |= XBF_UNMAPPED;
897
898 error = xfs_buf_read(mp->m_ddev_targp, buf_f->blf_blkno, buf_f->blf_len,
899 buf_flags, &bp, NULL);
900 if (error)
901 return error;
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922 lsn = xlog_recover_get_buf_lsn(mp, bp);
923 if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) {
924 trace_xfs_log_recover_buf_skip(log, buf_f);
925 xlog_recover_validate_buf_type(mp, bp, buf_f, NULLCOMMITLSN);
926 goto out_release;
927 }
928
929 if (buf_f->blf_flags & XFS_BLF_INODE_BUF) {
930 error = xlog_recover_do_inode_buffer(mp, item, bp, buf_f);
931 if (error)
932 goto out_release;
933 } else if (buf_f->blf_flags &
934 (XFS_BLF_UDQUOT_BUF|XFS_BLF_PDQUOT_BUF|XFS_BLF_GDQUOT_BUF)) {
935 bool dirty;
936
937 dirty = xlog_recover_do_dquot_buffer(mp, log, item, bp, buf_f);
938 if (!dirty)
939 goto out_release;
940 } else {
941 xlog_recover_do_reg_buffer(mp, item, bp, buf_f, current_lsn);
942 }
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959 if (XFS_DINODE_MAGIC ==
960 be16_to_cpu(*((__be16 *)xfs_buf_offset(bp, 0))) &&
961 (BBTOB(bp->b_length) != M_IGEO(log->l_mp)->inode_cluster_size)) {
962 xfs_buf_stale(bp);
963 error = xfs_bwrite(bp);
964 } else {
965 ASSERT(bp->b_mount == mp);
966 bp->b_flags |= _XBF_LOGRECOVERY;
967 xfs_buf_delwri_queue(bp, buffer_list);
968 }
969
970out_release:
971 xfs_buf_relse(bp);
972 return error;
973cancelled:
974 trace_xfs_log_recover_buf_cancel(log, buf_f);
975 return 0;
976}
977
978const struct xlog_recover_item_ops xlog_buf_item_ops = {
979 .item_type = XFS_LI_BUF,
980 .reorder = xlog_recover_buf_reorder,
981 .ra_pass2 = xlog_recover_buf_ra_pass2,
982 .commit_pass1 = xlog_recover_buf_commit_pass1,
983 .commit_pass2 = xlog_recover_buf_commit_pass2,
984};
985