Skip to content

Commit fa5a387

Browse files
author
Darrick J. Wong
committed
xfs: create a helper to convert rtextents to rtblocks
Create a helper to convert a realtime extent to a realtime block. Later on we'll change the helper to use bit shifts when possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 2d5f216 commit fa5a387

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
#ifndef __XFS_RTBITMAP_H__
77
#define __XFS_RTBITMAP_H__
88

9+
static inline xfs_rtblock_t
10+
xfs_rtx_to_rtb(
11+
struct xfs_mount *mp,
12+
xfs_rtxnum_t rtx)
13+
{
14+
return rtx * mp->m_sb.sb_rextsize;
15+
}
16+
17+
static inline xfs_extlen_t
18+
xfs_rtxlen_to_extlen(
19+
struct xfs_mount *mp,
20+
xfs_rtxlen_t rtxlen)
21+
{
22+
return rtxlen * mp->m_sb.sb_rextsize;
23+
}
24+
925
/*
1026
* Functions for walking free space rtextents in the realtime bitmap.
1127
*/

fs/xfs/scrub/rtbitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ xchk_rtbitmap_rec(
5050
xfs_rtblock_t startblock;
5151
xfs_filblks_t blockcount;
5252

53-
startblock = rec->ar_startext * mp->m_sb.sb_rextsize;
54-
blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize;
53+
startblock = xfs_rtx_to_rtb(mp, rec->ar_startext);
54+
blockcount = xfs_rtx_to_rtb(mp, rec->ar_extcount);
5555

5656
if (!xfs_verify_rtbext(mp, startblock, blockcount))
5757
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);

fs/xfs/scrub/rtsummary.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ xchk_rtsum_record_free(
134134
lenlog = XFS_RTBLOCKLOG(rec->ar_extcount);
135135
offs = XFS_SUMOFFS(mp, lenlog, rbmoff);
136136

137-
rtbno = rec->ar_startext * mp->m_sb.sb_rextsize;
138-
rtlen = rec->ar_extcount * mp->m_sb.sb_rextsize;
137+
rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
138+
rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount);
139139

140140
if (!xfs_verify_rtbext(mp, rtbno, rtlen)) {
141141
xchk_ino_xref_set_corrupt(sc, mp->m_rbmip->i_ino);

fs/xfs/xfs_bmap_util.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "xfs_icache.h"
2929
#include "xfs_iomap.h"
3030
#include "xfs_reflink.h"
31+
#include "xfs_rtbitmap.h"
3132

3233
/* Kernel only BMAP related definitions and functions */
3334

@@ -125,7 +126,7 @@ xfs_bmap_rtalloc(
125126
* XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't
126127
* adjust the starting point to match it.
127128
*/
128-
if (ralen * mp->m_sb.sb_rextsize >= XFS_MAX_BMBT_EXTLEN)
129+
if (xfs_rtxlen_to_extlen(mp, ralen) >= XFS_MAX_BMBT_EXTLEN)
129130
ralen = XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize;
130131

131132
/*
@@ -147,7 +148,7 @@ xfs_bmap_rtalloc(
147148
error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx);
148149
if (error)
149150
return error;
150-
ap->blkno = rtx * mp->m_sb.sb_rextsize;
151+
ap->blkno = xfs_rtx_to_rtb(mp, rtx);
151152
} else {
152153
ap->blkno = 0;
153154
}
@@ -170,8 +171,8 @@ xfs_bmap_rtalloc(
170171
return error;
171172

172173
if (rtx != NULLRTEXTNO) {
173-
ap->blkno = rtx * mp->m_sb.sb_rextsize;
174-
ap->length = ralen * mp->m_sb.sb_rextsize;
174+
ap->blkno = xfs_rtx_to_rtb(mp, rtx);
175+
ap->length = xfs_rtxlen_to_extlen(mp, ralen);
175176
ap->ip->i_nblocks += ap->length;
176177
xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE);
177178
if (ap->wasdel)

fs/xfs/xfs_fsmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,11 @@ xfs_getfsmap_rtdev_rtbitmap_helper(
483483
xfs_rtblock_t rtbno;
484484
xfs_daddr_t rec_daddr, len_daddr;
485485

486-
rtbno = rec->ar_startext * mp->m_sb.sb_rextsize;
486+
rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
487487
rec_daddr = XFS_FSB_TO_BB(mp, rtbno);
488488
irec.rm_startblock = rtbno;
489489

490-
rtbno = rec->ar_extcount * mp->m_sb.sb_rextsize;
490+
rtbno = xfs_rtx_to_rtb(mp, rec->ar_extcount);
491491
len_daddr = XFS_FSB_TO_BB(mp, rtbno);
492492
irec.rm_blockcount = rtbno;
493493

@@ -514,7 +514,7 @@ xfs_getfsmap_rtdev_rtbitmap(
514514
uint64_t eofs;
515515
int error;
516516

517-
eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rextents * mp->m_sb.sb_rextsize);
517+
eofs = XFS_FSB_TO_BB(mp, xfs_rtx_to_rtb(mp, mp->m_sb.sb_rextents));
518518
if (keys[0].fmr_physical >= eofs)
519519
return 0;
520520
start_rtb = XFS_BB_TO_FSBT(mp,

fs/xfs/xfs_super.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "xfs_xattr.h"
4343
#include "xfs_iunlink_item.h"
4444
#include "xfs_dahash_test.h"
45+
#include "xfs_rtbitmap.h"
4546
#include "scrub/stats.h"
4647

4748
#include <linux/magic.h>
@@ -890,7 +891,7 @@ xfs_fs_statfs(
890891

891892
statp->f_blocks = sbp->sb_rblocks;
892893
freertx = percpu_counter_sum_positive(&mp->m_frextents);
893-
statp->f_bavail = statp->f_bfree = freertx * sbp->sb_rextsize;
894+
statp->f_bavail = statp->f_bfree = xfs_rtx_to_rtb(mp, freertx);
894895
}
895896

896897
return 0;

0 commit comments

Comments
 (0)