diff mbox series

[2/9] xfs: improve the xfs_dabuf_map calling conventions

Message ID 20191116182214.23711-3-hch@lst.de (mailing list archive)
State Superseded
Headers show
Series [1/9] xfs: simplify mappedbno case from xfs_da_get_buf and xfs_da_read_buf | expand

Commit Message

Christoph Hellwig Nov. 16, 2019, 6:22 p.m. UTC
Use a flags argument with the XFS_DABUF_MAP_HOLE_OK flag to signal that
a hole is okay and not corruption, and return -ENOENT instead of the
nameless -1 to signal that case in the return value.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/libxfs/xfs_da_btree.c | 25 +++++++++++++++----------
 fs/xfs/libxfs/xfs_da_btree.h |  3 +++
 2 files changed, 18 insertions(+), 10 deletions(-)

Comments

Darrick J. Wong Nov. 17, 2019, 6:35 p.m. UTC | #1
On Sat, Nov 16, 2019 at 07:22:07PM +0100, Christoph Hellwig wrote:
> Use a flags argument with the XFS_DABUF_MAP_HOLE_OK flag to signal that
> a hole is okay and not corruption, and return -ENOENT instead of the
> nameless -1 to signal that case in the return value.

Why not set *nirecs = 0 and return 0 like we sometimes do for bmap
lookups?

