xfs: make RT extent numbers relative to the rtgroup

To prepare for adding per-rtgroup bitmap files, make the xfs_rtxnum_t
type encode the RT extent number relative to the rtgroup.  The biggest
part of this to clearly distinguish between the relative extent number
that gets masked when converting from a global block number and length
values that just have a factor applied to them when converting from
file system blocks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
This commit is contained in:
Christoph Hellwig 2024-11-03 20:19:15 -08:00 committed by Darrick J. Wong
parent f8c5a8415f
commit f220f6da5f
10 changed files with 69 additions and 51 deletions

View File

@ -4094,7 +4094,7 @@ retry:
fdblocks = indlen;
if (XFS_IS_REALTIME_INODE(ip)) {
error = xfs_dec_frextents(mp, xfs_rtb_to_rtx(mp, alen));
error = xfs_dec_frextents(mp, xfs_blen_to_rtbxlen(mp, alen));
if (error)
goto out_unreserve_quota;
} else {
@ -4129,7 +4129,7 @@ retry:
out_unreserve_frextents:
if (XFS_IS_REALTIME_INODE(ip))
xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, alen));
xfs_add_frextents(mp, xfs_blen_to_rtbxlen(mp, alen));
out_unreserve_quota:
if (XFS_IS_QUOTA_ON(mp))
xfs_quota_unreserve_blkres(ip, alen);
@ -5037,7 +5037,7 @@ xfs_bmap_del_extent_delay(
fdblocks = da_diff;
if (isrt)
xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount));
xfs_add_frextents(mp, xfs_blen_to_rtbxlen(mp, del->br_blockcount));
else
fdblocks += del->br_blockcount;

View File

