Re: [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 12, 2023 at 07:17:13AM +0200, Christoph Hellwig wrote:
> On Wed, Oct 11, 2023 at 11:05:27AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@xxxxxxxxxx>
> > 
> > Create helpers to do unit conversions of rt block numbers to rt extent
> > numbers.  There are two variations -- the suffix "t" denotes the one
> > that returns only the truncated extent number; the other one also
> > returns the misalignment.  Convert all the div_u64_rem users; we'll do
> > the do_div users in the next patch.
> 
> When trying to work with thee helpers I found the t prefix here a bit
> weird, as it works different than the T in say XFS_B_TO_FSB
> vs XFS_B_TO_FSBT which give you different results for the two versions.
> Here we get the same returned result, just with the additional
> return for the remainder.
> 
> Maybe have xfs_rtb_to_rtx and xfs_rtb_to_rtx_rem for the version with
> the modulo?

<nod> I've decided to go with:

/* 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)
{
	return div_u64(rtbno, mp->m_sb.sb_rextsize);
}

/* Return the offset of an rt block number within an rt extent. */
static inline xfs_extlen_t
xfs_rtb_to_rtxoff(
	struct xfs_mount	*mp,
	xfs_rtblock_t		rtbno)
{
	return do_div(rtbno, mp->m_sb.sb_rextsize);
}

/*
 * Crack an rt block number into an rt extent number and an offset within that
 * rt extent.  Returns the rt extent number directly and the offset in @off.
 */
static inline xfs_rtxnum_t
xfs_rtb_to_rtxrem(
	struct xfs_mount	*mp,
	xfs_rtblock_t		rtbno,
	xfs_extlen_t		*off)
{
	return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
}

> We also have quite a few places that only care about the mod,
> so an additƣonal xfs_rtb_rem/mod might be useful as well.

Agreed, I had noticed that there were a fair number of places where
we're really only checking for rtx alignment.  xfs_rtb_to_rtxoff is
the new helper.

--D



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux