Skip to content

Commit 5b7ca8b

Browse files
author
Darrick J. Wong
committed
xfs: simplify xfs_rmap_lookup_le call sites
Most callers of xfs_rmap_lookup_le will retrieve the btree record immediately if the lookup succeeds. The overlapped version of this function (xfs_rmap_lookup_le_range) will return the record if the lookup succeeds, so make the regular version do it too. Get rid of the useless len argument, since it's not part of the lookup key. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent c46eef3 commit 5b7ca8b

File tree

3 files changed

+28
-59
lines changed

3 files changed

+28
-59
lines changed

fs/xfs/libxfs/xfs_rmap.c

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,32 @@ int
3434
xfs_rmap_lookup_le(
3535
struct xfs_btree_cur *cur,
3636
xfs_agblock_t bno,
37-
xfs_extlen_t len,
3837
uint64_t owner,
3938
uint64_t offset,
4039
unsigned int flags,
40+
struct xfs_rmap_irec *irec,
4141
int *stat)
4242
{
43+
int get_stat = 0;
44+
int error;
45+
4346
cur->bc_rec.r.rm_startblock = bno;
44-
cur->bc_rec.r.rm_blockcount = len;
47+
cur->bc_rec.r.rm_blockcount = 0;
4548
cur->bc_rec.r.rm_owner = owner;
4649
cur->bc_rec.r.rm_offset = offset;
4750
cur->bc_rec.r.rm_flags = flags;
48-
return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
51+
52+
error = xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
53+
if (error || !(*stat) || !irec)
54+
return error;
55+
56+
error = xfs_rmap_get_rec(cur, irec, &get_stat);
57+
if (error)
58+
return error;
59+
if (!get_stat)
60+
return -EFSCORRUPTED;
61+
62+
return 0;
4963
}
5064

5165
/*
@@ -510,21 +524,14 @@ xfs_rmap_unmap(
510524
* for the AG headers at rm_startblock == 0 created by mkfs/growfs that
511525
* will not ever be removed from the tree.
512526
*/
513-
error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, flags, &i);
527+
error = xfs_rmap_lookup_le(cur, bno, owner, offset, flags, &ltrec, &i);
514528
if (error)
515529
goto out_error;
516530
if (XFS_IS_CORRUPT(mp, i != 1)) {
517531
error = -EFSCORRUPTED;
518532
goto out_error;
519533
}
520534

