Skip to contentSkip to conversation

xfs: Add error handling for xfs_reflink_cancel_cow_range

PATCH Superseded Wentao Liang 2 participants 2 messages Jan 20, 2025 – Jan 22, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: Add error handling for xfs_reflink_cancel_cow_range

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")
---
 fs/xfs/xfs_inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/xfs/xfs_inode.c +5 -2
index c8ad2606f928..1ff514b6c035 100644
@@ -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) {
 		/*
Signature · 1 line
2.42.0.windows.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · 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")
---
 fs/xfs/xfs_inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/xfs/xfs_inode.c +0 -0
index c8ad2606f928..1ff514b6c035 100644

fs/xfs/xfs_inode.c xfs_inactive( · line 1410

Quoted 9 lines
fs/xfs/xfs_inode.c +4 -2
@@ -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:

--D

Quoted 7 lines
fs/xfs/xfs_inode.c +1 -0
+	}
 
 	if (VFS_I(ip)->i_nlink != 0) {
 		/*
Signature · 1 line
2.42.0.windows.2