From: Chuck Lever <cel@kernel.org>
To: NeilBrown <neilb@ownmail.net>, Jeff Layton <jlayton@kernel.org>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: <linux-nfs@vger.kernel.org>, Chuck Lever <chuck.lever@oracle.com>
Subject: [PATCH v1 5/5] nfsd: close cached files on filesystem unmount
Date: Tue, 30 Dec 2025 09:18:38 -0500 [thread overview]
Message-ID: <20251230141838.2547848-6-cel@kernel.org> (raw)
In-Reply-To: <20251230141838.2547848-1-cel@kernel.org>
From: Chuck Lever <chuck.lever@oracle.com>
When a filesystem is unmounted while NFS is exporting it, the
unmount can fail with EBUSY even after NFSv4 state has been revoked.
This is because the nfsd_file cache can hold open NFSv2/3 file
handles that pin the filesystem, preventing the unmount from
completing.
Extend the mechanism that revokes NFSv4 state on unmount to also
close cached file handles. nfsd_file_close_sb() walks the nfsd_file
cache and disposes of entries belonging to the target superblock.
It runs after NFSv4 state revocation, so it handles only NFSv2/3
file handles that remain in the cache.
Entries still under construction (with nf_file not yet set) are
skipped; these have no open file to close.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/filecache.c | 39 +++++++++++++++++++++++++++++++++++++++
fs/nfsd/filecache.h | 1 +
fs/nfsd/pin.c | 6 ++++--
3 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
index 93798575b807..bbef58c1caa9 100644
--- a/fs/nfsd/filecache.c
+++ b/fs/nfsd/filecache.c
@@ -894,6 +894,45 @@ __nfsd_file_cache_purge(struct net *net)
nfsd_file_dispose_list(&dispose);
}
+/**
+ * nfsd_file_close_sb - close GC-managed cached files for a superblock
+ * @sb: target superblock
+ *
+ * Walk the nfsd_file cache and close out GC-managed entries (those
+ * acquired via nfsd_file_acquire_gc) that belong to @sb. Called during
+ * filesystem unmount after NFSv4 state revocation to release remaining
+ * cached file handles that may be pinning the filesystem.
+ */
+void nfsd_file_close_sb(struct super_block *sb)
+{
+ struct rhashtable_iter iter;
+ struct nfsd_file *nf;
+ LIST_HEAD(dispose);
+
+ if (test_bit(NFSD_FILE_CACHE_UP, &nfsd_file_flags) == 0)
+ return;
+
+ rhltable_walk_enter(&nfsd_file_rhltable, &iter);
+ do {
+ rhashtable_walk_start(&iter);
+
+ nf = rhashtable_walk_next(&iter);
+ while (!IS_ERR_OR_NULL(nf)) {
+ if (test_bit(NFSD_FILE_GC, &nf->nf_flags) == 0)
+ goto next;
+ if (nf->nf_file && file_inode(nf->nf_file)->i_sb == sb)
+ nfsd_file_cond_queue(nf, &dispose);
+next:
+ nf = rhashtable_walk_next(&iter);
+ }
+
+ rhashtable_walk_stop(&iter);
+ } while (nf == ERR_PTR(-EAGAIN));
+ rhashtable_walk_exit(&iter);
+
+ nfsd_file_dispose_list(&dispose);
+}
+
static struct nfsd_fcache_disposal *
nfsd_alloc_fcache_disposal(void)
{
diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h
index b383dbc5b921..66ca7fc6189b 100644
--- a/fs/nfsd/filecache.h
+++ b/fs/nfsd/filecache.h
@@ -70,6 +70,7 @@ struct net *nfsd_file_put_local(struct nfsd_file __rcu **nf);
struct nfsd_file *nfsd_file_get(struct nfsd_file *nf);
struct file *nfsd_file_file(struct nfsd_file *nf);
void nfsd_file_close_inode_sync(struct inode *inode);
+void nfsd_file_close_sb(struct super_block *sb);
void nfsd_file_net_dispose(struct nfsd_net *nn);
bool nfsd_file_is_cached(struct inode *inode);
__be32 nfsd_file_acquire_gc(struct svc_rqst *rqstp, struct svc_fh *fhp,
diff --git a/fs/nfsd/pin.c b/fs/nfsd/pin.c
index f8d0d7cda404..0c1de8fd0e43 100644
--- a/fs/nfsd/pin.c
+++ b/fs/nfsd/pin.c
@@ -19,6 +19,7 @@
#include "nfsd.h"
#include "netns.h"
#include "state.h"
+#include "filecache.h"
#define NFSDDBG_FACILITY NFSDDBG_PROC
@@ -49,8 +50,8 @@ static void nfsd_fs_pin_free_rcu(struct rcu_head *rcu)
/*
* Work function for nfsd_fs_pin - runs in process context.
- * Cancels async COPYs, releases NLM locks, and revokes NFSv4 state for
- * the superblock.
+ * Cancels async COPYs, releases NLM locks, revokes NFSv4 state, and closes
+ * cached NFSv2/3 files for the superblock.
*/
static void nfsd_fs_pin_work(struct work_struct *work)
{
@@ -63,6 +64,7 @@ static void nfsd_fs_pin_work(struct work_struct *work)
/* Errors are logged by lockd; no recovery is possible. */
(void)nlmsvc_unlock_all_by_sb(p->sb);
nfsd4_revoke_states(nn, p->sb);
+ nfsd_file_close_sb(p->sb);
pr_info("nfsd: state revocation for %s complete\n", p->sb->s_id);
--
2.52.0
next prev parent reply other threads:[~2025-12-30 14:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-30 14:18 [PATCH v1 0/5] Automatic NFSv4 state revocation on filesystem unmount Chuck Lever
2025-12-30 14:18 ` [PATCH v1 1/5] nfsd: cancel async COPY operations when admin revokes filesystem state Chuck Lever
2025-12-30 23:15 ` NeilBrown
2026-01-06 13:44 ` Jeff Layton
2025-12-30 14:18 ` [PATCH v1 2/5] fs: export pin_insert and pin_remove for modular filesystems Chuck Lever
2025-12-30 23:18 ` NeilBrown
2026-01-06 13:46 ` Jeff Layton
2025-12-30 14:18 ` [PATCH v1 3/5] fs: add pin_insert_group() for superblock-only pins Chuck Lever
2025-12-30 23:34 ` NeilBrown
2026-01-06 15:22 ` Jeff Layton
2026-01-06 15:24 ` Chuck Lever
2025-12-30 14:18 ` [PATCH v1 4/5] nfsd: revoke NFSv4 state when filesystem is unmounted Chuck Lever
2025-12-31 0:10 ` NeilBrown
2025-12-30 14:18 ` Chuck Lever [this message]
2025-12-31 0:16 ` [PATCH v1 5/5] nfsd: close cached files on filesystem unmount NeilBrown
2025-12-31 0:28 ` [PATCH v1 0/5] Automatic NFSv4 state revocation " NeilBrown
2025-12-31 2:18 ` Chuck Lever
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=20251230141838.2547848-6-cel@kernel.org \
--to=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=dai.ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@ownmail.net \
--cc=okorniev@redhat.com \
--cc=tom@talpey.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;
as well as URLs for NNTP newsgroup(s).