Skip to content

Commit 0556412

Browse files
author
Darrick J. Wong
committed
xfs: convert do_div calls to xfs_rtb_to_rtx helper calls
Convert these calls to use the helpers, and clean up all these places where the same variable can have different units depending on where it is in the function. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 5dc3a80 commit 0556412

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4826,12 +4826,8 @@ xfs_bmap_del_extent_delay(
48264826
ASSERT(got->br_startoff <= del->br_startoff);
48274827
ASSERT(got_endoff >= del_endoff);
48284828

4829-
if (isrt) {
4830-
uint64_t rtexts = del->br_blockcount;
4831-
4832-
do_div(rtexts, mp->m_sb.sb_rextsize);
4833-
xfs_mod_frextents(mp, rtexts);
4834-
}
4829+
if (isrt)
4830+
xfs_mod_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount));
48354831

48364832
/*
48374833
* Update the inode delalloc counter now and wait to update the

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ xfs_rtb_to_rtxrem(
7070
return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
7171
}
7272

73+
/*
74+
* Convert an rt block number into an rt extent number, rounding up to the next
75+
* rt extent if the rt block is not aligned to an rt extent boundary.
76+
*/
77+
static inline xfs_rtxnum_t
78+
xfs_rtb_to_rtxup(
79+
struct xfs_mount *mp,
80+
xfs_rtblock_t rtbno)
81+
{
82+
if (do_div(rtbno, mp->m_sb.sb_rextsize))
83+
rtbno++;
84+
return rtbno;
85+
}
86+
7387
/*
7488
* Functions for walking free space rtextents in the realtime bitmap.
7589
*/

fs/xfs/scrub/rtbitmap.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,22 @@ xchk_rtbitmap(
128128
void
129129
xchk_xref_is_used_rt_space(
130130
struct xfs_scrub *sc,
131-
xfs_rtblock_t fsbno,
131+
xfs_rtblock_t rtbno,
132132
xfs_extlen_t len)
133133
{
134134
xfs_rtxnum_t startext;
135135
xfs_rtxnum_t endext;
136-
xfs_rtxlen_t extcount;
137136
bool is_free;
138137
int error;
139138

140139
if (xchk_skip_xref(sc->sm))
141140
return;
142141

143-
startext = fsbno;
144-
endext = fsbno + len - 1;
145-
do_div(startext, sc->mp->m_sb.sb_rextsize);
146-
do_div(endext, sc->mp->m_sb.sb_rextsize);
147-
extcount = endext - startext + 1;
142+
startext = xfs_rtb_to_rtx(sc->mp, rtbno);
143+
endext = xfs_rtb_to_rtx(sc->mp, rtbno + len - 1);
148144
xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
149-
error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext, extcount,
150-
&is_free);
145+
error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext,
146+
endext - startext + 1, &is_free);
151147
if (!xchk_should_check_xref(sc, &error, NULL))
152148
goto out_unlock;
153149
if (is_free)

fs/xfs/xfs_bmap_util.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,12 @@ xfs_bmap_rtalloc(
156156
* Realtime allocation, done through xfs_rtallocate_extent.
157157
*/
158158
if (ignore_locality)
159-
ap->blkno = 0;
159+
rtx = 0;
160160
else
161-
do_div(ap->blkno, mp->m_sb.sb_rextsize);
162-
rtx = ap->blkno;
163-
ap->length = ralen;
161+
rtx = xfs_rtb_to_rtx(mp, ap->blkno);
164162
raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
165-
error = xfs_rtallocate_extent(ap->tp, ap->blkno, raminlen, ap->length,
166-
&ralen, ap->wasdel, prod, &rtx);
163+
error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen,
164+
ap->wasdel, prod, &rtx);
167165
if (error)
168166
return error;
169167

fs/xfs/xfs_fsmap.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,8 @@ xfs_getfsmap_rtdev_rtbitmap(
539539
* Set up query parameters to return free rtextents covering the range
540540
* we want.
541541
*/
542-
alow.ar_startext = start_rtb;
543-
ahigh.ar_startext = end_rtb;
544-
do_div(alow.ar_startext, mp->m_sb.sb_rextsize);
545-
if (do_div(ahigh.ar_startext, mp->m_sb.sb_rextsize))
546-
ahigh.ar_startext++;
542+
alow.ar_startext = xfs_rtb_to_rtx(mp, start_rtb);
543+
ahigh.ar_startext = xfs_rtb_to_rtxup(mp, end_rtb);
547544
error = xfs_rtalloc_query_range(mp, tp, &alow, &ahigh,
548545
xfs_getfsmap_rtdev_rtbitmap_helper, info);
549546
if (error)

fs/xfs/xfs_rtalloc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,7 @@ xfs_growfs_rt(
10581058
nrblocks_step = (bmbno + 1) * NBBY * nsbp->sb_blocksize *
10591059
nsbp->sb_rextsize;
10601060
nsbp->sb_rblocks = min(nrblocks, nrblocks_step);
1061-
nsbp->sb_rextents = nsbp->sb_rblocks;
1062-
do_div(nsbp->sb_rextents, nsbp->sb_rextsize);
1061+
nsbp->sb_rextents = xfs_rtb_to_rtx(nmp, nsbp->sb_rblocks);
10631062
ASSERT(nsbp->sb_rextents != 0);
10641063
nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents);
10651064
nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1;

0 commit comments

Comments
 (0)