521-
error = xfs_rmap_get_rec(cur, &ltrec, &i);
522-
if (error)
523-
goto out_error;
524-
if (XFS_IS_CORRUPT(mp, i != 1)) {
525-
error = -EFSCORRUPTED;
526-
goto out_error;
527-
}
528535
trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
529536
cur->bc_ag.pag->pag_agno, ltrec.rm_startblock,
530537
ltrec.rm_blockcount, ltrec.rm_owner,
@@ -786,18 +793,11 @@ xfs_rmap_map(
786793
* record for our insertion point. This will also give us the record for
787794
* start block contiguity tests.
788795
*/
789-
error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, flags,
796+
error = xfs_rmap_lookup_le(cur, bno, owner, offset, flags, &ltrec,
790797
&have_lt);
791798
if (error)
792799
goto out_error;
793800
if (have_lt) {
794-
error = xfs_rmap_get_rec(cur, &ltrec, &have_lt);
795-
if (error)
796-
goto out_error;
797-
if (XFS_IS_CORRUPT(mp, have_lt != 1)) {
798-
error = -EFSCORRUPTED;
799-
goto out_error;
800-
}
801801
trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
802802
cur->bc_ag.pag->pag_agno, ltrec.rm_startblock,
803803
ltrec.rm_blockcount, ltrec.rm_owner,
@@ -1022,21 +1022,14 @@ xfs_rmap_convert(
10221022
* record for our insertion point. This will also give us the record for
10231023
* start block contiguity tests.
10241024
*/
1025-
error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, oldext, &i);
1025+
error = xfs_rmap_lookup_le(cur, bno, owner, offset, oldext, &PREV, &i);
10261026
if (error)
10271027
goto done;
10281028
if (XFS_IS_CORRUPT(mp, i != 1)) {
10291029
error = -EFSCORRUPTED;
10301030
goto done;
10311031
}
10321032

1033-
error = xfs_rmap_get_rec(cur, &PREV, &i);
1034-
if (error)
1035-
goto done;
1036-
if (XFS_IS_CORRUPT(mp, i != 1)) {
1037-
error = -EFSCORRUPTED;
1038-
goto done;
1039-
}
10401033
trace_xfs_rmap_lookup_le_range_result(cur->bc_mp,
10411034
cur->bc_ag.pag->pag_agno, PREV.rm_startblock,
10421035
PREV.rm_blockcount, PREV.rm_owner,
@@ -1140,7 +1133,7 @@ xfs_rmap_convert(
11401133
_RET_IP_);
11411134

11421135
/* reset the cursor back to PREV */
1143-
error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, oldext, &i);
1136+
error = xfs_rmap_lookup_le(cur, bno, owner, offset, oldext, NULL, &i);
11441137
if (error)
11451138
goto done;
11461139
if (XFS_IS_CORRUPT(mp, i != 1)) {
@@ -2677,7 +2670,7 @@ xfs_rmap_record_exists(
26772670
ASSERT(XFS_RMAP_NON_INODE_OWNER(owner) ||
26782671
(flags & XFS_RMAP_BMBT_BLOCK));
26792672

2680-
error = xfs_rmap_lookup_le(cur, bno, len, owner, offset, flags,
2673+
error = xfs_rmap_lookup_le(cur, bno, owner, offset, flags, &irec,
26812674
&has_record);
26822675
if (error)
26832676
return error;
@@ -2686,14 +2679,6 @@ xfs_rmap_record_exists(
26862679
return 0;
26872680
}
26882681

2689-
error = xfs_rmap_get_rec(cur, &irec, &has_record);
2690-
if (error)
2691-
return error;
2692-
if (!has_record) {
2693-
*has_rmap = false;
2694-
return 0;
2695-
}
2696-
26972682
*has_rmap = (irec.rm_owner == owner && irec.rm_startblock <= bno &&
26982683
irec.rm_startblock + irec.rm_blockcount >= bno + len);
26992684
return 0;

fs/xfs/libxfs/xfs_rmap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
122122
const struct xfs_owner_info *oinfo);
123123

124124
int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
125-
xfs_extlen_t len, uint64_t owner, uint64_t offset,
126-
unsigned int flags, int *stat);
125+
uint64_t owner, uint64_t offset, unsigned int flags,
126+
struct xfs_rmap_irec *irec, int *stat);
127127
int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
128128
xfs_extlen_t len, uint64_t owner, uint64_t offset,
129129
unsigned int flags, int *stat);

fs/xfs/scrub/bmap.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,13 @@ xchk_bmap_get_rmap(
133133
if (info->is_shared) {
134134
error = xfs_rmap_lookup_le_range(info->sc->sa.rmap_cur, agbno,
135135
owner, offset, rflags, rmap, &has_rmap);
136-
if (!xchk_should_check_xref(info->sc, &error,
137-
&info->sc->sa.rmap_cur))
138-
return false;
139-
goto out;
136+
} else {
137+
error = xfs_rmap_lookup_le(info->sc->sa.rmap_cur, agbno,
138+
owner, offset, rflags, rmap, &has_rmap);
140139
}
141-
142-
/*
143-
* Otherwise, use the (faster) regular lookup.
144-
*/
145-
error = xfs_rmap_lookup_le(info->sc->sa.rmap_cur, agbno, 0, owner,
146-
offset, rflags, &has_rmap);
147-
if (!xchk_should_check_xref(info->sc, &error,
148-
&info->sc->sa.rmap_cur))
140+
if (!xchk_should_check_xref(info->sc, &error, &info->sc->sa.rmap_cur))
149141
return false;
150-
if (!has_rmap)
151-
goto out;
152142

153-
error = xfs_rmap_get_rec(info->sc->sa.rmap_cur, rmap, &has_rmap);
154-
if (!xchk_should_check_xref(info->sc, &error,
155-
&info->sc->sa.rmap_cur))
156-
return false;
157-
158-
out:
159143
if (!has_rmap)
160144
xchk_fblock_xref_set_corrupt(info->sc, info->whichfork,
161145
irec->br_startoff);

0 commit comments

Comments
 (0)