--D

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/libxfs/xfs_da_btree.c | 25 +++++++++++++++----------
>  fs/xfs/libxfs/xfs_da_btree.h |  3 +++
>  2 files changed, 18 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
> index 681fba5731c2..c26f139bcf00 100644
> --- a/fs/xfs/libxfs/xfs_da_btree.c
> +++ b/fs/xfs/libxfs/xfs_da_btree.c
> @@ -2571,7 +2571,7 @@ static int
>  xfs_dabuf_map(
>  	struct xfs_inode	*dp,
>  	xfs_dablk_t		bno,
> -	xfs_daddr_t		mappedbno,
> +	unsigned int		flags,
>  	int			whichfork,
>  	struct xfs_buf_map	**map,
>  	int			*nmaps)
> @@ -2596,8 +2596,8 @@ xfs_dabuf_map(
>  
>  	if (!xfs_da_map_covers_blocks(nirecs, irecs, bno, nfsb)) {
>  		/* Caller ok with no mapping. */
> -		if (mappedbno == -2) {
> -			error = -1;
> +		if (flags & XFS_DABUF_MAP_HOLE_OK) {
> +			error = -ENOENT;
>  			goto out;
>  		}
>  
> @@ -2655,10 +2655,12 @@ xfs_da_get_buf(
>  		goto done;
>  	}
>  
> -	error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
> +	error = xfs_dabuf_map(dp, bno,
> +			mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
> +			whichfork, &mapp, &nmap);
>  	if (error) {
>  		/* mapping a hole is not an error, but we don't continue */
> -		if (error == -1)
> +		if (error == -ENOENT)
>  			error = 0;
>  		goto out_free;
>  	}
> @@ -2710,10 +2712,12 @@ xfs_da_read_buf(
>  		goto done;
>  	}
>  
> -	error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
> +	error = xfs_dabuf_map(dp, bno,
> +			mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
> +			whichfork, &mapp, &nmap);
>  	if (error) {
>  		/* mapping a hole is not an error, but we don't continue */
> -		if (error == -1)
> +		if (error == -ENOENT)
>  			error = 0;
>  		goto out_free;
>  	}
> @@ -2757,11 +2761,12 @@ xfs_da_reada_buf(
>  
>  	mapp = &map;
>  	nmap = 1;
> -	error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
> -				&mapp, &nmap);
> +	error = xfs_dabuf_map(dp, bno,
> +			mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
> +			whichfork, &mapp, &nmap);
>  	if (error) {
>  		/* mapping a hole is not an error, but we don't continue */
> -		if (error == -1)
> +		if (error == -ENOENT)
>  			error = 0;
>  		goto out_free;
>  	}
> diff --git a/fs/xfs/libxfs/xfs_da_btree.h b/fs/xfs/libxfs/xfs_da_btree.h
> index 5af4df71e92b..9ec0d0243e96 100644
> --- a/fs/xfs/libxfs/xfs_da_btree.h
> +++ b/fs/xfs/libxfs/xfs_da_btree.h
> @@ -204,6 +204,9 @@ int	xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
>  /*
>   * Utility routines.
>   */
> +
> +#define XFS_DABUF_MAP_HOLE_OK	(1 << 0)
> +
>  int	xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
>  int	xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
>  			      int count);
> -- 
> 2.20.1
>
Christoph Hellwig Nov. 18, 2019, 6:25 a.m. UTC | #2
On Sun, Nov 17, 2019 at 10:35:21AM -0800, Darrick J. Wong wrote:
> On Sat, Nov 16, 2019 at 07:22:07PM +0100, Christoph Hellwig wrote:
> > Use a flags argument with the XFS_DABUF_MAP_HOLE_OK flag to signal that
> > a hole is okay and not corruption, and return -ENOENT instead of the
> > nameless -1 to signal that case in the return value.
> 
> Why not set *nirecs = 0 and return 0 like we sometimes do for bmap
> lookups?

Sure, I can change it to that for the next version.
Darrick J. Wong Nov. 19, 2019, 5:12 p.m. UTC | #3
On Mon, Nov 18, 2019 at 07:25:05AM +0100, Christoph Hellwig wrote:
> On Sun, Nov 17, 2019 at 10:35:21AM -0800, Darrick J. Wong wrote:
> > On Sat, Nov 16, 2019 at 07:22:07PM +0100, Christoph Hellwig wrote:
> > > Use a flags argument with the XFS_DABUF_MAP_HOLE_OK flag to signal that
> > > a hole is okay and not corruption, and return -ENOENT instead of the
> > > nameless -1 to signal that case in the return value.
> > 
> > Why not set *nirecs = 0 and return 0 like we sometimes do for bmap
> > lookups?
> 
> Sure, I can change it to that for the next version.

Also, I forgot to mention that some of the comments (particularly
xfs_dabuf_map) need to be updated to reflect the new "no mapping" return
style since there's no more @mappedbno, etc.

--D
Christoph Hellwig Nov. 19, 2019, 5:15 p.m. UTC | #4
On Tue, Nov 19, 2019 at 09:12:05AM -0800, Darrick J. Wong wrote:
> Also, I forgot to mention that some of the comments (particularly
> xfs_dabuf_map) need to be updated to reflect the new "no mapping" return
> style since there's no more @mappedbno, etc.

That is the one comment on xfs_dabuf_map, which in fact is already
wrong in the current tree.  When applying your changes I just removed
the comment entirely as it is a static function with just two callers
right below it.
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
index 681fba5731c2..c26f139bcf00 100644
--- a/fs/xfs/libxfs/xfs_da_btree.c
+++ b/fs/xfs/libxfs/xfs_da_btree.c
@@ -2571,7 +2571,7 @@  static int
 xfs_dabuf_map(
 	struct xfs_inode	*dp,
 	xfs_dablk_t		bno,
-	xfs_daddr_t		mappedbno,
+	unsigned int		flags,
 	int			whichfork,
 	struct xfs_buf_map	**map,
 	int			*nmaps)
@@ -2596,8 +2596,8 @@  xfs_dabuf_map(
 
 	if (!xfs_da_map_covers_blocks(nirecs, irecs, bno, nfsb)) {
 		/* Caller ok with no mapping. */
-		if (mappedbno == -2) {
-			error = -1;
+		if (flags & XFS_DABUF_MAP_HOLE_OK) {
+			error = -ENOENT;
 			goto out;
 		}
 
@@ -2655,10 +2655,12 @@  xfs_da_get_buf(
 		goto done;
 	}
 
-	error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
+	error = xfs_dabuf_map(dp, bno,
+			mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
+			whichfork, &mapp, &nmap);
 	if (error) {
 		/* mapping a hole is not an error, but we don't continue */
-		if (error == -1)
+		if (error == -ENOENT)
 			error = 0;
 		goto out_free;
 	}
@@ -2710,10 +2712,12 @@  xfs_da_read_buf(
 		goto done;
 	}
 
-	error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
+	error = xfs_dabuf_map(dp, bno,
+			mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
+			whichfork, &mapp, &nmap);
 	if (error) {
 		/* mapping a hole is not an error, but we don't continue */
-		if (error == -1)
+		if (error == -ENOENT)
 			error = 0;
 		goto out_free;
 	}
@@ -2757,11 +2761,12 @@  xfs_da_reada_buf(
 
 	mapp = &map;
 	nmap = 1;
-	error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
-				&mapp, &nmap);
+	error = xfs_dabuf_map(dp, bno,
+			mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
+			whichfork, &mapp, &nmap);
 	if (error) {
 		/* mapping a hole is not an error, but we don't continue */
-		if (error == -1)
+		if (error == -ENOENT)
 			error = 0;
 		goto out_free;
 	}
diff --git a/fs/xfs/libxfs/xfs_da_btree.h b/fs/xfs/libxfs/xfs_da_btree.h
index 5af4df71e92b..9ec0d0243e96 100644
--- a/fs/xfs/libxfs/xfs_da_btree.h
+++ b/fs/xfs/libxfs/xfs_da_btree.h
@@ -204,6 +204,9 @@  int	xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
 /*
  * Utility routines.
  */
+
+#define XFS_DABUF_MAP_HOLE_OK	(1 << 0)
+
 int	xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
 int	xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
 			      int count);