Skip to content

Commit 90d98a6

Browse files
author
Darrick J. Wong
committed
xfs: convert the rtbitmap block and bit macros to static inline functions
Replace these macros with typechecked helper functions. Eventually we're going to add more logic to the helpers and it'll be easier if we don't have to macro it up. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent ef5a83b commit 90d98a6

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

fs/xfs/libxfs/xfs_format.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,11 +1155,6 @@ static inline bool xfs_dinode_has_large_extent_counts(
11551155
((xfs_suminfo_t *)((bp)->b_addr + \
11561156
(((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
11571157

1158-
#define XFS_BITTOBLOCK(mp,bi) ((bi) >> (mp)->m_blkbit_log)
1159-
#define XFS_BLOCKTOBIT(mp,bb) ((bb) << (mp)->m_blkbit_log)
1160-
#define XFS_BITTOWORD(mp,bi) \
1161-
((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp)))
1162-
11631158
#define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b))
11641159
#define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b))
11651160

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ xfs_rtfind_back(
111111
xfs_rtword_t mask; /* mask of relevant bits for value */
112112
xfs_rtword_t want; /* mask for "good" values */
113113
xfs_rtword_t wdiff; /* difference from wanted value */
114-
int word; /* word number in the buffer */
114+
unsigned int word; /* word number in the buffer */
115115

116116
/*
117117
* Compute and read in starting bitmap block for starting block.
118118
*/
119-
block = XFS_BITTOBLOCK(mp, start);
119+
block = xfs_rtx_to_rbmblock(mp, start);
120120
error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
121121
if (error) {
122122
return error;
@@ -125,7 +125,7 @@ xfs_rtfind_back(
125125
/*
126126
* Get the first word's index & point to it.
127127
*/
128-
word = XFS_BITTOWORD(mp, start);
128+
word = xfs_rtx_to_rbmword(mp, start);
129129
b = &bufp[word];
130130
bit = (int)(start & (XFS_NBWORD - 1));
131131
len = start - limit + 1;
@@ -286,12 +286,12 @@ xfs_rtfind_forw(
286286
xfs_rtword_t mask; /* mask of relevant bits for value */
287287
xfs_rtword_t want; /* mask for "good" values */
288288
xfs_rtword_t wdiff; /* difference from wanted value */
289-
int word; /* word number in the buffer */
289+
unsigned int word; /* word number in the buffer */
290290

291291
/*
292292
* Compute and read in starting bitmap block for starting block.
293293
*/
294-
block = XFS_BITTOBLOCK(mp, start);
294+
block = xfs_rtx_to_rbmblock(mp, start);
295295
error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
296296
if (error) {
297297
return error;
@@ -300,7 +300,7 @@ xfs_rtfind_forw(
300300
/*
301301
* Get the first word's index & point to it.
302302
*/
303-
word = XFS_BITTOWORD(mp, start);
303+
word = xfs_rtx_to_rbmword(mp, start);
304304
b = &bufp[word];
305305
bit = (int)(start & (XFS_NBWORD - 1));
306306
len = limit - start + 1;
@@ -547,12 +547,12 @@ xfs_rtmodify_range(
547547
int i; /* current bit number rel. to start */
548548
int lastbit; /* last useful bit in word */
549549
xfs_rtword_t mask; /* mask o frelevant bits for value */
550-
int word; /* word number in the buffer */
550+
unsigned int word; /* word number in the buffer */
551551

552552
/*
553553
* Compute starting bitmap block number.
554554
*/
555-
block = XFS_BITTOBLOCK(mp, start);
555+
block = xfs_rtx_to_rbmblock(mp, start);
556556
/*
557557
* Read the bitmap block, and point to its data.
558558
*/
@@ -564,7 +564,7 @@ xfs_rtmodify_range(
564564
/*
565565
* Compute the starting word's address, and starting bit.
566566
*/
567-
word = XFS_BITTOWORD(mp, start);
567+
word = xfs_rtx_to_rbmword(mp, start);
568568
first = b = &bufp[word];
569569
bit = (int)(start & (XFS_NBWORD - 1));
570570
/*
@@ -730,7 +730,7 @@ xfs_rtfree_range(
730730
if (preblock < start) {
731731
error = xfs_rtmodify_summary(mp, tp,
732732
XFS_RTBLOCKLOG(start - preblock),
733-
XFS_BITTOBLOCK(mp, preblock), -1, rbpp, rsb);
733+
xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
734734
if (error) {
735735
return error;
736736
}
@@ -742,7 +742,7 @@ xfs_rtfree_range(
742742
if (postblock > end) {
743743
error = xfs_rtmodify_summary(mp, tp,
744744
XFS_RTBLOCKLOG(postblock - end),
745-
XFS_BITTOBLOCK(mp, end + 1), -1, rbpp, rsb);
745+
xfs_rtx_to_rbmblock(mp, end + 1), -1, rbpp, rsb);
746746
if (error) {
747747
return error;
748748
}
@@ -753,7 +753,7 @@ xfs_rtfree_range(
753753
*/
754754
error = xfs_rtmodify_summary(mp, tp,
755755
XFS_RTBLOCKLOG(postblock + 1 - preblock),
756-
XFS_BITTOBLOCK(mp, preblock), 1, rbpp, rsb);
756+
xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
757757
return error;
758758
}
759759

@@ -781,12 +781,12 @@ xfs_rtcheck_range(
781781
xfs_rtxnum_t lastbit; /* last useful bit in word */
782782
xfs_rtword_t mask; /* mask of relevant bits for value */
783783
xfs_rtword_t wdiff; /* difference from wanted value */
784-
int word; /* word number in the buffer */
784+
unsigned int word; /* word number in the buffer */
785785

786786
/*
787787
* Compute starting bitmap block number
788788
*/
789-
block = XFS_BITTOBLOCK(mp, start);
789+
block = xfs_rtx_to_rbmblock(mp, start);
790790
/*
791791
* Read the bitmap block.
792792
*/
@@ -798,7 +798,7 @@ xfs_rtcheck_range(
798798
/*
799799
* Compute the starting word's address, and starting bit.
800800
*/
801-
word = XFS_BITTOWORD(mp, start);
801+
word = xfs_rtx_to_rbmword(mp, start);
802802
b = &bufp[word];
803803
bit = (int)(start & (XFS_NBWORD - 1));
804804
/*

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,33 @@ xfs_rtb_rounddown_rtx(
131131
return rounddown_64(rtbno, mp->m_sb.sb_rextsize);
132132
}
133133

134+
/* Convert an rt extent number to a file block offset in the rt bitmap file. */
135+
static inline xfs_fileoff_t
136+
xfs_rtx_to_rbmblock(
137+
struct xfs_mount *mp,
138+
xfs_rtxnum_t rtx)
139+
{
140+
return rtx >> mp->m_blkbit_log;
141+
}
142+
143+
/* Convert an rt extent number to a word offset within an rt bitmap block. */
144+
static inline unsigned int
145+
xfs_rtx_to_rbmword(
146+
struct xfs_mount *mp,
147+
xfs_rtxnum_t rtx)
148+
{
149+
return (rtx >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp);
150+
}
151+
152+
/* Convert a file block offset in the rt bitmap file to an rt extent number. */
153+
static inline xfs_rtxnum_t
154+
xfs_rbmblock_to_rtx(
155+
struct xfs_mount *mp,
156+
xfs_fileoff_t rbmoff)
157+
{
158+
return rbmoff << mp->m_blkbit_log;
159+
}
160+
134161
/*
135162
* Functions for walking free space rtextents in the realtime bitmap.
136163
*/

fs/xfs/scrub/rtsummary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ xchk_rtsum_record_free(
130130
return error;
131131

132132
/* Compute the relevant location in the rtsum file. */
133-
rbmoff = XFS_BITTOBLOCK(mp, rec->ar_startext);
133+
rbmoff = xfs_rtx_to_rbmblock(mp, rec->ar_startext);
134134
lenlog = XFS_RTBLOCKLOG(rec->ar_extcount);
135135
offs = XFS_SUMOFFS(mp, lenlog, rbmoff);
136136

fs/xfs/xfs_rtalloc.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ xfs_rtallocate_range(
177177
*/
178178
error = xfs_rtmodify_summary(mp, tp,
179179
XFS_RTBLOCKLOG(postblock + 1 - preblock),
180-
XFS_BITTOBLOCK(mp, preblock), -1, rbpp, rsb);
180+
xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
181181
if (error) {
182182
return error;
183183
}
@@ -188,7 +188,7 @@ xfs_rtallocate_range(
188188
if (preblock < start) {
189189
error = xfs_rtmodify_summary(mp, tp,
190190
XFS_RTBLOCKLOG(start - preblock),
191-
XFS_BITTOBLOCK(mp, preblock), 1, rbpp, rsb);
191+
xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
192192
if (error) {
193193
return error;
194194
}
@@ -200,7 +200,7 @@ xfs_rtallocate_range(
200200
if (postblock > end) {
201201
error = xfs_rtmodify_summary(mp, tp,
202202
XFS_RTBLOCKLOG(postblock - end),
203-
XFS_BITTOBLOCK(mp, end + 1), 1, rbpp, rsb);
203+
xfs_rtx_to_rbmblock(mp, end + 1), 1, rbpp, rsb);
204204
if (error) {
205205
return error;
206206
}
@@ -261,8 +261,8 @@ xfs_rtallocate_extent_block(
261261
* Loop over all the extents starting in this bitmap block,
262262
* looking for one that's long enough.
263263
*/
264-
for (i = XFS_BLOCKTOBIT(mp, bbno), besti = -1, bestlen = 0,
265-
end = XFS_BLOCKTOBIT(mp, bbno + 1) - 1;
264+
for (i = xfs_rbmblock_to_rtx(mp, bbno), besti = -1, bestlen = 0,
265+
end = xfs_rbmblock_to_rtx(mp, bbno + 1) - 1;
266266
i <= end;
267267
i++) {
268268
/* Make sure we don't scan off the end of the rt volume. */
@@ -489,7 +489,7 @@ xfs_rtallocate_extent_near(
489489
*rtx = r;
490490
return 0;
491491
}
492-
bbno = XFS_BITTOBLOCK(mp, start);
492+
bbno = xfs_rtx_to_rbmblock(mp, start);
493493
i = 0;
494494
ASSERT(minlen != 0);
495495
log2len = xfs_highbit32(minlen);
@@ -708,8 +708,8 @@ xfs_rtallocate_extent_size(
708708
* allocator is beyond the next bitmap block,
709709
* skip to that bitmap block.
710710
*/
711-
if (XFS_BITTOBLOCK(mp, n) > i + 1)
712-
i = XFS_BITTOBLOCK(mp, n) - 1;
711+
if (xfs_rtx_to_rbmblock(mp, n) > i + 1)
712+
i = xfs_rtx_to_rbmblock(mp, n) - 1;
713713
}
714714
}
715715
/*
@@ -771,8 +771,8 @@ xfs_rtallocate_extent_size(
771771
* allocator is beyond the next bitmap block,
772772
* skip to that bitmap block.
773773
*/
774-
if (XFS_BITTOBLOCK(mp, n) > i + 1)
775-
i = XFS_BITTOBLOCK(mp, n) - 1;
774+
if (xfs_rtx_to_rbmblock(mp, n) > i + 1)
775+
i = xfs_rtx_to_rbmblock(mp, n) - 1;
776776
}
777777
}
778778
/*

0 commit comments

Comments
 (0)