public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: Add error handling for xfs_reflink_cancel_cow_range
@ 2025-01-20 15:46 Wentao Liang
  2025-01-22  3:21 ` Darrick J. Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2025-01-20 15:46 UTC (permalink / raw)
  To: Darrick J . Wong
  Cc: Chandan Babu R, Allison Henderson, Dave Chinner, Catherine Hoang,
	linux-kernel, linux-fsdevel, Wentao Liang

In xfs_inactive(), xfs_reflink_cancel_cow_range() is called
without error handling, risking unnoticed failures and
inconsistent behavior compared to other parts of the code.

Fix this issue by adding an error handling for the
xfs_reflink_cancel_cow_range(), improving code robustness.

Fixes: 6231848c3aa5 ("xfs: check for cow blocks before trying to clear them")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 fs/xfs/xfs_inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index c8ad2606f928..1ff514b6c035 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1404,8 +1404,11 @@ xfs_inactive(
 		goto out;
 
 	/* Try to clean out the cow blocks if there are any. */
-	if (xfs_inode_has_cow_data(ip))
-		xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, true);
+	if (xfs_inode_has_cow_data(ip)) {
+		error = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, true);
+		if (error)
+			goto out;
+	}
 
 	if (VFS_I(ip)->i_nlink != 0) {
 		/*
-- 
2.42.0.windows.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xfs: Add error handling for xfs_reflink_cancel_cow_range
  2025-01-20 15:46 [PATCH] xfs: Add error handling for xfs_reflink_cancel_cow_range Wentao Liang
@ 2025-01-22  3:21 ` Darrick J. Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2025-01-22  3:21 UTC (permalink / raw)
  To: Wentao Liang
  Cc: Chandan Babu R, Allison Henderson, Dave Chinner, Catherine Hoang,
	linux-kernel, linux-fsdevel

On Mon, Jan 20, 2025 at 11:46:24PM +0800, Wentao Liang wrote:
> In xfs_inactive(), xfs_reflink_cancel_cow_range() is called
> without error handling, risking unnoticed failures and
> inconsistent behavior compared to other parts of the code.
> 
> Fix this issue by adding an error handling for the
> xfs_reflink_cancel_cow_range(), improving code robustness.
> 
> Fixes: 6231848c3aa5 ("xfs: check for cow blocks before trying to clear them")
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  fs/xfs/xfs_inode.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index c8ad2606f928..1ff514b6c035 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -1404,8 +1404,11 @@ xfs_inactive(
>  		goto out;
>  
>  	/* Try to clean out the cow blocks if there are any. */
> -	if (xfs_inode_has_cow_data(ip))
> -		xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, true);
> +	if (xfs_inode_has_cow_data(ip)) {
> +		error = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, true);
> +		if (error)
> +			goto out;

If memory serves, we ignored the error return here on the grounds that
the worst that can happen is that we leak some cow staging reservations,
so we should continue freeing the file in the ondisk metadata.

That said, I /think/ the error case corresponds to the log being shut
down or going down due to a corruption error during the cow blocks
cancellation.  So I guess this can go ahead with:

Cc: <stable@vger.kernel.org> # v4.17
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> +	}
>  
>  	if (VFS_I(ip)->i_nlink != 0) {
>  		/*
> -- 
> 2.42.0.windows.2
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-22  3:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-20 15:46 [PATCH] xfs: Add error handling for xfs_reflink_cancel_cow_range Wentao Liang
2025-01-22  3:21 ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox