From nobody Sat Jul 11 17:28:54 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gyG0Y3wWsz6lNtC; Sat, 11 Jul 2026 17:29:33 +0000 (UTC) (envelope-from freebsd@walstatt-de.de) Received: from smtp6.goneo.de (smtp6.goneo.de [85.220.129.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4gyG0X51W8z3NNc; Sat, 11 Jul 2026 17:29:32 +0000 (UTC) (envelope-from freebsd@walstatt-de.de) Authentication-Results: mx1.freebsd.org; none Received: from hub2.goneo.de (hub2.goneo.de [IPv6:2001:1640:5::8:53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by smtp6.goneo.de (Postfix) with ESMTPS id 7A460240548; Sat, 11 Jul 2026 19:29:30 +0200 (CEST) Received: from hub2.goneo.de (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by hub2.goneo.de (Postfix) with ESMTPS id 96D63240363; Sat, 11 Jul 2026 19:29:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walstatt-de.de; s=DKIM001; t=1783790965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XN7uD7y03eKL6+Hg0UbztGsgO7dgnGJi6Hvdu2jx8tA=; b=ZHNvbV3mSBXkl4/W+tIzATWrCUOSbu6hNfTb/DgpllpEx9U/Qv+JPsFHNh2ta0+14O8zfI EHLW2AkrZEspC476o3/vKP0QlEe2p28Sb/BS4YANWZwSUWfNVsoToOGynnonm8wdUeXsD5 yucvZPjtNFWBeqOszqFOZ4Jk7xFhuVr2IJLuz0/yj1K6wCAQbfpR7XJOuJlm/RT6IRbZ/G FV4kKbxO1mkvUegyj8hqWiNLN98ZqoDrkRulbwbZqEF19EARW9lJoSGAJ9JQauBX5syluH FDFeV1OdPW9sKqWoh4rtHcvq6hWPQ6wLxCRdLPKF98sCt1U6fh8UyXWhKqTwqQ== Received: from thor.sb211.local (dynamic-2a02-3100-253b-6f02-e310-7648-7860-5ce4.310.pool.telefonica.de [IPv6:2a02:3100:253b:6f02:e310:7648:7860:5ce4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by hub2.goneo.de (Postfix) with ESMTPSA id 504DD240182; Sat, 11 Jul 2026 19:29:25 +0200 (CEST) Date: Sat, 11 Jul 2026 19:28:54 +0200 From: A FreeBSD User To: Rick Macklem Cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: c52bcd09c2a6 - main - nfsd: Garbage collect stray NFSv4 state Message-ID: <20260711192455.1fcbe221@thor.sb211.local> In-Reply-To: <6a526688.386dd.2aa996fc@gitrepo.freebsd.org> References: <6a526688.386dd.2aa996fc@gitrepo.freebsd.org> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; amd64-portbld-freebsd16.0) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/5ZIBhD6k_kyyD9D73.tkZGc"; protocol="application/pgp-signature"; micalg=pgp-sha512 X-Rspamd-UID: 461517 X-Rspamd-UID: 36345b X-Rspamd-Queue-Id: 4gyG0X51W8z3NNc X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25394, ipnet:85.220.128.0/17, country:DE] X-Spamd-Bar: ---- --Sig_/5ZIBhD6k_kyyD9D73.tkZGc Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Am Tage des Herren Sat, 11 Jul 2026 15:51:36 +0000 Rick Macklem schrieb: > The branch main has been updated by rmacklem: >=20 > URL: https://cgit.FreeBSD.org/src/commit/?id=3Dc52bcd09c2a6736fe841fd72e3= cfb74de5a35b03 >=20 > commit c52bcd09c2a6736fe841fd72e3cfb74de5a35b03 > Author: Rick Macklem > AuthorDate: 2026-07-11 15:49:12 +0000 > Commit: Rick Macklem > CommitDate: 2026-07-11 15:49:12 +0000 >=20 > nfsd: Garbage collect stray NFSv4 state > =20 > When a file is deleted on the NFS server by another client, > any NFSv4 state related to that file is left stranded. > This happens because the NFSv4 operations that free the > state use a CFH, which is set by a PutFH operation. > However, the PutFH fails with ESTALE because the file has > been deleted. > =20 > This patch adds a function called nfsrv_freestrandedstate() > that frees all the NFSv4 state related to a file and calls > this function when PutFH will be replying ESTALE. > =20 > While here, a helper function was defined to handle free'ng > of the nfslockfile structure and replaces the two places > where nearly identical code does this. > =20 > Reported by: Richard Purdie > Tested by: Michael Halstead > MFC after: 2 weeks > --- > sys/fs/nfsserver/nfs_nfsdstate.c | 89 +++++++++++++++++++++++++++++++++-= ------ > 1 file changed, 75 insertions(+), 14 deletions(-) >=20 > diff --git a/sys/fs/nfsserver/nfs_nfsdstate.c b/sys/fs/nfsserver/nfs_nfsd= state.c > index 102af9bb2951..d790ab974d07 100644 > --- a/sys/fs/nfsserver/nfs_nfsdstate.c > +++ b/sys/fs/nfsserver/nfs_nfsdstate.c > @@ -253,6 +253,7 @@ static void nfsrv_issuedelegation(struct vnode *vp, s= truct nfsclient > *clp, nfsv4stateid_t *delegstateidp); > static void nfsrv_clientlock(bool mlocked); > static void nfsrv_clientunlock(bool mlocked); > +static void nfsrv_freelockifnotinuse(struct nfslockfile *lfp); > =20 > /* > * Lock the client structure, either with the mutex or the exclusive nfs= d lock. > @@ -1537,20 +1538,13 @@ nfsrv_freedeleglist(struct nfsstatehead *sthp) > static void > nfsrv_freedeleg(struct nfsstate *stp) > { > - struct nfslockfile *lfp; > =20 > LIST_REMOVE(stp, ls_hash); > LIST_REMOVE(stp, ls_list); > LIST_REMOVE(stp, ls_file); > if ((stp->ls_flags & NFSLCK_DELEGWRITE) !=3D 0) > nfsrv_writedelegcnt--; > - lfp =3D stp->ls_lfp; > - if (LIST_EMPTY(&lfp->lf_open) && > - LIST_EMPTY(&lfp->lf_lock) && LIST_EMPTY(&lfp->lf_deleg) && > - LIST_EMPTY(&lfp->lf_locallock) && LIST_EMPTY(&lfp->lf_rollback) && > - lfp->lf_usecount =3D=3D 0 && > - nfsv4_testlock(&lfp->lf_locallock_lck) =3D=3D 0) > - nfsrv_freenfslockfile(lfp); > + nfsrv_freelockifnotinuse(stp->ls_lfp); > free(stp, M_NFSDSTATE); > VNET(nfsstatsv1_p)->srvdelegates--; > nfsrv_openpluslock--; > @@ -1632,12 +1626,7 @@ nfsrv_freeopen(struct nfsstate *stp, vnode_t vp, i= nt cansleep, > NFSPROC_T *p) > * If there are locks associated with the open, the > * nfslockfile structure can be freed via nfsrv_freelockowner(). > */ > - if (lfp !=3D NULL && LIST_EMPTY(&lfp->lf_open) && > - LIST_EMPTY(&lfp->lf_deleg) && LIST_EMPTY(&lfp->lf_lock) && > - LIST_EMPTY(&lfp->lf_locallock) && LIST_EMPTY(&lfp->lf_rollback) && > - lfp->lf_usecount =3D=3D 0 && > - nfsv4_testlock(&lfp->lf_locallock_lck) =3D=3D 0) > - nfsrv_freenfslockfile(lfp); > + nfsrv_freelockifnotinuse(lfp); > free(stp, M_NFSDSTATE); > VNET(nfsstatsv1_p)->srvopens--; > nfsrv_openpluslock--; > @@ -8881,3 +8870,75 @@ nfsrv_removedeleg(fhandle_t *fhp, struct nfsrv_des= cript *nd, > NFSPROC_T *p) } > NFSUNLOCKSTATE(); > } > + > +/* > + * Free the nfslockfile structure if not in use. > + */ > +static void > +nfsrv_freelockifnotinuse(struct nfslockfile *lfp) > +{ > + > + /* > + * The nfslockfile is freed here if there are no locks > + * associated with the open. > + * If there are locks associated with the open, the > + * nfslockfile structure can be freed via nfsrv_freelockowner(). > + */ > + if (lfp !=3D NULL && LIST_EMPTY(&lfp->lf_open) && > + LIST_EMPTY(&lfp->lf_deleg) && LIST_EMPTY(&lfp->lf_lock) && > + LIST_EMPTY(&lfp->lf_locallock) && LIST_EMPTY(&lfp->lf_rollback) && > + lfp->lf_usecount =3D=3D 0 && > + nfsv4_testlock(&lfp->lf_locallock_lck) =3D=3D 0) > + nfsrv_freenfslockfile(lfp); > +} > + > +/* > + * Free stranded open/lock/delegation/layouts. > + * (These become stranded if the file has been deleted.) > + */ > +void > +nfsrv_freestrandedstate(struct nfsrvfh *nfp) > +{ > + struct nfslockfile *lfp; > + struct nfsstate *stp, *nstp; > + struct nfslayouthash *lhyp; > + struct nfslayout *lyp, *nlyp; > + fhandle_t *fhp; > + > + if (nfp->nfsrvfh_len !=3D NFSX_MYFH) > + return; > + fhp =3D (fhandle_t *)nfp->nfsrvfh_data; > + NFSLOCKSTATE(); > + if (nfsrv_getlockfile(0, NULL, &lfp, fhp, 0) < 0) { > + NFSUNLOCKSTATE(); > + return; > + } > + lfp->lf_usecount++; /* So nfsrv_freeopen() does not free it. */ > + /* Note that nfsrv_freeopen() will also free the byte range locks. */ > + LIST_FOREACH_SAFE(stp, &lfp->lf_open, ls_file, nstp) > + nfsrv_freeopen(stp, NULL, 0, curthread); > + > + /* > + * Normally, a delegation will have been recalled when the file is > + * removed. However, get rid of any that have somehow been > + * left stranded. > + */ > + LIST_FOREACH_SAFE(stp, &lfp->lf_deleg, ls_file, nstp) > + nfsrv_freedeleg(stp); > + > + /* Get rid of the nfslockfile, if no longer in use. */ > + lfp->lf_usecount--; > + nfsrv_freelockifnotinuse(lfp); > + NFSUNLOCKSTATE(); > + > + /* Free any layouts for the pNFS server case. */ > + if (nfsrv_devidcnt =3D=3D 0) > + return; > + lhyp =3D NFSLAYOUTHASH(fhp); > + NFSLOCKLAYOUT(lhyp); > + TAILQ_FOREACH_SAFE(lyp, &lhyp->list, lay_list, nlyp) { > + if (NFSBCMP(&lyp->lay_fh, fhp, sizeof(*fhp)) =3D=3D 0) > + nfsrv_freelayout(&lhyp->list, lyp); > + } > + NFSUNLOCKLAYOUT(lhyp); > +} >=20 It seems this commit breaks buildkernel for me: [...] /usr/src/sys/fs/nfsserver/nfs_nfsdstate.c:8900:1: error: no previous protot= ype for function 'nfsrv_freestrandedstate' [-Werror,-Wmissing-prototypes] 8900 | nfsrv_frees= trandedstate(struct nfsrvfh *nfp Kind regards, oh --=20 A FreeBSD user --Sig_/5ZIBhD6k_kyyD9D73.tkZGc Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iJEEARYKADkWIQRQheDybVktG5eW/1Kxzvs8OqokrwUCalJ9cRsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwyLDMACgkQsc77PDqqJK+7agD9EoSdyu3IwmFusl5AUjJD BzwqD/s5OMSSJs/AugyPwcEBAMvkLGCyLDzx8BluuJMGsc+QK0UMVKXPBztBWYia CbEG =Myfr -----END PGP SIGNATURE----- --Sig_/5ZIBhD6k_kyyD9D73.tkZGc--