Skip to contentSkip to conversation

xfs: fix error code in xfs_iflush_cluster()

PATCH In review Dan Carpenter 4 participants 5 messages May 13, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix error code in xfs_iflush_cluster()

Originally this function used to always return -EFSCORRUPTED on error but now we're trying to return more informative error codes. Unfortunately, there was one error path missed. If this kmem_alloc() allocation fails then we need to return -ENOMEM instead of success.

Fixes f20192991d79 ("xfs: simplify inode flush error handling")
---
 fs/xfs/xfs_inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/xfs_inode.c +3 -1
index ab31a5dec7aab..63aeda7cbafb0 100644
@@ -3505,8 +3505,10 @@ xfs_iflush_cluster(
 
 	cilist_size = igeo->inodes_per_cluster * sizeof(struct xfs_inode *);
 	cilist = kmem_alloc(cilist_size, KM_MAYFAIL|KM_NOFS);
-	if (!cilist)
+	if (!cilist) {
+		error = -ENOMEM;
 		goto out_put;
+	}
 
 	mask = ~(igeo->inodes_per_cluster - 1);
 	first_index = XFS_INO_TO_AGINO(mp, ip->i_ino) & mask;
Signature · 1 line
2.26.2
#1 lore raw
Quoted 6 lines · Dan Carpenter

Originally this function used to always return -EFSCORRUPTED on error but now we're trying to return more informative error codes. Unfortunately, there was one error path missed. If this kmem_alloc() allocation fails then we need to return -ENOMEM instead of success.

Fixes f20192991d79 ("xfs: simplify inode flush error handling")

This logic predates that patch, and I think it may be by design. Inode cluster flushing is an optimization to flush other dirty inodes in the same cluster we're about to queue for writeback. If the cluster flush fails due to an operational error such as memory allocation failure, we don't want to report an error because that would shutdown the fs when otherwise the side effect would be that the other inodes in the cluster would be flushed individually. This is distinct from failing to flush a particular inode due to corruption, which is a fatal filesystem error.

Brian

Quoted 24 lines
---
 fs/xfs/xfs_inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/xfs_inode.c +3 -1
index ab31a5dec7aab..63aeda7cbafb0 100644
@@ -3505,8 +3505,10 @@ xfs_iflush_cluster(
 
 	cilist_size = igeo->inodes_per_cluster * sizeof(struct xfs_inode *);
 	cilist = kmem_alloc(cilist_size, KM_MAYFAIL|KM_NOFS);
-	if (!cilist)
+	if (!cilist) {
+		error = -ENOMEM;
 		goto out_put;
+	}
 
 	mask = ~(igeo->inodes_per_cluster - 1);
 	first_index = XFS_INO_TO_AGINO(mp, ip->i_ino) & mask;
Signature · 1 line
2.26.2
#2 lore raw

Oh yeah. You're right. This patch isn't correct. Sorry about that.

I worry that there are several static analyzer's which will warn about this code...

regards,
dan carpenter

#3 lore raw
Quoted 4 lines · Dan Carpenter

Oh yeah. You're right. This patch isn't correct. Sorry about that.

I worry that there are several static analyzer's which will warn about this code...

/me wonders if this particular instance ought to have a breadcrumb to remind future readers that we can handle the lack of memory, e.g.

cilist = kmem_alloc(..., KM_MAYFAIL...);

if (!cilist) {
	/* memory is tight, so defer the inode cluster flush */
	goto out_put;
}

--D

Quoted 3 lines

regards,
dan carpenter

#4 lore raw
Quoted 6 lines · Darrick J. Wong
Quoted 4 lines · Dan Carpenter

Oh yeah. You're right. This patch isn't correct. Sorry about that.

I worry that there are several static analyzer's which will warn about this code...

Quoted 8 lines

/me wonders if this particular instance ought to have a breadcrumb to remind future readers that we can handle the lack of memory, e.g.

cilist = kmem_alloc(..., KM_MAYFAIL...);

if (!cilist) {
	/* memory is tight, so defer the inode cluster flush */
	goto out_put;
}

I'm working on patches that make this memory allocation go away altogether, so I'd suggest just ignoring it for now.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]