From: Li Lingfeng <lilingfeng3@huawei.com> hulk inclusion category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/21279 -------------------------------- When file access conflicts occur between clients, the server recalls delegations. If the client holding delegation fails to return it after a recall, nfs4_laundromat adds the delegation to cl_revoked list. This causes subsequent SEQUENCE operations to set the SEQ4_STATUS_RECALLABLE_STATE_REVOKED flag, forcing the client to validate all delegations and return the revoked one. However, if the client fails to return the delegation like this: nfs4_laundromat nfsd4_delegreturn unhash_delegation_locked list_add // add dp to reaplist // by dl_recall_lru list_del_init // delete dp from // reaplist destroy_delegation unhash_delegation_locked // do nothing but return false revoke_delegation list_add // add dp to cl_revoked // by dl_recall_lru The delegation will remain in the server's cl_revoked list while the client marks it revoked and won't find it upon detecting SEQ4_STATUS_RECALLABLE_STATE_REVOKED. This leads to a loop: the server persistently sets SEQ4_STATUS_RECALLABLE_STATE_REVOKED, and the client repeatedly tests all delegations, severely impacting performance when numerous delegations exist. Since abnormal delegations are removed from flc_lease via nfs4_laundromat --> revoke_delegation --> destroy_unhashed_deleg --> nfs4_unlock_deleg_lease --> kernel_setlease, and do not block new open requests indefinitely, retaining such a delegation on the server is unnecessary. Reported-by: Zhang Jian <zhangjian496@huawei.com> Closes: https://lore.kernel.org/all/ff8debe9-6877-4cf7-ba29-fc98eae0ffa0@huawei.com/ Fixes: 3bd64a5ba171 ("nfsd4: implement SEQ4_STATUS_RECALLABLE_STATE_REVOKED") Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com> Signed-off-by: Zizhi Wo <wozizhi@huawei.com> --- fs/nfsd/nfs4state.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 76a512eafcfb..664175ed3af6 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1446,10 +1446,16 @@ static void destroy_delegation(struct nfs4_delegation *dp) { bool unhashed; spin_lock(&state_lock); unhashed = unhash_delegation_locked(dp); + /* + * Unconditionally set NFS4_CLOSED_DELEG_STID, regardless of + * whether the delegation is hashed, to mark the current + * delegation as invalid. + */ + dp->dl_stid.sc_type = NFS4_CLOSED_DELEG_STID; spin_unlock(&state_lock); if (unhashed) destroy_unhashed_deleg(dp); } @@ -1461,13 +1467,15 @@ static void revoke_delegation(struct nfs4_delegation *dp) trace_nfsd_stid_revoke(&dp->dl_stid); if (clp->cl_minorversion) { spin_lock(&clp->cl_lock); - dp->dl_stid.sc_type = NFS4_REVOKED_DELEG_STID; - refcount_inc(&dp->dl_stid.sc_count); - list_add(&dp->dl_recall_lru, &clp->cl_revoked); + if (dp->dl_stid.sc_type != NFS4_CLOSED_DELEG_STID) { + dp->dl_stid.sc_type = NFS4_REVOKED_DELEG_STID; + refcount_inc(&dp->dl_stid.sc_count); + list_add(&dp->dl_recall_lru, &clp->cl_revoked); + } spin_unlock(&clp->cl_lock); } destroy_unhashed_deleg(dp); } @@ -4077,10 +4085,12 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, __be32 status; int buflen; u32 maxlen, respsize; struct net *net = SVC_NET(rqstp); struct nfsd_net *nn = net_generic(net, nfsd_net_id); + struct list_head *pos, *next; + struct nfs4_delegation *dp; if (resp->opcnt != 1) return nfserr_sequence_pos; /* @@ -4190,10 +4200,24 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, seq->status_flags = SEQ4_STATUS_BACKCHANNEL_FAULT; break; default: seq->status_flags = 0; } + if (!list_empty(&clp->cl_revoked)) { + spin_lock(&clp->cl_lock); + list_for_each_safe(pos, next, &clp->cl_revoked) { + dp = list_entry(pos, struct nfs4_delegation, dl_recall_lru); + if (dp->dl_stid.sc_type & NFS4_CLOSED_DELEG_STID) { + list_del_init(&dp->dl_recall_lru); + spin_unlock(&clp->cl_lock); + nfs4_put_stid(&dp->dl_stid); + spin_lock(&clp->cl_lock); + } + } + spin_unlock(&clp->cl_lock); + } + if (!list_empty(&clp->cl_revoked)) seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED; out_no_session: if (conn) free_conn(conn); -- 2.52.0