public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Li Lingfeng <lilingfeng3@huawei.com>
To: <trondmy@kernel.org>, <anna@kernel.org>, <jlayton@kernel.org>
Cc: <linux-nfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<chengzhihao1@huawei.com>, <houtao1@huawei.com>,
	<yi.zhang@huawei.com>, <yangerkun@huawei.com>,
	<zhangjian496@h-partners.com>, <lilingfeng@huaweicloud.com>,
	<lilingfeng3@huawei.com>
Subject: [PATCH] NFS: stop trying writing page after getting -EBADF
Date: Mon, 23 Mar 2026 09:16:30 +0800	[thread overview]
Message-ID: <20260323011630.3547783-1-lilingfeng3@huawei.com> (raw)

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


                 reply	other threads:[~2026-03-23  1:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260323011630.3547783-1-lilingfeng3@huawei.com \
    --to=lilingfeng3@huawei.com \
    --cc=anna@kernel.org \
    --cc=chengzhihao1@huawei.com \
    --cc=houtao1@huawei.com \
    --cc=jlayton@kernel.org \
    --cc=lilingfeng@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trondmy@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=zhangjian496@h-partners.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox