2 * Copyright (c) 2014 Red Hat, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs_shared.h"
21 #include "xfs_format.h"
22 #include "xfs_log_format.h"
23 #include "xfs_trans_resv.h"
26 #include "xfs_mount.h"
27 #include "xfs_defer.h"
28 #include "xfs_da_format.h"
29 #include "xfs_da_btree.h"
30 #include "xfs_btree.h"
31 #include "xfs_trans.h"
32 #include "xfs_alloc.h"
34 #include "xfs_rmap_btree.h"
35 #include "xfs_trans_space.h"
36 #include "xfs_trace.h"
37 #include "xfs_error.h"
38 #include "xfs_extent_busy.h"
40 #include "xfs_inode.h"
43 * Lookup the first record less than or equal to [bno, len, owner, offset]
44 * in the btree given by cur.
48 struct xfs_btree_cur *cur,
56 cur->bc_rec.r.rm_startblock = bno;
57 cur->bc_rec.r.rm_blockcount = len;
58 cur->bc_rec.r.rm_owner = owner;
59 cur->bc_rec.r.rm_offset = offset;
60 cur->bc_rec.r.rm_flags = flags;
61 return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
65 * Lookup the record exactly matching [bno, len, owner, offset]
66 * in the btree given by cur.
70 struct xfs_btree_cur *cur,
78 cur->bc_rec.r.rm_startblock = bno;
79 cur->bc_rec.r.rm_blockcount = len;
80 cur->bc_rec.r.rm_owner = owner;
81 cur->bc_rec.r.rm_offset = offset;
82 cur->bc_rec.r.rm_flags = flags;
83 return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
87 * Update the record referred to by cur to the value given
88 * by [bno, len, owner, offset].
89 * This either works (return 0) or gets an EFSCORRUPTED error.
93 struct xfs_btree_cur *cur,
94 struct xfs_rmap_irec *irec)
96 union xfs_btree_rec rec;
99 trace_xfs_rmap_update(cur->bc_mp, cur->bc_private.a.agno,
100 irec->rm_startblock, irec->rm_blockcount,
101 irec->rm_owner, irec->rm_offset, irec->rm_flags);
103 rec.rmap.rm_startblock = cpu_to_be32(irec->rm_startblock);
104 rec.rmap.rm_blockcount = cpu_to_be32(irec->rm_blockcount);
105 rec.rmap.rm_owner = cpu_to_be64(irec->rm_owner);
106 rec.rmap.rm_offset = cpu_to_be64(
107 xfs_rmap_irec_offset_pack(irec));
108 error = xfs_btree_update(cur, &rec);
110 trace_xfs_rmap_update_error(cur->bc_mp,
111 cur->bc_private.a.agno, error, _RET_IP_);
117 struct xfs_btree_cur *rcur,
127 trace_xfs_rmap_insert(rcur->bc_mp, rcur->bc_private.a.agno, agbno,
128 len, owner, offset, flags);
130 error = xfs_rmap_lookup_eq(rcur, agbno, len, owner, offset, flags, &i);
133 XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 0, done);
135 rcur->bc_rec.r.rm_startblock = agbno;
136 rcur->bc_rec.r.rm_blockcount = len;
137 rcur->bc_rec.r.rm_owner = owner;
138 rcur->bc_rec.r.rm_offset = offset;
139 rcur->bc_rec.r.rm_flags = flags;
140 error = xfs_btree_insert(rcur, &i);
143 XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 1, done);
146 trace_xfs_rmap_insert_error(rcur->bc_mp,
147 rcur->bc_private.a.agno, error, _RET_IP_);
153 struct xfs_btree_cur *rcur,
163 trace_xfs_rmap_delete(rcur->bc_mp, rcur->bc_private.a.agno, agbno,
164 len, owner, offset, flags);
166 error = xfs_rmap_lookup_eq(rcur, agbno, len, owner, offset, flags, &i);
169 XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 1, done);
171 error = xfs_btree_delete(rcur, &i);
174 XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 1, done);
177 trace_xfs_rmap_delete_error(rcur->bc_mp,
178 rcur->bc_private.a.agno, error, _RET_IP_);
182 /* Convert an internal btree record to an rmap record. */
184 xfs_rmap_btrec_to_irec(
185 union xfs_btree_rec *rec,
186 struct xfs_rmap_irec *irec)
189 irec->rm_startblock = be32_to_cpu(rec->rmap.rm_startblock);
190 irec->rm_blockcount = be32_to_cpu(rec->rmap.rm_blockcount);
191 irec->rm_owner = be64_to_cpu(rec->rmap.rm_owner);
192 return xfs_rmap_irec_offset_unpack(be64_to_cpu(rec->rmap.rm_offset),
197 * Get the data from the pointed-to record.
201 struct xfs_btree_cur *cur,
202 struct xfs_rmap_irec *irec,
205 union xfs_btree_rec *rec;
208 error = xfs_btree_get_rec(cur, &rec, stat);
212 return xfs_rmap_btrec_to_irec(rec, irec);
215 struct xfs_find_left_neighbor_info {
216 struct xfs_rmap_irec high;
217 struct xfs_rmap_irec *irec;
221 /* For each rmap given, figure out if it matches the key we want. */
223 xfs_rmap_find_left_neighbor_helper(
224 struct xfs_btree_cur *cur,
225 struct xfs_rmap_irec *rec,
228 struct xfs_find_left_neighbor_info *info = priv;
230 trace_xfs_rmap_find_left_neighbor_candidate(cur->bc_mp,
231 cur->bc_private.a.agno, rec->rm_startblock,
232 rec->rm_blockcount, rec->rm_owner, rec->rm_offset,
235 if (rec->rm_owner != info->high.rm_owner)
236 return XFS_BTREE_QUERY_RANGE_CONTINUE;
237 if (!XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) &&
238 !(rec->rm_flags & XFS_RMAP_BMBT_BLOCK) &&
239 rec->rm_offset + rec->rm_blockcount - 1 != info->high.rm_offset)
240 return XFS_BTREE_QUERY_RANGE_CONTINUE;
244 return XFS_BTREE_QUERY_RANGE_ABORT;
248 * Find the record to the left of the given extent, being careful only to
249 * return a match with the same owner and adjacent physical and logical
253 xfs_rmap_find_left_neighbor(
254 struct xfs_btree_cur *cur,
259 struct xfs_rmap_irec *irec,
262 struct xfs_find_left_neighbor_info info;
268 info.high.rm_startblock = bno - 1;
269 info.high.rm_owner = owner;
270 if (!XFS_RMAP_NON_INODE_OWNER(owner) &&
271 !(flags & XFS_RMAP_BMBT_BLOCK)) {
274 info.high.rm_offset = offset - 1;
276 info.high.rm_offset = 0;
277 info.high.rm_flags = flags;
278 info.high.rm_blockcount = 0;
282 trace_xfs_rmap_find_left_neighbor_query(cur->bc_mp,
283 cur->bc_private.a.agno, bno, 0, owner, offset, flags);
285 error = xfs_rmap_query_range(cur, &info.high, &info.high,
286 xfs_rmap_find_left_neighbor_helper, &info);
287 if (error == XFS_BTREE_QUERY_RANGE_ABORT)
290 trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp,
291 cur->bc_private.a.agno, irec->rm_startblock,
292 irec->rm_blockcount, irec->rm_owner,
293 irec->rm_offset, irec->rm_flags);
297 /* For each rmap given, figure out if it matches the key we want. */
299 xfs_rmap_lookup_le_range_helper(
300 struct xfs_btree_cur *cur,
301 struct xfs_rmap_irec *rec,
304 struct xfs_find_left_neighbor_info *info = priv;
306 trace_xfs_rmap_lookup_le_range_candidate(cur->bc_mp,
307 cur->bc_private.a.agno, rec->rm_startblock,
308 rec->rm_blockcount, rec->rm_owner, rec->rm_offset,
311 if (rec->rm_owner != info->high.rm_owner)
312 return XFS_BTREE_QUERY_RANGE_CONTINUE;
313 if (!XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) &&
314 !(rec->rm_flags & XFS_RMAP_BMBT_BLOCK) &&
315 (rec->rm_offset > info->high.rm_offset ||
316 rec->rm_offset + rec->rm_blockcount <= info->high.rm_offset))
317 return XFS_BTREE_QUERY_RANGE_CONTINUE;
321 return XFS_BTREE_QUERY_RANGE_ABORT;
325 * Find the record to the left of the given extent, being careful only to
326 * return a match with the same owner and overlapping physical and logical
327 * block ranges. This is the overlapping-interval version of
328 * xfs_rmap_lookup_le.
331 xfs_rmap_lookup_le_range(
332 struct xfs_btree_cur *cur,
337 struct xfs_rmap_irec *irec,
340 struct xfs_find_left_neighbor_info info;
343 info.high.rm_startblock = bno;
344 info.high.rm_owner = owner;
345 if (!XFS_RMAP_NON_INODE_OWNER(owner) && !(flags & XFS_RMAP_BMBT_BLOCK))
346 info.high.rm_offset = offset;
348 info.high.rm_offset = 0;
349 info.high.rm_flags = flags;
350 info.high.rm_blockcount = 0;
355 trace_xfs_rmap_lookup_le_range(cur->bc_mp,
356 cur->bc_private.a.agno, bno, 0, owner, offset, flags);
357 error = xfs_rmap_query_range(cur, &info.high, &info.high,
358 xfs_rmap_lookup_le_range_helper, &info);
359 if (error == XFS_BTREE_QUERY_RANGE_ABORT)
362 trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
363 cur->bc_private.a.agno, irec->rm_startblock,
364 irec->rm_blockcount, irec->rm_owner,
365 irec->rm_offset, irec->rm_flags);
370 * Find the extent in the rmap btree and remove it.
372 * The record we find should always be an exact match for the extent that we're
373 * looking for, since we insert them into the btree without modification.
375 * Special Case #1: when growing the filesystem, we "free" an extent when
376 * growing the last AG. This extent is new space and so it is not tracked as
377 * used space in the btree. The growfs code will pass in an owner of
378 * XFS_RMAP_OWN_NULL to indicate that it expected that there is no owner of this
379 * extent. We verify that - the extent lookup result in a record that does not
382 * Special Case #2: EFIs do not record the owner of the extent, so when
383 * recovering EFIs from the log we pass in XFS_RMAP_OWN_UNKNOWN to tell the rmap
384 * btree to ignore the owner (i.e. wildcard match) so we don't trigger
385 * corruption checks during log recovery.
389 struct xfs_btree_cur *cur,
393 struct xfs_owner_info *oinfo)
395 struct xfs_mount *mp = cur->bc_mp;
396 struct xfs_rmap_irec ltrec;
405 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
406 ignore_off = XFS_RMAP_NON_INODE_OWNER(owner) ||
407 (flags & XFS_RMAP_BMBT_BLOCK);
409 flags |= XFS_RMAP_UNWRITTEN;
410 trace_xfs_rmap_unmap(mp, cur->bc_private.a.agno, bno, len,
414 * We should always have a left record because there's a static record
415 * for the AG headers at rm_startblock == 0 created by mkfs/growfs that
416 * will not ever be removed from the tree.
418 error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, flags, &i);
421 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
423 error = xfs_rmap_get_rec(cur, <rec, &i);
426 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
427 trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
428 cur->bc_private.a.agno, ltrec.rm_startblock,
429 ltrec.rm_blockcount, ltrec.rm_owner,
430 ltrec.rm_offset, ltrec.rm_flags);
431 ltoff = ltrec.rm_offset;
434 * For growfs, the incoming extent must be beyond the left record we
435 * just found as it is new space and won't be used by anyone. This is
436 * just a corruption check as we don't actually do anything with this
437 * extent. Note that we need to use >= instead of > because it might
438 * be the case that the "left" extent goes all the way to EOFS.
440 if (owner == XFS_RMAP_OWN_NULL) {
441 XFS_WANT_CORRUPTED_GOTO(mp, bno >= ltrec.rm_startblock +
442 ltrec.rm_blockcount, out_error);
446 /* Make sure the unwritten flag matches. */
447 XFS_WANT_CORRUPTED_GOTO(mp, (flags & XFS_RMAP_UNWRITTEN) ==
448 (ltrec.rm_flags & XFS_RMAP_UNWRITTEN), out_error);
450 /* Make sure the extent we found covers the entire freeing range. */
451 XFS_WANT_CORRUPTED_GOTO(mp, ltrec.rm_startblock <= bno &&
452 ltrec.rm_startblock + ltrec.rm_blockcount >=
453 bno + len, out_error);
455 /* Make sure the owner matches what we expect to find in the tree. */
456 XFS_WANT_CORRUPTED_GOTO(mp, owner == ltrec.rm_owner ||
457 XFS_RMAP_NON_INODE_OWNER(owner), out_error);
459 /* Check the offset, if necessary. */
460 if (!XFS_RMAP_NON_INODE_OWNER(owner)) {
461 if (flags & XFS_RMAP_BMBT_BLOCK) {
462 XFS_WANT_CORRUPTED_GOTO(mp,
463 ltrec.rm_flags & XFS_RMAP_BMBT_BLOCK,
466 XFS_WANT_CORRUPTED_GOTO(mp,
467 ltrec.rm_offset <= offset, out_error);
468 XFS_WANT_CORRUPTED_GOTO(mp,
469 ltoff + ltrec.rm_blockcount >= offset + len,
474 if (ltrec.rm_startblock == bno && ltrec.rm_blockcount == len) {
475 /* exact match, simply remove the record from rmap tree */
476 trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
477 ltrec.rm_startblock, ltrec.rm_blockcount,
478 ltrec.rm_owner, ltrec.rm_offset,
480 error = xfs_btree_delete(cur, &i);
483 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
484 } else if (ltrec.rm_startblock == bno) {
486 * overlap left hand side of extent: move the start, trim the
487 * length and update the current record.
490 * Orig: |oooooooooooooooooooo|
491 * Freeing: |fffffffff|
492 * Result: |rrrrrrrrrr|
495 ltrec.rm_startblock += len;
496 ltrec.rm_blockcount -= len;
498 ltrec.rm_offset += len;
499 error = xfs_rmap_update(cur, <rec);
502 } else if (ltrec.rm_startblock + ltrec.rm_blockcount == bno + len) {
504 * overlap right hand side of extent: trim the length and update
505 * the current record.
508 * Orig: |oooooooooooooooooooo|
509 * Freeing: |fffffffff|
510 * Result: |rrrrrrrrrr|
513 ltrec.rm_blockcount -= len;
514 error = xfs_rmap_update(cur, <rec);
520 * overlap middle of extent: trim the length of the existing
521 * record to the length of the new left-extent size, increment
522 * the insertion position so we can insert a new record
523 * containing the remaining right-extent space.
526 * Orig: |oooooooooooooooooooo|
527 * Freeing: |fffffffff|
528 * Result: |rrrrr| |rrrr|
531 xfs_extlen_t orig_len = ltrec.rm_blockcount;
533 ltrec.rm_blockcount = bno - ltrec.rm_startblock;
534 error = xfs_rmap_update(cur, <rec);
538 error = xfs_btree_increment(cur, 0, &i);
542 cur->bc_rec.r.rm_startblock = bno + len;
543 cur->bc_rec.r.rm_blockcount = orig_len - len -
545 cur->bc_rec.r.rm_owner = ltrec.rm_owner;
547 cur->bc_rec.r.rm_offset = 0;
549 cur->bc_rec.r.rm_offset = offset + len;
550 cur->bc_rec.r.rm_flags = flags;
551 trace_xfs_rmap_insert(mp, cur->bc_private.a.agno,
552 cur->bc_rec.r.rm_startblock,
553 cur->bc_rec.r.rm_blockcount,
554 cur->bc_rec.r.rm_owner,
555 cur->bc_rec.r.rm_offset,
556 cur->bc_rec.r.rm_flags);
557 error = xfs_btree_insert(cur, &i);
563 trace_xfs_rmap_unmap_done(mp, cur->bc_private.a.agno, bno, len,
567 trace_xfs_rmap_unmap_error(mp, cur->bc_private.a.agno,
573 * Remove a reference to an extent in the rmap btree.
577 struct xfs_trans *tp,
578 struct xfs_buf *agbp,
582 struct xfs_owner_info *oinfo)
584 struct xfs_mount *mp = tp->t_mountp;
585 struct xfs_btree_cur *cur;
588 if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
591 cur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno);
593 error = xfs_rmap_unmap(cur, bno, len, false, oinfo);
597 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
601 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
606 * A mergeable rmap must have the same owner and the same values for
607 * the unwritten, attr_fork, and bmbt flags. The startblock and
608 * offset are checked separately.
611 xfs_rmap_is_mergeable(
612 struct xfs_rmap_irec *irec,
616 if (irec->rm_owner == XFS_RMAP_OWN_NULL)
618 if (irec->rm_owner != owner)
620 if ((flags & XFS_RMAP_UNWRITTEN) ^
621 (irec->rm_flags & XFS_RMAP_UNWRITTEN))
623 if ((flags & XFS_RMAP_ATTR_FORK) ^
624 (irec->rm_flags & XFS_RMAP_ATTR_FORK))
626 if ((flags & XFS_RMAP_BMBT_BLOCK) ^
627 (irec->rm_flags & XFS_RMAP_BMBT_BLOCK))
633 * When we allocate a new block, the first thing we do is add a reference to
634 * the extent in the rmap btree. This takes the form of a [agbno, length,
635 * owner, offset] record. Flags are encoded in the high bits of the offset
640 struct xfs_btree_cur *cur,
644 struct xfs_owner_info *oinfo)
646 struct xfs_mount *mp = cur->bc_mp;
647 struct xfs_rmap_irec ltrec;
648 struct xfs_rmap_irec gtrec;
655 unsigned int flags = 0;
658 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
660 ignore_off = XFS_RMAP_NON_INODE_OWNER(owner) ||
661 (flags & XFS_RMAP_BMBT_BLOCK);
663 flags |= XFS_RMAP_UNWRITTEN;
664 trace_xfs_rmap_map(mp, cur->bc_private.a.agno, bno, len,
668 * For the initial lookup, look for an exact match or the left-adjacent
669 * record for our insertion point. This will also give us the record for
670 * start block contiguity tests.
672 error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, flags,
676 XFS_WANT_CORRUPTED_GOTO(mp, have_lt == 1, out_error);
678 error = xfs_rmap_get_rec(cur, <rec, &have_lt);
681 XFS_WANT_CORRUPTED_GOTO(mp, have_lt == 1, out_error);
682 trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
683 cur->bc_private.a.agno, ltrec.rm_startblock,
684 ltrec.rm_blockcount, ltrec.rm_owner,
685 ltrec.rm_offset, ltrec.rm_flags);
687 if (!xfs_rmap_is_mergeable(<rec, owner, flags))
690 XFS_WANT_CORRUPTED_GOTO(mp,
692 ltrec.rm_startblock + ltrec.rm_blockcount <= bno, out_error);
695 * Increment the cursor to see if we have a right-adjacent record to our
696 * insertion point. This will give us the record for end block
699 error = xfs_btree_increment(cur, 0, &have_gt);
703 error = xfs_rmap_get_rec(cur, >rec, &have_gt);
706 XFS_WANT_CORRUPTED_GOTO(mp, have_gt == 1, out_error);
707 XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= gtrec.rm_startblock,
709 trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp,
710 cur->bc_private.a.agno, gtrec.rm_startblock,
711 gtrec.rm_blockcount, gtrec.rm_owner,
712 gtrec.rm_offset, gtrec.rm_flags);
713 if (!xfs_rmap_is_mergeable(>rec, owner, flags))
718 * Note: cursor currently points one record to the right of ltrec, even
719 * if there is no record in the tree to the right.
722 ltrec.rm_startblock + ltrec.rm_blockcount == bno &&
723 (ignore_off || ltrec.rm_offset + ltrec.rm_blockcount == offset)) {
725 * left edge contiguous, merge into left record.
729 * adding: |aaaaaaaaa|
730 * result: |rrrrrrrrrrrrrrrrrrr|
733 ltrec.rm_blockcount += len;
735 bno + len == gtrec.rm_startblock &&
736 (ignore_off || offset + len == gtrec.rm_offset) &&
737 (unsigned long)ltrec.rm_blockcount + len +
738 gtrec.rm_blockcount <= XFS_RMAP_LEN_MAX) {
740 * right edge also contiguous, delete right record
741 * and merge into left record.
743 * ltbno ltlen gtbno gtlen
744 * orig: |ooooooooo| |ooooooooo|
745 * adding: |aaaaaaaaa|
746 * result: |rrrrrrrrrrrrrrrrrrrrrrrrrrrrr|
748 ltrec.rm_blockcount += gtrec.rm_blockcount;
749 trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
755 error = xfs_btree_delete(cur, &i);
758 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
761 /* point the cursor back to the left record and update */
762 error = xfs_btree_decrement(cur, 0, &have_gt);
765 error = xfs_rmap_update(cur, <rec);
768 } else if (have_gt &&
769 bno + len == gtrec.rm_startblock &&
770 (ignore_off || offset + len == gtrec.rm_offset)) {
772 * right edge contiguous, merge into right record.
776 * adding: |aaaaaaaaa|
777 * Result: |rrrrrrrrrrrrrrrrrrr|
780 gtrec.rm_startblock = bno;
781 gtrec.rm_blockcount += len;
783 gtrec.rm_offset = offset;
784 error = xfs_rmap_update(cur, >rec);
789 * no contiguous edge with identical owner, insert
790 * new record at current cursor position.
792 cur->bc_rec.r.rm_startblock = bno;
793 cur->bc_rec.r.rm_blockcount = len;
794 cur->bc_rec.r.rm_owner = owner;
795 cur->bc_rec.r.rm_offset = offset;
796 cur->bc_rec.r.rm_flags = flags;
797 trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno, len,
798 owner, offset, flags);
799 error = xfs_btree_insert(cur, &i);
802 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
805 trace_xfs_rmap_map_done(mp, cur->bc_private.a.agno, bno, len,
809 trace_xfs_rmap_map_error(mp, cur->bc_private.a.agno,
815 * Add a reference to an extent in the rmap btree.
819 struct xfs_trans *tp,
820 struct xfs_buf *agbp,
824 struct xfs_owner_info *oinfo)
826 struct xfs_mount *mp = tp->t_mountp;
827 struct xfs_btree_cur *cur;
830 if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
833 cur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno);
834 error = xfs_rmap_map(cur, bno, len, false, oinfo);
838 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
842 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
846 #define RMAP_LEFT_CONTIG (1 << 0)
847 #define RMAP_RIGHT_CONTIG (1 << 1)
848 #define RMAP_LEFT_FILLING (1 << 2)
849 #define RMAP_RIGHT_FILLING (1 << 3)
850 #define RMAP_LEFT_VALID (1 << 6)
851 #define RMAP_RIGHT_VALID (1 << 7)
859 * Convert an unwritten extent to a real extent or vice versa.
860 * Does not handle overlapping extents.
864 struct xfs_btree_cur *cur,
868 struct xfs_owner_info *oinfo)
870 struct xfs_mount *mp = cur->bc_mp;
871 struct xfs_rmap_irec r[4]; /* neighbor extent entries */
872 /* left is 0, right is 1, prev is 2 */
879 unsigned int flags = 0;
884 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
885 ASSERT(!(XFS_RMAP_NON_INODE_OWNER(owner) ||
886 (flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK))));
887 oldext = unwritten ? XFS_RMAP_UNWRITTEN : 0;
888 new_endoff = offset + len;
889 trace_xfs_rmap_convert(mp, cur->bc_private.a.agno, bno, len,
893 * For the initial lookup, look for an exact match or the left-adjacent
894 * record for our insertion point. This will also give us the record for
895 * start block contiguity tests.
897 error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, oldext, &i);
900 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
902 error = xfs_rmap_get_rec(cur, &PREV, &i);
905 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
906 trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
907 cur->bc_private.a.agno, PREV.rm_startblock,
908 PREV.rm_blockcount, PREV.rm_owner,
909 PREV.rm_offset, PREV.rm_flags);
911 ASSERT(PREV.rm_offset <= offset);
912 ASSERT(PREV.rm_offset + PREV.rm_blockcount >= new_endoff);
913 ASSERT((PREV.rm_flags & XFS_RMAP_UNWRITTEN) == oldext);
914 newext = ~oldext & XFS_RMAP_UNWRITTEN;
917 * Set flags determining what part of the previous oldext allocation
918 * extent is being replaced by a newext allocation.
920 if (PREV.rm_offset == offset)
921 state |= RMAP_LEFT_FILLING;
922 if (PREV.rm_offset + PREV.rm_blockcount == new_endoff)
923 state |= RMAP_RIGHT_FILLING;
926 * Decrement the cursor to see if we have a left-adjacent record to our
927 * insertion point. This will give us the record for end block
930 error = xfs_btree_decrement(cur, 0, &i);
934 state |= RMAP_LEFT_VALID;
935 error = xfs_rmap_get_rec(cur, &LEFT, &i);
938 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
939 XFS_WANT_CORRUPTED_GOTO(mp,
940 LEFT.rm_startblock + LEFT.rm_blockcount <= bno,
942 trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp,
943 cur->bc_private.a.agno, LEFT.rm_startblock,
944 LEFT.rm_blockcount, LEFT.rm_owner,
945 LEFT.rm_offset, LEFT.rm_flags);
946 if (LEFT.rm_startblock + LEFT.rm_blockcount == bno &&
947 LEFT.rm_offset + LEFT.rm_blockcount == offset &&
948 xfs_rmap_is_mergeable(&LEFT, owner, newext))
949 state |= RMAP_LEFT_CONTIG;
953 * Increment the cursor to see if we have a right-adjacent record to our
954 * insertion point. This will give us the record for end block
957 error = xfs_btree_increment(cur, 0, &i);
960 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
961 error = xfs_btree_increment(cur, 0, &i);
965 state |= RMAP_RIGHT_VALID;
966 error = xfs_rmap_get_rec(cur, &RIGHT, &i);
969 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
970 XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= RIGHT.rm_startblock,
972 trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp,
973 cur->bc_private.a.agno, RIGHT.rm_startblock,
974 RIGHT.rm_blockcount, RIGHT.rm_owner,
975 RIGHT.rm_offset, RIGHT.rm_flags);
976 if (bno + len == RIGHT.rm_startblock &&
977 offset + len == RIGHT.rm_offset &&
978 xfs_rmap_is_mergeable(&RIGHT, owner, newext))
979 state |= RMAP_RIGHT_CONTIG;
982 /* check that left + prev + right is not too long */
983 if ((state & (RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG |
984 RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG)) ==
985 (RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG |
986 RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG) &&
987 (unsigned long)LEFT.rm_blockcount + len +
988 RIGHT.rm_blockcount > XFS_RMAP_LEN_MAX)
989 state &= ~RMAP_RIGHT_CONTIG;
991 trace_xfs_rmap_convert_state(mp, cur->bc_private.a.agno, state,
994 /* reset the cursor back to PREV */
995 error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, oldext, &i);
998 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1001 * Switch out based on the FILLING and CONTIG state bits.
1003 switch (state & (RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG |
1004 RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG)) {
1005 case RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG |
1006 RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG:
1008 * Setting all of a previous oldext extent to newext.
1009 * The left and right neighbors are both contiguous with new.
1011 error = xfs_btree_increment(cur, 0, &i);
1014 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1015 trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
1016 RIGHT.rm_startblock, RIGHT.rm_blockcount,
1017 RIGHT.rm_owner, RIGHT.rm_offset,
1019 error = xfs_btree_delete(cur, &i);
1022 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1023 error = xfs_btree_decrement(cur, 0, &i);
1026 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1027 trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
1028 PREV.rm_startblock, PREV.rm_blockcount,
1029 PREV.rm_owner, PREV.rm_offset,
1031 error = xfs_btree_delete(cur, &i);
1034 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1035 error = xfs_btree_decrement(cur, 0, &i);
1038 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1040 NEW.rm_blockcount += PREV.rm_blockcount + RIGHT.rm_blockcount;
1041 error = xfs_rmap_update(cur, &NEW);
1046 case RMAP_LEFT_FILLING | RMAP_RIGHT_FILLING | RMAP_LEFT_CONTIG:
1048 * Setting all of a previous oldext extent to newext.
1049 * The left neighbor is contiguous, the right is not.
1051 trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
1052 PREV.rm_startblock, PREV.rm_blockcount,
1053 PREV.rm_owner, PREV.rm_offset,
1055 error = xfs_btree_delete(cur, &i);
1058 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1059 error = xfs_btree_decrement(cur, 0, &i);
1062 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1064 NEW.rm_blockcount += PREV.rm_blockcount;
1065 error = xfs_rmap_update(cur, &NEW);
1070 case RMAP_LEFT_FILLING | RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG:
1072 * Setting all of a previous oldext extent to newext.
1073 * The right neighbor is contiguous, the left is not.
1075 error = xfs_btree_increment(cur, 0, &i);
1078 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1079 trace_xfs_rmap_delete(mp, cur->bc_private.a.agno,
1080 RIGHT.rm_startblock, RIGHT.rm_blockcount,
1081 RIGHT.rm_owner, RIGHT.rm_offset,
1083 error = xfs_btree_delete(cur, &i);
1086 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1087 error = xfs_btree_decrement(cur, 0, &i);
1090 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1092 NEW.rm_blockcount = len + RIGHT.rm_blockcount;
1093 NEW.rm_flags = newext;
1094 error = xfs_rmap_update(cur, &NEW);
1099 case RMAP_LEFT_FILLING | RMAP_RIGHT_FILLING:
1101 * Setting all of a previous oldext extent to newext.
1102 * Neither the left nor right neighbors are contiguous with
1106 NEW.rm_flags = newext;
1107 error = xfs_rmap_update(cur, &NEW);
1112 case RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG:
1114 * Setting the first part of a previous oldext extent to newext.
1115 * The left neighbor is contiguous.
1118 NEW.rm_offset += len;
1119 NEW.rm_startblock += len;
1120 NEW.rm_blockcount -= len;
1121 error = xfs_rmap_update(cur, &NEW);
1124 error = xfs_btree_decrement(cur, 0, &i);
1128 NEW.rm_blockcount += len;
1129 error = xfs_rmap_update(cur, &NEW);
1134 case RMAP_LEFT_FILLING:
1136 * Setting the first part of a previous oldext extent to newext.
1137 * The left neighbor is not contiguous.
1140 NEW.rm_startblock += len;
1141 NEW.rm_offset += len;
1142 NEW.rm_blockcount -= len;
1143 error = xfs_rmap_update(cur, &NEW);
1146 NEW.rm_startblock = bno;
1147 NEW.rm_owner = owner;
1148 NEW.rm_offset = offset;
1149 NEW.rm_blockcount = len;
1150 NEW.rm_flags = newext;
1151 cur->bc_rec.r = NEW;
1152 trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno,
1153 len, owner, offset, newext);
1154 error = xfs_btree_insert(cur, &i);
1157 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1160 case RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG:
1162 * Setting the last part of a previous oldext extent to newext.
1163 * The right neighbor is contiguous with the new allocation.
1166 NEW.rm_blockcount -= len;
1167 error = xfs_rmap_update(cur, &NEW);
1170 error = xfs_btree_increment(cur, 0, &i);
1174 NEW.rm_offset = offset;
1175 NEW.rm_startblock = bno;
1176 NEW.rm_blockcount += len;
1177 error = xfs_rmap_update(cur, &NEW);
1182 case RMAP_RIGHT_FILLING:
1184 * Setting the last part of a previous oldext extent to newext.
1185 * The right neighbor is not contiguous.
1188 NEW.rm_blockcount -= len;
1189 error = xfs_rmap_update(cur, &NEW);
1192 error = xfs_rmap_lookup_eq(cur, bno, len, owner, offset,
1196 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
1197 NEW.rm_startblock = bno;
1198 NEW.rm_owner = owner;
1199 NEW.rm_offset = offset;
1200 NEW.rm_blockcount = len;
1201 NEW.rm_flags = newext;
1202 cur->bc_rec.r = NEW;
1203 trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno,
1204 len, owner, offset, newext);
1205 error = xfs_btree_insert(cur, &i);
1208 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1213 * Setting the middle part of a previous oldext extent to
1214 * newext. Contiguity is impossible here.
1215 * One extent becomes three extents.
1217 /* new right extent - oldext */
1218 NEW.rm_startblock = bno + len;
1219 NEW.rm_owner = owner;
1220 NEW.rm_offset = new_endoff;
1221 NEW.rm_blockcount = PREV.rm_offset + PREV.rm_blockcount -
1223 NEW.rm_flags = PREV.rm_flags;
1224 error = xfs_rmap_update(cur, &NEW);
1227 /* new left extent - oldext */
1229 NEW.rm_blockcount = offset - PREV.rm_offset;
1230 cur->bc_rec.r = NEW;
1231 trace_xfs_rmap_insert(mp, cur->bc_private.a.agno,
1232 NEW.rm_startblock, NEW.rm_blockcount,
1233 NEW.rm_owner, NEW.rm_offset,
1235 error = xfs_btree_insert(cur, &i);
1238 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1240 * Reset the cursor to the position of the new extent
1241 * we are about to insert as we can't trust it after
1242 * the previous insert.
1244 error = xfs_rmap_lookup_eq(cur, bno, len, owner, offset,
1248 XFS_WANT_CORRUPTED_GOTO(mp, i == 0, done);
1249 /* new middle extent - newext */
1250 cur->bc_rec.r.rm_flags &= ~XFS_RMAP_UNWRITTEN;
1251 cur->bc_rec.r.rm_flags |= newext;
1252 trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno, len,
1253 owner, offset, newext);
1254 error = xfs_btree_insert(cur, &i);
1257 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1260 case RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG | RMAP_RIGHT_CONTIG:
1261 case RMAP_RIGHT_FILLING | RMAP_LEFT_CONTIG | RMAP_RIGHT_CONTIG:
1262 case RMAP_LEFT_FILLING | RMAP_RIGHT_CONTIG:
1263 case RMAP_RIGHT_FILLING | RMAP_LEFT_CONTIG:
1264 case RMAP_LEFT_CONTIG | RMAP_RIGHT_CONTIG:
1265 case RMAP_LEFT_CONTIG:
1266 case RMAP_RIGHT_CONTIG:
1268 * These cases are all impossible.
1273 trace_xfs_rmap_convert_done(mp, cur->bc_private.a.agno, bno, len,
1277 trace_xfs_rmap_convert_error(cur->bc_mp,
1278 cur->bc_private.a.agno, error, _RET_IP_);
1283 * Convert an unwritten extent to a real extent or vice versa. If there is no
1284 * possibility of overlapping extents, delegate to the simpler convert
1288 xfs_rmap_convert_shared(
1289 struct xfs_btree_cur *cur,
1293 struct xfs_owner_info *oinfo)
1295 struct xfs_mount *mp = cur->bc_mp;
1296 struct xfs_rmap_irec r[4]; /* neighbor extent entries */
1297 /* left is 0, right is 1, prev is 2 */
1301 uint64_t new_endoff;
1302 unsigned int oldext;
1303 unsigned int newext;
1304 unsigned int flags = 0;
1309 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
1310 ASSERT(!(XFS_RMAP_NON_INODE_OWNER(owner) ||
1311 (flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK))));
1312 oldext = unwritten ? XFS_RMAP_UNWRITTEN : 0;
1313 new_endoff = offset + len;
1314 trace_xfs_rmap_convert(mp, cur->bc_private.a.agno, bno, len,
1318 * For the initial lookup, look for and exact match or the left-adjacent
1319 * record for our insertion point. This will also give us the record for
1320 * start block contiguity tests.
1322 error = xfs_rmap_lookup_le_range(cur, bno, owner, offset, flags,
1324 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1326 ASSERT(PREV.rm_offset <= offset);
1327 ASSERT(PREV.rm_offset + PREV.rm_blockcount >= new_endoff);
1328 ASSERT((PREV.rm_flags & XFS_RMAP_UNWRITTEN) == oldext);
1329 newext = ~oldext & XFS_RMAP_UNWRITTEN;
1332 * Set flags determining what part of the previous oldext allocation
1333 * extent is being replaced by a newext allocation.
1335 if (PREV.rm_offset == offset)
1336 state |= RMAP_LEFT_FILLING;
1337 if (PREV.rm_offset + PREV.rm_blockcount == new_endoff)
1338 state |= RMAP_RIGHT_FILLING;
1340 /* Is there a left record that abuts our range? */
1341 error = xfs_rmap_find_left_neighbor(cur, bno, owner, offset, newext,
1346 state |= RMAP_LEFT_VALID;
1347 XFS_WANT_CORRUPTED_GOTO(mp,
1348 LEFT.rm_startblock + LEFT.rm_blockcount <= bno,
1350 if (xfs_rmap_is_mergeable(&LEFT, owner, newext))
1351 state |= RMAP_LEFT_CONTIG;
1354 /* Is there a right record that abuts our range? */
1355 error = xfs_rmap_lookup_eq(cur, bno + len, len, owner, offset + len,
1360 state |= RMAP_RIGHT_VALID;
1361 error = xfs_rmap_get_rec(cur, &RIGHT, &i);
1364 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1365 XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= RIGHT.rm_startblock,
1367 trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp,
1368 cur->bc_private.a.agno, RIGHT.rm_startblock,
1369 RIGHT.rm_blockcount, RIGHT.rm_owner,
1370 RIGHT.rm_offset, RIGHT.rm_flags);
1371 if (xfs_rmap_is_mergeable(&RIGHT, owner, newext))
1372 state |= RMAP_RIGHT_CONTIG;
1375 /* check that left + prev + right is not too long */
1376 if ((state & (RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG |
1377 RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG)) ==
1378 (RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG |
1379 RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG) &&
1380 (unsigned long)LEFT.rm_blockcount + len +
1381 RIGHT.rm_blockcount > XFS_RMAP_LEN_MAX)
1382 state &= ~RMAP_RIGHT_CONTIG;
1384 trace_xfs_rmap_convert_state(mp, cur->bc_private.a.agno, state,
1387 * Switch out based on the FILLING and CONTIG state bits.
1389 switch (state & (RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG |
1390 RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG)) {
1391 case RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG |
1392 RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG:
1394 * Setting all of a previous oldext extent to newext.
1395 * The left and right neighbors are both contiguous with new.
1397 error = xfs_rmap_delete(cur, RIGHT.rm_startblock,
1398 RIGHT.rm_blockcount, RIGHT.rm_owner,
1399 RIGHT.rm_offset, RIGHT.rm_flags);
1402 error = xfs_rmap_delete(cur, PREV.rm_startblock,
1403 PREV.rm_blockcount, PREV.rm_owner,
1404 PREV.rm_offset, PREV.rm_flags);
1408 error = xfs_rmap_lookup_eq(cur, NEW.rm_startblock,
1409 NEW.rm_blockcount, NEW.rm_owner,
1410 NEW.rm_offset, NEW.rm_flags, &i);
1413 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1414 NEW.rm_blockcount += PREV.rm_blockcount + RIGHT.rm_blockcount;
1415 error = xfs_rmap_update(cur, &NEW);
1420 case RMAP_LEFT_FILLING | RMAP_RIGHT_FILLING | RMAP_LEFT_CONTIG:
1422 * Setting all of a previous oldext extent to newext.
1423 * The left neighbor is contiguous, the right is not.
1425 error = xfs_rmap_delete(cur, PREV.rm_startblock,
1426 PREV.rm_blockcount, PREV.rm_owner,
1427 PREV.rm_offset, PREV.rm_flags);
1431 error = xfs_rmap_lookup_eq(cur, NEW.rm_startblock,
1432 NEW.rm_blockcount, NEW.rm_owner,
1433 NEW.rm_offset, NEW.rm_flags, &i);
1436 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1437 NEW.rm_blockcount += PREV.rm_blockcount;
1438 error = xfs_rmap_update(cur, &NEW);
1443 case RMAP_LEFT_FILLING | RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG:
1445 * Setting all of a previous oldext extent to newext.
1446 * The right neighbor is contiguous, the left is not.
1448 error = xfs_rmap_delete(cur, RIGHT.rm_startblock,
1449 RIGHT.rm_blockcount, RIGHT.rm_owner,
1450 RIGHT.rm_offset, RIGHT.rm_flags);
1454 error = xfs_rmap_lookup_eq(cur, NEW.rm_startblock,
1455 NEW.rm_blockcount, NEW.rm_owner,
1456 NEW.rm_offset, NEW.rm_flags, &i);
1459 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1460 NEW.rm_blockcount += RIGHT.rm_blockcount;
1461 NEW.rm_flags = RIGHT.rm_flags;
1462 error = xfs_rmap_update(cur, &NEW);
1467 case RMAP_LEFT_FILLING | RMAP_RIGHT_FILLING:
1469 * Setting all of a previous oldext extent to newext.
1470 * Neither the left nor right neighbors are contiguous with
1474 error = xfs_rmap_lookup_eq(cur, NEW.rm_startblock,
1475 NEW.rm_blockcount, NEW.rm_owner,
1476 NEW.rm_offset, NEW.rm_flags, &i);
1479 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1480 NEW.rm_flags = newext;
1481 error = xfs_rmap_update(cur, &NEW);
1486 case RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG:
1488 * Setting the first part of a previous oldext extent to newext.
1489 * The left neighbor is contiguous.
1492 error = xfs_rmap_delete(cur, NEW.rm_startblock,
1493 NEW.rm_blockcount, NEW.rm_owner,
1494 NEW.rm_offset, NEW.rm_flags);
1497 NEW.rm_offset += len;
1498 NEW.rm_startblock += len;
1499 NEW.rm_blockcount -= len;
1500 error = xfs_rmap_insert(cur, NEW.rm_startblock,
1501 NEW.rm_blockcount, NEW.rm_owner,
1502 NEW.rm_offset, NEW.rm_flags);
1506 error = xfs_rmap_lookup_eq(cur, NEW.rm_startblock,
1507 NEW.rm_blockcount, NEW.rm_owner,
1508 NEW.rm_offset, NEW.rm_flags, &i);
1511 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1512 NEW.rm_blockcount += len;
1513 error = xfs_rmap_update(cur, &NEW);
1518 case RMAP_LEFT_FILLING:
1520 * Setting the first part of a previous oldext extent to newext.
1521 * The left neighbor is not contiguous.
1524 error = xfs_rmap_delete(cur, NEW.rm_startblock,
1525 NEW.rm_blockcount, NEW.rm_owner,
1526 NEW.rm_offset, NEW.rm_flags);
1529 NEW.rm_offset += len;
1530 NEW.rm_startblock += len;
1531 NEW.rm_blockcount -= len;
1532 error = xfs_rmap_insert(cur, NEW.rm_startblock,
1533 NEW.rm_blockcount, NEW.rm_owner,
1534 NEW.rm_offset, NEW.rm_flags);
1537 error = xfs_rmap_insert(cur, bno, len, owner, offset, newext);
1542 case RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG:
1544 * Setting the last part of a previous oldext extent to newext.
1545 * The right neighbor is contiguous with the new allocation.
1548 error = xfs_rmap_lookup_eq(cur, NEW.rm_startblock,
1549 NEW.rm_blockcount, NEW.rm_owner,
1550 NEW.rm_offset, NEW.rm_flags, &i);
1553 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1554 NEW.rm_blockcount = offset - NEW.rm_offset;
1555 error = xfs_rmap_update(cur, &NEW);
1559 error = xfs_rmap_delete(cur, NEW.rm_startblock,
1560 NEW.rm_blockcount, NEW.rm_owner,
1561 NEW.rm_offset, NEW.rm_flags);
1564 NEW.rm_offset = offset;
1565 NEW.rm_startblock = bno;
1566 NEW.rm_blockcount += len;
1567 error = xfs_rmap_insert(cur, NEW.rm_startblock,
1568 NEW.rm_blockcount, NEW.rm_owner,
1569 NEW.rm_offset, NEW.rm_flags);
1574 case RMAP_RIGHT_FILLING:
1576 * Setting the last part of a previous oldext extent to newext.
1577 * The right neighbor is not contiguous.
1580 error = xfs_rmap_lookup_eq(cur, NEW.rm_startblock,
1581 NEW.rm_blockcount, NEW.rm_owner,
1582 NEW.rm_offset, NEW.rm_flags, &i);
1585 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1586 NEW.rm_blockcount -= len;
1587 error = xfs_rmap_update(cur, &NEW);
1590 error = xfs_rmap_insert(cur, bno, len, owner, offset, newext);
1597 * Setting the middle part of a previous oldext extent to
1598 * newext. Contiguity is impossible here.
1599 * One extent becomes three extents.
1601 /* new right extent - oldext */
1602 NEW.rm_startblock = bno + len;
1603 NEW.rm_owner = owner;
1604 NEW.rm_offset = new_endoff;
1605 NEW.rm_blockcount = PREV.rm_offset + PREV.rm_blockcount -
1607 NEW.rm_flags = PREV.rm_flags;
1608 error = xfs_rmap_insert(cur, NEW.rm_startblock,
1609 NEW.rm_blockcount, NEW.rm_owner, NEW.rm_offset,
1613 /* new left extent - oldext */
1615 error = xfs_rmap_lookup_eq(cur, NEW.rm_startblock,
1616 NEW.rm_blockcount, NEW.rm_owner,
1617 NEW.rm_offset, NEW.rm_flags, &i);
1620 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done);
1621 NEW.rm_blockcount = offset - NEW.rm_offset;
1622 error = xfs_rmap_update(cur, &NEW);
1625 /* new middle extent - newext */
1626 NEW.rm_startblock = bno;
1627 NEW.rm_blockcount = len;
1628 NEW.rm_owner = owner;
1629 NEW.rm_offset = offset;
1630 NEW.rm_flags = newext;
1631 error = xfs_rmap_insert(cur, NEW.rm_startblock,
1632 NEW.rm_blockcount, NEW.rm_owner, NEW.rm_offset,
1638 case RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG | RMAP_RIGHT_CONTIG:
1639 case RMAP_RIGHT_FILLING | RMAP_LEFT_CONTIG | RMAP_RIGHT_CONTIG:
1640 case RMAP_LEFT_FILLING | RMAP_RIGHT_CONTIG:
1641 case RMAP_RIGHT_FILLING | RMAP_LEFT_CONTIG:
1642 case RMAP_LEFT_CONTIG | RMAP_RIGHT_CONTIG:
1643 case RMAP_LEFT_CONTIG:
1644 case RMAP_RIGHT_CONTIG:
1646 * These cases are all impossible.
1651 trace_xfs_rmap_convert_done(mp, cur->bc_private.a.agno, bno, len,
1655 trace_xfs_rmap_convert_error(cur->bc_mp,
1656 cur->bc_private.a.agno, error, _RET_IP_);
1666 * Find an extent in the rmap btree and unmap it. For rmap extent types that
1667 * can overlap (data fork rmaps on reflink filesystems) we must be careful
1668 * that the prev/next records in the btree might belong to another owner.
1669 * Therefore we must use delete+insert to alter any of the key fields.
1671 * For every other situation there can only be one owner for a given extent,
1672 * so we can call the regular _free function.
1675 xfs_rmap_unmap_shared(
1676 struct xfs_btree_cur *cur,
1680 struct xfs_owner_info *oinfo)
1682 struct xfs_mount *mp = cur->bc_mp;
1683 struct xfs_rmap_irec ltrec;
1691 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
1693 flags |= XFS_RMAP_UNWRITTEN;
1694 trace_xfs_rmap_unmap(mp, cur->bc_private.a.agno, bno, len,
1698 * We should always have a left record because there's a static record
1699 * for the AG headers at rm_startblock == 0 created by mkfs/growfs that
1700 * will not ever be removed from the tree.
1702 error = xfs_rmap_lookup_le_range(cur, bno, owner, offset, flags,
1706 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
1707 ltoff = ltrec.rm_offset;
1709 /* Make sure the extent we found covers the entire freeing range. */
1710 XFS_WANT_CORRUPTED_GOTO(mp, ltrec.rm_startblock <= bno &&
1711 ltrec.rm_startblock + ltrec.rm_blockcount >=
1712 bno + len, out_error);
1714 /* Make sure the owner matches what we expect to find in the tree. */
1715 XFS_WANT_CORRUPTED_GOTO(mp, owner == ltrec.rm_owner, out_error);
1717 /* Make sure the unwritten flag matches. */
1718 XFS_WANT_CORRUPTED_GOTO(mp, (flags & XFS_RMAP_UNWRITTEN) ==
1719 (ltrec.rm_flags & XFS_RMAP_UNWRITTEN), out_error);
1721 /* Check the offset. */
1722 XFS_WANT_CORRUPTED_GOTO(mp, ltrec.rm_offset <= offset, out_error);
1723 XFS_WANT_CORRUPTED_GOTO(mp, offset <= ltoff + ltrec.rm_blockcount,
1726 if (ltrec.rm_startblock == bno && ltrec.rm_blockcount == len) {
1727 /* Exact match, simply remove the record from rmap tree. */
1728 error = xfs_rmap_delete(cur, ltrec.rm_startblock,
1729 ltrec.rm_blockcount, ltrec.rm_owner,
1730 ltrec.rm_offset, ltrec.rm_flags);
1733 } else if (ltrec.rm_startblock == bno) {
1735 * Overlap left hand side of extent: move the start, trim the
1736 * length and update the current record.
1739 * Orig: |oooooooooooooooooooo|
1740 * Freeing: |fffffffff|
1741 * Result: |rrrrrrrrrr|
1745 /* Delete prev rmap. */
1746 error = xfs_rmap_delete(cur, ltrec.rm_startblock,
1747 ltrec.rm_blockcount, ltrec.rm_owner,
1748 ltrec.rm_offset, ltrec.rm_flags);
1752 /* Add an rmap at the new offset. */
1753 ltrec.rm_startblock += len;
1754 ltrec.rm_blockcount -= len;
1755 ltrec.rm_offset += len;
1756 error = xfs_rmap_insert(cur, ltrec.rm_startblock,
1757 ltrec.rm_blockcount, ltrec.rm_owner,
1758 ltrec.rm_offset, ltrec.rm_flags);
1761 } else if (ltrec.rm_startblock + ltrec.rm_blockcount == bno + len) {
1763 * Overlap right hand side of extent: trim the length and
1764 * update the current record.
1767 * Orig: |oooooooooooooooooooo|
1768 * Freeing: |fffffffff|
1769 * Result: |rrrrrrrrrr|
1772 error = xfs_rmap_lookup_eq(cur, ltrec.rm_startblock,
1773 ltrec.rm_blockcount, ltrec.rm_owner,
1774 ltrec.rm_offset, ltrec.rm_flags, &i);
1777 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
1778 ltrec.rm_blockcount -= len;
1779 error = xfs_rmap_update(cur, <rec);
1784 * Overlap middle of extent: trim the length of the existing
1785 * record to the length of the new left-extent size, increment
1786 * the insertion position so we can insert a new record
1787 * containing the remaining right-extent space.
1790 * Orig: |oooooooooooooooooooo|
1791 * Freeing: |fffffffff|
1792 * Result: |rrrrr| |rrrr|
1795 xfs_extlen_t orig_len = ltrec.rm_blockcount;
1797 /* Shrink the left side of the rmap */
1798 error = xfs_rmap_lookup_eq(cur, ltrec.rm_startblock,
1799 ltrec.rm_blockcount, ltrec.rm_owner,
1800 ltrec.rm_offset, ltrec.rm_flags, &i);
1803 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
1804 ltrec.rm_blockcount = bno - ltrec.rm_startblock;
1805 error = xfs_rmap_update(cur, <rec);
1809 /* Add an rmap at the new offset */
1810 error = xfs_rmap_insert(cur, bno + len,
1811 orig_len - len - ltrec.rm_blockcount,
1812 ltrec.rm_owner, offset + len,
1818 trace_xfs_rmap_unmap_done(mp, cur->bc_private.a.agno, bno, len,
1822 trace_xfs_rmap_unmap_error(cur->bc_mp,
1823 cur->bc_private.a.agno, error, _RET_IP_);
1828 * Find an extent in the rmap btree and map it. For rmap extent types that
1829 * can overlap (data fork rmaps on reflink filesystems) we must be careful
1830 * that the prev/next records in the btree might belong to another owner.
1831 * Therefore we must use delete+insert to alter any of the key fields.
1833 * For every other situation there can only be one owner for a given extent,
1834 * so we can call the regular _alloc function.
1837 xfs_rmap_map_shared(
1838 struct xfs_btree_cur *cur,
1842 struct xfs_owner_info *oinfo)
1844 struct xfs_mount *mp = cur->bc_mp;
1845 struct xfs_rmap_irec ltrec;
1846 struct xfs_rmap_irec gtrec;
1853 unsigned int flags = 0;
1855 xfs_owner_info_unpack(oinfo, &owner, &offset, &flags);
1857 flags |= XFS_RMAP_UNWRITTEN;
1858 trace_xfs_rmap_map(mp, cur->bc_private.a.agno, bno, len,
1861 /* Is there a left record that abuts our range? */
1862 error = xfs_rmap_find_left_neighbor(cur, bno, owner, offset, flags,
1867 !xfs_rmap_is_mergeable(<rec, owner, flags))
1870 /* Is there a right record that abuts our range? */
1871 error = xfs_rmap_lookup_eq(cur, bno + len, len, owner, offset + len,
1876 error = xfs_rmap_get_rec(cur, >rec, &have_gt);
1879 XFS_WANT_CORRUPTED_GOTO(mp, have_gt == 1, out_error);
1880 trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp,
1881 cur->bc_private.a.agno, gtrec.rm_startblock,
1882 gtrec.rm_blockcount, gtrec.rm_owner,
1883 gtrec.rm_offset, gtrec.rm_flags);
1885 if (!xfs_rmap_is_mergeable(>rec, owner, flags))
1890 ltrec.rm_startblock + ltrec.rm_blockcount == bno &&
1891 ltrec.rm_offset + ltrec.rm_blockcount == offset) {
1893 * Left edge contiguous, merge into left record.
1897 * adding: |aaaaaaaaa|
1898 * result: |rrrrrrrrrrrrrrrrrrr|
1901 ltrec.rm_blockcount += len;
1903 bno + len == gtrec.rm_startblock &&
1904 offset + len == gtrec.rm_offset) {
1906 * Right edge also contiguous, delete right record
1907 * and merge into left record.
1909 * ltbno ltlen gtbno gtlen
1910 * orig: |ooooooooo| |ooooooooo|
1911 * adding: |aaaaaaaaa|
1912 * result: |rrrrrrrrrrrrrrrrrrrrrrrrrrrrr|
1914 ltrec.rm_blockcount += gtrec.rm_blockcount;
1915 error = xfs_rmap_delete(cur, gtrec.rm_startblock,
1916 gtrec.rm_blockcount, gtrec.rm_owner,
1917 gtrec.rm_offset, gtrec.rm_flags);
1922 /* Point the cursor back to the left record and update. */
1923 error = xfs_rmap_lookup_eq(cur, ltrec.rm_startblock,
1924 ltrec.rm_blockcount, ltrec.rm_owner,
1925 ltrec.rm_offset, ltrec.rm_flags, &i);
1928 XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
1930 error = xfs_rmap_update(cur, <rec);
1933 } else if (have_gt &&
1934 bno + len == gtrec.rm_startblock &&
1935 offset + len == gtrec.rm_offset) {
1937 * Right edge contiguous, merge into right record.
1941 * adding: |aaaaaaaaa|
1942 * Result: |rrrrrrrrrrrrrrrrrrr|
1945 /* Delete the old record. */
1946 error = xfs_rmap_delete(cur, gtrec.rm_startblock,
1947 gtrec.rm_blockcount, gtrec.rm_owner,
1948 gtrec.rm_offset, gtrec.rm_flags);
1952 /* Move the start and re-add it. */
1953 gtrec.rm_startblock = bno;
1954 gtrec.rm_blockcount += len;
1955 gtrec.rm_offset = offset;
1956 error = xfs_rmap_insert(cur, gtrec.rm_startblock,
1957 gtrec.rm_blockcount, gtrec.rm_owner,
1958 gtrec.rm_offset, gtrec.rm_flags);
1963 * No contiguous edge with identical owner, insert
1964 * new record at current cursor position.
1966 error = xfs_rmap_insert(cur, bno, len, owner, offset, flags);
1971 trace_xfs_rmap_map_done(mp, cur->bc_private.a.agno, bno, len,
1975 trace_xfs_rmap_map_error(cur->bc_mp,
1976 cur->bc_private.a.agno, error, _RET_IP_);
1980 struct xfs_rmap_query_range_info {
1981 xfs_rmap_query_range_fn fn;
1985 /* Format btree record and pass to our callback. */
1987 xfs_rmap_query_range_helper(
1988 struct xfs_btree_cur *cur,
1989 union xfs_btree_rec *rec,
1992 struct xfs_rmap_query_range_info *query = priv;
1993 struct xfs_rmap_irec irec;
1996 error = xfs_rmap_btrec_to_irec(rec, &irec);
1999 return query->fn(cur, &irec, query->priv);
2002 /* Find all rmaps between two keys. */
2004 xfs_rmap_query_range(
2005 struct xfs_btree_cur *cur,
2006 struct xfs_rmap_irec *low_rec,
2007 struct xfs_rmap_irec *high_rec,
2008 xfs_rmap_query_range_fn fn,
2011 union xfs_btree_irec low_brec;
2012 union xfs_btree_irec high_brec;
2013 struct xfs_rmap_query_range_info query;
2015 low_brec.r = *low_rec;
2016 high_brec.r = *high_rec;
2019 return xfs_btree_query_range(cur, &low_brec, &high_brec,
2020 xfs_rmap_query_range_helper, &query);
2023 /* Find all rmaps. */
2026 struct xfs_btree_cur *cur,
2027 xfs_rmap_query_range_fn fn,
2030 struct xfs_rmap_query_range_info query;
2034 return xfs_btree_query_all(cur, xfs_rmap_query_range_helper, &query);
2037 /* Clean up after calling xfs_rmap_finish_one. */
2039 xfs_rmap_finish_one_cleanup(
2040 struct xfs_trans *tp,
2041 struct xfs_btree_cur *rcur,
2044 struct xfs_buf *agbp;
2048 agbp = rcur->bc_private.a.agbp;
2049 xfs_btree_del_cursor(rcur, error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
2051 xfs_trans_brelse(tp, agbp);
2055 * Process one of the deferred rmap operations. We pass back the
2056 * btree cursor to maintain our lock on the rmapbt between calls.
2057 * This saves time and eliminates a buffer deadlock between the
2058 * superblock and the AGF because we'll always grab them in the same
2062 xfs_rmap_finish_one(
2063 struct xfs_trans *tp,
2064 enum xfs_rmap_intent_type type,
2067 xfs_fileoff_t startoff,
2068 xfs_fsblock_t startblock,
2069 xfs_filblks_t blockcount,
2071 struct xfs_btree_cur **pcur)
2073 struct xfs_mount *mp = tp->t_mountp;
2074 struct xfs_btree_cur *rcur;
2075 struct xfs_buf *agbp = NULL;
2077 xfs_agnumber_t agno;
2078 struct xfs_owner_info oinfo;
2082 agno = XFS_FSB_TO_AGNO(mp, startblock);
2083 ASSERT(agno != NULLAGNUMBER);
2084 bno = XFS_FSB_TO_AGBNO(mp, startblock);
2086 trace_xfs_rmap_deferred(mp, agno, type, bno, owner, whichfork,
2087 startoff, blockcount, state);
2089 if (XFS_TEST_ERROR(false, mp,
2090 XFS_ERRTAG_RMAP_FINISH_ONE))
2094 * If we haven't gotten a cursor or the cursor AG doesn't match
2095 * the startblock, get one now.
2098 if (rcur != NULL && rcur->bc_private.a.agno != agno) {
2099 xfs_rmap_finish_one_cleanup(tp, rcur, 0);
2105 * Refresh the freelist before we start changing the
2106 * rmapbt, because a shape change could cause us to
2109 error = xfs_free_extent_fix_freelist(tp, agno, &agbp);
2113 return -EFSCORRUPTED;
2115 rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno);
2123 xfs_rmap_ino_owner(&oinfo, owner, whichfork, startoff);
2124 unwritten = state == XFS_EXT_UNWRITTEN;
2125 bno = XFS_FSB_TO_AGBNO(rcur->bc_mp, startblock);
2128 case XFS_RMAP_ALLOC:
2130 error = xfs_rmap_map(rcur, bno, blockcount, unwritten, &oinfo);
2132 case XFS_RMAP_MAP_SHARED:
2133 error = xfs_rmap_map_shared(rcur, bno, blockcount, unwritten,
2137 case XFS_RMAP_UNMAP:
2138 error = xfs_rmap_unmap(rcur, bno, blockcount, unwritten,
2141 case XFS_RMAP_UNMAP_SHARED:
2142 error = xfs_rmap_unmap_shared(rcur, bno, blockcount, unwritten,
2145 case XFS_RMAP_CONVERT:
2146 error = xfs_rmap_convert(rcur, bno, blockcount, !unwritten,
2149 case XFS_RMAP_CONVERT_SHARED:
2150 error = xfs_rmap_convert_shared(rcur, bno, blockcount,
2151 !unwritten, &oinfo);
2155 error = -EFSCORRUPTED;
2160 xfs_trans_brelse(tp, agbp);
2166 * Don't defer an rmap if we aren't an rmap filesystem.
2169 xfs_rmap_update_is_needed(
2170 struct xfs_mount *mp,
2173 return xfs_sb_version_hasrmapbt(&mp->m_sb) && whichfork != XFS_COW_FORK;
2177 * Record a rmap intent; the list is kept sorted first by AG and then by
2182 struct xfs_mount *mp,
2183 struct xfs_defer_ops *dfops,
2184 enum xfs_rmap_intent_type type,
2187 struct xfs_bmbt_irec *bmap)
2189 struct xfs_rmap_intent *ri;
2191 trace_xfs_rmap_defer(mp, XFS_FSB_TO_AGNO(mp, bmap->br_startblock),
2193 XFS_FSB_TO_AGBNO(mp, bmap->br_startblock),
2196 bmap->br_blockcount,
2199 ri = kmem_alloc(sizeof(struct xfs_rmap_intent), KM_SLEEP | KM_NOFS);
2200 INIT_LIST_HEAD(&ri->ri_list);
2202 ri->ri_owner = owner;
2203 ri->ri_whichfork = whichfork;
2204 ri->ri_bmap = *bmap;
2206 xfs_defer_add(dfops, XFS_DEFER_OPS_TYPE_RMAP, &ri->ri_list);
2210 /* Map an extent into a file. */
2212 xfs_rmap_map_extent(
2213 struct xfs_mount *mp,
2214 struct xfs_defer_ops *dfops,
2215 struct xfs_inode *ip,
2217 struct xfs_bmbt_irec *PREV)
2219 if (!xfs_rmap_update_is_needed(mp, whichfork))
2222 return __xfs_rmap_add(mp, dfops, xfs_is_reflink_inode(ip) ?
2223 XFS_RMAP_MAP_SHARED : XFS_RMAP_MAP, ip->i_ino,
2227 /* Unmap an extent out of a file. */
2229 xfs_rmap_unmap_extent(
2230 struct xfs_mount *mp,
2231 struct xfs_defer_ops *dfops,
2232 struct xfs_inode *ip,
2234 struct xfs_bmbt_irec *PREV)
2236 if (!xfs_rmap_update_is_needed(mp, whichfork))
2239 return __xfs_rmap_add(mp, dfops, xfs_is_reflink_inode(ip) ?
2240 XFS_RMAP_UNMAP_SHARED : XFS_RMAP_UNMAP, ip->i_ino,
2244 /* Convert a data fork extent from unwritten to real or vice versa. */
2246 xfs_rmap_convert_extent(
2247 struct xfs_mount *mp,
2248 struct xfs_defer_ops *dfops,
2249 struct xfs_inode *ip,
2251 struct xfs_bmbt_irec *PREV)
2253 if (!xfs_rmap_update_is_needed(mp, whichfork))
2256 return __xfs_rmap_add(mp, dfops, xfs_is_reflink_inode(ip) ?
2257 XFS_RMAP_CONVERT_SHARED : XFS_RMAP_CONVERT, ip->i_ino,
2261 /* Schedule the creation of an rmap for non-file data. */
2263 xfs_rmap_alloc_extent(
2264 struct xfs_mount *mp,
2265 struct xfs_defer_ops *dfops,
2266 xfs_agnumber_t agno,
2271 struct xfs_bmbt_irec bmap;
2273 if (!xfs_rmap_update_is_needed(mp, XFS_DATA_FORK))
2276 bmap.br_startblock = XFS_AGB_TO_FSB(mp, agno, bno);
2277 bmap.br_blockcount = len;
2278 bmap.br_startoff = 0;
2279 bmap.br_state = XFS_EXT_NORM;
2281 return __xfs_rmap_add(mp, dfops, XFS_RMAP_ALLOC, owner,
2282 XFS_DATA_FORK, &bmap);
2285 /* Schedule the deletion of an rmap for non-file data. */
2287 xfs_rmap_free_extent(
2288 struct xfs_mount *mp,
2289 struct xfs_defer_ops *dfops,
2290 xfs_agnumber_t agno,
2295 struct xfs_bmbt_irec bmap;
2297 if (!xfs_rmap_update_is_needed(mp, XFS_DATA_FORK))
2300 bmap.br_startblock = XFS_AGB_TO_FSB(mp, agno, bno);
2301 bmap.br_blockcount = len;
2302 bmap.br_startoff = 0;
2303 bmap.br_state = XFS_EXT_NORM;
2305 return __xfs_rmap_add(mp, dfops, XFS_RMAP_FREE, owner,
2306 XFS_DATA_FORK, &bmap);
2309 /* Compare rmap records. Returns -1 if a < b, 1 if a > b, and 0 if equal. */
2312 const struct xfs_rmap_irec *a,
2313 const struct xfs_rmap_irec *b)
2318 oa = xfs_rmap_irec_offset_pack(a);
2319 ob = xfs_rmap_irec_offset_pack(b);
2321 if (a->rm_startblock < b->rm_startblock)
2323 else if (a->rm_startblock > b->rm_startblock)
2325 else if (a->rm_owner < b->rm_owner)
2327 else if (a->rm_owner > b->rm_owner)