[PATCH] NFS: stop trying writing page after getting -EBADF

Li Lingfeng posted 1 patch 1 week, 4 days ago
fs/nfs/write.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] NFS: stop trying writing page after getting -EBADF
Posted by Li Lingfeng 1 week, 4 days ago
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")
Link: https://lore.kernel.org/all/64fecc88-6b11-4fdf-a26f-271c4445be1a@huawei.com/
Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
---
 fs/nfs/write.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 1ed4b3590b1a..608b299b1613 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -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)
-- 
2.52.0