Skip to content

Commit 3f0205e

Browse files
author
Darrick J. Wong
committed
xfs: create helpers to deal with rounding xfs_filblks_t to rtx boundaries
We're about to segment xfs_rtblock_t addresses, so we must create type-specific helpers to do rt extent rounding of file mapping block lengths because the rtb helpers soon will not do the right thing there. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent fd7588f commit 3f0205e

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ xfs_rtfree_blocks(
11231123

11241124
ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN);
11251125

1126-
mod = xfs_rtb_to_rtxoff(mp, rtlen);
1126+
mod = xfs_blen_to_rtxoff(mp, rtlen);
11271127
if (mod) {
11281128
ASSERT(mod == 0);
11291129
return -EIO;

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ xfs_blen_to_rtbxlen(
101101
return div_u64(blen, mp->m_sb.sb_rextsize);
102102
}
103103

104+
/* Return the offset of a file block length within an rt extent. */
105+
static inline xfs_extlen_t
106+
xfs_blen_to_rtxoff(
107+
struct xfs_mount *mp,
108+
xfs_filblks_t blen)
109+
{
110+
if (likely(mp->m_rtxblklog >= 0))
111+
return blen & mp->m_rtxblkmask;
112+
113+
return do_div(blen, mp->m_sb.sb_rextsize);
114+
}
115+
116+
/* Round this block count up to the nearest rt extent size. */
117+
static inline xfs_filblks_t
118+
xfs_blen_roundup_rtx(
119+
struct xfs_mount *mp,
120+
xfs_filblks_t blen)
121+
{
122+
return roundup_64(blen, mp->m_sb.sb_rextsize);
123+
}
124+
104125
/* Convert an rt block number into an rt extent number. */
105126
static inline xfs_rtxnum_t
106127
xfs_rtb_to_rtx(
@@ -126,15 +147,6 @@ xfs_rtb_to_rtxoff(
126147
return do_div(rtbno, mp->m_sb.sb_rextsize);
127148
}
128149

129-
/* Round this rtblock up to the nearest rt extent size. */
130-
static inline xfs_rtblock_t
131-
xfs_rtb_roundup_rtx(
132-
struct xfs_mount *mp,
133-
xfs_rtblock_t rtbno)
134-
{
135-
return roundup_64(rtbno, mp->m_sb.sb_rextsize);
136-
}
137-
138150
/* Round this file block offset up to the nearest rt extent size. */
139151
static inline xfs_rtblock_t
140152
xfs_fileoff_roundup_rtx(

fs/xfs/xfs_exchrange.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ xfs_exchrange_mappings(
217217
* length in @fxr are safe to round up.
218218
*/
219219
if (xfs_inode_has_bigrtalloc(ip2))
220-
req.blockcount = xfs_rtb_roundup_rtx(mp, req.blockcount);
220+
req.blockcount = xfs_blen_roundup_rtx(mp, req.blockcount);
221221

222222
error = xfs_exchrange_estimate(&req);
223223
if (error)

0 commit comments

Comments
 (0)