@ -22,13 +22,37 @@ struct xfs_rtalloc_args {
static inline xfs_rtblock_t
xfs_rtx_to_rtb(
struct xfs_mount *mp,
struct xfs_rtgroup *rtg,
xfs_rtxnum_t rtx)
{
if (mp->m_rtxblklog >= 0)
return rtx << mp->m_rtxblklog;
struct xfs_mount *mp = rtg_mount(rtg);
xfs_rtblock_t start = xfs_rgno_start_rtb(mp, rtg_rgno(rtg));
return rtx * mp->m_sb.sb_rextsize;
if (mp->m_rtxblklog >= 0)
return start + (rtx << mp->m_rtxblklog);
return start + (rtx * mp->m_sb.sb_rextsize);
}
/* Convert an rgbno into an rt extent number. */
static inline xfs_rtxnum_t
xfs_rgbno_to_rtx(
struct xfs_mount *mp,
xfs_rgblock_t rgbno)
{
if (likely(mp->m_rtxblklog >= 0))
return rgbno >> mp->m_rtxblklog;
return rgbno / mp->m_sb.sb_rextsize;
}
static inline uint64_t
xfs_rtbxlen_to_blen(
struct xfs_mount *mp,
xfs_rtbxlen_t rtbxlen)
{
if (mp->m_rtxblklog >= 0)
return rtbxlen << mp->m_rtxblklog;
return rtbxlen * mp->m_sb.sb_rextsize;
}
static inline xfs_extlen_t
@ -65,16 +89,29 @@ xfs_extlen_to_rtxlen(
return len / mp->m_sb.sb_rextsize;
}
/* Convert an rt block count into an rt extent count. */
static inline xfs_rtbxlen_t
xfs_blen_to_rtbxlen(
struct xfs_mount *mp,
uint64_t blen)
{
if (likely(mp->m_rtxblklog >= 0))
return blen >> mp->m_rtxblklog;
return div_u64(blen, mp->m_sb.sb_rextsize);
}
/* Convert an rt block number into an rt extent number. */
static inline xfs_rtxnum_t
xfs_rtb_to_rtx(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
if (likely(mp->m_rtxblklog >= 0))
return rtbno >> mp->m_rtxblklog;
uint64_t __rgbno = __xfs_rtb_to_rgbno(mp, rtbno);
return div_u64(rtbno, mp->m_sb.sb_rextsize);
if (likely(mp->m_rtxblklog >= 0))
return __rgbno >> mp->m_rtxblklog;
return div_u64(__rgbno, mp->m_sb.sb_rextsize);
}
/* Return the offset of an rt block number within an rt extent. */
@ -89,26 +126,6 @@ xfs_rtb_to_rtxoff(
return do_div(rtbno, mp->m_sb.sb_rextsize);
}
/*
* Convert an rt block number into an rt extent number, rounding up to the next
* rt extent if the rt block is not aligned to an rt extent boundary.
*/
static inline xfs_rtxnum_t
xfs_rtb_to_rtxup(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
if (likely(mp->m_rtxblklog >= 0)) {
if (rtbno & mp->m_rtxblkmask)
return (rtbno >> mp->m_rtxblklog) + 1;
return rtbno >> mp->m_rtxblklog;
}
if (do_div(rtbno, mp->m_sb.sb_rextsize))
rtbno++;
return rtbno;
}
/* Round this rtblock up to the nearest rt extent size. */
static inline xfs_rtblock_t
xfs_rtb_roundup_rtx(

View File

@ -65,7 +65,7 @@ xchk_setup_rtbitmap(
*/
xchk_rtgroup_lock(&sc->sr, XFS_RTGLOCK_BITMAP);
if (mp->m_sb.sb_rblocks) {
rtb->rextents = xfs_rtb_to_rtx(mp, mp->m_sb.sb_rblocks);
rtb->rextents = xfs_blen_to_rtbxlen(mp, mp->m_sb.sb_rblocks);
rtb->rextslog = xfs_compute_rextslog(rtb->rextents);
rtb->rbmblocks = xfs_rtbitmap_blockcount(mp);
}
@ -83,15 +83,14 @@ xchk_rtbitmap_rec(
const struct xfs_rtalloc_rec *rec,
void *priv)
{
struct xfs_mount *mp = rtg_mount(rtg);
struct xfs_scrub *sc = priv;
xfs_rtblock_t startblock;
xfs_filblks_t blockcount;
startblock = xfs_rtx_to_rtb(mp, rec->ar_startext);
blockcount = xfs_rtx_to_rtb(mp, rec->ar_extcount);
startblock = xfs_rtx_to_rtb(rtg, rec->ar_startext);
blockcount = xfs_rtxlen_to_extlen(rtg_mount(rtg), rec->ar_extcount);
if (!xfs_verify_rtbext(mp, startblock, blockcount))
if (!xfs_verify_rtbext(rtg_mount(rtg), startblock, blockcount))
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
return 0;
}

View File

@ -102,7 +102,7 @@ xchk_setup_rtsummary(
*/
xchk_rtgroup_lock(&sc->sr, XFS_RTGLOCK_BITMAP);
if (mp->m_sb.sb_rblocks) {
rts->rextents = xfs_rtb_to_rtx(mp, mp->m_sb.sb_rblocks);
rts->rextents = xfs_blen_to_rtbxlen(mp, mp->m_sb.sb_rblocks);
rts->rbmblocks = xfs_rtbitmap_blockcount(mp);
rts->rsumblocks =
xfs_rtsummary_blockcount(mp, &rts->rsumlevels);
@ -182,8 +182,8 @@ xchk_rtsum_record_free(
lenlog = xfs_highbit64(rec->ar_extcount);
offs = xfs_rtsumoffs(mp, lenlog, rbmoff);
rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount);
rtbno = xfs_rtx_to_rtb(rtg, rec->ar_startext);
rtlen = xfs_rtxlen_to_extlen(mp, rec->ar_extcount);
if (!xfs_verify_rtbext(mp, rtbno, rtlen)) {
xchk_ino_xref_set_corrupt(sc,

View File

@ -526,8 +526,8 @@ xfs_trim_gather_rtextent(
return -ECANCELED;
}
rbno = xfs_rtx_to_rtb(rtg_mount(rtg), rec->ar_startext);
rlen = xfs_rtx_to_rtb(rtg_mount(rtg), rec->ar_extcount);
rbno = xfs_rtx_to_rtb(rtg, rec->ar_startext);
rlen = xfs_rtbxlen_to_blen(rtg_mount(rtg), rec->ar_extcount);
/* Ignore too small. */
if (rlen < tr->minlen_fsb) {

View File

@ -722,7 +722,10 @@ xfs_getfsmap_rtdev_rtbitmap_helper(
};
struct xfs_mount *mp = rtg_mount(rtg);
struct xfs_getfsmap_info *info = priv;
xfs_rtblock_t rtbno;
xfs_rtblock_t start_rtb =
xfs_rtx_to_rtb(rtg, rec->ar_startext);
uint64_t rtbcount =
xfs_rtbxlen_to_blen(mp, rec->ar_extcount);
/*
* For an info->last query, we're looking for a gap between the last
@ -736,12 +739,10 @@ xfs_getfsmap_rtdev_rtbitmap_helper(
if (info->last && info->end_daddr != XFS_BUF_DADDR_NULL) {
frec.start_daddr = info->end_daddr;
} else {
rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
frec.start_daddr = xfs_rtb_to_daddr(mp, rtbno);
frec.start_daddr = xfs_rtb_to_daddr(mp, start_rtb);
}
rtbno = xfs_rtx_to_rtb(mp, rec->ar_extcount);
frec.len_daddr = XFS_FSB_TO_BB(mp, rtbno);
frec.len_daddr = XFS_FSB_TO_BB(mp, rtbcount);
return xfs_getfsmap_helper(tp, info, &frec);
}

View File

@ -501,8 +501,8 @@ xfs_iomap_prealloc_size(
alloc_blocks);
if (unlikely(XFS_IS_REALTIME_INODE(ip)))
freesp = xfs_rtx_to_rtb(mp,
xfs_iomap_freesp(&mp->m_frextents,
freesp = xfs_rtbxlen_to_blen(mp,
xfs_iomap_freesp(&mp->m_frextents,
mp->m_low_rtexts, &shift));
else
freesp = xfs_iomap_freesp(&mp->m_fdblocks, mp->m_low_space,

View File

@ -1474,7 +1474,7 @@ xfs_mod_delalloc(
if (XFS_IS_REALTIME_INODE(ip)) {
percpu_counter_add_batch(&mp->m_delalloc_rtextents,
xfs_rtb_to_rtx(mp, data_delta),
xfs_blen_to_rtbxlen(mp, data_delta),
XFS_DELALLOC_BATCH);
if (!ind_delta)
return;

View File

@ -748,7 +748,7 @@ xfs_growfs_rt_alloc_fake_mount(
nmp->m_sb.sb_rextsize = rextsize;
xfs_mount_sb_set_rextsize(nmp, &nmp->m_sb);
nmp->m_sb.sb_rblocks = rblocks;
nmp->m_sb.sb_rextents = xfs_rtb_to_rtx(nmp, nmp->m_sb.sb_rblocks);
nmp->m_sb.sb_rextents = xfs_blen_to_rtbxlen(nmp, nmp->m_sb.sb_rblocks);
nmp->m_sb.sb_rbmblocks = xfs_rtbitmap_blockcount(nmp);
nmp->m_sb.sb_rextslog = xfs_compute_rextslog(nmp->m_sb.sb_rextents);
nmp->m_rsumblocks = xfs_rtsummary_blockcount(nmp, &nmp->m_rsumlevels);
@ -1463,7 +1463,7 @@ xfs_rtallocate(
xfs_trans_mod_sb(tp, wasdel ?
XFS_TRANS_SB_RES_FREXTENTS : XFS_TRANS_SB_FREXTENTS,
-(long)len);
*bno = xfs_rtx_to_rtb(args.mp, rtx);
*bno = xfs_rtx_to_rtb(args.rtg, rtx);
*blen = xfs_rtxlen_to_extlen(args.mp, len);
out_release:

View File

@ -885,7 +885,8 @@ xfs_fs_statfs(
statp->f_blocks = sbp->sb_rblocks;
freertx = percpu_counter_sum_positive(&mp->m_frextents);
statp->f_bavail = statp->f_bfree = xfs_rtx_to_rtb(mp, freertx);
statp->f_bavail = statp->f_bfree =
xfs_rtbxlen_to_blen(mp, freertx);
}
return 0;