diff mbox series

[2/6] xfs: cleanup xfs_ilock_iocb_for_write

Message ID 20240619115426.332708-3-hch@lst.de (mailing list archive)
State Superseded, archived
Headers show
Series [1/6] xfs: move the dio write relocking out of xfs_ilock_for_iomap | expand

Commit Message

Christoph Hellwig June 19, 2024, 11:53 a.m. UTC
Move the relock path out of the straight line and add a comment
explaining why it exists.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_file.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Comments

Darrick J. Wong June 20, 2024, 6:41 p.m. UTC | #1
On Wed, Jun 19, 2024 at 01:53:52PM +0200, Christoph Hellwig wrote:
> Move the relock path out of the straight line and add a comment
> explaining why it exists.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_file.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index b240ea5241dc9d..74c2c8d253e69b 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -213,14 +213,18 @@ xfs_ilock_iocb_for_write(
>  	if (ret)
>  		return ret;
>  
> -	if (*lock_mode == XFS_IOLOCK_EXCL)
> -		return 0;
> -	if (!xfs_iflags_test(ip, XFS_IREMAPPING))
> -		return 0;
> +	/*
> +	 * If a reflink remap is in progress we always need to take the iolock
> +	 * exclusively to wait for it to finish.
> +	 */
> +	if (*lock_mode == XFS_IOLOCK_SHARED &&
> +	    xfs_iflags_test(ip, XFS_IREMAPPING)) {
> +		xfs_iunlock(ip, *lock_mode);
> +		*lock_mode = XFS_IOLOCK_EXCL;
> +		return xfs_ilock_iocb(iocb, *lock_mode);
> +	}
>  
> -	xfs_iunlock(ip, *lock_mode);
> -	*lock_mode = XFS_IOLOCK_EXCL;
> -	return xfs_ilock_iocb(iocb, *lock_mode);
> +	return 0;
>  }
>  
>  static unsigned int
> -- 
> 2.43.0
> 
>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index b240ea5241dc9d..74c2c8d253e69b 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -213,14 +213,18 @@  xfs_ilock_iocb_for_write(
 	if (ret)
 		return ret;
 
-	if (*lock_mode == XFS_IOLOCK_EXCL)
-		return 0;
-	if (!xfs_iflags_test(ip, XFS_IREMAPPING))
-		return 0;
+	/*
+	 * If a reflink remap is in progress we always need to take the iolock
+	 * exclusively to wait for it to finish.
+	 */
+	if (*lock_mode == XFS_IOLOCK_SHARED &&
+	    xfs_iflags_test(ip, XFS_IREMAPPING)) {
+		xfs_iunlock(ip, *lock_mode);
+		*lock_mode = XFS_IOLOCK_EXCL;
+		return xfs_ilock_iocb(iocb, *lock_mode);
+	}
 
-	xfs_iunlock(ip, *lock_mode);
-	*lock_mode = XFS_IOLOCK_EXCL;
-	return xfs_ilock_iocb(iocb, *lock_mode);
+	return 0;
 }
 
 static unsigned int