Skip to content

Commit f220f6d

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
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>
1 parent f8c5a84 commit f220f6d

File tree

10 files changed

+68
-50
lines changed

10 files changed

+68
-50
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4094,7 +4094,7 @@ xfs_bmapi_reserve_delalloc(
40944094

40954095
fdblocks = indlen;
40964096
if (XFS_IS_REALTIME_INODE(ip)) {
4097-
error = xfs_dec_frextents(mp, xfs_rtb_to_rtx(mp, alen));
4097+
error = xfs_dec_frextents(mp, xfs_blen_to_rtbxlen(mp, alen));
40984098
if (error)
40994099
goto out_unreserve_quota;
41004100
} else {
@@ -4129,7 +4129,7 @@ xfs_bmapi_reserve_delalloc(
41294129

41304130
out_unreserve_frextents:
41314131
if (XFS_IS_REALTIME_INODE(ip))
4132-
xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, alen));
4132+
xfs_add_frextents(mp, xfs_blen_to_rtbxlen(mp, alen));
41334133
out_unreserve_quota:
41344134
if (XFS_IS_QUOTA_ON(mp))
41354135
xfs_quota_unreserve_blkres(ip, alen);
@@ -5037,7 +5037,7 @@ xfs_bmap_del_extent_delay(
50375037
fdblocks = da_diff;
50385038

50395039
if (isrt)
5040-
xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount));
5040+
xfs_add_frextents(mp, xfs_blen_to_rtbxlen(mp, del->br_blockcount));
50415041
else
50425042
fdblocks += del->br_blockcount;
50435043

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,37 @@ struct xfs_rtalloc_args {
2222

2323
static inline xfs_rtblock_t
2424
xfs_rtx_to_rtb(
25-
struct xfs_mount *mp,
25+
struct xfs_rtgroup *rtg,
2626
xfs_rtxnum_t rtx)
2727
{
28+
struct xfs_mount *mp = rtg_mount(rtg);
29+
xfs_rtblock_t start = xfs_rgno_start_rtb(mp, rtg_rgno(rtg));
30+
2831
if (mp->m_rtxblklog >= 0)
29-
return rtx << mp->m_rtxblklog;
32+
return start + (rtx << mp->m_rtxblklog);
33+
return start + (rtx * mp->m_sb.sb_rextsize);
34+
}
3035

31-
return rtx * mp->m_sb.sb_rextsize;
36+
/* Convert an rgbno into an rt extent number. */
37+
static inline xfs_rtxnum_t
38+
xfs_rgbno_to_rtx(
39+
struct xfs_mount *mp,
40+
xfs_rgblock_t rgbno)
41+
{
42+
if (likely(mp->m_rtxblklog >= 0))
43+
return rgbno >> mp->m_rtxblklog;
44+
return rgbno / mp->m_sb.sb_rextsize;
45+
}
46+
47+
static inline uint64_t
48+
xfs_rtbxlen_to_blen(
49+
struct xfs_mount *mp,
50+
xfs_rtbxlen_t rtbxlen)
51+
{
52+
if (mp->m_rtxblklog >= 0)
53+
return rtbxlen << mp->m_rtxblklog;
54+
55+
return rtbxlen * mp->m_sb.sb_rextsize;
3256
}
3357

3458
static inline xfs_extlen_t
@@ -65,16 +89,29 @@ xfs_extlen_to_rtxlen(
6589
return len / mp->m_sb.sb_rextsize;
6690
}
6791

92+
/* Convert an rt block count into an rt extent count. */
93+
static inline xfs_rtbxlen_t
94+
xfs_blen_to_rtbxlen(
95+
struct xfs_mount *mp,
96+
uint64_t blen)
97+
{
98+
if (likely(mp->m_rtxblklog >= 0))
99+
return blen >> mp->m_rtxblklog;
100+
101+
return div_u64(blen, mp->m_sb.sb_rextsize);
102+
}
103+
68104
/* Convert an rt block number into an rt extent number. */
69105
static inline xfs_rtxnum_t
70106
xfs_rtb_to_rtx(
71107
struct xfs_mount *mp,
72108
xfs_rtblock_t rtbno)
73109
{
74-
if (likely(mp->m_rtxblklog >= 0))
75-
return rtbno >> mp->m_rtxblklog;
110+
uint64_t __rgbno = __xfs_rtb_to_rgbno(mp, rtbno);
76111

77-
return div_u64(rtbno, mp->m_sb.sb_rextsize);
112+
if (likely(mp->m_rtxblklog >= 0))
113+
return __rgbno >> mp->m_rtxblklog;
114+
return div_u64(__rgbno, mp->m_sb.sb_rextsize);
78115
}
79116

80117
/* Return the offset of an rt block number within an rt extent. */
@@ -89,26 +126,6 @@ xfs_rtb_to_rtxoff(
89126
return do_div(rtbno, mp->m_sb.sb_rextsize);
90127
}
91128

92-
/*
93-
* Convert an rt block number into an rt extent number, rounding up to the next
94-
* rt extent if the rt block is not aligned to an rt extent boundary.
95-
*/
96-
static inline xfs_rtxnum_t
97-
xfs_rtb_to_rtxup(
98-
struct xfs_mount *mp,
99-
xfs_rtblock_t rtbno)
100-
{
101-
if (likely(mp->m_rtxblklog >= 0)) {
102-
if (rtbno & mp->m_rtxblkmask)
103-
return (rtbno >> mp->m_rtxblklog) + 1;
104-
return rtbno >> mp->m_rtxblklog;
105-
}
106-
107-
if (do_div(rtbno, mp->m_sb.sb_rextsize))
108-
rtbno++;
109-
return rtbno;
110-
}
111-
112129
/* Round this rtblock up to the nearest rt extent size. */
113130
static inline xfs_rtblock_t
114131
xfs_rtb_roundup_rtx(

fs/xfs/scrub/rtbitmap.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ xchk_setup_rtbitmap(
6565
*/
6666
xchk_rtgroup_lock(&sc->sr, XFS_RTGLOCK_BITMAP);
6767
if (mp->m_sb.sb_rblocks) {
68-
rtb->rextents = xfs_rtb_to_rtx(mp, mp->m_sb.sb_rblocks);
68+
rtb->rextents = xfs_blen_to_rtbxlen(mp, mp->m_sb.sb_rblocks);
6969
rtb->rextslog = xfs_compute_rextslog(rtb->rextents);
7070
rtb->rbmblocks = xfs_rtbitmap_blockcount(mp);
7171
}
@@ -83,15 +83,14 @@ xchk_rtbitmap_rec(
8383
const struct xfs_rtalloc_rec *rec,
8484
void *priv)
8585
{
86-
struct xfs_mount *mp = rtg_mount(rtg);
8786
struct xfs_scrub *sc = priv;
8887
xfs_rtblock_t startblock;
8988
xfs_filblks_t blockcount;
9089

91-
startblock = xfs_rtx_to_rtb(mp, rec->ar_startext);
92-
blockcount = xfs_rtx_to_rtb(mp, rec->ar_extcount);
90+
startblock = xfs_rtx_to_rtb(rtg, rec->ar_startext);
91+
blockcount = xfs_rtxlen_to_extlen(rtg_mount(rtg), rec->ar_extcount);
9392

94-
if (!xfs_verify_rtbext(mp, startblock, blockcount))
93+
if (!xfs_verify_rtbext(rtg_mount(rtg), startblock, blockcount))
9594
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
9695
return 0;
9796
}

fs/xfs/scrub/rtsummary.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ xchk_setup_rtsummary(
102102
*/
103103
xchk_rtgroup_lock(&sc->sr, XFS_RTGLOCK_BITMAP);
104104
if (mp->m_sb.sb_rblocks) {
105-
rts->rextents = xfs_rtb_to_rtx(mp, mp->m_sb.sb_rblocks);
105+
rts->rextents = xfs_blen_to_rtbxlen(mp, mp->m_sb.sb_rblocks);
106106
rts->rbmblocks = xfs_rtbitmap_blockcount(mp);
107107
rts->rsumblocks =
108108
xfs_rtsummary_blockcount(mp, &rts->rsumlevels);
@@ -182,8 +182,8 @@ xchk_rtsum_record_free(
182182
lenlog = xfs_highbit64(rec->ar_extcount);
183183
offs = xfs_rtsumoffs(mp, lenlog, rbmoff);
184184

185-
rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
186-
rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount);
185+
rtbno = xfs_rtx_to_rtb(rtg, rec->ar_startext);
186+
rtlen = xfs_rtxlen_to_extlen(mp, rec->ar_extcount);
187187

188188
if (!xfs_verify_rtbext(mp, rtbno, rtlen)) {
189189
xchk_ino_xref_set_corrupt(sc,

fs/xfs/xfs_discard.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ xfs_trim_gather_rtextent(
526526
return -ECANCELED;
527527
}
528528

529-
rbno = xfs_rtx_to_rtb(rtg_mount(rtg), rec->ar_startext);
530-
rlen = xfs_rtx_to_rtb(rtg_mount(rtg), rec->ar_extcount);
529+
rbno = xfs_rtx_to_rtb(rtg, rec->ar_startext);
530+
rlen = xfs_rtbxlen_to_blen(rtg_mount(rtg), rec->ar_extcount);
531531

532532
/* Ignore too small. */
533533
if (rlen < tr->minlen_fsb) {

fs/xfs/xfs_fsmap.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,10 @@ xfs_getfsmap_rtdev_rtbitmap_helper(
722722
};
723723
struct xfs_mount *mp = rtg_mount(rtg);
724724
struct xfs_getfsmap_info *info = priv;
725-
xfs_rtblock_t rtbno;
725+
xfs_rtblock_t start_rtb =
726+
xfs_rtx_to_rtb(rtg, rec->ar_startext);
727+
uint64_t rtbcount =
728+
xfs_rtbxlen_to_blen(mp, rec->ar_extcount);
726729

727730
/*
728731
* For an info->last query, we're looking for a gap between the last
@@ -736,12 +739,10 @@ xfs_getfsmap_rtdev_rtbitmap_helper(
736739
if (info->last && info->end_daddr != XFS_BUF_DADDR_NULL) {
737740
frec.start_daddr = info->end_daddr;
738741
} else {
739-
rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
740-
frec.start_daddr = xfs_rtb_to_daddr(mp, rtbno);
742+
frec.start_daddr = xfs_rtb_to_daddr(mp, start_rtb);
741743
}
742744

743-
rtbno = xfs_rtx_to_rtb(mp, rec->ar_extcount);
744-
frec.len_daddr = XFS_FSB_TO_BB(mp, rtbno);
745+
frec.len_daddr = XFS_FSB_TO_BB(mp, rtbcount);
745746
return xfs_getfsmap_helper(tp, info, &frec);
746747
}
747748

fs/xfs/xfs_iomap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ xfs_iomap_prealloc_size(
501501
alloc_blocks);
502502

503503
if (unlikely(XFS_IS_REALTIME_INODE(ip)))
504-
freesp = xfs_rtx_to_rtb(mp,
505-
xfs_iomap_freesp(&mp->m_frextents,
504+
freesp = xfs_rtbxlen_to_blen(mp,
505+
xfs_iomap_freesp(&mp->m_frextents,
506506
mp->m_low_rtexts, &shift));
507507
else
508508
freesp = xfs_iomap_freesp(&mp->m_fdblocks, mp->m_low_space,

fs/xfs/xfs_mount.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ xfs_mod_delalloc(
14741474

14751475
if (XFS_IS_REALTIME_INODE(ip)) {
14761476
percpu_counter_add_batch(&mp->m_delalloc_rtextents,
1477-
xfs_rtb_to_rtx(mp, data_delta),
1477+
xfs_blen_to_rtbxlen(mp, data_delta),
14781478
XFS_DELALLOC_BATCH);
14791479
if (!ind_delta)
14801480
return;

fs/xfs/xfs_rtalloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ xfs_growfs_rt_alloc_fake_mount(
748748
nmp->m_sb.sb_rextsize = rextsize;
749749
xfs_mount_sb_set_rextsize(nmp, &nmp->m_sb);
750750
nmp->m_sb.sb_rblocks = rblocks;
751-
nmp->m_sb.sb_rextents = xfs_rtb_to_rtx(nmp, nmp->m_sb.sb_rblocks);
751+
nmp->m_sb.sb_rextents = xfs_blen_to_rtbxlen(nmp, nmp->m_sb.sb_rblocks);
752752
nmp->m_sb.sb_rbmblocks = xfs_rtbitmap_blockcount(nmp);
753753
nmp->m_sb.sb_rextslog = xfs_compute_rextslog(nmp->m_sb.sb_rextents);
754754
nmp->m_rsumblocks = xfs_rtsummary_blockcount(nmp, &nmp->m_rsumlevels);
@@ -1463,7 +1463,7 @@ xfs_rtallocate(
14631463
xfs_trans_mod_sb(tp, wasdel ?
14641464
XFS_TRANS_SB_RES_FREXTENTS : XFS_TRANS_SB_FREXTENTS,
14651465
-(long)len);
1466-
*bno = xfs_rtx_to_rtb(args.mp, rtx);
1466+
*bno = xfs_rtx_to_rtb(args.rtg, rtx);
14671467
*blen = xfs_rtxlen_to_extlen(args.mp, len);
14681468

14691469
out_release:

fs/xfs/xfs_super.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ xfs_fs_statfs(
885885

886886
statp->f_blocks = sbp->sb_rblocks;
887887
freertx = percpu_counter_sum_positive(&mp->m_frextents);
888-
statp->f_bavail = statp->f_bfree = xfs_rtx_to_rtb(mp, freertx);
888+
statp->f_bavail = statp->f_bfree =
889+
xfs_rtbxlen_to_blen(mp, freertx);
889890
}
890891

891892
return 0;

0 commit comments

Comments
 (0)