[9/9] xfs: make xfs_btree_get_buf functions return an error code
diff mbox series

Message ID 157910787821.2028217.9307411154179566922.stgit@magnolia
State Superseded
Headers show
Series
  • xfs: make buffer functions return error codes
Related show

Commit Message

Darrick J. Wong Jan. 15, 2020, 5:04 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Convert both xfs_btree_get_buf() functions to return numeric error codes
like most everywhere else in xfs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_alloc.c |   13 ++++++-------
 fs/xfs/libxfs/xfs_bmap.c  |   10 +++++-----
 fs/xfs/libxfs/xfs_btree.c |   36 ++++++++++++++----------------------
 fs/xfs/libxfs/xfs_btree.h |   16 +++++-----------
 4 files changed, 30 insertions(+), 45 deletions(-)

Comments

Christoph Hellwig Jan. 16, 2020, 4:33 p.m. UTC | #1
> -		if (XFS_IS_CORRUPT(args->mp, !bp)) {
> -			error = -EFSCORRUPTED;
> +		error = xfs_btree_get_bufs(args->mp, args->tp, args->agno,
> +				fbno, &bp);
> +		if (error)

Should we keep the XFS_IS_CORRUPT checks in some form?   Not sure they
matter all that much, though.

>  	ASSERT(fsbno != NULLFSBLOCK);
>  	d = XFS_FSB_TO_DADDR(mp, fsbno);
> -	error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
> -	if (error)
> -		return NULL;
> -	return bp;
> +	return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, bpp);

Maybe kill the local variable while you're at it?

>  	ASSERT(agno != NULLAGNUMBER);
>  	ASSERT(agbno != NULLAGBLOCK);
>  	d = XFS_AGB_TO_DADDR(mp, agno, agbno);
> -	error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
> -	if (error)
> -		return NULL;
> -	return bp;
> +	return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, bpp);

Same here.
Christoph Hellwig Jan. 16, 2020, 4:43 p.m. UTC | #2
On Thu, Jan 16, 2020 at 08:33:55AM -0800, Christoph Hellwig wrote:
> >  	ASSERT(fsbno != NULLFSBLOCK);
> >  	d = XFS_FSB_TO_DADDR(mp, fsbno);
> > -	error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
> > -	if (error)
> > -		return NULL;
> > -	return bp;
> > +	return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, bpp);
> 
> Maybe kill the local variable while you're at it?

Or maybe just kill xfs_btree_get_bufl and xfs_btree_get_bufs?  They
are completely trivial now, and each one just has two callers.
Darrick J. Wong Jan. 16, 2020, 10:40 p.m. UTC | #3
On Thu, Jan 16, 2020 at 08:33:55AM -0800, Christoph Hellwig wrote:
> > -		if (XFS_IS_CORRUPT(args->mp, !bp)) {
> > -			error = -EFSCORRUPTED;
> > +		error = xfs_btree_get_bufs(args->mp, args->tp, args->agno,
> > +				fbno, &bp);
> > +		if (error)
> 
> Should we keep the XFS_IS_CORRUPT checks in some form?   Not sure they
> matter all that much, though.

The XFS_IS_CORRUPT checks exist to report a corrupted filesystem, and
the only errors that the _get_buf* variants can return are runtime
errors like ENOMEM.

> >  	ASSERT(fsbno != NULLFSBLOCK);
> >  	d = XFS_FSB_TO_DADDR(mp, fsbno);
> > -	error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
> > -	if (error)
> > -		return NULL;
> > -	return bp;
> > +	return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, bpp);
> 
> Maybe kill the local variable while you're at it?
> 
> >  	ASSERT(agno != NULLAGNUMBER);
> >  	ASSERT(agbno != NULLAGBLOCK);
> >  	d = XFS_AGB_TO_DADDR(mp, agno, agbno);
> > -	error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
> > -	if (error)
> > -		return NULL;
> > -	return bp;
> > +	return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, bpp);
> 
> Same here.

Will just get rid of them as you suggest later in this thread.

--D

Patch
diff mbox series

diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 53410819691b..542f6ad7e5b4 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -1070,11 +1070,10 @@  xfs_alloc_ag_vextent_small(
 	if (args->datatype & XFS_ALLOC_USERDATA) {
 		struct xfs_buf	*bp;
 
-		bp = xfs_btree_get_bufs(args->mp, args->tp, args->agno, fbno);
-		if (XFS_IS_CORRUPT(args->mp, !bp)) {
-			error = -EFSCORRUPTED;
+		error = xfs_btree_get_bufs(args->mp, args->tp, args->agno,
+				fbno, &bp);
+		if (error)
 			goto error;
-		}
 		xfs_trans_binval(args->tp, bp);
 	}
 	*fbnop = args->agbno = fbno;
@@ -2347,9 +2346,9 @@  xfs_free_agfl_block(
 	if (error)
 		return error;
 
-	bp = xfs_btree_get_bufs(tp->t_mountp, tp, agno, agbno);
-	if (XFS_IS_CORRUPT(tp->t_mountp, !bp))
-		return -EFSCORRUPTED;
+	error = xfs_btree_get_bufs(tp->t_mountp, tp, agno, agbno, &bp);
+	if (error)
+		return error;
 	xfs_trans_binval(tp, bp);
 
 	return 0;
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 4c2e046fbfad..4544732d09a5 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -730,11 +730,9 @@  xfs_bmap_extents_to_btree(
 	cur->bc_private.b.allocated++;
 	ip->i_d.di_nblocks++;
 	xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L);
-	abp = xfs_btree_get_bufl(mp, tp, args.fsbno);
-	if (XFS_IS_CORRUPT(mp, !abp)) {
-		error = -EFSCORRUPTED;
+	error = xfs_btree_get_bufl(mp, tp, args.fsbno, &abp);
+	if (error)
 		goto out_unreserve_dquot;
-	}
 
 	/*
 	 * Fill in the child block.
@@ -878,7 +876,9 @@  xfs_bmap_local_to_extents(
 	ASSERT(args.fsbno != NULLFSBLOCK);
 	ASSERT(args.len == 1);
 	tp->t_firstblock = args.fsbno;
-	bp = xfs_btree_get_bufl(args.mp, tp, args.fsbno);
+	error = xfs_btree_get_bufl(args.mp, tp, args.fsbno, &bp);
+	if (error)
+		goto done;
 
 	/*
 	 * Initialize the block, copy the data and log the remote buffer.
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
index 2d53e5fdff70..0a7e2265dec1 100644
--- a/fs/xfs/libxfs/xfs_btree.c
+++ b/fs/xfs/libxfs/xfs_btree.c
@@ -682,46 +682,38 @@  xfs_btree_get_block(
  * Get a buffer for the block, return it with no data read.
  * Long-form addressing.
  */
-xfs_buf_t *				/* buffer for fsbno */
+int
 xfs_btree_get_bufl(
-	xfs_mount_t	*mp,		/* file system mount point */
-	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_fsblock_t	fsbno)		/* file system block number */
+	struct xfs_mount	*mp,
+	struct xfs_trans	*tp,
+	xfs_fsblock_t		fsbno,
+	struct xfs_buf		**bpp)
 {
-	struct xfs_buf		*bp;
 	xfs_daddr_t		d;		/* real disk block address */
-	int			error;
 
 	ASSERT(fsbno != NULLFSBLOCK);
 	d = XFS_FSB_TO_DADDR(mp, fsbno);
-	error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
-	if (error)
-		return NULL;
-	return bp;
+	return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, bpp);
 }
 
 /*
  * Get a buffer for the block, return it with no data read.
  * Short-form addressing.
  */
-xfs_buf_t *				/* buffer for agno/agbno */
+int
 xfs_btree_get_bufs(
-	xfs_mount_t	*mp,		/* file system mount point */
-	xfs_trans_t	*tp,		/* transaction pointer */
-	xfs_agnumber_t	agno,		/* allocation group number */
-	xfs_agblock_t	agbno)		/* allocation group block number */
+	struct xfs_mount	*mp,
+	struct xfs_trans	*tp,
+	xfs_agnumber_t		agno,
+	xfs_agblock_t		agbno,
+	struct xfs_buf		**bpp)
 {
-	struct xfs_buf		*bp;
-	xfs_daddr_t		d;		/* real disk block address */
-	int			error;
+	xfs_daddr_t		d;
 
 	ASSERT(agno != NULLAGNUMBER);
 	ASSERT(agbno != NULLAGBLOCK);
 	d = XFS_AGB_TO_DADDR(mp, agno, agbno);
-	error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
-	if (error)
-		return NULL;
-	return bp;
+	return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, bpp);
 }
 
 /*
diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h
index fb9b2121c628..97c2b5e75210 100644
--- a/fs/xfs/libxfs/xfs_btree.h
+++ b/fs/xfs/libxfs/xfs_btree.h
@@ -300,22 +300,16 @@  xfs_btree_dup_cursor(
  * Get a buffer for the block, return it with no data read.
  * Long-form addressing.
  */
-struct xfs_buf *				/* buffer for fsbno */
-xfs_btree_get_bufl(
-	struct xfs_mount	*mp,	/* file system mount point */
-	struct xfs_trans	*tp,	/* transaction pointer */
-	xfs_fsblock_t		fsbno);	/* file system block number */
+int xfs_btree_get_bufl(struct xfs_mount *mp, struct xfs_trans *tp,
+		xfs_fsblock_t fsbno, struct xfs_buf **bpp);
 
 /*
  * Get a buffer for the block, return it with no data read.
  * Short-form addressing.
  */
-struct xfs_buf *				/* buffer for agno/agbno */
-xfs_btree_get_bufs(
-	struct xfs_mount	*mp,	/* file system mount point */
-	struct xfs_trans	*tp,	/* transaction pointer */
-	xfs_agnumber_t		agno,	/* allocation group number */
-	xfs_agblock_t		agbno);	/* allocation group block number */
+int xfs_btree_get_bufs(struct xfs_mount *mp, struct xfs_trans *tp,
+		xfs_agnumber_t agno, xfs_agblock_t agbno,
+		struct xfs_buf **bpp);
 
 /*
  * Compute first and last byte offsets for the fields given.