Commit 3ef52c01 authored by Chandan Babu R's avatar Chandan Babu R
Browse files

Merge tag 'clean-up-realtime-units-6.7_2023-10-19' of...

Merge tag 'clean-up-realtime-units-6.7_2023-10-19' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux

 into xfs-6.7-mergeA

xfs: clean up realtime type usage [v1.1]

The realtime code uses xfs_rtblock_t and xfs_fsblock_t in a lot of
places, and it's very confusing.  Clean up all the type usage so that an
xfs_rtblock_t is always a block within the realtime volume, an
xfs_fileoff_t is always a file offset within a realtime metadata file,
and an xfs_rtxnumber_t is always a rt extent within the realtime volume.

v1.1: various cleanups suggested by hch

With a bit of luck, this should all go splendidly.

Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>

* tag 'clean-up-realtime-units-6.7_2023-10-19' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: convert rt extent numbers to xfs_rtxnum_t
  xfs: rename xfs_verify_rtext to xfs_verify_rtbext
  xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t
  xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t
  xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator
  xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h
  xfs: make sure maxlen is still congruent with prod when rounding down
  xfs: fix units conversion error in xfs_bmap_del_extent_delay
parents d0e85e79 2d5f216b
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
#include "xfs_bmap.h"
#include "xfs_bmap_util.h"
#include "xfs_bmap_btree.h"
#include "xfs_rtalloc.h"
#include "xfs_rtbitmap.h"
#include "xfs_errortag.h"
#include "xfs_error.h"
#include "xfs_quota.h"
@@ -4827,7 +4827,7 @@ xfs_bmap_del_extent_delay(
	ASSERT(got_endoff >= del_endoff);

	if (isrt) {
		uint64_t rtexts = XFS_FSB_TO_B(mp, del->br_blockcount);
		uint64_t	rtexts = del->br_blockcount;

		do_div(rtexts, mp->m_sb.sb_rextsize);
		xfs_mod_frextents(mp, rtexts);
@@ -6196,7 +6196,7 @@ xfs_bmap_validate_extent(
		return __this_address;

	if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) {
		if (!xfs_verify_rtext(mp, irec->br_startblock,
		if (!xfs_verify_rtbext(mp, irec->br_startblock,
					   irec->br_blockcount))
			return __this_address;
	} else {
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ typedef struct xfs_sb {
	uint32_t	sb_blocksize;	/* logical block size, bytes */
	xfs_rfsblock_t	sb_dblocks;	/* number of data blocks */
	xfs_rfsblock_t	sb_rblocks;	/* number of realtime blocks */
	xfs_rtblock_t	sb_rextents;	/* number of realtime extents */
	xfs_rtbxlen_t	sb_rextents;	/* number of realtime extents */
	uuid_t		sb_uuid;	/* user-visible file system unique id */
	xfs_fsblock_t	sb_logstart;	/* starting block of log if internal */
	xfs_ino_t	sb_rootino;	/* root inode number */
+61 −60
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include "xfs_trans.h"
#include "xfs_rtalloc.h"
#include "xfs_error.h"
#include "xfs_rtbitmap.h"

/*
 * Realtime allocator bitmap functions shared with userspace.
@@ -54,7 +55,7 @@ int
xfs_rtbuf_get(
	xfs_mount_t	*mp,		/* file system mount structure */
	xfs_trans_t	*tp,		/* transaction pointer */
	xfs_rtblock_t	block,		/* block number in bitmap or summary */
	xfs_fileoff_t	block,		/* block number in bitmap or summary */
	int		issum,		/* is summary not bitmap */
	struct xfs_buf	**bpp)		/* output: buffer for the block */
{
@@ -94,19 +95,19 @@ int
xfs_rtfind_back(
	xfs_mount_t	*mp,		/* file system mount point */
	xfs_trans_t	*tp,		/* transaction pointer */
	xfs_rtblock_t	start,		/* starting block to look at */
	xfs_rtblock_t	limit,		/* last block to look at */
	xfs_rtblock_t	*rtblock)	/* out: start block found */
	xfs_rtxnum_t	start,		/* starting rtext to look at */
	xfs_rtxnum_t	limit,		/* last rtext to look at */
	xfs_rtxnum_t	*rtx)		/* out: start rtext found */
{
	xfs_rtword_t	*b;		/* current word in buffer */
	int		bit;		/* bit number in the word */
	xfs_rtblock_t	block;		/* bitmap block number */
	xfs_fileoff_t	block;		/* bitmap block number */
	struct xfs_buf	*bp;		/* buf for the block */
	xfs_rtword_t	*bufp;		/* starting word in buffer */
	int		error;		/* error value */
	xfs_rtblock_t	firstbit;	/* first useful bit in the word */
	xfs_rtblock_t	i;		/* current bit number rel. to start */
	xfs_rtblock_t	len;		/* length of inspected area */
	xfs_rtxnum_t	firstbit;	/* first useful bit in the word */
	xfs_rtxnum_t	i;		/* current bit number rel. to start */
	xfs_rtxnum_t	len;		/* length of inspected area */
	xfs_rtword_t	mask;		/* mask of relevant bits for value */
	xfs_rtword_t	want;		/* mask for "good" values */
	xfs_rtword_t	wdiff;		/* difference from wanted value */
@@ -155,7 +156,7 @@ xfs_rtfind_back(
			 */
			xfs_trans_brelse(tp, bp);
			i = bit - XFS_RTHIBIT(wdiff);
			*rtblock = start - i + 1;
			*rtx = start - i + 1;
			return 0;
		}
		i = bit - firstbit + 1;
@@ -201,7 +202,7 @@ xfs_rtfind_back(
			 */
			xfs_trans_brelse(tp, bp);
			i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
			*rtblock = start - i + 1;
			*rtx = start - i + 1;
			return 0;
		}
		i += XFS_NBWORD;
@@ -248,7 +249,7 @@ xfs_rtfind_back(
			 */
			xfs_trans_brelse(tp, bp);
			i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
			*rtblock = start - i + 1;
			*rtx = start - i + 1;
			return 0;
		} else
			i = len;
@@ -257,7 +258,7 @@ xfs_rtfind_back(
	 * No match, return that we scanned the whole area.
	 */
	xfs_trans_brelse(tp, bp);
	*rtblock = start - i + 1;
	*rtx = start - i + 1;
	return 0;
}

@@ -269,19 +270,19 @@ int
xfs_rtfind_forw(
	xfs_mount_t	*mp,		/* file system mount point */
	xfs_trans_t	*tp,		/* transaction pointer */
	xfs_rtblock_t	start,		/* starting block to look at */
	xfs_rtblock_t	limit,		/* last block to look at */
	xfs_rtblock_t	*rtblock)	/* out: start block found */
	xfs_rtxnum_t	start,		/* starting rtext to look at */
	xfs_rtxnum_t	limit,		/* last rtext to look at */
	xfs_rtxnum_t	*rtx)		/* out: start rtext found */
{
	xfs_rtword_t	*b;		/* current word in buffer */
	int		bit;		/* bit number in the word */
	xfs_rtblock_t	block;		/* bitmap block number */
	xfs_fileoff_t	block;		/* bitmap block number */
	struct xfs_buf	*bp;		/* buf for the block */
	xfs_rtword_t	*bufp;		/* starting word in buffer */
	int		error;		/* error value */
	xfs_rtblock_t	i;		/* current bit number rel. to start */
	xfs_rtblock_t	lastbit;	/* last useful bit in the word */
	xfs_rtblock_t	len;		/* length of inspected area */
	xfs_rtxnum_t	i;		/* current bit number rel. to start */
	xfs_rtxnum_t	lastbit;	/* last useful bit in the word */
	xfs_rtxnum_t	len;		/* length of inspected area */
	xfs_rtword_t	mask;		/* mask of relevant bits for value */
	xfs_rtword_t	want;		/* mask for "good" values */
	xfs_rtword_t	wdiff;		/* difference from wanted value */
@@ -329,7 +330,7 @@ xfs_rtfind_forw(
			 */
			xfs_trans_brelse(tp, bp);
			i = XFS_RTLOBIT(wdiff) - bit;
			*rtblock = start + i - 1;
			*rtx = start + i - 1;
			return 0;
		}
		i = lastbit - bit;
@@ -374,7 +375,7 @@ xfs_rtfind_forw(
			 */
			xfs_trans_brelse(tp, bp);
			i += XFS_RTLOBIT(wdiff);
			*rtblock = start + i - 1;
			*rtx = start + i - 1;
			return 0;
		}
		i += XFS_NBWORD;
@@ -418,7 +419,7 @@ xfs_rtfind_forw(
			 */
			xfs_trans_brelse(tp, bp);
			i += XFS_RTLOBIT(wdiff);
			*rtblock = start + i - 1;
			*rtx = start + i - 1;
			return 0;
		} else
			i = len;
@@ -427,7 +428,7 @@ xfs_rtfind_forw(
	 * No match, return that we scanned the whole area.
	 */
	xfs_trans_brelse(tp, bp);
	*rtblock = start + i - 1;
	*rtx = start + i - 1;
	return 0;
}

@@ -445,15 +446,15 @@ xfs_rtmodify_summary_int(
	xfs_mount_t	*mp,		/* file system mount structure */
	xfs_trans_t	*tp,		/* transaction pointer */
	int		log,		/* log2 of extent size */
	xfs_rtblock_t	bbno,		/* bitmap block number */
	xfs_fileoff_t	bbno,		/* bitmap block number */
	int		delta,		/* change to make to summary info */
	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
	xfs_fsblock_t	*rsb,		/* in/out: summary block number */
	xfs_fileoff_t	*rsb,		/* in/out: summary block number */
	xfs_suminfo_t	*sum)		/* out: summary info for this block */
{
	struct xfs_buf	*bp;		/* buffer for the summary block */
	int		error;		/* error value */
	xfs_fsblock_t	sb;		/* summary fsblock */
	xfs_fileoff_t	sb;		/* summary fsblock */
	int		so;		/* index into the summary file */
	xfs_suminfo_t	*sp;		/* pointer to returned data */

@@ -515,10 +516,10 @@ xfs_rtmodify_summary(
	xfs_mount_t	*mp,		/* file system mount structure */
	xfs_trans_t	*tp,		/* transaction pointer */
	int		log,		/* log2 of extent size */
	xfs_rtblock_t	bbno,		/* bitmap block number */
	xfs_fileoff_t	bbno,		/* bitmap block number */
	int		delta,		/* change to make to summary info */
	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
	xfs_fsblock_t	*rsb)		/* in/out: summary block number */
	xfs_fileoff_t	*rsb)		/* in/out: summary block number */
{
	return xfs_rtmodify_summary_int(mp, tp, log, bbno,
					delta, rbpp, rsb, NULL);
@@ -532,13 +533,13 @@ int
xfs_rtmodify_range(
	xfs_mount_t	*mp,		/* file system mount point */
	xfs_trans_t	*tp,		/* transaction pointer */
	xfs_rtblock_t	start,		/* starting block to modify */
	xfs_extlen_t	len,		/* length of extent to modify */
	xfs_rtxnum_t	start,		/* starting rtext to modify */
	xfs_rtxlen_t	len,		/* length of extent to modify */
	int		val)		/* 1 for free, 0 for allocated */
{
	xfs_rtword_t	*b;		/* current word in buffer */
	int		bit;		/* bit number in the word */
	xfs_rtblock_t	block;		/* bitmap block number */
	xfs_fileoff_t	block;		/* bitmap block number */
	struct xfs_buf	*bp;		/* buf for the block */
	xfs_rtword_t	*bufp;		/* starting word in buffer */
	int		error;		/* error value */
@@ -688,15 +689,15 @@ int
xfs_rtfree_range(
	xfs_mount_t	*mp,		/* file system mount point */
	xfs_trans_t	*tp,		/* transaction pointer */
	xfs_rtblock_t	start,		/* starting block to free */
	xfs_extlen_t	len,		/* length to free */
	xfs_rtxnum_t	start,		/* starting rtext to free */
	xfs_rtxlen_t	len,		/* length to free */
	struct xfs_buf	**rbpp,		/* in/out: summary block buffer */
	xfs_fsblock_t	*rsb)		/* in/out: summary block number */
	xfs_fileoff_t	*rsb)		/* in/out: summary block number */
{
	xfs_rtblock_t	end;		/* end of the freed extent */
	xfs_rtxnum_t	end;		/* end of the freed extent */
	int		error;		/* error value */
	xfs_rtblock_t	postblock;	/* first block freed > end */
	xfs_rtblock_t	preblock;	/* first block freed < start */
	xfs_rtxnum_t	postblock;	/* first rtext freed > end */
	xfs_rtxnum_t	preblock;	/* first rtext freed < start */

	end = start + len - 1;
	/*
@@ -764,20 +765,20 @@ int
xfs_rtcheck_range(
	xfs_mount_t	*mp,		/* file system mount point */
	xfs_trans_t	*tp,		/* transaction pointer */
	xfs_rtblock_t	start,		/* starting block number of extent */
	xfs_extlen_t	len,		/* length of extent */
	xfs_rtxnum_t	start,		/* starting rtext number of extent */
	xfs_rtxlen_t	len,		/* length of extent */
	int		val,		/* 1 for free, 0 for allocated */
	xfs_rtblock_t	*new,		/* out: first block not matching */
	xfs_rtxnum_t	*new,		/* out: first rtext not matching */
	int		*stat)		/* out: 1 for matches, 0 for not */
{
	xfs_rtword_t	*b;		/* current word in buffer */
	int		bit;		/* bit number in the word */
	xfs_rtblock_t	block;		/* bitmap block number */
	xfs_fileoff_t	block;		/* bitmap block number */
	struct xfs_buf	*bp;		/* buf for the block */
	xfs_rtword_t	*bufp;		/* starting word in buffer */
	int		error;		/* error value */
	xfs_rtblock_t	i;		/* current bit number rel. to start */
	xfs_rtblock_t	lastbit;	/* last useful bit in word */
	xfs_rtxnum_t	i;		/* current bit number rel. to start */
	xfs_rtxnum_t	lastbit;	/* last useful bit in word */
	xfs_rtword_t	mask;		/* mask of relevant bits for value */
	xfs_rtword_t	wdiff;		/* difference from wanted value */
	int		word;		/* word number in the buffer */
@@ -940,14 +941,14 @@ STATIC int /* error */
xfs_rtcheck_alloc_range(
	xfs_mount_t	*mp,		/* file system mount point */
	xfs_trans_t	*tp,		/* transaction pointer */
	xfs_rtblock_t	bno,		/* starting block number of extent */
	xfs_extlen_t	len)		/* length of extent */
	xfs_rtxnum_t	start,		/* starting rtext number of extent */
	xfs_rtxlen_t	len)		/* length of extent */
{
	xfs_rtblock_t	new;		/* dummy for xfs_rtcheck_range */
	xfs_rtxnum_t	new;		/* dummy for xfs_rtcheck_range */
	int		stat;
	int		error;

	error = xfs_rtcheck_range(mp, tp, bno, len, 0, &new, &stat);
	error = xfs_rtcheck_range(mp, tp, start, len, 0, &new, &stat);
	if (error)
		return error;
	ASSERT(stat);
@@ -963,8 +964,8 @@ xfs_rtcheck_alloc_range(
int					/* error */
xfs_rtfree_extent(
	xfs_trans_t	*tp,		/* transaction pointer */
	xfs_rtblock_t	bno,		/* starting block number to free */
	xfs_extlen_t	len)		/* length of extent freed */
	xfs_rtxnum_t	start,		/* starting rtext number to free */
	xfs_rtxlen_t	len)		/* length of extent freed */
{
	int		error;		/* error value */
	xfs_mount_t	*mp;		/* file system mount structure */
@@ -976,14 +977,14 @@ xfs_rtfree_extent(
	ASSERT(mp->m_rbmip->i_itemp != NULL);
	ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL));

	error = xfs_rtcheck_alloc_range(mp, tp, bno, len);
	error = xfs_rtcheck_alloc_range(mp, tp, start, len);
	if (error)
		return error;

	/*
	 * Free the range of realtime blocks.
	 */
	error = xfs_rtfree_range(mp, tp, bno, len, &sumbp, &sb);
	error = xfs_rtfree_range(mp, tp, start, len, &sumbp, &sb);
	if (error) {
		return error;
	}
@@ -1017,7 +1018,7 @@ xfs_rtfree_blocks(
	xfs_filblks_t		rtlen)
{
	struct xfs_mount	*mp = tp->t_mountp;
	xfs_rtblock_t		bno;
	xfs_rtxnum_t		start;
	xfs_filblks_t		len;
	xfs_extlen_t		mod;

@@ -1029,13 +1030,13 @@ xfs_rtfree_blocks(
		return -EIO;
	}

	bno = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
	start = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
	if (mod) {
		ASSERT(mod == 0);
		return -EIO;
	}

	return xfs_rtfree_extent(tp, bno, len);
	return xfs_rtfree_extent(tp, start, len);
}

/* Find all the free records within a given range. */
@@ -1049,9 +1050,9 @@ xfs_rtalloc_query_range(
	void				*priv)
{
	struct xfs_rtalloc_rec		rec;
	xfs_rtblock_t			rtstart;
	xfs_rtblock_t			rtend;
	xfs_rtblock_t			high_key;
	xfs_rtxnum_t			rtstart;
	xfs_rtxnum_t			rtend;
	xfs_rtxnum_t			high_key;
	int				is_free;
	int				error = 0;

@@ -1114,11 +1115,11 @@ int
xfs_rtalloc_extent_is_free(
	struct xfs_mount		*mp,
	struct xfs_trans		*tp,
	xfs_rtblock_t			start,
	xfs_extlen_t			len,
	xfs_rtxnum_t			start,
	xfs_rtxlen_t			len,
	bool				*is_free)
{
	xfs_rtblock_t			end;
	xfs_rtxnum_t			end;
	int				matches;
	int				error;

+79 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
 * All Rights Reserved.
 */
#ifndef __XFS_RTBITMAP_H__
#define	__XFS_RTBITMAP_H__

/*
 * Functions for walking free space rtextents in the realtime bitmap.
 */
struct xfs_rtalloc_rec {
	xfs_rtxnum_t		ar_startext;
	xfs_rtbxlen_t		ar_extcount;
};

typedef int (*xfs_rtalloc_query_range_fn)(
	struct xfs_mount		*mp,
	struct xfs_trans		*tp,
	const struct xfs_rtalloc_rec	*rec,
	void				*priv);

#ifdef CONFIG_XFS_RT
int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
		  xfs_fileoff_t block, int issum, struct xfs_buf **bpp);
int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
		      xfs_rtxnum_t start, xfs_rtxlen_t len, int val,
		      xfs_rtxnum_t *new, int *stat);
int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
		    xfs_rtxnum_t start, xfs_rtxnum_t limit,
		    xfs_rtxnum_t *rtblock);
int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
		    xfs_rtxnum_t start, xfs_rtxnum_t limit,
		    xfs_rtxnum_t *rtblock);
int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
		       xfs_rtxnum_t start, xfs_rtxlen_t len, int val);
int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
			     int log, xfs_fileoff_t bbno, int delta,
			     struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
			     xfs_suminfo_t *sum);
int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
			 xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
			 xfs_fileoff_t *rsb);
int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
		     xfs_rtxnum_t start, xfs_rtxlen_t len,
		     struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
		const struct xfs_rtalloc_rec *low_rec,
		const struct xfs_rtalloc_rec *high_rec,
		xfs_rtalloc_query_range_fn fn, void *priv);
int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
			  xfs_rtalloc_query_range_fn fn,
			  void *priv);
int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
			       xfs_rtxnum_t start, xfs_rtxlen_t len,
			       bool *is_free);
