diff mbox series

[2/2] xfs: rework breaking of shared extents in xfs_file_iomap_begin

Message ID 155104026500.24373.14839198455533713908.stgit@magnolia (mailing list archive)
State Accepted, archived
Headers show
Series [1/2] xfs: don't pass iomap flags to xfs_reflink_allocate_cow | expand

Commit Message

Darrick J. Wong Feb. 24, 2019, 8:31 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Rework the data flow in xfs_file_iomap_begin where we decide if we have
to break shared extents.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_iomap.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Brian Foster Feb. 25, 2019, 12:55 p.m. UTC | #1
On Sun, Feb 24, 2019 at 12:31:05PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Rework the data flow in xfs_file_iomap_begin where we decide if we have
> to break shared extents.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/xfs_iomap.c |   13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> 
> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
> index a376fb2d4b94..a3043b1bcd9a 100644
> --- a/fs/xfs/xfs_iomap.c
> +++ b/fs/xfs/xfs_iomap.c
> @@ -982,7 +982,7 @@ xfs_file_iomap_begin(
>  	 * been done up front, so we don't need to do them here.
>  	 */
>  	if (xfs_is_cow_inode(ip)) {
> -		struct xfs_bmbt_irec	orig = imap;
> +		struct xfs_bmbt_irec	cmap;
>  		bool			convert_now = (flags & IOMAP_DIRECT);
>  
>  		/* if zeroing doesn't need COW allocation, then we are done. */
> @@ -991,7 +991,8 @@ xfs_file_iomap_begin(
>  			goto out_found;
>  
>  		/* may drop and re-acquire the ilock */
> -		error = xfs_reflink_allocate_cow(ip, &imap, &shared, &lockmode,
> +		cmap = imap;
> +		error = xfs_reflink_allocate_cow(ip, &cmap, &shared, &lockmode,
>  				convert_now);
>  		if (error)
>  			goto out_unlock;
> @@ -1001,10 +1002,12 @@ xfs_file_iomap_begin(
>  		 * previous block (if there was any) so that the higher level
>  		 * write code can perform read-modify-write operations.  For
>  		 * direct I/O code, which must be block aligned we need to
> -		 * report the newly allocated address.
> +		 * report the newly allocated address.  If the data fork has
> +		 * a hole, copy the COW fork mapping to avoid allocating to
> +		 * the data fork.
>  		 */
> -		if (!convert_now && orig.br_startblock != HOLESTARTBLOCK)
> -			imap = orig;
> +		if (convert_now || imap.br_startblock == HOLESTARTBLOCK)
> +			imap = cmap;
>  
>  		end_fsb = imap.br_startoff + imap.br_blockcount;
>  		length = XFS_FSB_TO_B(mp, end_fsb) - offset;
>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index a376fb2d4b94..a3043b1bcd9a 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -982,7 +982,7 @@  xfs_file_iomap_begin(
 	 * been done up front, so we don't need to do them here.
 	 */
 	if (xfs_is_cow_inode(ip)) {
-		struct xfs_bmbt_irec	orig = imap;
+		struct xfs_bmbt_irec	cmap;
 		bool			convert_now = (flags & IOMAP_DIRECT);
 
 		/* if zeroing doesn't need COW allocation, then we are done. */
@@ -991,7 +991,8 @@  xfs_file_iomap_begin(
 			goto out_found;
 
 		/* may drop and re-acquire the ilock */
-		error = xfs_reflink_allocate_cow(ip, &imap, &shared, &lockmode,
+		cmap = imap;
+		error = xfs_reflink_allocate_cow(ip, &cmap, &shared, &lockmode,
 				convert_now);
 		if (error)
 			goto out_unlock;
@@ -1001,10 +1002,12 @@  xfs_file_iomap_begin(
 		 * previous block (if there was any) so that the higher level
 		 * write code can perform read-modify-write operations.  For
 		 * direct I/O code, which must be block aligned we need to
-		 * report the newly allocated address.
+		 * report the newly allocated address.  If the data fork has
+		 * a hole, copy the COW fork mapping to avoid allocating to
+		 * the data fork.
 		 */
-		if (!convert_now && orig.br_startblock != HOLESTARTBLOCK)
-			imap = orig;
+		if (convert_now || imap.br_startblock == HOLESTARTBLOCK)
+			imap = cmap;
 
 		end_fsb = imap.br_startoff + imap.br_blockcount;
 		length = XFS_FSB_TO_B(mp, end_fsb) - offset;