hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/fs/xfs/libxfs/xfs_refcount.c
....@@ -9,7 +9,6 @@
99 #include "xfs_format.h"
1010 #include "xfs_log_format.h"
1111 #include "xfs_trans_resv.h"
12
-#include "xfs_sb.h"
1312 #include "xfs_mount.h"
1413 #include "xfs_defer.h"
1514 #include "xfs_btree.h"
....@@ -19,7 +18,6 @@
1918 #include "xfs_errortag.h"
2019 #include "xfs_error.h"
2120 #include "xfs_trace.h"
22
-#include "xfs_cksum.h"
2321 #include "xfs_trans.h"
2422 #include "xfs_bit.h"
2523 #include "xfs_refcount.h"
....@@ -48,7 +46,7 @@
4846 xfs_agblock_t bno,
4947 int *stat)
5048 {
51
- trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_private.a.agno, bno,
49
+ trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.agno, bno,
5250 XFS_LOOKUP_LE);
5351 cur->bc_rec.rc.rc_startblock = bno;
5452 cur->bc_rec.rc.rc_blockcount = 0;
....@@ -65,7 +63,7 @@
6563 xfs_agblock_t bno,
6664 int *stat)
6765 {
68
- trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_private.a.agno, bno,
66
+ trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.agno, bno,
6967 XFS_LOOKUP_GE);
7068 cur->bc_rec.rc.rc_startblock = bno;
7169 cur->bc_rec.rc.rc_blockcount = 0;
....@@ -82,7 +80,7 @@
8280 xfs_agblock_t bno,
8381 int *stat)
8482 {
85
- trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_private.a.agno, bno,
83
+ trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.agno, bno,
8684 XFS_LOOKUP_LE);
8785 cur->bc_rec.rc.rc_startblock = bno;
8886 cur->bc_rec.rc.rc_blockcount = 0;
....@@ -110,7 +108,7 @@
110108 int *stat)
111109 {
112110 struct xfs_mount *mp = cur->bc_mp;
113
- xfs_agnumber_t agno = cur->bc_private.a.agno;
111
+ xfs_agnumber_t agno = cur->bc_ag.agno;
114112 union xfs_btree_rec *rec;
115113 int error;
116114 xfs_agblock_t realstart;
....@@ -121,7 +119,7 @@
121119
122120 xfs_refcount_btrec_to_irec(rec, irec);
123121
124
- agno = cur->bc_private.a.agno;
122
+ agno = cur->bc_ag.agno;
125123 if (irec->rc_blockcount == 0 || irec->rc_blockcount > MAXREFCEXTLEN)
126124 goto out_bad_rec;
127125
....@@ -146,7 +144,7 @@
146144 if (irec->rc_refcount == 0 || irec->rc_refcount > MAXREFCOUNT)
147145 goto out_bad_rec;
148146
149
- trace_xfs_refcount_get(cur->bc_mp, cur->bc_private.a.agno, irec);
147
+ trace_xfs_refcount_get(cur->bc_mp, cur->bc_ag.agno, irec);
150148 return 0;
151149
152150 out_bad_rec:
....@@ -171,14 +169,14 @@
171169 union xfs_btree_rec rec;
172170 int error;
173171
174
- trace_xfs_refcount_update(cur->bc_mp, cur->bc_private.a.agno, irec);
172
+ trace_xfs_refcount_update(cur->bc_mp, cur->bc_ag.agno, irec);
175173 rec.refc.rc_startblock = cpu_to_be32(irec->rc_startblock);
176174 rec.refc.rc_blockcount = cpu_to_be32(irec->rc_blockcount);
177175 rec.refc.rc_refcount = cpu_to_be32(irec->rc_refcount);
178176 error = xfs_btree_update(cur, &rec);
179177 if (error)
180178 trace_xfs_refcount_update_error(cur->bc_mp,
181
- cur->bc_private.a.agno, error, _RET_IP_);
179
+ cur->bc_ag.agno, error, _RET_IP_);
182180 return error;
183181 }
184182
....@@ -195,19 +193,22 @@
195193 {
196194 int error;
197195
198
- trace_xfs_refcount_insert(cur->bc_mp, cur->bc_private.a.agno, irec);
196
+ trace_xfs_refcount_insert(cur->bc_mp, cur->bc_ag.agno, irec);
199197 cur->bc_rec.rc.rc_startblock = irec->rc_startblock;
200198 cur->bc_rec.rc.rc_blockcount = irec->rc_blockcount;
201199 cur->bc_rec.rc.rc_refcount = irec->rc_refcount;
202200 error = xfs_btree_insert(cur, i);
203201 if (error)
204202 goto out_error;
205
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, *i == 1, out_error);
203
+ if (XFS_IS_CORRUPT(cur->bc_mp, *i != 1)) {
204
+ error = -EFSCORRUPTED;
205
+ goto out_error;
206
+ }
206207
207208 out_error:
208209 if (error)
209210 trace_xfs_refcount_insert_error(cur->bc_mp,
210
- cur->bc_private.a.agno, error, _RET_IP_);
211
+ cur->bc_ag.agno, error, _RET_IP_);
211212 return error;
212213 }
213214
....@@ -229,17 +230,23 @@
229230 error = xfs_refcount_get_rec(cur, &irec, &found_rec);
230231 if (error)
231232 goto out_error;
232
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
233
- trace_xfs_refcount_delete(cur->bc_mp, cur->bc_private.a.agno, &irec);
233
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
234
+ error = -EFSCORRUPTED;
235
+ goto out_error;
236
+ }
237
+ trace_xfs_refcount_delete(cur->bc_mp, cur->bc_ag.agno, &irec);
234238 error = xfs_btree_delete(cur, i);
235
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, *i == 1, out_error);
239
+ if (XFS_IS_CORRUPT(cur->bc_mp, *i != 1)) {
240
+ error = -EFSCORRUPTED;
241
+ goto out_error;
242
+ }
236243 if (error)
237244 goto out_error;
238245 error = xfs_refcount_lookup_ge(cur, irec.rc_startblock, &found_rec);
239246 out_error:
240247 if (error)
241248 trace_xfs_refcount_delete_error(cur->bc_mp,
242
- cur->bc_private.a.agno, error, _RET_IP_);
249
+ cur->bc_ag.agno, error, _RET_IP_);
243250 return error;
244251 }
245252
....@@ -351,12 +358,15 @@
351358 error = xfs_refcount_get_rec(cur, &rcext, &found_rec);
352359 if (error)
353360 goto out_error;
354
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
361
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
362
+ error = -EFSCORRUPTED;
363
+ goto out_error;
364
+ }
355365 if (rcext.rc_startblock == agbno || xfs_refc_next(&rcext) <= agbno)
356366 return 0;
357367
358368 *shape_changed = true;
359
- trace_xfs_refcount_split_extent(cur->bc_mp, cur->bc_private.a.agno,
369
+ trace_xfs_refcount_split_extent(cur->bc_mp, cur->bc_ag.agno,
360370 &rcext, agbno);
361371
362372 /* Establish the right extent. */
....@@ -373,12 +383,15 @@
373383 error = xfs_refcount_insert(cur, &tmp, &found_rec);
374384 if (error)
375385 goto out_error;
376
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
386
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
387
+ error = -EFSCORRUPTED;
388
+ goto out_error;
389
+ }
377390 return error;
378391
379392 out_error:
380393 trace_xfs_refcount_split_extent_error(cur->bc_mp,
381
- cur->bc_private.a.agno, error, _RET_IP_);
394
+ cur->bc_ag.agno, error, _RET_IP_);
382395 return error;
383396 }
384397
....@@ -398,7 +411,7 @@
398411 int found_rec;
399412
400413 trace_xfs_refcount_merge_center_extents(cur->bc_mp,
401
- cur->bc_private.a.agno, left, center, right);
414
+ cur->bc_ag.agno, left, center, right);
402415
403416 /*
404417 * Make sure the center and right extents are not in the btree.
....@@ -412,19 +425,27 @@
412425 &found_rec);
413426 if (error)
414427 goto out_error;
415
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
428
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
429
+ error = -EFSCORRUPTED;
430
+ goto out_error;
431
+ }
416432
417433 error = xfs_refcount_delete(cur, &found_rec);
418434 if (error)
419435 goto out_error;
420
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
436
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
437
+ error = -EFSCORRUPTED;
438
+ goto out_error;
439
+ }
421440
422441 if (center->rc_refcount > 1) {
423442 error = xfs_refcount_delete(cur, &found_rec);
424443 if (error)
425444 goto out_error;
426
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1,
427
- out_error);
445
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
446
+ error = -EFSCORRUPTED;
447
+ goto out_error;
448
+ }
428449 }
429450
430451 /* Enlarge the left extent. */
....@@ -432,7 +453,10 @@
432453 &found_rec);
433454 if (error)
434455 goto out_error;
435
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
456
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
457
+ error = -EFSCORRUPTED;
458
+ goto out_error;
459
+ }
436460
437461 left->rc_blockcount = extlen;
438462 error = xfs_refcount_update(cur, left);
....@@ -444,7 +468,7 @@
444468
445469 out_error:
446470 trace_xfs_refcount_merge_center_extents_error(cur->bc_mp,
447
- cur->bc_private.a.agno, error, _RET_IP_);
471
+ cur->bc_ag.agno, error, _RET_IP_);
448472 return error;
449473 }
450474
....@@ -463,7 +487,7 @@
463487 int found_rec;
464488
465489 trace_xfs_refcount_merge_left_extent(cur->bc_mp,
466
- cur->bc_private.a.agno, left, cleft);
490
+ cur->bc_ag.agno, left, cleft);
467491
468492 /* If the extent at agbno (cleft) wasn't synthesized, remove it. */
469493 if (cleft->rc_refcount > 1) {
....@@ -471,14 +495,18 @@
471495 &found_rec);
472496 if (error)
473497 goto out_error;
474
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1,
475
- out_error);
498
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
499
+ error = -EFSCORRUPTED;
500
+ goto out_error;
501
+ }
476502
477503 error = xfs_refcount_delete(cur, &found_rec);
478504 if (error)
479505 goto out_error;
480
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1,
481
- out_error);
506
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
507
+ error = -EFSCORRUPTED;
508
+ goto out_error;
509
+ }
482510 }
483511
484512 /* Enlarge the left extent. */
....@@ -486,7 +514,10 @@
486514 &found_rec);
487515 if (error)
488516 goto out_error;
489
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
517
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
518
+ error = -EFSCORRUPTED;
519
+ goto out_error;
520
+ }
490521
491522 left->rc_blockcount += cleft->rc_blockcount;
492523 error = xfs_refcount_update(cur, left);
....@@ -499,7 +530,7 @@
499530
500531 out_error:
501532 trace_xfs_refcount_merge_left_extent_error(cur->bc_mp,
502
- cur->bc_private.a.agno, error, _RET_IP_);
533
+ cur->bc_ag.agno, error, _RET_IP_);
503534 return error;
504535 }
505536
....@@ -517,7 +548,7 @@
517548 int found_rec;
518549
519550 trace_xfs_refcount_merge_right_extent(cur->bc_mp,
520
- cur->bc_private.a.agno, cright, right);
551
+ cur->bc_ag.agno, cright, right);
521552
522553 /*
523554 * If the extent ending at agbno+aglen (cright) wasn't synthesized,
....@@ -528,14 +559,18 @@
528559 &found_rec);
529560 if (error)
530561 goto out_error;
531
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1,
532
- out_error);
562
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
563
+ error = -EFSCORRUPTED;
564
+ goto out_error;
565
+ }
533566
534567 error = xfs_refcount_delete(cur, &found_rec);
535568 if (error)
536569 goto out_error;
537
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1,
538
- out_error);
570
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
571
+ error = -EFSCORRUPTED;
572
+ goto out_error;
573
+ }
539574 }
540575
541576 /* Enlarge the right extent. */
....@@ -543,7 +578,10 @@
543578 &found_rec);
544579 if (error)
545580 goto out_error;
546
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
581
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
582
+ error = -EFSCORRUPTED;
583
+ goto out_error;
584
+ }
547585
548586 right->rc_startblock -= cright->rc_blockcount;
549587 right->rc_blockcount += cright->rc_blockcount;
....@@ -556,7 +594,7 @@
556594
557595 out_error:
558596 trace_xfs_refcount_merge_right_extent_error(cur->bc_mp,
559
- cur->bc_private.a.agno, error, _RET_IP_);
597
+ cur->bc_ag.agno, error, _RET_IP_);
560598 return error;
561599 }
562600
....@@ -589,7 +627,10 @@
589627 error = xfs_refcount_get_rec(cur, &tmp, &found_rec);
590628 if (error)
591629 goto out_error;
592
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
630
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
631
+ error = -EFSCORRUPTED;
632
+ goto out_error;
633
+ }
593634
594635 if (xfs_refc_next(&tmp) != agbno)
595636 return 0;
....@@ -607,8 +648,10 @@
607648 error = xfs_refcount_get_rec(cur, &tmp, &found_rec);
608649 if (error)
609650 goto out_error;
610
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1,
611
- out_error);
651
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
652
+ error = -EFSCORRUPTED;
653
+ goto out_error;
654
+ }
612655
613656 /* if tmp starts at the end of our range, just use that */
614657 if (tmp.rc_startblock == agbno)
....@@ -636,13 +679,13 @@
636679 cleft->rc_blockcount = aglen;
637680 cleft->rc_refcount = 1;
638681 }
639
- trace_xfs_refcount_find_left_extent(cur->bc_mp, cur->bc_private.a.agno,
682
+ trace_xfs_refcount_find_left_extent(cur->bc_mp, cur->bc_ag.agno,
640683 left, cleft, agbno);
641684 return error;
642685
643686 out_error:
644687 trace_xfs_refcount_find_left_extent_error(cur->bc_mp,
645
- cur->bc_private.a.agno, error, _RET_IP_);
688
+ cur->bc_ag.agno, error, _RET_IP_);
646689 return error;
647690 }
648691
....@@ -673,7 +716,10 @@
673716 error = xfs_refcount_get_rec(cur, &tmp, &found_rec);
674717 if (error)
675718 goto out_error;
676
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1, out_error);
719
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
720
+ error = -EFSCORRUPTED;
721
+ goto out_error;
722
+ }
677723
678724 if (tmp.rc_startblock != agbno + aglen)
679725 return 0;
....@@ -691,8 +737,10 @@
691737 error = xfs_refcount_get_rec(cur, &tmp, &found_rec);
692738 if (error)
693739 goto out_error;
694
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, found_rec == 1,
695
- out_error);
740
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
741
+ error = -EFSCORRUPTED;
742
+ goto out_error;
743
+ }
696744
697745 /* if tmp ends at the end of our range, just use that */
698746 if (xfs_refc_next(&tmp) == agbno + aglen)
....@@ -720,13 +768,13 @@
720768 cright->rc_blockcount = aglen;
721769 cright->rc_refcount = 1;
722770 }
723
- trace_xfs_refcount_find_right_extent(cur->bc_mp, cur->bc_private.a.agno,
771
+ trace_xfs_refcount_find_right_extent(cur->bc_mp, cur->bc_ag.agno,
724772 cright, right, agbno + aglen);
725773 return error;
726774
727775 out_error:
728776 trace_xfs_refcount_find_right_extent_error(cur->bc_mp,
729
- cur->bc_private.a.agno, error, _RET_IP_);
777
+ cur->bc_ag.agno, error, _RET_IP_);
730778 return error;
731779 }
732780
....@@ -835,7 +883,7 @@
835883 {
836884 unsigned long overhead;
837885
838
- overhead = cur->bc_private.a.priv.refc.shape_changes *
886
+ overhead = cur->bc_ag.refc.shape_changes *
839887 xfs_allocfree_log_count(cur->bc_mp, 1);
840888 overhead *= cur->bc_mp->m_sb.sb_blocksize;
841889
....@@ -843,17 +891,17 @@
843891 * Only allow 2 refcount extent updates per transaction if the
844892 * refcount continue update "error" has been injected.
845893 */
846
- if (cur->bc_private.a.priv.refc.nr_ops > 2 &&
894
+ if (cur->bc_ag.refc.nr_ops > 2 &&
847895 XFS_TEST_ERROR(false, cur->bc_mp,
848896 XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE))
849897 return false;
850898
851
- if (cur->bc_private.a.priv.refc.nr_ops == 0)
899
+ if (cur->bc_ag.refc.nr_ops == 0)
852900 return true;
853901 else if (overhead > cur->bc_tp->t_log_res)
854902 return false;
855903 return cur->bc_tp->t_log_res - overhead >
856
- cur->bc_private.a.priv.refc.nr_ops * XFS_REFCOUNT_ITEM_OVERHEAD;
904
+ cur->bc_ag.refc.nr_ops * XFS_REFCOUNT_ITEM_OVERHEAD;
857905 }
858906
859907 /*
....@@ -904,7 +952,7 @@
904952 ext.rc_startblock - *agbno);
905953 tmp.rc_refcount = 1 + adj;
906954 trace_xfs_refcount_modify_extent(cur->bc_mp,
907
- cur->bc_private.a.agno, &tmp);
955
+ cur->bc_ag.agno, &tmp);
908956
909957 /*
910958 * Either cover the hole (increment) or
....@@ -915,12 +963,15 @@
915963 &found_tmp);
916964 if (error)
917965 goto out_error;
918
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp,
919
- found_tmp == 1, out_error);
920
- cur->bc_private.a.priv.refc.nr_ops++;
966
+ if (XFS_IS_CORRUPT(cur->bc_mp,
967
+ found_tmp != 1)) {
968
+ error = -EFSCORRUPTED;
969
+ goto out_error;
970
+ }
971
+ cur->bc_ag.refc.nr_ops++;
921972 } else {
922973 fsbno = XFS_AGB_TO_FSB(cur->bc_mp,
923
- cur->bc_private.a.agno,
974
+ cur->bc_ag.agno,
924975 tmp.rc_startblock);
925976 xfs_bmap_add_free(cur->bc_tp, fsbno,
926977 tmp.rc_blockcount, oinfo);
....@@ -947,23 +998,25 @@
947998 goto skip;
948999 ext.rc_refcount += adj;
9491000 trace_xfs_refcount_modify_extent(cur->bc_mp,
950
- cur->bc_private.a.agno, &ext);
1001
+ cur->bc_ag.agno, &ext);
9511002 if (ext.rc_refcount > 1) {
9521003 error = xfs_refcount_update(cur, &ext);
9531004 if (error)
9541005 goto out_error;
955
- cur->bc_private.a.priv.refc.nr_ops++;
1006
+ cur->bc_ag.refc.nr_ops++;
9561007 } else if (ext.rc_refcount == 1) {
9571008 error = xfs_refcount_delete(cur, &found_rec);
9581009 if (error)
9591010 goto out_error;
960
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp,
961
- found_rec == 1, out_error);
962
- cur->bc_private.a.priv.refc.nr_ops++;
1011
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
1012
+ error = -EFSCORRUPTED;
1013
+ goto out_error;
1014
+ }
1015
+ cur->bc_ag.refc.nr_ops++;
9631016 goto advloop;
9641017 } else {
9651018 fsbno = XFS_AGB_TO_FSB(cur->bc_mp,
966
- cur->bc_private.a.agno,
1019
+ cur->bc_ag.agno,
9671020 ext.rc_startblock);
9681021 xfs_bmap_add_free(cur->bc_tp, fsbno, ext.rc_blockcount,
9691022 oinfo);
....@@ -982,7 +1035,7 @@
9821035 return error;
9831036 out_error:
9841037 trace_xfs_refcount_modify_extent_error(cur->bc_mp,
985
- cur->bc_private.a.agno, error, _RET_IP_);
1038
+ cur->bc_ag.agno, error, _RET_IP_);
9861039 return error;
9871040 }
9881041
....@@ -1004,10 +1057,10 @@
10041057 *new_agbno = agbno;
10051058 *new_aglen = aglen;
10061059 if (adj == XFS_REFCOUNT_ADJUST_INCREASE)
1007
- trace_xfs_refcount_increase(cur->bc_mp, cur->bc_private.a.agno,
1060
+ trace_xfs_refcount_increase(cur->bc_mp, cur->bc_ag.agno,
10081061 agbno, aglen);
10091062 else
1010
- trace_xfs_refcount_decrease(cur->bc_mp, cur->bc_private.a.agno,
1063
+ trace_xfs_refcount_decrease(cur->bc_mp, cur->bc_ag.agno,
10111064 agbno, aglen);
10121065
10131066 /*
....@@ -1035,7 +1088,7 @@
10351088 if (shape_changed)
10361089 shape_changes++;
10371090 if (shape_changes)
1038
- cur->bc_private.a.priv.refc.shape_changes++;
1091
+ cur->bc_ag.refc.shape_changes++;
10391092
10401093 /* Now that we've taken care of the ends, adjust the middle extents */
10411094 error = xfs_refcount_adjust_extents(cur, new_agbno, new_aglen,
....@@ -1046,7 +1099,7 @@
10461099 return 0;
10471100
10481101 out_error:
1049
- trace_xfs_refcount_adjust_error(cur->bc_mp, cur->bc_private.a.agno,
1102
+ trace_xfs_refcount_adjust_error(cur->bc_mp, cur->bc_ag.agno,
10501103 error, _RET_IP_);
10511104 return error;
10521105 }
....@@ -1062,7 +1115,7 @@
10621115
10631116 if (rcur == NULL)
10641117 return;
1065
- agbp = rcur->bc_private.a.agbp;
1118
+ agbp = rcur->bc_ag.agbp;
10661119 xfs_btree_del_cursor(rcur, error);
10671120 if (error)
10681121 xfs_trans_brelse(tp, agbp);
....@@ -1112,9 +1165,9 @@
11121165 * the startblock, get one now.
11131166 */
11141167 rcur = *pcur;
1115
- if (rcur != NULL && rcur->bc_private.a.agno != agno) {
1116
- nr_ops = rcur->bc_private.a.priv.refc.nr_ops;
1117
- shape_changes = rcur->bc_private.a.priv.refc.shape_changes;
1168
+ if (rcur != NULL && rcur->bc_ag.agno != agno) {
1169
+ nr_ops = rcur->bc_ag.refc.nr_ops;
1170
+ shape_changes = rcur->bc_ag.refc.shape_changes;
11181171 xfs_refcount_finish_one_cleanup(tp, rcur, 0);
11191172 rcur = NULL;
11201173 *pcur = NULL;
....@@ -1124,16 +1177,14 @@
11241177 XFS_ALLOC_FLAG_FREEING, &agbp);
11251178 if (error)
11261179 return error;
1127
- if (!agbp)
1128
- return -EFSCORRUPTED;
11291180
11301181 rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno);
11311182 if (!rcur) {
11321183 error = -ENOMEM;
11331184 goto out_cur;
11341185 }
1135
- rcur->bc_private.a.priv.refc.nr_ops = nr_ops;
1136
- rcur->bc_private.a.priv.refc.shape_changes = shape_changes;
1186
+ rcur->bc_ag.refc.nr_ops = nr_ops;
1187
+ rcur->bc_ag.refc.shape_changes = shape_changes;
11371188 }
11381189 *pcur = rcur;
11391190
....@@ -1176,7 +1227,7 @@
11761227 /*
11771228 * Record a refcount intent for later processing.
11781229 */
1179
-static int
1230
+static void
11801231 __xfs_refcount_add(
11811232 struct xfs_trans *tp,
11821233 enum xfs_refcount_intent_type type,
....@@ -1191,44 +1242,43 @@
11911242 blockcount);
11921243
11931244 ri = kmem_alloc(sizeof(struct xfs_refcount_intent),
1194
- KM_SLEEP | KM_NOFS);
1245
+ KM_NOFS);
11951246 INIT_LIST_HEAD(&ri->ri_list);
11961247 ri->ri_type = type;
11971248 ri->ri_startblock = startblock;
11981249 ri->ri_blockcount = blockcount;
11991250
12001251 xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_REFCOUNT, &ri->ri_list);
1201
- return 0;
12021252 }
12031253
12041254 /*
12051255 * Increase the reference count of the blocks backing a file's extent.
12061256 */
1207
-int
1257
+void
12081258 xfs_refcount_increase_extent(
12091259 struct xfs_trans *tp,
12101260 struct xfs_bmbt_irec *PREV)
12111261 {
12121262 if (!xfs_sb_version_hasreflink(&tp->t_mountp->m_sb))
1213
- return 0;
1263
+ return;
12141264
1215
- return __xfs_refcount_add(tp, XFS_REFCOUNT_INCREASE,
1216
- PREV->br_startblock, PREV->br_blockcount);
1265
+ __xfs_refcount_add(tp, XFS_REFCOUNT_INCREASE, PREV->br_startblock,
1266
+ PREV->br_blockcount);
12171267 }
12181268
12191269 /*
12201270 * Decrease the reference count of the blocks backing a file's extent.
12211271 */
1222
-int
1272
+void
12231273 xfs_refcount_decrease_extent(
12241274 struct xfs_trans *tp,
12251275 struct xfs_bmbt_irec *PREV)
12261276 {
12271277 if (!xfs_sb_version_hasreflink(&tp->t_mountp->m_sb))
1228
- return 0;
1278
+ return;
12291279
1230
- return __xfs_refcount_add(tp, XFS_REFCOUNT_DECREASE,
1231
- PREV->br_startblock, PREV->br_blockcount);
1280
+ __xfs_refcount_add(tp, XFS_REFCOUNT_DECREASE, PREV->br_startblock,
1281
+ PREV->br_blockcount);
12321282 }
12331283
12341284 /*
....@@ -1253,7 +1303,7 @@
12531303 int have;
12541304 int error;
12551305
1256
- trace_xfs_refcount_find_shared(cur->bc_mp, cur->bc_private.a.agno,
1306
+ trace_xfs_refcount_find_shared(cur->bc_mp, cur->bc_ag.agno,
12571307 agbno, aglen);
12581308
12591309 /* By default, skip the whole range */
....@@ -1275,7 +1325,10 @@
12751325 error = xfs_refcount_get_rec(cur, &tmp, &i);
12761326 if (error)
12771327 goto out_error;
1278
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, out_error);
1328
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
1329
+ error = -EFSCORRUPTED;
1330
+ goto out_error;
1331
+ }
12791332
12801333 /* If the extent ends before the start, look at the next one */
12811334 if (tmp.rc_startblock + tmp.rc_blockcount <= agbno) {
....@@ -1287,7 +1340,10 @@
12871340 error = xfs_refcount_get_rec(cur, &tmp, &i);
12881341 if (error)
12891342 goto out_error;
1290
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, out_error);
1343
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
1344
+ error = -EFSCORRUPTED;
1345
+ goto out_error;
1346
+ }
12911347 }
12921348
12931349 /* If the extent starts after the range we want, bail out */
....@@ -1315,7 +1371,10 @@
13151371 error = xfs_refcount_get_rec(cur, &tmp, &i);
13161372 if (error)
13171373 goto out_error;
1318
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp, i == 1, out_error);
1374
+ if (XFS_IS_CORRUPT(cur->bc_mp, i != 1)) {
1375
+ error = -EFSCORRUPTED;
1376
+ goto out_error;
1377
+ }
13191378 if (tmp.rc_startblock >= agbno + aglen ||
13201379 tmp.rc_startblock != *fbno + *flen)
13211380 break;
....@@ -1324,12 +1383,12 @@
13241383
13251384 done:
13261385 trace_xfs_refcount_find_shared_result(cur->bc_mp,
1327
- cur->bc_private.a.agno, *fbno, *flen);
1386
+ cur->bc_ag.agno, *fbno, *flen);
13281387
13291388 out_error:
13301389 if (error)
13311390 trace_xfs_refcount_find_shared_error(cur->bc_mp,
1332
- cur->bc_private.a.agno, error, _RET_IP_);
1391
+ cur->bc_ag.agno, error, _RET_IP_);
13331392 return error;
13341393 }
13351394
....@@ -1416,39 +1475,52 @@
14161475 switch (adj) {
14171476 case XFS_REFCOUNT_ADJUST_COW_ALLOC:
14181477 /* Adding a CoW reservation, there should be nothing here. */
1419
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp,
1420
- ext.rc_startblock >= agbno + aglen, out_error);
1478
+ if (XFS_IS_CORRUPT(cur->bc_mp,
1479
+ agbno + aglen > ext.rc_startblock)) {
1480
+ error = -EFSCORRUPTED;
1481
+ goto out_error;
1482
+ }
14211483
14221484 tmp.rc_startblock = agbno;
14231485 tmp.rc_blockcount = aglen;
14241486 tmp.rc_refcount = 1;
14251487 trace_xfs_refcount_modify_extent(cur->bc_mp,
1426
- cur->bc_private.a.agno, &tmp);
1488
+ cur->bc_ag.agno, &tmp);
14271489
14281490 error = xfs_refcount_insert(cur, &tmp,
14291491 &found_tmp);
14301492 if (error)
14311493 goto out_error;
1432
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp,
1433
- found_tmp == 1, out_error);
1494
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_tmp != 1)) {
1495
+ error = -EFSCORRUPTED;
1496
+ goto out_error;
1497
+ }
14341498 break;
14351499 case XFS_REFCOUNT_ADJUST_COW_FREE:
14361500 /* Removing a CoW reservation, there should be one extent. */
1437
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp,
1438
- ext.rc_startblock == agbno, out_error);
1439
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp,
1440
- ext.rc_blockcount == aglen, out_error);
1441
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp,
1442
- ext.rc_refcount == 1, out_error);
1501
+ if (XFS_IS_CORRUPT(cur->bc_mp, ext.rc_startblock != agbno)) {
1502
+ error = -EFSCORRUPTED;
1503
+ goto out_error;
1504
+ }
1505
+ if (XFS_IS_CORRUPT(cur->bc_mp, ext.rc_blockcount != aglen)) {
1506
+ error = -EFSCORRUPTED;
1507
+ goto out_error;
1508
+ }
1509
+ if (XFS_IS_CORRUPT(cur->bc_mp, ext.rc_refcount != 1)) {
1510
+ error = -EFSCORRUPTED;
1511
+ goto out_error;
1512
+ }
14431513
14441514 ext.rc_refcount = 0;
14451515 trace_xfs_refcount_modify_extent(cur->bc_mp,
1446
- cur->bc_private.a.agno, &ext);
1516
+ cur->bc_ag.agno, &ext);
14471517 error = xfs_refcount_delete(cur, &found_rec);
14481518 if (error)
14491519 goto out_error;
1450
- XFS_WANT_CORRUPTED_GOTO(cur->bc_mp,
1451
- found_rec == 1, out_error);
1520
+ if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
1521
+ error = -EFSCORRUPTED;
1522
+ goto out_error;
1523
+ }
14521524 break;
14531525 default:
14541526 ASSERT(0);
....@@ -1457,7 +1529,7 @@
14571529 return error;
14581530 out_error:
14591531 trace_xfs_refcount_modify_extent_error(cur->bc_mp,
1460
- cur->bc_private.a.agno, error, _RET_IP_);
1532
+ cur->bc_ag.agno, error, _RET_IP_);
14611533 return error;
14621534 }
14631535
....@@ -1503,7 +1575,7 @@
15031575 return 0;
15041576
15051577 out_error:
1506
- trace_xfs_refcount_adjust_cow_error(cur->bc_mp, cur->bc_private.a.agno,
1578
+ trace_xfs_refcount_adjust_cow_error(cur->bc_mp, cur->bc_ag.agno,
15071579 error, _RET_IP_);
15081580 return error;
15091581 }
....@@ -1517,7 +1589,7 @@
15171589 xfs_agblock_t agbno,
15181590 xfs_extlen_t aglen)
15191591 {
1520
- trace_xfs_refcount_cow_increase(rcur->bc_mp, rcur->bc_private.a.agno,
1592
+ trace_xfs_refcount_cow_increase(rcur->bc_mp, rcur->bc_ag.agno,
15211593 agbno, aglen);
15221594
15231595 /* Add refcount btree reservation */
....@@ -1534,7 +1606,7 @@
15341606 xfs_agblock_t agbno,
15351607 xfs_extlen_t aglen)
15361608 {
1537
- trace_xfs_refcount_cow_decrease(rcur->bc_mp, rcur->bc_private.a.agno,
1609
+ trace_xfs_refcount_cow_decrease(rcur->bc_mp, rcur->bc_ag.agno,
15381610 agbno, aglen);
15391611
15401612 /* Remove refcount btree reservation */
....@@ -1543,47 +1615,40 @@
15431615 }
15441616
15451617 /* Record a CoW staging extent in the refcount btree. */
1546
-int
1618
+void
15471619 xfs_refcount_alloc_cow_extent(
15481620 struct xfs_trans *tp,
15491621 xfs_fsblock_t fsb,
15501622 xfs_extlen_t len)
15511623 {
15521624 struct xfs_mount *mp = tp->t_mountp;
1553
- int error;
15541625
15551626 if (!xfs_sb_version_hasreflink(&mp->m_sb))
1556
- return 0;
1627
+ return;
15571628
1558
- error = __xfs_refcount_add(tp, XFS_REFCOUNT_ALLOC_COW, fsb, len);
1559
- if (error)
1560
- return error;
1629
+ __xfs_refcount_add(tp, XFS_REFCOUNT_ALLOC_COW, fsb, len);
15611630
15621631 /* Add rmap entry */
1563
- return xfs_rmap_alloc_extent(tp, XFS_FSB_TO_AGNO(mp, fsb),
1632
+ xfs_rmap_alloc_extent(tp, XFS_FSB_TO_AGNO(mp, fsb),
15641633 XFS_FSB_TO_AGBNO(mp, fsb), len, XFS_RMAP_OWN_COW);
15651634 }
15661635
15671636 /* Forget a CoW staging event in the refcount btree. */
1568
-int
1637
+void
15691638 xfs_refcount_free_cow_extent(
15701639 struct xfs_trans *tp,
15711640 xfs_fsblock_t fsb,
15721641 xfs_extlen_t len)
15731642 {
15741643 struct xfs_mount *mp = tp->t_mountp;
1575
- int error;
15761644
15771645 if (!xfs_sb_version_hasreflink(&mp->m_sb))
1578
- return 0;
1646
+ return;
15791647
15801648 /* Remove rmap entry */
1581
- error = xfs_rmap_free_extent(tp, XFS_FSB_TO_AGNO(mp, fsb),
1649
+ xfs_rmap_free_extent(tp, XFS_FSB_TO_AGNO(mp, fsb),
15821650 XFS_FSB_TO_AGBNO(mp, fsb), len, XFS_RMAP_OWN_COW);
1583
- if (error)
1584
- return error;
1585
-
1586
- return __xfs_refcount_add(tp, XFS_REFCOUNT_FREE_COW, fsb, len);
1651
+ __xfs_refcount_add(tp, XFS_REFCOUNT_FREE_COW, fsb, len);
15871652 }
15881653
15891654 struct xfs_refcount_recovery {
....@@ -1594,17 +1659,18 @@
15941659 /* Stuff an extent on the recovery list. */
15951660 STATIC int
15961661 xfs_refcount_recover_extent(
1597
- struct xfs_btree_cur *cur,
1662
+ struct xfs_btree_cur *cur,
15981663 union xfs_btree_rec *rec,
15991664 void *priv)
16001665 {
16011666 struct list_head *debris = priv;
16021667 struct xfs_refcount_recovery *rr;
16031668
1604
- if (be32_to_cpu(rec->refc.rc_refcount) != 1)
1669
+ if (XFS_IS_CORRUPT(cur->bc_mp,
1670
+ be32_to_cpu(rec->refc.rc_refcount) != 1))
16051671 return -EFSCORRUPTED;
16061672
1607
- rr = kmem_alloc(sizeof(struct xfs_refcount_recovery), KM_SLEEP);
1673
+ rr = kmem_alloc(sizeof(struct xfs_refcount_recovery), 0);
16081674 xfs_refcount_btrec_to_irec(rec, &rr->rr_rrec);
16091675 list_add_tail(&rr->rr_list, debris);
16101676
....@@ -1650,10 +1716,6 @@
16501716 error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
16511717 if (error)
16521718 goto out_trans;
1653
- if (!agbp) {
1654
- error = -ENOMEM;
1655
- goto out_trans;
1656
- }
16571719 cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno);
16581720
16591721 /* Find all the leftover CoW staging extents. */
....@@ -1681,10 +1743,8 @@
16811743 /* Free the orphan record */
16821744 agbno = rr->rr_rrec.rc_startblock - XFS_REFC_COW_START;
16831745 fsb = XFS_AGB_TO_FSB(mp, agno, agbno);
1684
- error = xfs_refcount_free_cow_extent(tp, fsb,
1746
+ xfs_refcount_free_cow_extent(tp, fsb,
16851747 rr->rr_rrec.rc_blockcount);
1686
- if (error)
1687
- goto out_trans;
16881748
16891749 /* Free the block. */
16901750 xfs_bmap_add_free(tp, fsb, rr->rr_rrec.rc_blockcount, NULL);