From nobody Fri Oct 3 07:42:26 2025 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2F072FD7A7; Wed, 3 Sep 2025 12:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756900808; cv=none; b=k2XB12I3KmVpiCe5eEhFoNaB1O3CF6f1ziTh+fJO89jtS1UbIsEpVQABlijkvY9jVO2CuADPOgAuxvGh994lgNIzbSZ2gttKgmsxjwCb+K842zoO4MrtHUhrcBPewuF1rW4iG0UtLyxpacWX7RiOxN7na7ixA4yzRH2R2NYugCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756900808; c=relaxed/simple; bh=45SFBCX7ymFr1NNsVrJRsAAdN4WtgrdDrn+YDV+in/E=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=S3kxRrq1HBhKEL/Ao4GDJ2weicY88KBdyDzdRAbu0n3ZG/E29xistbzKSgzcHKRsbf6WkMTp8rs43V0/XevRv8cH7DsUNnj6WVHT2HXhCLspCFMOB/WTRqUQLOljpfTJSb6LMFSlVWMPguCGH5EgCRWDom8zdUOJMFHI32oh4GM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4cH1RB5cs9z2wB80; Wed, 3 Sep 2025 20:01:10 +0800 (CST) Received: from kwepemj200013.china.huawei.com (unknown [7.202.194.25]) by mail.maildlp.com (Postfix) with ESMTPS id DF8DC140155; Wed, 3 Sep 2025 20:00:02 +0800 (CST) Received: from huawei.com (10.50.85.155) by kwepemj200013.china.huawei.com (7.202.194.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 3 Sep 2025 20:00:02 +0800 From: Li Lingfeng To: , , , , , , , CC: , , , , , , , Subject: [PATCH v2] nfsd: remove long-standing revoked delegations by force Date: Wed, 3 Sep 2025 19:59:18 +0800 Message-ID: <20250903115918.788159-1-lilingfeng3@huawei.com> X-Mailer: git-send-email 2.46.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemj200013.china.huawei.com (7.202.194.25) Content-Type: text/plain; charset="utf-8" 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 Fixes: 3bd64a5ba171 ("nfsd4: implement SEQ4_STATUS_RECALLABLE_STATE_REVOKED= ") Closes: https://lore.kernel.org/all/ff8debe9-6877-4cf7-ba29-fc98eae0ffa0@hu= awei.com/ Signed-off-by: Li Lingfeng Reviewed-by: Jeff Layton --- Changes in v2: 1) Set SC_STATUS_CLOSED unconditionally in destroy_delegation(); 2) Determine whether to remove the delegation based on SC_STATUS_CLOSED, rather than by timeout; 3) Modify the commit message. fs/nfsd/nfs4state.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 88c347957da5..bb9e1df4e41f 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1336,6 +1336,11 @@ static void destroy_delegation(struct nfs4_delegatio= n *dp) =20 spin_lock(&state_lock); unhashed =3D unhash_delegation_locked(dp, SC_STATUS_CLOSED); + /* + * Unconditionally set SC_STATUS_CLOSED, regardless of whether the + * delegation is hashed, to mark the current delegation as invalid. + */ + dp->dl_stid.sc_status |=3D SC_STATUS_CLOSED; spin_unlock(&state_lock); if (unhashed) destroy_unhashed_deleg(dp); @@ -4326,6 +4331,8 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_c= ompound_state *cstate, int buflen; struct net *net =3D SVC_NET(rqstp); struct nfsd_net *nn =3D net_generic(net, nfsd_net_id); + struct list_head *pos, *next; + struct nfs4_delegation *dp; =20 if (resp->opcnt !=3D 1) return nfserr_sequence_pos; @@ -4470,6 +4477,19 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_= compound_state *cstate, default: seq->status_flags =3D 0; } + if (!list_empty(&clp->cl_revoked)) { + spin_lock(&clp->cl_lock); + list_for_each_safe(pos, next, &clp->cl_revoked) { + dp =3D list_entry(pos, struct nfs4_delegation, dl_recall_lru); + if (dp->dl_stid.sc_status & SC_STATUS_CLOSED) { + 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 |=3D SEQ4_STATUS_RECALLABLE_STATE_REVOKED; if (atomic_read(&clp->cl_admin_revoked)) --=20 2.46.1