From: Christoph Hellwig <hch@lst.de>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: Chris Mason <clm@meta.com>, linux-nfs@vger.kernel.org
Subject: [PATCH 7/7] NFS: fix delayed delegation return handling
Date: Wed, 28 Jan 2026 05:46:09 +0100 [thread overview]
Message-ID: <20260128044706.556046-8-hch@lst.de> (raw)
In-Reply-To: <20260128044706.556046-1-hch@lst.de>
Rework this code that was totally busted at least as of my most
recent changes. Introduce a separate list for delayed delegations
so that they can't get lost and don't clutter up the returns list.
Add a missing spin_unlock in the helper marking it as a regular
pending return.
Fixes: 0ebe655bd033 ("NFS: add a separate delegation return list")
Reported-by: Chris Mason <clm@meta.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/nfs/client.c | 1 +
fs/nfs/delegation.c | 30 ++++++++++++------------------
fs/nfs/delegation.h | 1 -
fs/nfs/nfs4trace.h | 3 +--
include/linux/nfs_fs_sb.h | 2 +-
5 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 62aece00f810..4c0bba1488cc 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -1063,6 +1063,7 @@ struct nfs_server *nfs_alloc_server(void)
spin_lock_init(&server->delegations_lock);
INIT_LIST_HEAD(&server->delegations_return);
INIT_LIST_HEAD(&server->delegations_lru);
+ INIT_LIST_HEAD(&server->delegations_delayed);
INIT_LIST_HEAD(&server->layouts);
INIT_LIST_HEAD(&server->state_owners_lru);
INIT_LIST_HEAD(&server->ss_copies);
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index cff49a934c9e..94103f8d3f21 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -336,10 +336,8 @@ nfs_start_delegation_return(struct nfs_inode *nfsi)
spin_lock(&delegation->lock);
if (delegation->inode &&
- !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) {
- clear_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags);
+ !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
return_now = true;
- }
spin_unlock(&delegation->lock);
if (!return_now) {
@@ -586,8 +584,11 @@ static int nfs_end_delegation_return(struct inode *inode,
out_return:
return nfs_do_return_delegation(inode, delegation, issync);
delay:
- set_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags);
- set_bit(NFS4SERV_DELEGRETURN_DELAYED, &server->delegation_flags);
+ spin_lock(&server->delegations_lock);
+ if (list_empty(&delegation->entry))
+ refcount_inc(&delegation->refcount);
+ list_move_tail(&delegation->entry, &server->delegations_return);
+ spin_unlock(&server->delegations_lock);
set_bit(NFS4CLNT_DELEGRETURN_DELAYED, &server->nfs_client->cl_state);
abort:
clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
@@ -616,22 +617,16 @@ static int nfs_return_one_delegation(struct nfs_server *server)
spin_unlock(&delegation->lock);
goto out_put_delegation;
}
- if (test_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags) ||
- test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) ||
+ if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) ||
test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) {
spin_unlock(&delegation->lock);
goto out_put_inode;
}
- clear_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags);
spin_unlock(&delegation->lock);
nfs_clear_verifier_delegated(inode);
err = nfs_end_delegation_return(inode, delegation, false);
- if (err) {
- nfs_mark_return_delegation(server, delegation);
- goto out_put_inode;
- }
out_put_inode:
iput(inode);
@@ -708,19 +703,18 @@ static void nfs_delegation_add_lru(struct nfs_server *server,
static bool nfs_server_clear_delayed_delegations(struct nfs_server *server)
{
- struct nfs_delegation *d;
bool ret = false;
- if (!test_and_clear_bit(NFS4SERV_DELEGRETURN_DELAYED,
- &server->delegation_flags))
+ if (list_empty_careful(&server->delegations_delayed))
return false;
spin_lock(&server->delegations_lock);
- list_for_each_entry_rcu(d, &server->delegations_return, entry) {
- if (test_bit(NFS_DELEGATION_RETURN_DELAYED, &d->flags))
- clear_bit(NFS_DELEGATION_RETURN_DELAYED, &d->flags);
+ if (!list_empty(&server->delegations_delayed)) {
+ list_splice_tail_init(&server->delegations_delayed,
+ &server->delegations_return);
ret = true;
}
+ spin_unlock(&server->delegations_lock);
return ret;
}
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index eda39fcb032b..fba4699952b8 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -37,7 +37,6 @@ enum {
NFS_DELEGATION_RETURNING,
NFS_DELEGATION_REVOKED,
NFS_DELEGATION_TEST_EXPIRED,
- NFS_DELEGATION_RETURN_DELAYED,
NFS_DELEGATION_DELEGTIME,
};
diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h
index 8ff6396bc206..bf44aabb844c 100644
--- a/fs/nfs/nfs4trace.h
+++ b/fs/nfs/nfs4trace.h
@@ -994,8 +994,7 @@ DEFINE_NFS4_SET_DELEGATION_EVENT(nfs4_detach_delegation);
{ BIT(NFS_DELEGATION_REFERENCED), "REFERENCED" }, \
{ BIT(NFS_DELEGATION_RETURNING), "RETURNING" }, \
{ BIT(NFS_DELEGATION_REVOKED), "REVOKED" }, \
- { BIT(NFS_DELEGATION_TEST_EXPIRED), "TEST_EXPIRED" }, \
- { BIT(NFS_DELEGATION_RETURN_DELAYED), "RETURN_DELAYED" })
+ { BIT(NFS_DELEGATION_TEST_EXPIRED), "TEST_EXPIRED" })
DECLARE_EVENT_CLASS(nfs4_delegation_event,
TP_PROTO(
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h
index bb13a294b69e..cfda0ff0174d 100644
--- a/include/linux/nfs_fs_sb.h
+++ b/include/linux/nfs_fs_sb.h
@@ -262,6 +262,7 @@ struct nfs_server {
spinlock_t delegations_lock;
struct list_head delegations_return;
struct list_head delegations_lru;
+ struct list_head delegations_delayed;
atomic_long_t nr_active_delegations;
unsigned int delegation_hash_mask;
struct hlist_head *delegation_hash_table;
@@ -270,7 +271,6 @@ struct nfs_server {
unsigned long delegation_flags;
#define NFS4SERV_DELEGATION_EXPIRED (1)
-#define NFS4SERV_DELEGRETURN_DELAYED (2)
unsigned long delegation_gen;
unsigned long mig_gen;
unsigned long mig_status;
--
2.47.3
next prev parent reply other threads:[~2026-01-28 4:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 4:46 delayed delegation return handling fix Christoph Hellwig
2026-01-28 4:46 ` [PATCH 1/7] NFS: return void from nfs4_inode_make_writeable Christoph Hellwig
2026-01-28 4:46 ` [PATCH 2/7] NFS: return void from ->return_delegation Christoph Hellwig
2026-01-28 4:46 ` [PATCH 3/7] NFS: use bool for the issync argument to nfs_end_delegation_return Christoph Hellwig
2026-01-28 4:46 ` [PATCH 4/7] NFS: remove the delegation == NULL check in nfs_end_delegation_return Christoph Hellwig
2026-01-28 4:46 ` [PATCH 5/7] NFS: fold nfs_abort_delegation_return into nfs_end_delegation_return Christoph Hellwig
2026-01-28 4:46 ` [PATCH 6/7] NFS: simplify error handling in nfs_end_delegation_return Christoph Hellwig
2026-01-28 4:46 ` Christoph Hellwig [this message]
2026-01-28 19:15 ` delayed delegation return handling fix Chris Mason
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=20260128044706.556046-8-hch@lst.de \
--to=hch@lst.de \
--cc=anna@kernel.org \
--cc=clm@meta.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@kernel.org \
/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