Skip to contentSkip to conversation

NFS: stop trying writing page after getting -EBADF

PATCH New Li Lingfeng 1 participant 1 message Mar 23

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

PATCH 1/1 NFS: stop trying writing page after getting -EBADF

We encountered an infinite loop in nfs_writepages. The process is as follows:

nfs4_do_reclaim
nfs4_reclaim_open_state
__nfs4_reclaim_open_state // get -ESTALE
nfs4_state_mark_recovery_failed
nfs4_state_mark_open_context_bad
set_bit // NFS_CONTEXT_BAD

wb_workfn
wb_do_writeback
wb_writeback
writeback_sb_inodes
__writeback_single_inode
do_writepages
nfs_writepages // loop here
write_cache_pages
nfs_writepages_callback
nfs_do_writepage
nfs_page_async_flush
nfs_pageio_add_request
nfs_pageio_add_request_mirror
__nfs_pageio_add_request
nfs_create_subreq
nfs_page_create // return -EBADF

After a server restart, it may fail to recognize file handles sent by the client and return -ESTALE. As a result, the client sets NFS_CONTEXT_BAD in nfs_open_context.

During the writeback of dirty pages, the presence of NFS_CONTEXT_BAD causes -EBADF to be returned. Since NFS_CONTEXT_BAD is not cleared and -EBADF is treated as a non-fatal error, nfs_writepages() keeps retrying and eventually falls into an infinite loop.

Exit the loop when -EBADF is encountered to avoid this issue.

Fixes c6fd3511c339 ("NFS: Further fixes to the writeback error handling")
---
 fs/nfs/write.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/write.c +1 -1
index 1ed4b3590b1a..608b299b1613 100644
@@ -692,7 +692,7 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
 		nfs_pageio_complete(&pgio);
 		if (err == -EAGAIN && mntflags & NFS_MOUNT_SOFTERR)
 			break;
-	} while (err < 0 && !nfs_error_is_fatal(err));
+	} while (err < 0 && !nfs_error_is_fatal(err) && (err != -EBADF));
 	nfs_io_completion_put(ioc);
 
 	if (err > 0)
Signature · 1 line
2.52.0