Skip to content

Commit 097b4b7

Browse files
author
Darrick J. Wong
committed
xfs: convert rt summary macros to helpers
Convert the realtime summary file macros to helper functions so that we can improve type checking. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent a994862 commit 097b4b7

File tree

5 files changed

+67
-18
lines changed

5 files changed

+67
-18
lines changed

fs/xfs/libxfs/xfs_format.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,15 +1144,8 @@ static inline bool xfs_dinode_has_large_extent_counts(
11441144
#define XFS_BLOCKMASK(mp) ((mp)->m_blockmask)
11451145

11461146
/*
1147-
* RT Summary and bit manipulation macros.
1147+
* RT bit manipulation macros.
11481148
*/
1149-
#define XFS_SUMOFFS(mp,ls,bb) ((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
1150-
#define XFS_SUMOFFSTOBLOCK(mp,s) \
1151-
(((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
1152-
#define XFS_SUMPTR(mp,bp,so) \
1153-
((xfs_suminfo_t *)((bp)->b_addr + \
1154-
(((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
1155-
11561149
#define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b))
11571150
#define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b))
11581151

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,17 +455,18 @@ xfs_rtmodify_summary_int(
455455
struct xfs_buf *bp; /* buffer for the summary block */
456456
int error; /* error value */
457457
xfs_fileoff_t sb; /* summary fsblock */
458-
int so; /* index into the summary file */
458+
xfs_rtsumoff_t so; /* index into the summary file */
459459
xfs_suminfo_t *sp; /* pointer to returned data */
460+
unsigned int infoword;
460461

461462
/*
462463
* Compute entry number in the summary file.
463464
*/
464-
so = XFS_SUMOFFS(mp, log, bbno);
465+
so = xfs_rtsumoffs(mp, log, bbno);
465466
/*
466467
* Compute the block number in the summary file.
467468
*/
468-
sb = XFS_SUMOFFSTOBLOCK(mp, so);
469+
sb = xfs_rtsumoffs_to_block(mp, so);
469470
/*
470471
* If we have an old buffer, and the block number matches, use that.
471472
*/
@@ -493,7 +494,8 @@ xfs_rtmodify_summary_int(
493494
/*
494495
* Point to the summary information, modify/log it, and/or copy it out.
495496
*/
496-
sp = XFS_SUMPTR(mp, bp, so);
497+
infoword = xfs_rtsumoffs_to_infoword(mp, so);
498+
sp = xfs_rsumblock_infoptr(bp, infoword);
497499
if (delta) {
498500
uint first = (uint)((char *)sp - (char *)bp->b_addr);
499501

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,56 @@ xfs_rbmblock_wordptr(
169169
return words + index;
170170
}
171171

172+
/*
173+
* Convert a rt extent length and rt bitmap block number to a xfs_suminfo_t
174+
* offset within the rt summary file.
175+
*/
176+
static inline xfs_rtsumoff_t
177+
xfs_rtsumoffs(
178+
struct xfs_mount *mp,
179+
int log2_len,
180+
xfs_fileoff_t rbmoff)
181+
{
182+
return log2_len * mp->m_sb.sb_rbmblocks + rbmoff;
183+
}
184+
185+
/*
186+
* Convert an xfs_suminfo_t offset to a file block offset within the rt summary
187+
* file.
188+
*/
189+
static inline xfs_fileoff_t
190+
xfs_rtsumoffs_to_block(
191+
struct xfs_mount *mp,
192+
xfs_rtsumoff_t rsumoff)
193+
{
194+
return XFS_B_TO_FSBT(mp, rsumoff * sizeof(xfs_suminfo_t));
195+
}
196+
197+
/*
198+
* Convert an xfs_suminfo_t offset to an info word offset within an rt summary
199+
* block.
200+
*/
201+
static inline unsigned int
202+
xfs_rtsumoffs_to_infoword(
203+
struct xfs_mount *mp,
204+
xfs_rtsumoff_t rsumoff)
205+
{
206+
unsigned int mask = mp->m_blockmask >> XFS_SUMINFOLOG;
207+
208+
return rsumoff & mask;
209+
}
210+
211+
/* Return a pointer to a summary info word within a rt summary block. */
212+
static inline xfs_suminfo_t *
213+
xfs_rsumblock_infoptr(
214+
struct xfs_buf *bp,
215+
unsigned int index)
216+
{
217+
xfs_suminfo_t *info = bp->b_addr;
218+
219+
return info + index;
220+
}
221+
172222
/*
173223
* Functions for walking free space rtextents in the realtime bitmap.
174224
*/

fs/xfs/libxfs/xfs_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef int64_t xfs_fsize_t; /* bytes in a file */
1919
typedef uint64_t xfs_ufsize_t; /* unsigned bytes in a file */
2020

2121
typedef int32_t xfs_suminfo_t; /* type of bitmap summary info */
22+
typedef uint32_t xfs_rtsumoff_t; /* offset of an rtsummary info word */
2223
typedef uint32_t xfs_rtword_t; /* word type for bitmap manipulations */
2324

2425
typedef int64_t xfs_lsn_t; /* log sequence number */
@@ -149,6 +150,7 @@ typedef uint32_t xfs_dqid_t;
149150
*/
150151
#define XFS_NBBYLOG 3 /* log2(NBBY) */
151152
#define XFS_WORDLOG 2 /* log2(sizeof(xfs_rtword_t)) */
153+
#define XFS_SUMINFOLOG 2 /* log2(sizeof(xfs_suminfo_t)) */
152154
#define XFS_NBWORDLOG (XFS_NBBYLOG + XFS_WORDLOG)
153155
#define XFS_NBWORD (1 << XFS_NBWORDLOG)
154156
#define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1)

fs/xfs/scrub/rtsummary.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ typedef unsigned int xchk_rtsumoff_t;
8181
static inline int
8282
xfsum_load(
8383
struct xfs_scrub *sc,
84-
xchk_rtsumoff_t sumoff,
84+
xfs_rtsumoff_t sumoff,
8585
xfs_suminfo_t *info)
8686
{
8787
return xfile_obj_load(sc->xfile, info, sizeof(xfs_suminfo_t),
@@ -91,7 +91,7 @@ xfsum_load(
9191
static inline int
9292
xfsum_store(
9393
struct xfs_scrub *sc,
94-
xchk_rtsumoff_t sumoff,
94+
xfs_rtsumoff_t sumoff,
9595
const xfs_suminfo_t info)
9696
{
9797
return xfile_obj_store(sc->xfile, &info, sizeof(xfs_suminfo_t),
@@ -101,7 +101,7 @@ xfsum_store(
101101
static inline int
102102
xfsum_copyout(
103103
struct xfs_scrub *sc,
104-
xchk_rtsumoff_t sumoff,
104+
xfs_rtsumoff_t sumoff,
105105
xfs_suminfo_t *info,
106106
unsigned int nr_words)
107107
{
@@ -121,7 +121,7 @@ xchk_rtsum_record_free(
121121
xfs_fileoff_t rbmoff;
122122
xfs_rtblock_t rtbno;
123123
xfs_filblks_t rtlen;
124-
xchk_rtsumoff_t offs;
124+
xfs_rtsumoff_t offs;
125125
unsigned int lenlog;
126126
xfs_suminfo_t v = 0;
127127
int error = 0;
@@ -132,7 +132,7 @@ xchk_rtsum_record_free(
132132
/* Compute the relevant location in the rtsum file. */
133133
rbmoff = xfs_rtx_to_rbmblock(mp, rec->ar_startext);
134134
lenlog = XFS_RTBLOCKLOG(rec->ar_extcount);
135-
offs = XFS_SUMOFFS(mp, lenlog, rbmoff);
135+
offs = xfs_rtsumoffs(mp, lenlog, rbmoff);
136136

137137
rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
138138
rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount);
@@ -185,6 +185,7 @@ xchk_rtsum_compare(
185185
int nmap;
186186

187187
for (off = 0; off < XFS_B_TO_FSB(mp, mp->m_rsumsize); off++) {
188+
xfs_suminfo_t *ondisk_info;
188189
int error = 0;
189190

190191
if (xchk_should_terminate(sc, &error))
@@ -216,7 +217,8 @@ xchk_rtsum_compare(
216217
return error;
217218
}
218219

219-
if (memcmp(bp->b_addr, sc->buf,
220+
ondisk_info = xfs_rsumblock_infoptr(bp, 0);
221+
if (memcmp(ondisk_info, sc->buf,
220222
mp->m_blockwsize << XFS_WORDLOG) != 0)
221223
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off);
222224

0 commit comments

Comments
 (0)