When an OPEN reply grants a delegation whose stateid "other" differs from the live delegation on the inode, and it is not an upgrade to a write delegation, nfs_inode_set_delegation() keeps the old delegation and hands the new one back. It does so by parking the freshly allocated object in @freeme and clearing @delegation, so the exit path runs nfs_do_return_delegation(), nfs_mark_delegation_revoked() and nfs_put_delegation() on it. nfs_mark_delegation_revoked() decrements server->nr_active_delegations whenever NFS_DELEGATION_REVOKED was not set before, but that counter is only incremented for delegations that reach the add_new label. The duplicate object never did, so each such OPEN reply drops the counter by one while the old delegation is still held. After the first one the counter reads zero with a live delegation on the server, and further ones drive it negative. With the counter at zero nfs_delegations_present() tells renewd that no delegations are held, so it no longer sets NFS4_RENEW_DELEGATION_CB for RENEW, and nfs_delegations_over_limit() never trips, so the per-server delegation watermark no longer bounds the delegation cache. The revoked path also clears the delegated dentry verifiers of an inode whose old delegation is still valid. Treat the duplicate like the other delegations the client fails to record: set @orphaned and leave the object in @delegation, so the exit path sends DELEGRETURN and frees it without marking it revoked. @freeme is then only ever the old, counted delegation of the upgrade path. Fixes: d2269ea14ebd2 ("NFSv4: Add accounting for the number of active delegations held") Cc: stable@vger.kernel.org Signed-off-by: Xingyuan Mo --- fs/nfs/delegation.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index ad774316f7166..a9eee4654ffd1 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -498,8 +498,7 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred, __func__, clp->cl_hostname); if (delegation->type == old_delegation->type || !(delegation->type & FMODE_WRITE)) { - freeme = delegation; - delegation = NULL; + orphaned = true; goto out; } if (test_and_set_bit(NFS_DELEGATION_RETURNING, -- 2.43.0