hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/xfs/libxfs/xfs_rmap.c
....@@ -10,24 +10,17 @@
1010 #include "xfs_log_format.h"
1111 #include "xfs_trans_resv.h"
1212 #include "xfs_bit.h"
13
-#include "xfs_sb.h"
1413 #include "xfs_mount.h"
1514 #include "xfs_defer.h"
16
-#include "xfs_da_format.h"
17
-#include "xfs_da_btree.h"
1815 #include "xfs_btree.h"
1916 #include "xfs_trans.h"
2017 #include "xfs_alloc.h"
2118 #include "xfs_rmap.h"
2219 #include "xfs_rmap_btree.h"
23
-#include "xfs_trans_space.h"
2420 #include "xfs_trace.h"
2521 #include "xfs_errortag.h"
2622 #include "xfs_error.h"
27
-#include "xfs_extent_busy.h"
28
-#include "xfs_bmap.h"
2923 #include "xfs_inode.h"
30
-#include "xfs_ialloc.h"
3124
3225 /*
3326 * Lookup the first record less than or equal to [bno, len, owner, offset]
....@@ -86,7 +79,7 @@
8679 union xfs_btree_rec rec;
8780 int error;
8881
89
- trace_xfs_rmap_update(cur->bc_mp, cur->bc_private.a.agno,
82
+ trace_xfs_rmap_update(cur->bc_mp, cur->bc_ag.agno,
9083 irec->rm_startblock, irec->rm_blockcount,
9184 irec->rm_owner, irec->rm_offset, irec->rm_flags);
9285
....@@ -98,7 +91,7 @@
9891 error = xfs_btree_update(cur, &rec);
9992 if (error)
10093 trace_xfs_rmap_update_error(cur->bc_mp,
101
- cur->bc_private.a.agno, error, _RET_IP_);
94
+ cur->bc_ag.agno, error, _RET_IP_);
10295 return error;
10396 }
10497
....@@ -114,13 +107,16 @@
114107 int i;
115108 int error;
116109
117
- trace_xfs_rmap_insert(rcur->bc_mp, rcur->bc_private.a.agno, agbno,
110
+ trace_xfs_rmap_insert(rcur->bc_mp, rcur->bc_ag.agno, agbno,
118111 len, owner, offset, flags);
119112
120113 error = xfs_rmap_lookup_eq(rcur, agbno, len, owner, offset, flags, &i);
121114 if (error)
122115 goto done;
123
- XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 0, done);
116
+ if (XFS_IS_CORRUPT(rcur->bc_mp, i != 0)) {
117
+ error = -EFSCORRUPTED;
118
+ goto done;
119
+ }
124120
125121 rcur->bc_rec.r.rm_startblock = agbno;
126122 rcur->bc_rec.r.rm_blockcount = len;
....@@ -130,11 +126,14 @@
130126 error = xfs_btree_insert(rcur, &i);
131127 if (error)
132128 goto done;
133
- XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 1, done);
129
+ if (XFS_IS_CORRUPT(rcur->bc_mp, i != 1)) {
130
+ error = -EFSCORRUPTED;
131
+ goto done;
132
+ }
134133 done:
135134 if (error)
136135 trace_xfs_rmap_insert_error(rcur->bc_mp,
137
- rcur->bc_private.a.agno, error, _RET_IP_);
136
+ rcur->bc_ag.agno, error, _RET_IP_);
138137 return error;
139138 }
140139
....@@ -150,22 +149,28 @@
150149 int i;
151150 int error;
152151
153
- trace_xfs_rmap_delete(rcur->bc_mp, rcur->bc_private.a.agno, agbno,
152
+ trace_xfs_rmap_delete(rcur->bc_mp, rcur->bc_ag.agno, agbno,
154153 len, owner, offset, flags);
155154
156155 error = xfs_rmap_lookup_eq(rcur, agbno, len, owner, offset, flags, &i);
157156 if (error)
158157 goto done;
159
- XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 1, done);
158
+ if (XFS_IS_CORRUPT(rcur->bc_mp, i != 1)) {
159
+ error = -EFSCORRUPTED;
160
+ goto done;
161
+ }
160162
161163 error = xfs_btree_delete(rcur, &i);
162164 if (error)
163165 goto done;
164
- XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 1, done);
166
+ if (XFS_IS_CORRUPT(rcur->bc_mp, i != 1)) {
167
+ error = -EFSCORRUPTED;
168
+ goto done;
169
+ }
165170 done:
166171 if (error)
167172 trace_xfs_rmap_delete_error(rcur->bc_mp,
168
- rcur->bc_private.a.agno, error, _RET_IP_);
173
+ rcur->bc_ag.agno, error, _RET_IP_);
169174 return error;
170175 }
171176
....@@ -175,7 +180,6 @@
175180 union xfs_btree_rec *rec,
176181 struct xfs_rmap_irec *irec)
177182 {
178
- irec->rm_flags = 0;
179183 irec->rm_startblock = be32_to_cpu(rec->rmap.rm_startblock);
180184 irec->rm_blockcount = be32_to_cpu(rec->rmap.rm_blockcount);
181185 irec->rm_owner = be64_to_cpu(rec->rmap.rm_owner);
....@@ -193,7 +197,7 @@
193197 int *stat)
194198 {
195199 struct xfs_mount *mp = cur->bc_mp;
196
- xfs_agnumber_t agno = cur->bc_private.a.agno;
200
+ xfs_agnumber_t agno = cur->bc_ag.agno;
197201 union xfs_btree_rec *rec;
198202 int error;
199203
....@@ -256,20 +260,20 @@
256260 struct xfs_find_left_neighbor_info *info = priv;
257261
258262 trace_xfs_rmap_find_left_neighbor_candidate(cur->bc_mp,
259
- cur->bc_private.a.agno, rec->rm_startblock,
263
+ cur->bc_ag.agno, rec->rm_startblock,
260264 rec->rm_blockcount, rec->rm_owner, rec->rm_offset,
261265 rec->rm_flags);
262266
263267 if (rec->rm_owner != info->high.rm_owner)
264
- return XFS_BTREE_QUERY_RANGE_CONTINUE;
268
+ return 0;
265269 if (!XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) &&
266270 !(rec->rm_flags & XFS_RMAP_BMBT_BLOCK) &&
267271 rec->rm_offset + rec->rm_blockcount - 1 != info->high.rm_offset)
268
- return XFS_BTREE_QUERY_RANGE_CONTINUE;
272
+ return 0;
269273
270274 *info->irec = *rec;
271275 *info->stat = 1;
272
- return XFS_BTREE_QUERY_RANGE_ABORT;
276
+ return -ECANCELED;
273277 }
274278
275279 /*
....@@ -308,15 +312,15 @@
308312 info.stat = stat;
309313
310314 trace_xfs_rmap_find_left_neighbor_query(cur->bc_mp,
311
- cur->bc_private.a.agno, bno, 0, owner, offset, flags);
315
+ cur->bc_ag.agno, bno, 0, owner, offset, flags);
312316
313317 error = xfs_rmap_query_range(cur, &info.high, &info.high,
314318 xfs_rmap_find_left_neighbor_helper, &info);
315
- if (error == XFS_BTREE_QUERY_RANGE_ABORT)
319
+ if (error == -ECANCELED)
316320 error = 0;
317321 if (*stat)
318322 trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp,
319
- cur->bc_private.a.agno, irec->rm_startblock,
323
+ cur->bc_ag.agno, irec->rm_startblock,
320324 irec->rm_blockcount, irec->rm_owner,
321325 irec->rm_offset, irec->rm_flags);
322326 return error;
....@@ -332,21 +336,21 @@
332336 struct xfs_find_left_neighbor_info *info = priv;
333337
334338 trace_xfs_rmap_lookup_le_range_candidate(cur->bc_mp,
335
- cur->bc_private.a.agno, rec->rm_startblock,
339
+ cur->bc_ag.agno, rec->rm_startblock,
336340 rec->rm_blockcount, rec->rm_owner, rec->rm_offset,
337341 rec->rm_flags);
338342
339343 if (rec->rm_owner != info->high.rm_owner)
340
- return XFS_BTREE_QUERY_RANGE_CONTINUE;
344
+ return 0;
341345 if (!XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) &&
342346 !(rec->rm_flags & XFS_RMAP_BMBT_BLOCK) &&
343347 (rec->rm_offset > info->high.rm_offset ||
344348 rec->rm_offset + rec->rm_blockcount <= info->high.rm_offset))
345
- return XFS_BTREE_QUERY_RANGE_CONTINUE;
349
+ return 0;
346350
347351 *info->irec = *rec;
348352 *info->stat = 1;
349
- return XFS_BTREE_QUERY_RANGE_ABORT;
353
+ return -ECANCELED;
350354 }
351355
352356 /*
....@@ -381,14 +385,14 @@
381385 info.stat = stat;
382386
383387 trace_xfs_rmap_lookup_le_range(cur->bc_mp,
384
- cur->bc_private.a.agno, bno, 0, owner, offset, flags);
388
+ cur->bc_ag.agno, bno, 0, owner, offset, flags);
385389 error = xfs_rmap_query_range(cur, &info.high, &info.high,
386390 xfs_rmap_lookup_le_range_helper, &info);
387
- if (error == XFS_BTREE_QUERY_RANGE_ABORT)
391
+ if (error == -ECANCELED)
388392 error = 0;
389393 if (*stat)
390394 trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
391
- cur->bc_private.a.agno, irec->rm_startblock,
395
+ cur->bc_ag.agno, irec->rm_startblock,
392396 irec->rm_blockcount, irec->rm_owner,
393397 irec->rm_offset, irec->rm_flags);
394398 return error;
....@@ -414,24 +418,39 @@
414418 return 0;
415419
416420 /* Make sure the unwritten flag matches. */
417
- XFS_WANT_CORRUPTED_GOTO(mp, (flags & XFS_RMAP_UNWRITTEN) ==
418
- (rec->rm_flags & XFS_RMAP_UNWRITTEN), out);
421
+ if (XFS_IS_CORRUPT(mp,
422
+ (flags & XFS_RMAP_UNWRITTEN) !=
423
+ (rec->rm_flags & XFS_RMAP_UNWRITTEN))) {
424
+ error = -EFSCORRUPTED;
425
+ goto out;
426
+ }
419427
420428 /* Make sure the owner matches what we expect to find in the tree. */
421
- XFS_WANT_CORRUPTED_GOTO(mp, owner == rec->rm_owner, out);
429
+ if (XFS_IS_CORRUPT(mp, owner != rec->rm_owner)) {
430
+ error = -EFSCORRUPTED;
431
+ goto out;
432
+ }
422433
423434 /* Check the offset, if necessary. */
424435 if (XFS_RMAP_NON_INODE_OWNER(owner))
425436 goto out;
426437
427438 if (flags & XFS_RMAP_BMBT_BLOCK) {
428
- XFS_WANT_CORRUPTED_GOTO(mp, rec->rm_flags & XFS_RMAP_BMBT_BLOCK,
429
- out);
439
+ if (XFS_IS_CORRUPT(mp,
440
+ !(rec->rm_flags & XFS_RMAP_BMBT_BLOCK))) {
441
+ error = -EFSCORRUPTED;
442
+ goto out;
443
+ }
430444 } else {
431
- XFS_WANT_CORRUPTED_GOTO(mp, rec->rm_offset <= offset, out);
432
- XFS_WANT_CORRUPTED_GOTO(mp,
433
- ltoff + rec->rm_blockcount >= offset + len,
434
- out);
445
+ if (XFS_IS_CORRUPT(mp, rec->rm_offset > offset)) {
446
+ error = -EFSCORRUPTED;
447
+ goto out;
448
+ }
449
+ if (XFS_IS_CORRUPT(mp,
450
+ offset + len > ltoff + rec->rm_blockcount)) {
451
+ error = -EFSCORRUPTED;
452
+ goto out;
453
+ }
435454 }
436455
437456 out:
....@@ -458,28 +477,28 @@
458477 */
459478 STATIC int
460479 xfs_rmap_unmap(
461
- struct xfs_btree_cur *cur,
462
- xfs_agblock_t bno,
463
- xfs_extlen_t len,
464
- bool unwritten,
465
- struct xfs_owner_info *oinfo)
480
+ struct xfs_btree_cur *cur,
481
+ xfs_agblock_t bno,
482
+ xfs_extlen_t len,
483
+ bool unwritten,
484
+ const struct xfs_owner_info *oinfo)
466485 {
467
- struct xfs_mount *mp = cur->bc_mp;
468
- struct xfs_rmap_irec ltrec;
469
- uint64_t ltoff;
470
- int error = 0;
471
- int i;
472
- uint64_t owner;
473
- uint64_t offset;
474
- unsigned int flags;
475
- bool ignore_off;
486
+ struct xfs_mount *mp = cur->bc_mp;
487
+ struct xfs_rmap_irec ltrec;
488
+ uint64_t ltoff;
489
+ int error = 0;
490
+ int i;
491
+ uint64_t owner;
492
+ uint64_t offset;
493
+ unsigned int flags;
494
+ bool ignore_off;
476495
477496 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
478497 ignore_off = XFS_RMAP_NON_INODE_OWNER(owner) ||
479498 (flags & XFS_RMAP_BMBT_BLOCK);
480499 if (unwritten)
481500 flags |= XFS_RMAP_UNWRITTEN;
482
- trace_xfs_rmap_unmap(mp, cur->bc_private.a.agno, bno, len,
501
+ trace_xfs_rmap_unmap(mp, cur->bc_ag.agno, bno, len,
483502 unwritten, oinfo);
484503
485504 /*
....@@ -490,14 +509,20 @@
490509 error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, flags, &i);
491510 if (error)
492511 goto out_error;
493
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
512
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
513
+ error = -EFSCORRUPTED;
514
+ goto out_error;
515
+ }
494516
495517 error = xfs_rmap_get_rec(cur, &ltrec, &i);
496518 if (error)
497519 goto out_error;
498
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
520
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
521
+ error = -EFSCORRUPTED;
522
+ goto out_error;
523
+ }
499524 trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
500
- cur->bc_private.a.agno, ltrec.rm_startblock,
525
+ cur->bc_ag.agno, ltrec.rm_startblock,
501526 ltrec.rm_blockcount, ltrec.rm_owner,
502527 ltrec.rm_offset, ltrec.rm_flags);
503528 ltoff = ltrec.rm_offset;
....@@ -510,8 +535,12 @@
510535 * be the case that the "left" extent goes all the way to EOFS.
511536 */
512537 if (owner == XFS_RMAP_OWN_NULL) {
513
- XFS_WANT_CORRUPTED_GOTO(mp, bno >= ltrec.rm_startblock +
514
- ltrec.rm_blockcount, out_error);
538
+ if (XFS_IS_CORRUPT(mp,
539
+ bno <
540
+ ltrec.rm_startblock + ltrec.rm_blockcount)) {
541
+ error = -EFSCORRUPTED;
542
+ goto out_error;
543
+ }
515544 goto out_done;
516545 }
517546
....@@ -534,15 +563,22 @@
534563 error = xfs_rmap_get_rec(cur, &rtrec, &i);
535564 if (error)
536565 goto out_error;
537
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
566
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
567
+ error = -EFSCORRUPTED;
568
+ goto out_error;
569
+ }
538570 if (rtrec.rm_startblock >= bno + len)
539571 goto out_done;
540572 }
541573
542574 /* Make sure the extent we found covers the entire freeing range. */
543
- XFS_WANT_CORRUPTED_GOTO(mp, ltrec.rm_startblock <= bno &&
544
- ltrec.rm_startblock + ltrec.rm_blockcount >=
545
- bno + len, out_error);
575
+ if (XFS_IS_CORRUPT(mp,
576
+ ltrec.rm_startblock > bno ||
577
+ ltrec.rm_startblock + ltrec.rm_blockcount <
578
+ bno + len)) {
579
+ error = -EFSCORRUPTED;
580
+ goto out_error;
581
+ }
546582
547583 /* Check owner information. */
548584 error = xfs_rmap_free_check_owner(mp, ltoff, &ltrec, len, owner,
....@@ -552,14 +588,17 @@
552588
553589 if (ltrec.rm_startblock == bno && ltrec.rm_blockcount == len) {
554590 /* exact match, simply remove the record from rmap tree */
555
- trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
591
+ trace_xfs_rmap_delete(mp, cur->bc_ag.agno,
556592 ltrec.rm_startblock, ltrec.rm_blockcount,
557593 ltrec.rm_owner, ltrec.rm_offset,
558594 ltrec.rm_flags);
559595 error = xfs_btree_delete(cur, &i);
560596 if (error)
561597 goto out_error;
562
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
598
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
599
+ error = -EFSCORRUPTED;
600
+ goto out_error;
601
+ }
563602 } else if (ltrec.rm_startblock == bno) {
564603 /*
565604 * overlap left hand side of extent: move the start, trim the
....@@ -627,7 +666,7 @@
627666 else
628667 cur->bc_rec.r.rm_offset = offset + len;
629668 cur->bc_rec.r.rm_flags = flags;
630
- trace_xfs_rmap_insert(mp, cur->bc_private.a.agno,
669
+ trace_xfs_rmap_insert(mp, cur->bc_ag.agno,
631670 cur->bc_rec.r.rm_startblock,
632671 cur->bc_rec.r.rm_blockcount,
633672 cur->bc_rec.r.rm_owner,
....@@ -639,11 +678,11 @@
639678 }
640679
641680 out_done:
642
- trace_xfs_rmap_unmap_done(mp, cur->bc_private.a.agno, bno, len,
681
+ trace_xfs_rmap_unmap_done(mp, cur->bc_ag.agno, bno, len,
643682 unwritten, oinfo);
644683 out_error:
645684 if (error)
646
- trace_xfs_rmap_unmap_error(mp, cur->bc_private.a.agno,
685
+ trace_xfs_rmap_unmap_error(mp, cur->bc_ag.agno,
647686 error, _RET_IP_);
648687 return error;
649688 }
....@@ -653,16 +692,16 @@
653692 */
654693 int
655694 xfs_rmap_free(
656
- struct xfs_trans *tp,
657
- struct xfs_buf *agbp,
658
- xfs_agnumber_t agno,
659
- xfs_agblock_t bno,
660
- xfs_extlen_t len,
661
- struct xfs_owner_info *oinfo)
695
+ struct xfs_trans *tp,
696
+ struct xfs_buf *agbp,
697
+ xfs_agnumber_t agno,
698
+ xfs_agblock_t bno,
699
+ xfs_extlen_t len,
700
+ const struct xfs_owner_info *oinfo)
662701 {
663
- struct xfs_mount *mp = tp->t_mountp;
664
- struct xfs_btree_cur *cur;
665
- int error;
702
+ struct xfs_mount *mp = tp->t_mountp;
703
+ struct xfs_btree_cur *cur;
704
+ int error;
666705
667706 if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
668707 return 0;
....@@ -710,23 +749,23 @@
710749 */
711750 STATIC int
712751 xfs_rmap_map(
713
- struct xfs_btree_cur *cur,
714
- xfs_agblock_t bno,
715
- xfs_extlen_t len,
716
- bool unwritten,
717
- struct xfs_owner_info *oinfo)
752
+ struct xfs_btree_cur *cur,
753
+ xfs_agblock_t bno,
754
+ xfs_extlen_t len,
755
+ bool unwritten,
756
+ const struct xfs_owner_info *oinfo)
718757 {
719
- struct xfs_mount *mp = cur->bc_mp;
720
- struct xfs_rmap_irec ltrec;
721
- struct xfs_rmap_irec gtrec;
722
- int have_gt;
723
- int have_lt;
724
- int error = 0;
725
- int i;
726
- uint64_t owner;
727
- uint64_t offset;
728
- unsigned int flags = 0;
729
- bool ignore_off;
758
+ struct xfs_mount *mp = cur->bc_mp;
759
+ struct xfs_rmap_irec ltrec;
760
+ struct xfs_rmap_irec gtrec;
761
+ int have_gt;
762
+ int have_lt;
763
+ int error = 0;
764
+ int i;
765
+ uint64_t owner;
766
+ uint64_t offset;
767
+ unsigned int flags = 0;
768
+ bool ignore_off;
730769
731770 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
732771 ASSERT(owner != 0);
....@@ -734,7 +773,7 @@
734773 (flags & XFS_RMAP_BMBT_BLOCK);
735774 if (unwritten)
736775 flags |= XFS_RMAP_UNWRITTEN;
737
- trace_xfs_rmap_map(mp, cur->bc_private.a.agno, bno, len,
776
+ trace_xfs_rmap_map(mp, cur->bc_ag.agno, bno, len,
738777 unwritten, oinfo);
739778 ASSERT(!xfs_rmap_should_skip_owner_update(oinfo));
740779
....@@ -751,9 +790,12 @@
751790 error = xfs_rmap_get_rec(cur, &ltrec, &have_lt);
752791 if (error)
753792 goto out_error;
754
- XFS_WANT_CORRUPTED_GOTO(mp, have_lt == 1, out_error);
793
+ if (XFS_IS_CORRUPT(mp, have_lt != 1)) {
794
+ error = -EFSCORRUPTED;
795
+ goto out_error;
796
+ }
755797 trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
756
- cur->bc_private.a.agno, ltrec.rm_startblock,
798
+ cur->bc_ag.agno, ltrec.rm_startblock,
757799 ltrec.rm_blockcount, ltrec.rm_owner,
758800 ltrec.rm_offset, ltrec.rm_flags);
759801
....@@ -761,9 +803,12 @@
761803 have_lt = 0;
762804 }
763805
764
- XFS_WANT_CORRUPTED_GOTO(mp,
765
- have_lt == 0 ||
766
- ltrec.rm_startblock + ltrec.rm_blockcount <= bno, out_error);
806
+ if (XFS_IS_CORRUPT(mp,
807
+ have_lt != 0 &&
808
+ ltrec.rm_startblock + ltrec.rm_blockcount > bno)) {
809
+ error = -EFSCORRUPTED;
810
+ goto out_error;
811
+ }
767812
768813 /*
769814 * Increment the cursor to see if we have a right-adjacent record to our
....@@ -777,11 +822,16 @@
777822 error = xfs_rmap_get_rec(cur, &gtrec, &have_gt);
778823 if (error)
779824 goto out_error;
780
- XFS_WANT_CORRUPTED_GOTO(mp, have_gt == 1, out_error);
781
- XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= gtrec.rm_startblock,
782
- out_error);
825
+ if (XFS_IS_CORRUPT(mp, have_gt != 1)) {
826
+ error = -EFSCORRUPTED;
827
+ goto out_error;
828
+ }
829
+ if (XFS_IS_CORRUPT(mp, bno + len > gtrec.rm_startblock)) {
830
+ error = -EFSCORRUPTED;
831
+ goto out_error;
832
+ }
783833 trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp,
784
- cur->bc_private.a.agno, gtrec.rm_startblock,
834
+ cur->bc_ag.agno, gtrec.rm_startblock,
785835 gtrec.rm_blockcount, gtrec.rm_owner,
786836 gtrec.rm_offset, gtrec.rm_flags);
787837 if (!xfs_rmap_is_mergeable(&gtrec, owner, flags))
....@@ -820,7 +870,7 @@
820870 * result: |rrrrrrrrrrrrrrrrrrrrrrrrrrrrr|
821871 */
822872 ltrec.rm_blockcount += gtrec.rm_blockcount;
823
- trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
873
+ trace_xfs_rmap_delete(mp, cur->bc_ag.agno,
824874 gtrec.rm_startblock,
825875 gtrec.rm_blockcount,
826876 gtrec.rm_owner,
....@@ -829,7 +879,10 @@
829879 error = xfs_btree_delete(cur, &i);
830880 if (error)
831881 goto out_error;
832
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
882
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
883
+ error = -EFSCORRUPTED;
884
+ goto out_error;
885
+ }
833886 }
834887
835888 /* point the cursor back to the left record and update */
....@@ -868,19 +921,22 @@
868921 cur->bc_rec.r.rm_owner = owner;
869922 cur->bc_rec.r.rm_offset = offset;
870923 cur->bc_rec.r.rm_flags = flags;
871
- trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno, len,
924
+ trace_xfs_rmap_insert(mp, cur->bc_ag.agno, bno, len,
872925 owner, offset, flags);
873926 error = xfs_btree_insert(cur, &i);
874927 if (error)
875928 goto out_error;
876
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
929
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
930
+ error = -EFSCORRUPTED;
931
+ goto out_error;
932
+ }
877933 }
878934
879
- trace_xfs_rmap_map_done(mp, cur->bc_private.a.agno, bno, len,
935
+ trace_xfs_rmap_map_done(mp, cur->bc_ag.agno, bno, len,
880936 unwritten, oinfo);
881937 out_error:
882938 if (error)
883
- trace_xfs_rmap_map_error(mp, cur->bc_private.a.agno,
939
+ trace_xfs_rmap_map_error(mp, cur->bc_ag.agno,
884940 error, _RET_IP_);
885941 return error;
886942 }
....@@ -890,16 +946,16 @@
890946 */
891947 int
892948 xfs_rmap_alloc(
893
- struct xfs_trans *tp,
894
- struct xfs_buf *agbp,
895
- xfs_agnumber_t agno,
896
- xfs_agblock_t bno,
897
- xfs_extlen_t len,
898
- struct xfs_owner_info *oinfo)
949
+ struct xfs_trans *tp,
950
+ struct xfs_buf *agbp,
951
+ xfs_agnumber_t agno,
952
+ xfs_agblock_t bno,
953
+ xfs_extlen_t len,
954
+ const struct xfs_owner_info *oinfo)
899955 {
900
- struct xfs_mount *mp = tp->t_mountp;
901
- struct xfs_btree_cur *cur;
902
- int error;
956
+ struct xfs_mount *mp = tp->t_mountp;
957
+ struct xfs_btree_cur *cur;
958
+ int error;
903959
904960 if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
905961 return 0;
....@@ -929,16 +985,16 @@
929985 */
930986 STATIC int
931987 xfs_rmap_convert(
932
- struct xfs_btree_cur *cur,
933
- xfs_agblock_t bno,
934
- xfs_extlen_t len,
935
- bool unwritten,
936
- struct xfs_owner_info *oinfo)
988
+ struct xfs_btree_cur *cur,
989
+ xfs_agblock_t bno,
990
+ xfs_extlen_t len,
991
+ bool unwritten,
992
+ const struct xfs_owner_info *oinfo)
937993 {
938
- struct xfs_mount *mp = cur->bc_mp;
939
- struct xfs_rmap_irec r[4]; /* neighbor extent entries */
940
- /* left is 0, right is 1, prev is 2 */
941
- /* new is 3 */
994
+ struct xfs_mount *mp = cur->bc_mp;
995
+ struct xfs_rmap_irec r[4]; /* neighbor extent entries */
996
+ /* left is 0, right is 1, */
997
+ /* prev is 2, new is 3 */
942998 uint64_t owner;
943999 uint64_t offset;
9441000 uint64_t new_endoff;
....@@ -954,7 +1010,7 @@
9541010 (flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK))));
9551011 oldext = unwritten ? XFS_RMAP_UNWRITTEN : 0;
9561012 new_endoff = offset + len;
957
- trace_xfs_rmap_convert(mp, cur->bc_private.a.agno, bno, len,
1013
+ trace_xfs_rmap_convert(mp, cur->bc_ag.agno, bno, len,
9581014 unwritten, oinfo);
9591015
9601016 /*
....@@ -965,14 +1021,20 @@
9651021 error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, oldext, &i);
9661022 if (error)
9671023 goto done;
968
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1024
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1025
+ error = -EFSCORRUPTED;
1026
+ goto done;
1027
+ }
9691028
9701029 error = xfs_rmap_get_rec(cur, &PREV, &i);
9711030 if (error)
9721031 goto done;
973
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1032
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1033
+ error = -EFSCORRUPTED;
1034
+ goto done;
1035
+ }
9741036 trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
975
- cur->bc_private.a.agno, PREV.rm_startblock,
1037
+ cur->bc_ag.agno, PREV.rm_startblock,
9761038 PREV.rm_blockcount, PREV.rm_owner,
9771039 PREV.rm_offset, PREV.rm_flags);
9781040
....@@ -1003,12 +1065,18 @@
10031065 error = xfs_rmap_get_rec(cur, &LEFT, &i);
10041066 if (error)
10051067 goto done;
1006
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1007
- XFS_WANT_CORRUPTED_GOTO(mp,
1008
- LEFT.rm_startblock + LEFT.rm_blockcount <= bno,
1009
- done);
1068
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1069
+ error = -EFSCORRUPTED;
1070
+ goto done;
1071
+ }
1072
+ if (XFS_IS_CORRUPT(mp,
1073
+ LEFT.rm_startblock + LEFT.rm_blockcount >
1074
+ bno)) {
1075
+ error = -EFSCORRUPTED;
1076
+ goto done;
1077
+ }
10101078 trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp,
1011
- cur->bc_private.a.agno, LEFT.rm_startblock,
1079
+ cur->bc_ag.agno, LEFT.rm_startblock,
10121080 LEFT.rm_blockcount, LEFT.rm_owner,
10131081 LEFT.rm_offset, LEFT.rm_flags);
10141082 if (LEFT.rm_startblock + LEFT.rm_blockcount == bno &&
....@@ -1025,7 +1093,10 @@
10251093 error = xfs_btree_increment(cur, 0, &i);
10261094 if (error)
10271095 goto done;
1028
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1096
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1097
+ error = -EFSCORRUPTED;
1098
+ goto done;
1099
+ }
10291100 error = xfs_btree_increment(cur, 0, &i);
10301101 if (error)
10311102 goto done;
....@@ -1034,11 +1105,16 @@
10341105 error = xfs_rmap_get_rec(cur, &RIGHT, &i);
10351106 if (error)
10361107 goto done;
1037
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1038
- XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= RIGHT.rm_startblock,
1039
- done);
1108
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1109
+ error = -EFSCORRUPTED;
1110
+ goto done;
1111
+ }
1112
+ if (XFS_IS_CORRUPT(mp, bno + len > RIGHT.rm_startblock)) {
1113
+ error = -EFSCORRUPTED;
1114
+ goto done;
1115
+ }
10401116 trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp,
1041
- cur->bc_private.a.agno, RIGHT.rm_startblock,
1117
+ cur->bc_ag.agno, RIGHT.rm_startblock,
10421118 RIGHT.rm_blockcount, RIGHT.rm_owner,
10431119 RIGHT.rm_offset, RIGHT.rm_flags);
10441120 if (bno + len == RIGHT.rm_startblock &&
....@@ -1056,14 +1132,17 @@
10561132 RIGHT.rm_blockcount > XFS_RMAP_LEN_MAX)
10571133 state &= ~RMAP_RIGHT_CONTIG;
10581134
1059
- trace_xfs_rmap_convert_state(mp, cur->bc_private.a.agno, state,
1135
+ trace_xfs_rmap_convert_state(mp, cur->bc_ag.agno, state,
10601136 _RET_IP_);
10611137
10621138 /* reset the cursor back to PREV */
10631139 error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, oldext, &i);
10641140 if (error)
10651141 goto done;
1066
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1142
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1143
+ error = -EFSCORRUPTED;
1144
+ goto done;
1145
+ }
10671146
10681147 /*
10691148 * Switch out based on the FILLING and CONTIG state bits.
....@@ -1079,31 +1158,46 @@
10791158 error = xfs_btree_increment(cur, 0, &i);
10801159 if (error)
10811160 goto done;
1082
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1083
- trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
1161
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1162
+ error = -EFSCORRUPTED;
1163
+ goto done;
1164
+ }
1165
+ trace_xfs_rmap_delete(mp, cur->bc_ag.agno,
10841166 RIGHT.rm_startblock, RIGHT.rm_blockcount,
10851167 RIGHT.rm_owner, RIGHT.rm_offset,
10861168 RIGHT.rm_flags);
10871169 error = xfs_btree_delete(cur, &i);
10881170 if (error)
10891171 goto done;
1090
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1172
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1173
+ error = -EFSCORRUPTED;
1174
+ goto done;
1175
+ }
10911176 error = xfs_btree_decrement(cur, 0, &i);
10921177 if (error)
10931178 goto done;
1094
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1095
- trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
1179
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1180
+ error = -EFSCORRUPTED;
1181
+ goto done;
1182
+ }
1183
+ trace_xfs_rmap_delete(mp, cur->bc_ag.agno,
10961184 PREV.rm_startblock, PREV.rm_blockcount,
10971185 PREV.rm_owner, PREV.rm_offset,
10981186 PREV.rm_flags);
10991187 error = xfs_btree_delete(cur, &i);
11001188 if (error)
11011189 goto done;
1102
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1190
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1191
+ error = -EFSCORRUPTED;
1192
+ goto done;
1193
+ }
11031194 error = xfs_btree_decrement(cur, 0, &i);
11041195 if (error)
11051196 goto done;
1106
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1197
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1198
+ error = -EFSCORRUPTED;
1199
+ goto done;
1200
+ }
11071201 NEW = LEFT;
11081202 NEW.rm_blockcount += PREV.rm_blockcount + RIGHT.rm_blockcount;
11091203 error = xfs_rmap_update(cur, &NEW);
....@@ -1116,18 +1210,24 @@
11161210 * Setting all of a previous oldext extent to newext.
11171211 * The left neighbor is contiguous, the right is not.
11181212 */
1119
- trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
1213
+ trace_xfs_rmap_delete(mp, cur->bc_ag.agno,
11201214 PREV.rm_startblock, PREV.rm_blockcount,
11211215 PREV.rm_owner, PREV.rm_offset,
11221216 PREV.rm_flags);
11231217 error = xfs_btree_delete(cur, &i);
11241218 if (error)
11251219 goto done;
1126
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1220
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1221
+ error = -EFSCORRUPTED;
1222
+ goto done;
1223
+ }
11271224 error = xfs_btree_decrement(cur, 0, &i);
11281225 if (error)
11291226 goto done;
1130
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1227
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1228
+ error = -EFSCORRUPTED;
1229
+ goto done;
1230
+ }
11311231 NEW = LEFT;
11321232 NEW.rm_blockcount += PREV.rm_blockcount;
11331233 error = xfs_rmap_update(cur, &NEW);
....@@ -1143,19 +1243,28 @@
11431243 error = xfs_btree_increment(cur, 0, &i);
11441244 if (error)
11451245 goto done;
1146
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1147
- trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
1246
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1247
+ error = -EFSCORRUPTED;
1248
+ goto done;
1249
+ }
1250
+ trace_xfs_rmap_delete(mp, cur->bc_ag.agno,
11481251 RIGHT.rm_startblock, RIGHT.rm_blockcount,
11491252 RIGHT.rm_owner, RIGHT.rm_offset,
11501253 RIGHT.rm_flags);
11511254 error = xfs_btree_delete(cur, &i);
11521255 if (error)
11531256 goto done;
1154
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1257
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1258
+ error = -EFSCORRUPTED;
1259
+ goto done;
1260
+ }
11551261 error = xfs_btree_decrement(cur, 0, &i);
11561262 if (error)
11571263 goto done;
1158
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1264
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1265
+ error = -EFSCORRUPTED;
1266
+ goto done;
1267
+ }
11591268 NEW = PREV;
11601269 NEW.rm_blockcount = len + RIGHT.rm_blockcount;
11611270 NEW.rm_flags = newext;
....@@ -1217,12 +1326,15 @@
12171326 NEW.rm_blockcount = len;
12181327 NEW.rm_flags = newext;
12191328 cur->bc_rec.r = NEW;
1220
- trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno,
1329
+ trace_xfs_rmap_insert(mp, cur->bc_ag.agno, bno,
12211330 len, owner, offset, newext);
12221331 error = xfs_btree_insert(cur, &i);
12231332 if (error)
12241333 goto done;
1225
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1334
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1335
+ error = -EFSCORRUPTED;
1336
+ goto done;
1337
+ }
12261338 break;
12271339
12281340 case RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG:
....@@ -1261,19 +1373,25 @@
12611373 oldext, &i);
12621374 if (error)
12631375 goto done;
1264
- XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
1376
+ if (XFS_IS_CORRUPT(mp, i != 0)) {
1377
+ error = -EFSCORRUPTED;
1378
+ goto done;
1379
+ }
12651380 NEW.rm_startblock = bno;
12661381 NEW.rm_owner = owner;
12671382 NEW.rm_offset = offset;
12681383 NEW.rm_blockcount = len;
12691384 NEW.rm_flags = newext;
12701385 cur->bc_rec.r = NEW;
1271
- trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno,
1386
+ trace_xfs_rmap_insert(mp, cur->bc_ag.agno, bno,
12721387 len, owner, offset, newext);
12731388 error = xfs_btree_insert(cur, &i);
12741389 if (error)
12751390 goto done;
1276
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1391
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1392
+ error = -EFSCORRUPTED;
1393
+ goto done;
1394
+ }
12771395 break;
12781396
12791397 case 0:
....@@ -1296,14 +1414,17 @@
12961414 NEW = PREV;
12971415 NEW.rm_blockcount = offset - PREV.rm_offset;
12981416 cur->bc_rec.r = NEW;
1299
- trace_xfs_rmap_insert(mp, cur->bc_private.a.agno,
1417
+ trace_xfs_rmap_insert(mp, cur->bc_ag.agno,
13001418 NEW.rm_startblock, NEW.rm_blockcount,
13011419 NEW.rm_owner, NEW.rm_offset,
13021420 NEW.rm_flags);
13031421 error = xfs_btree_insert(cur, &i);
13041422 if (error)
13051423 goto done;
1306
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1424
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1425
+ error = -EFSCORRUPTED;
1426
+ goto done;
1427
+ }
13071428 /*
13081429 * Reset the cursor to the position of the new extent
13091430 * we are about to insert as we can't trust it after
....@@ -1313,16 +1434,22 @@
13131434 oldext, &i);
13141435 if (error)
13151436 goto done;
1316
- XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
1437
+ if (XFS_IS_CORRUPT(mp, i != 0)) {
1438
+ error = -EFSCORRUPTED;
1439
+ goto done;
1440
+ }
13171441 /* new middle extent - newext */
13181442 cur->bc_rec.r.rm_flags &= ~XFS_RMAP_UNWRITTEN;
13191443 cur->bc_rec.r.rm_flags |= newext;
1320
- trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno, len,
1444
+ trace_xfs_rmap_insert(mp, cur->bc_ag.agno, bno, len,
13211445 owner, offset, newext);
13221446 error = xfs_btree_insert(cur, &i);
13231447 if (error)
13241448 goto done;
1325
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1449
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1450
+ error = -EFSCORRUPTED;
1451
+ goto done;
1452
+ }
13261453 break;
13271454
13281455 case RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG | RMAP_RIGHT_CONTIG:
....@@ -1338,12 +1465,12 @@
13381465 ASSERT(0);
13391466 }
13401467
1341
- trace_xfs_rmap_convert_done(mp, cur->bc_private.a.agno, bno, len,
1468
+ trace_xfs_rmap_convert_done(mp, cur->bc_ag.agno, bno, len,
13421469 unwritten, oinfo);
13431470 done:
13441471 if (error)
13451472 trace_xfs_rmap_convert_error(cur->bc_mp,
1346
- cur->bc_private.a.agno, error, _RET_IP_);
1473
+ cur->bc_ag.agno, error, _RET_IP_);
13471474 return error;
13481475 }
13491476
....@@ -1354,16 +1481,16 @@
13541481 */
13551482 STATIC int
13561483 xfs_rmap_convert_shared(
1357
- struct xfs_btree_cur *cur,
1358
- xfs_agblock_t bno,
1359
- xfs_extlen_t len,
1360
- bool unwritten,
1361
- struct xfs_owner_info *oinfo)
1484
+ struct xfs_btree_cur *cur,
1485
+ xfs_agblock_t bno,
1486
+ xfs_extlen_t len,
1487
+ bool unwritten,
1488
+ const struct xfs_owner_info *oinfo)
13621489 {
1363
- struct xfs_mount *mp = cur->bc_mp;
1364
- struct xfs_rmap_irec r[4]; /* neighbor extent entries */
1365
- /* left is 0, right is 1, prev is 2 */
1366
- /* new is 3 */
1490
+ struct xfs_mount *mp = cur->bc_mp;
1491
+ struct xfs_rmap_irec r[4]; /* neighbor extent entries */
1492
+ /* left is 0, right is 1, */
1493
+ /* prev is 2, new is 3 */
13671494 uint64_t owner;
13681495 uint64_t offset;
13691496 uint64_t new_endoff;
....@@ -1379,7 +1506,7 @@
13791506 (flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK))));
13801507 oldext = unwritten ? XFS_RMAP_UNWRITTEN : 0;
13811508 new_endoff = offset + len;
1382
- trace_xfs_rmap_convert(mp, cur->bc_private.a.agno, bno, len,
1509
+ trace_xfs_rmap_convert(mp, cur->bc_ag.agno, bno, len,
13831510 unwritten, oinfo);
13841511
13851512 /*
....@@ -1391,7 +1518,10 @@
13911518 &PREV, &i);
13921519 if (error)
13931520 goto done;
1394
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1521
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1522
+ error = -EFSCORRUPTED;
1523
+ goto done;
1524
+ }
13951525
13961526 ASSERT(PREV.rm_offset <= offset);
13971527 ASSERT(PREV.rm_offset + PREV.rm_blockcount >= new_endoff);
....@@ -1414,9 +1544,12 @@
14141544 goto done;
14151545 if (i) {
14161546 state |= RMAP_LEFT_VALID;
1417
- XFS_WANT_CORRUPTED_GOTO(mp,
1418
- LEFT.rm_startblock + LEFT.rm_blockcount <= bno,
1419
- done);
1547
+ if (XFS_IS_CORRUPT(mp,
1548
+ LEFT.rm_startblock + LEFT.rm_blockcount >
1549
+ bno)) {
1550
+ error = -EFSCORRUPTED;
1551
+ goto done;
1552
+ }
14201553 if (xfs_rmap_is_mergeable(&LEFT, owner, newext))
14211554 state |= RMAP_LEFT_CONTIG;
14221555 }
....@@ -1431,11 +1564,16 @@
14311564 error = xfs_rmap_get_rec(cur, &RIGHT, &i);
14321565 if (error)
14331566 goto done;
1434
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1435
- XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= RIGHT.rm_startblock,
1436
- done);
1567
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1568
+ error = -EFSCORRUPTED;
1569
+ goto done;
1570
+ }
1571
+ if (XFS_IS_CORRUPT(mp, bno + len > RIGHT.rm_startblock)) {
1572
+ error = -EFSCORRUPTED;
1573
+ goto done;
1574
+ }
14371575 trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp,
1438
- cur->bc_private.a.agno, RIGHT.rm_startblock,
1576
+ cur->bc_ag.agno, RIGHT.rm_startblock,
14391577 RIGHT.rm_blockcount, RIGHT.rm_owner,
14401578 RIGHT.rm_offset, RIGHT.rm_flags);
14411579 if (xfs_rmap_is_mergeable(&RIGHT, owner, newext))
....@@ -1451,7 +1589,7 @@
14511589 RIGHT.rm_blockcount > XFS_RMAP_LEN_MAX)
14521590 state &= ~RMAP_RIGHT_CONTIG;
14531591
1454
- trace_xfs_rmap_convert_state(mp, cur->bc_private.a.agno, state,
1592
+ trace_xfs_rmap_convert_state(mp, cur->bc_ag.agno, state,
14551593 _RET_IP_);
14561594 /*
14571595 * Switch out based on the FILLING and CONTIG state bits.
....@@ -1480,7 +1618,10 @@
14801618 NEW.rm_offset, NEW.rm_flags, &i);
14811619 if (error)
14821620 goto done;
1483
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1621
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1622
+ error = -EFSCORRUPTED;
1623
+ goto done;
1624
+ }
14841625 NEW.rm_blockcount += PREV.rm_blockcount + RIGHT.rm_blockcount;
14851626 error = xfs_rmap_update(cur, &NEW);
14861627 if (error)
....@@ -1503,7 +1644,10 @@
15031644 NEW.rm_offset, NEW.rm_flags, &i);
15041645 if (error)
15051646 goto done;
1506
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1647
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1648
+ error = -EFSCORRUPTED;
1649
+ goto done;
1650
+ }
15071651 NEW.rm_blockcount += PREV.rm_blockcount;
15081652 error = xfs_rmap_update(cur, &NEW);
15091653 if (error)
....@@ -1526,7 +1670,10 @@
15261670 NEW.rm_offset, NEW.rm_flags, &i);
15271671 if (error)
15281672 goto done;
1529
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1673
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1674
+ error = -EFSCORRUPTED;
1675
+ goto done;
1676
+ }
15301677 NEW.rm_blockcount += RIGHT.rm_blockcount;
15311678 NEW.rm_flags = RIGHT.rm_flags;
15321679 error = xfs_rmap_update(cur, &NEW);
....@@ -1546,7 +1693,10 @@
15461693 NEW.rm_offset, NEW.rm_flags, &i);
15471694 if (error)
15481695 goto done;
1549
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1696
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1697
+ error = -EFSCORRUPTED;
1698
+ goto done;
1699
+ }
15501700 NEW.rm_flags = newext;
15511701 error = xfs_rmap_update(cur, &NEW);
15521702 if (error)
....@@ -1578,7 +1728,10 @@
15781728 NEW.rm_offset, NEW.rm_flags, &i);
15791729 if (error)
15801730 goto done;
1581
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1731
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1732
+ error = -EFSCORRUPTED;
1733
+ goto done;
1734
+ }
15821735 NEW.rm_blockcount += len;
15831736 error = xfs_rmap_update(cur, &NEW);
15841737 if (error)
....@@ -1620,7 +1773,10 @@
16201773 NEW.rm_offset, NEW.rm_flags, &i);
16211774 if (error)
16221775 goto done;
1623
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1776
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1777
+ error = -EFSCORRUPTED;
1778
+ goto done;
1779
+ }
16241780 NEW.rm_blockcount = offset - NEW.rm_offset;
16251781 error = xfs_rmap_update(cur, &NEW);
16261782 if (error)
....@@ -1652,7 +1808,10 @@
16521808 NEW.rm_offset, NEW.rm_flags, &i);
16531809 if (error)
16541810 goto done;
1655
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1811
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1812
+ error = -EFSCORRUPTED;
1813
+ goto done;
1814
+ }
16561815 NEW.rm_blockcount -= len;
16571816 error = xfs_rmap_update(cur, &NEW);
16581817 if (error)
....@@ -1687,7 +1846,10 @@
16871846 NEW.rm_offset, NEW.rm_flags, &i);
16881847 if (error)
16891848 goto done;
1690
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1849
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1850
+ error = -EFSCORRUPTED;
1851
+ goto done;
1852
+ }
16911853 NEW.rm_blockcount = offset - NEW.rm_offset;
16921854 error = xfs_rmap_update(cur, &NEW);
16931855 if (error)
....@@ -1718,12 +1880,12 @@
17181880 ASSERT(0);
17191881 }
17201882
1721
- trace_xfs_rmap_convert_done(mp, cur->bc_private.a.agno, bno, len,
1883
+ trace_xfs_rmap_convert_done(mp, cur->bc_ag.agno, bno, len,
17221884 unwritten, oinfo);
17231885 done:
17241886 if (error)
17251887 trace_xfs_rmap_convert_error(cur->bc_mp,
1726
- cur->bc_private.a.agno, error, _RET_IP_);
1888
+ cur->bc_ag.agno, error, _RET_IP_);
17271889 return error;
17281890 }
17291891
....@@ -1743,25 +1905,25 @@
17431905 */
17441906 STATIC int
17451907 xfs_rmap_unmap_shared(
1746
- struct xfs_btree_cur *cur,
1747
- xfs_agblock_t bno,
1748
- xfs_extlen_t len,
1749
- bool unwritten,
1750
- struct xfs_owner_info *oinfo)
1908
+ struct xfs_btree_cur *cur,
1909
+ xfs_agblock_t bno,
1910
+ xfs_extlen_t len,
1911
+ bool unwritten,
1912
+ const struct xfs_owner_info *oinfo)
17511913 {
1752
- struct xfs_mount *mp = cur->bc_mp;
1753
- struct xfs_rmap_irec ltrec;
1754
- uint64_t ltoff;
1755
- int error = 0;
1756
- int i;
1757
- uint64_t owner;
1758
- uint64_t offset;
1759
- unsigned int flags;
1914
+ struct xfs_mount *mp = cur->bc_mp;
1915
+ struct xfs_rmap_irec ltrec;
1916
+ uint64_t ltoff;
1917
+ int error = 0;
1918
+ int i;
1919
+ uint64_t owner;
1920
+ uint64_t offset;
1921
+ unsigned int flags;
17601922
17611923 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
17621924 if (unwritten)
17631925 flags |= XFS_RMAP_UNWRITTEN;
1764
- trace_xfs_rmap_unmap(mp, cur->bc_private.a.agno, bno, len,
1926
+ trace_xfs_rmap_unmap(mp, cur->bc_ag.agno, bno, len,
17651927 unwritten, oinfo);
17661928
17671929 /*
....@@ -1773,25 +1935,44 @@
17731935 &ltrec, &i);
17741936 if (error)
17751937 goto out_error;
1776
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
1938
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
1939
+ error = -EFSCORRUPTED;
1940
+ goto out_error;
1941
+ }
17771942 ltoff = ltrec.rm_offset;
17781943
17791944 /* Make sure the extent we found covers the entire freeing range. */
1780
- XFS_WANT_CORRUPTED_GOTO(mp, ltrec.rm_startblock <= bno &&
1781
- ltrec.rm_startblock + ltrec.rm_blockcount >=
1782
- bno + len, out_error);
1945
+ if (XFS_IS_CORRUPT(mp,
1946
+ ltrec.rm_startblock > bno ||
1947
+ ltrec.rm_startblock + ltrec.rm_blockcount <
1948
+ bno + len)) {
1949
+ error = -EFSCORRUPTED;
1950
+ goto out_error;
1951
+ }
17831952
17841953 /* Make sure the owner matches what we expect to find in the tree. */
1785
- XFS_WANT_CORRUPTED_GOTO(mp, owner == ltrec.rm_owner, out_error);
1954
+ if (XFS_IS_CORRUPT(mp, owner != ltrec.rm_owner)) {
1955
+ error = -EFSCORRUPTED;
1956
+ goto out_error;
1957
+ }
17861958
17871959 /* Make sure the unwritten flag matches. */
1788
- XFS_WANT_CORRUPTED_GOTO(mp, (flags & XFS_RMAP_UNWRITTEN) ==
1789
- (ltrec.rm_flags & XFS_RMAP_UNWRITTEN), out_error);
1960
+ if (XFS_IS_CORRUPT(mp,
1961
+ (flags & XFS_RMAP_UNWRITTEN) !=
1962
+ (ltrec.rm_flags & XFS_RMAP_UNWRITTEN))) {
1963
+ error = -EFSCORRUPTED;
1964
+ goto out_error;
1965
+ }
17901966
17911967 /* Check the offset. */
1792
- XFS_WANT_CORRUPTED_GOTO(mp, ltrec.rm_offset <= offset, out_error);
1793
- XFS_WANT_CORRUPTED_GOTO(mp, offset <= ltoff + ltrec.rm_blockcount,
1794
- out_error);
1968
+ if (XFS_IS_CORRUPT(mp, ltrec.rm_offset > offset)) {
1969
+ error = -EFSCORRUPTED;
1970
+ goto out_error;
1971
+ }
1972
+ if (XFS_IS_CORRUPT(mp, offset > ltoff + ltrec.rm_blockcount)) {
1973
+ error = -EFSCORRUPTED;
1974
+ goto out_error;
1975
+ }
17951976
17961977 if (ltrec.rm_startblock == bno && ltrec.rm_blockcount == len) {
17971978 /* Exact match, simply remove the record from rmap tree. */
....@@ -1844,7 +2025,10 @@
18442025 ltrec.rm_offset, ltrec.rm_flags, &i);
18452026 if (error)
18462027 goto out_error;
1847
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
2028
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
2029
+ error = -EFSCORRUPTED;
2030
+ goto out_error;
2031
+ }
18482032 ltrec.rm_blockcount -= len;
18492033 error = xfs_rmap_update(cur, &ltrec);
18502034 if (error)
....@@ -1870,7 +2054,10 @@
18702054 ltrec.rm_offset, ltrec.rm_flags, &i);
18712055 if (error)
18722056 goto out_error;
1873
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
2057
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
2058
+ error = -EFSCORRUPTED;
2059
+ goto out_error;
2060
+ }
18742061 ltrec.rm_blockcount = bno - ltrec.rm_startblock;
18752062 error = xfs_rmap_update(cur, &ltrec);
18762063 if (error)
....@@ -1885,12 +2072,12 @@
18852072 goto out_error;
18862073 }
18872074
1888
- trace_xfs_rmap_unmap_done(mp, cur->bc_private.a.agno, bno, len,
2075
+ trace_xfs_rmap_unmap_done(mp, cur->bc_ag.agno, bno, len,
18892076 unwritten, oinfo);
18902077 out_error:
18912078 if (error)
18922079 trace_xfs_rmap_unmap_error(cur->bc_mp,
1893
- cur->bc_private.a.agno, error, _RET_IP_);
2080
+ cur->bc_ag.agno, error, _RET_IP_);
18942081 return error;
18952082 }
18962083
....@@ -1905,27 +2092,27 @@
19052092 */
19062093 STATIC int
19072094 xfs_rmap_map_shared(
1908
- struct xfs_btree_cur *cur,
1909
- xfs_agblock_t bno,
1910
- xfs_extlen_t len,
1911
- bool unwritten,
1912
- struct xfs_owner_info *oinfo)
2095
+ struct xfs_btree_cur *cur,
2096
+ xfs_agblock_t bno,
2097
+ xfs_extlen_t len,
2098
+ bool unwritten,
2099
+ const struct xfs_owner_info *oinfo)
19132100 {
1914
- struct xfs_mount *mp = cur->bc_mp;
1915
- struct xfs_rmap_irec ltrec;
1916
- struct xfs_rmap_irec gtrec;
1917
- int have_gt;
1918
- int have_lt;
1919
- int error = 0;
1920
- int i;
1921
- uint64_t owner;
1922
- uint64_t offset;
1923
- unsigned int flags = 0;
2101
+ struct xfs_mount *mp = cur->bc_mp;
2102
+ struct xfs_rmap_irec ltrec;
2103
+ struct xfs_rmap_irec gtrec;
2104
+ int have_gt;
2105
+ int have_lt;
2106
+ int error = 0;
2107
+ int i;
2108
+ uint64_t owner;
2109
+ uint64_t offset;
2110
+ unsigned int flags = 0;
19242111
19252112 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
19262113 if (unwritten)
19272114 flags |= XFS_RMAP_UNWRITTEN;
1928
- trace_xfs_rmap_map(mp, cur->bc_private.a.agno, bno, len,
2115
+ trace_xfs_rmap_map(mp, cur->bc_ag.agno, bno, len,
19292116 unwritten, oinfo);
19302117
19312118 /* Is there a left record that abuts our range? */
....@@ -1946,9 +2133,12 @@
19462133 error = xfs_rmap_get_rec(cur, &gtrec, &have_gt);
19472134 if (error)
19482135 goto out_error;
1949
- XFS_WANT_CORRUPTED_GOTO(mp, have_gt == 1, out_error);
2136
+ if (XFS_IS_CORRUPT(mp, have_gt != 1)) {
2137
+ error = -EFSCORRUPTED;
2138
+ goto out_error;
2139
+ }
19502140 trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp,
1951
- cur->bc_private.a.agno, gtrec.rm_startblock,
2141
+ cur->bc_ag.agno, gtrec.rm_startblock,
19522142 gtrec.rm_blockcount, gtrec.rm_owner,
19532143 gtrec.rm_offset, gtrec.rm_flags);
19542144
....@@ -1995,7 +2185,10 @@
19952185 ltrec.rm_offset, ltrec.rm_flags, &i);
19962186 if (error)
19972187 goto out_error;
1998
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
2188
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
2189
+ error = -EFSCORRUPTED;
2190
+ goto out_error;
2191
+ }
19992192
20002193 error = xfs_rmap_update(cur, &ltrec);
20012194 if (error)
....@@ -2038,12 +2231,12 @@
20382231 goto out_error;
20392232 }
20402233
2041
- trace_xfs_rmap_map_done(mp, cur->bc_private.a.agno, bno, len,
2234
+ trace_xfs_rmap_map_done(mp, cur->bc_ag.agno, bno, len,
20422235 unwritten, oinfo);
20432236 out_error:
20442237 if (error)
20452238 trace_xfs_rmap_map_error(cur->bc_mp,
2046
- cur->bc_private.a.agno, error, _RET_IP_);
2239
+ cur->bc_ag.agno, error, _RET_IP_);
20472240 return error;
20482241 }
20492242
....@@ -2143,7 +2336,7 @@
21432336
21442337 if (rcur == NULL)
21452338 return;
2146
- agbp = rcur->bc_private.a.agbp;
2339
+ agbp = rcur->bc_ag.agbp;
21472340 xfs_btree_del_cursor(rcur, error);
21482341 if (error)
21492342 xfs_trans_brelse(tp, agbp);
....@@ -2193,7 +2386,7 @@
21932386 * the startblock, get one now.
21942387 */
21952388 rcur = *pcur;
2196
- if (rcur != NULL && rcur->bc_private.a.agno != agno) {
2389
+ if (rcur != NULL && rcur->bc_ag.agno != agno) {
21972390 xfs_rmap_finish_one_cleanup(tp, rcur, 0);
21982391 rcur = NULL;
21992392 *pcur = NULL;
....@@ -2207,7 +2400,7 @@
22072400 error = xfs_free_extent_fix_freelist(tp, agno, &agbp);
22082401 if (error)
22092402 return error;
2210
- if (!agbp)
2403
+ if (XFS_IS_CORRUPT(tp->t_mountp, !agbp))
22112404 return -EFSCORRUPTED;
22122405
22132406 rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno);
....@@ -2275,7 +2468,7 @@
22752468 * Record a rmap intent; the list is kept sorted first by AG and then by
22762469 * increasing age.
22772470 */
2278
-static int
2471
+static void
22792472 __xfs_rmap_add(
22802473 struct xfs_trans *tp,
22812474 enum xfs_rmap_intent_type type,
....@@ -2294,7 +2487,7 @@
22942487 bmap->br_blockcount,
22952488 bmap->br_state);
22962489
2297
- ri = kmem_alloc(sizeof(struct xfs_rmap_intent), KM_SLEEP | KM_NOFS);
2490
+ ri = kmem_alloc(sizeof(struct xfs_rmap_intent), KM_NOFS);
22982491 INIT_LIST_HEAD(&ri->ri_list);
22992492 ri->ri_type = type;
23002493 ri->ri_owner = owner;
....@@ -2302,39 +2495,44 @@
23022495 ri->ri_bmap = *bmap;
23032496
23042497 xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_RMAP, &ri->ri_list);
2305
- return 0;
23062498 }
23072499
23082500 /* Map an extent into a file. */
2309
-int
2501
+void
23102502 xfs_rmap_map_extent(
23112503 struct xfs_trans *tp,
23122504 struct xfs_inode *ip,
23132505 int whichfork,
23142506 struct xfs_bmbt_irec *PREV)
23152507 {
2316
- if (!xfs_rmap_update_is_needed(tp->t_mountp, whichfork))
2317
- return 0;
2508
+ enum xfs_rmap_intent_type type = XFS_RMAP_MAP;
23182509
2319
- return __xfs_rmap_add(tp, xfs_is_reflink_inode(ip) ?
2320
- XFS_RMAP_MAP_SHARED : XFS_RMAP_MAP, ip->i_ino,
2321
- whichfork, PREV);
2510
+ if (!xfs_rmap_update_is_needed(tp->t_mountp, whichfork))
2511
+ return;
2512
+
2513
+ if (whichfork != XFS_ATTR_FORK && xfs_is_reflink_inode(ip))
2514
+ type = XFS_RMAP_MAP_SHARED;
2515
+
2516
+ __xfs_rmap_add(tp, type, ip->i_ino, whichfork, PREV);
23222517 }
23232518
23242519 /* Unmap an extent out of a file. */
2325
-int
2520
+void
23262521 xfs_rmap_unmap_extent(
23272522 struct xfs_trans *tp,
23282523 struct xfs_inode *ip,
23292524 int whichfork,
23302525 struct xfs_bmbt_irec *PREV)
23312526 {
2332
- if (!xfs_rmap_update_is_needed(tp->t_mountp, whichfork))
2333
- return 0;
2527
+ enum xfs_rmap_intent_type type = XFS_RMAP_UNMAP;
23342528
2335
- return __xfs_rmap_add(tp, xfs_is_reflink_inode(ip) ?
2336
- XFS_RMAP_UNMAP_SHARED : XFS_RMAP_UNMAP, ip->i_ino,
2337
- whichfork, PREV);
2529
+ if (!xfs_rmap_update_is_needed(tp->t_mountp, whichfork))
2530
+ return;
2531
+
2532
+ if (whichfork != XFS_ATTR_FORK && xfs_is_reflink_inode(ip))
2533
+ type = XFS_RMAP_UNMAP_SHARED;
2534
+
2535
+ __xfs_rmap_add(tp, type, ip->i_ino, whichfork, PREV);
23382536 }
23392537
23402538 /*
....@@ -2343,7 +2541,7 @@
23432541 * Note that tp can be NULL here as no transaction is used for COW fork
23442542 * unwritten conversion.
23452543 */
2346
-int
2544
+void
23472545 xfs_rmap_convert_extent(
23482546 struct xfs_mount *mp,
23492547 struct xfs_trans *tp,
....@@ -2351,16 +2549,19 @@
23512549 int whichfork,
23522550 struct xfs_bmbt_irec *PREV)
23532551 {
2354
- if (!xfs_rmap_update_is_needed(mp, whichfork))
2355
- return 0;
2552
+ enum xfs_rmap_intent_type type = XFS_RMAP_CONVERT;
23562553
2357
- return __xfs_rmap_add(tp, xfs_is_reflink_inode(ip) ?
2358
- XFS_RMAP_CONVERT_SHARED : XFS_RMAP_CONVERT, ip->i_ino,
2359
- whichfork, PREV);
2554
+ if (!xfs_rmap_update_is_needed(mp, whichfork))
2555
+ return;
2556
+
2557
+ if (whichfork != XFS_ATTR_FORK && xfs_is_reflink_inode(ip))
2558
+ type = XFS_RMAP_CONVERT_SHARED;
2559
+
2560
+ __xfs_rmap_add(tp, type, ip->i_ino, whichfork, PREV);
23602561 }
23612562
23622563 /* Schedule the creation of an rmap for non-file data. */
2363
-int
2564
+void
23642565 xfs_rmap_alloc_extent(
23652566 struct xfs_trans *tp,
23662567 xfs_agnumber_t agno,
....@@ -2371,18 +2572,18 @@
23712572 struct xfs_bmbt_irec bmap;
23722573
23732574 if (!xfs_rmap_update_is_needed(tp->t_mountp, XFS_DATA_FORK))
2374
- return 0;
2575
+ return;
23752576
23762577 bmap.br_startblock = XFS_AGB_TO_FSB(tp->t_mountp, agno, bno);
23772578 bmap.br_blockcount = len;
23782579 bmap.br_startoff = 0;
23792580 bmap.br_state = XFS_EXT_NORM;
23802581
2381
- return __xfs_rmap_add(tp, XFS_RMAP_ALLOC, owner, XFS_DATA_FORK, &bmap);
2582
+ __xfs_rmap_add(tp, XFS_RMAP_ALLOC, owner, XFS_DATA_FORK, &bmap);
23822583 }
23832584
23842585 /* Schedule the deletion of an rmap for non-file data. */
2385
-int
2586
+void
23862587 xfs_rmap_free_extent(
23872588 struct xfs_trans *tp,
23882589 xfs_agnumber_t agno,
....@@ -2393,14 +2594,14 @@
23932594 struct xfs_bmbt_irec bmap;
23942595
23952596 if (!xfs_rmap_update_is_needed(tp->t_mountp, XFS_DATA_FORK))
2396
- return 0;
2597
+ return;
23972598
23982599 bmap.br_startblock = XFS_AGB_TO_FSB(tp->t_mountp, agno, bno);
23992600 bmap.br_blockcount = len;
24002601 bmap.br_startoff = 0;
24012602 bmap.br_state = XFS_EXT_NORM;
24022603
2403
- return __xfs_rmap_add(tp, XFS_RMAP_FREE, owner, XFS_DATA_FORK, &bmap);
2604
+ __xfs_rmap_add(tp, XFS_RMAP_FREE, owner, XFS_DATA_FORK, &bmap);
24042605 }
24052606
24062607 /* Compare rmap records. Returns -1 if a < b, 1 if a > b, and 0 if equal. */
....@@ -2459,18 +2660,18 @@
24592660 */
24602661 int
24612662 xfs_rmap_record_exists(
2462
- struct xfs_btree_cur *cur,
2463
- xfs_agblock_t bno,
2464
- xfs_extlen_t len,
2465
- struct xfs_owner_info *oinfo,
2466
- bool *has_rmap)
2663
+ struct xfs_btree_cur *cur,
2664
+ xfs_agblock_t bno,
2665
+ xfs_extlen_t len,
2666
+ const struct xfs_owner_info *oinfo,
2667
+ bool *has_rmap)
24672668 {
2468
- uint64_t owner;
2469
- uint64_t offset;
2470
- unsigned int flags;
2471
- int has_record;
2472
- struct xfs_rmap_irec irec;
2473
- int error;
2669
+ uint64_t owner;
2670
+ uint64_t offset;
2671
+ unsigned int flags;
2672
+ int has_record;
2673
+ struct xfs_rmap_irec irec;
2674
+ int error;
24742675
24752676 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
24762677 ASSERT(XFS_RMAP_NON_INODE_OWNER(owner) ||
....@@ -2502,7 +2703,6 @@
25022703 uint64_t owner;
25032704 uint64_t offset;
25042705 unsigned int flags;
2505
- bool has_rmap;
25062706 };
25072707
25082708 /* For each rmap given, figure out if it doesn't match the key we want. */
....@@ -2517,8 +2717,7 @@
25172717 if (rks->owner == rec->rm_owner && rks->offset == rec->rm_offset &&
25182718 ((rks->flags & rec->rm_flags) & XFS_RMAP_KEY_FLAGS) == rks->flags)
25192719 return 0;
2520
- rks->has_rmap = true;
2521
- return XFS_BTREE_QUERY_RANGE_ABORT;
2720
+ return -ECANCELED;
25222721 }
25232722
25242723 /*
....@@ -2530,7 +2729,7 @@
25302729 struct xfs_btree_cur *cur,
25312730 xfs_agblock_t bno,
25322731 xfs_extlen_t len,
2533
- struct xfs_owner_info *oinfo,
2732
+ const struct xfs_owner_info *oinfo,
25342733 bool *has_rmap)
25352734 {
25362735 struct xfs_rmap_irec low = {0};
....@@ -2539,7 +2738,7 @@
25392738 int error;
25402739
25412740 xfs_owner_info_unpack(oinfo, &rks.owner, &rks.offset, &rks.flags);
2542
- rks.has_rmap = false;
2741
+ *has_rmap = false;
25432742
25442743 low.rm_startblock = bno;
25452744 memset(&high, 0xFF, sizeof(high));
....@@ -2547,6 +2746,38 @@
25472746
25482747 error = xfs_rmap_query_range(cur, &low, &high,
25492748 xfs_rmap_has_other_keys_helper, &rks);
2550
- *has_rmap = rks.has_rmap;
2749
+ if (error == -ECANCELED) {
2750
+ *has_rmap = true;
2751
+ return 0;
2752
+ }
2753
+
25512754 return error;
25522755 }
2756
+
2757
+const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE = {
2758
+ .oi_owner = XFS_RMAP_OWN_NULL,
2759
+};
2760
+const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER = {
2761
+ .oi_owner = XFS_RMAP_OWN_UNKNOWN,
2762
+};
2763
+const struct xfs_owner_info XFS_RMAP_OINFO_FS = {
2764
+ .oi_owner = XFS_RMAP_OWN_FS,
2765
+};
2766
+const struct xfs_owner_info XFS_RMAP_OINFO_LOG = {
2767
+ .oi_owner = XFS_RMAP_OWN_LOG,
2768
+};
2769
+const struct xfs_owner_info XFS_RMAP_OINFO_AG = {
2770
+ .oi_owner = XFS_RMAP_OWN_AG,
2771
+};
2772
+const struct xfs_owner_info XFS_RMAP_OINFO_INOBT = {
2773
+ .oi_owner = XFS_RMAP_OWN_INOBT,
2774
+};
2775
+const struct xfs_owner_info XFS_RMAP_OINFO_INODES = {
2776
+ .oi_owner = XFS_RMAP_OWN_INODES,
2777
+};
2778
+const struct xfs_owner_info XFS_RMAP_OINFO_REFC = {
2779
+ .oi_owner = XFS_RMAP_OWN_REFC,
2780
+};
2781
+const struct xfs_owner_info XFS_RMAP_OINFO_COW = {
2782
+ .oi_owner = XFS_RMAP_OWN_COW,
2783
+};