Skip to contentSkip to conversation

xfs: fix xfs_ifree() error handling to not leak perag ref

PATCH In review Brian Foster 3 participants 3 messages May 27, 2022 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix xfs_ifree() error handling to not leak perag ref

For some reason commit 9a5280b312e2e ("xfs: reorder iunlink remove operation in xfs_ifree") replaced a jump to the exit path in the event of an xfs_difree() error with a direct return, which skips releasing the perag reference acquired at the top of the function. Restore the original code to drop the reference on error.

Fixes 9a5280b312e2e ("xfs: reorder iunlink remove operation in xfs_ifree")
---
 fs/xfs/xfs_inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_inode.c +1 -1
index b2879870a17e..52d6f2c7d58b 100644
@@ -2622,7 +2622,7 @@ xfs_ifree(
 	 */
 	error = xfs_difree(tp, pag, ip->i_ino, &xic);
 	if (error)
-		return error;
+		goto out;
 
 	error = xfs_iunlink_remove(tp, pag, ip);
 	if (error)
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Brian Foster

For some reason commit 9a5280b312e2e ("xfs: reorder iunlink remove operation in xfs_ifree") replaced a jump to the exit path in the event of an xfs_difree() error with a direct return, which skips releasing the perag reference acquired at the top of the function. Restore the original code to drop the reference on error.

Fixes 9a5280b312e2e ("xfs: reorder iunlink remove operation in xfs_ifree")

Doh. Good catch!

--D

Quoted 20 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_inode.c +1 -1
index b2879870a17e..52d6f2c7d58b 100644
@@ -2622,7 +2622,7 @@ xfs_ifree(
 	 */
 	error = xfs_difree(tp, pag, ip->i_ino, &xic);
 	if (error)
-		return error;
+		goto out;
 
 	error = xfs_iunlink_remove(tp, pag, ip);
 	if (error)
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Brian Foster
Quoted 3 lines · Brian Foster

For some reason commit 9a5280b312e2e ("xfs: reorder iunlink remove operation in xfs_ifree") replaced a jump to the exit path in the event of an xfs_difree() error with a direct return, which skips

Reason: the patchset that the fix was promoted from had moved all the pag handling out of xfs_ifree to the caller, so direct return was, in fact, the correct behaviour in the code it originated from.

The patch applied to upstream with no errors or fuzz, and I had completely forgotten that somewhere in the ~50 patches in the stack before that fix had completely reworked unlink pag handling...

How did you find this? I haven't noticed any specific increase in unmount perag accounting leaks as a result of this, so I'm curious as to how you noticed it and isolated it to this specific bug.

Quoted 13 lines

Restore the original code to drop the reference on error.

Fixes 9a5280b312e2e ("xfs: reorder iunlink remove operation in xfs_ifree")
---
 fs/xfs/xfs_inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_inode.c +0 -0
index b2879870a17e..52d6f2c7d58b 100644

fs/xfs/xfs_inode.c xfs_ifree( · line 2625

Quoted 5 lines
fs/xfs/xfs_inode.c +1 -1
@@ -2622,7 +2622,7 @@ xfs_ifree(
 	 */
 	error = xfs_difree(tp, pag, ip->i_ino, &xic);
 	if (error)
-		return error;
+		goto out;

Looks good,

Signature · 2 lines
Dave Chinner
[email protected]