/*
 * Free an extent in the realtime subvolume.  Length is expressed in
 * realtime extents, as is the block number.
 */
int					/* error */
xfs_rtfree_extent(
	struct xfs_trans	*tp,	/* transaction pointer */
	xfs_rtxnum_t		start,	/* starting rtext number to free */
	xfs_rtxlen_t		len);	/* length of extent freed */

/* Same as above, but in units of rt blocks. */
int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
		xfs_filblks_t rtlen);
#else /* CONFIG_XFS_RT */
# define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
# define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
# define xfs_rtalloc_query_range(m,t,l,h,f,p)		(-ENOSYS)
# define xfs_rtalloc_query_all(m,t,f,p)			(-ENOSYS)
# define xfs_rtbuf_get(m,t,b,i,p)			(-ENOSYS)
# define xfs_rtalloc_extent_is_free(m,t,s,l,i)		(-ENOSYS)
#endif /* CONFIG_XFS_RT */

#endif /* __XFS_RTBITMAP_H__ */
+2 −2
Original line number Diff line number Diff line
@@ -148,10 +148,10 @@ xfs_verify_rtbno(

/* Verify that a realtime device extent is fully contained inside the volume. */
bool
xfs_verify_rtext(
xfs_verify_rtbext(
	struct xfs_mount	*mp,
	xfs_rtblock_t		rtbno,
	xfs_rtblock_t		len)
	xfs_filblks_t		len)
{
	if (rtbno + len <= rtbno)
		return false;
Loading