Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796411324; b=X+iLpanxSyqdayq3xkIr2nCHnW8S91xam/KUIwcyAZMHPIjjB8O0/q9ip7sIyruH5qg9 DvigBYsb9j6KESgcdfiB1uK3jYxD2RBKf9f21BWE3pT/9DvEXrD7ipDWKDbLInUk78OOt M4r5I8hdqqR9ddyTI0N78Z06rh3nnhmJpWESqT5cEeLmy4lVd3ZE3xxXMVj0HuwswUzHy 9BOuhjGLVYJ+DSrCLgCklMzJ3evkQr7wE85bJz5wjwxK6zoUR+TNj3okGYT5QIBiDXME4 d4h+GZ5MKNDqZSXKfpHg8onDlUWKENa0B4oyLtDts797FH5LUPosL4WEn0plpcPt+iA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796411324; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=4D3mWHY80JT5mK3g9t/TZLX0g/3x+TakKqoMAyUQnJY=; b=TRuSQk/z1mcWz7vCx3ph1bTelJOee7Mw9w/cCY/OzctXYA1zemKEB3xt2FYqxSQQMSTl 0sFSOzcQQc/Ja9bWF9eTsyTJqzj6wDelOaoS35pqF5dMbjzdVenoafpa1qDcWPQjRdn1b QcyYjQDx+IjttCrfds5JDHudgcJ+hZHuW1II7LwgNh7/xxehHPKBHnsnBG/3TdsuXhEUS r7GxoAzPAo7Nw+yr3yP9YCDYXWJU5aJeNETs0Z76ssIHnzEfklxOKQs2G/VxZr42WJEVw 2BQyuyXtPU3mY0lZYMkAucBczKxQnDM3Qe51yOS5cthq4jQH3UAUKkTB57cvp2KqOcg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FTm8+bDu; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27B34606A322 for ; Fri, 4 Dec 2026 19:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FTm8+bDu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1175B1F00A11; Fri, 4 Dec 2026 19:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796411323; bh=4D3mWHY80JT5mK3g9t/TZLX0g/3x+TakKqoMAyUQnJY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=FTm8+bDuKsh33dqG8dev8k/D6KU9jE7BGyLQMyAAx3unphEDij2jUbITfFObr6Zg9 /Tjg/HuFjFC8NOy9bCYFEXfdMOl4bHD951uqgFvMKobrLqnd3vWz61QxOiw3NgMLt1 osJqTnJS9B9N49NibRRGQtmgKfNJKl4Is8xO00fnrl/MG7AWxltFj1felGHinVCRNp iuEsPEXL6kH2r1HpjDoZTsSkCkLL59Pq1ju25/nG8d7dwdA8CurInM7BCBTmn5elHo N6TQD9OI/pnQTloGMHgtMohKS/4dzu98Oey/0L/ciAFzlAHw+xPMc+0nDZQD21f3XV 0R0C0428BJunQ== From: Jeff Layton Date: Fri, 04 Dec 2026 14:08:26 -0500 Subject: [PATCH 2/3] NFS: tell nfsd which client a LOCALIO open is for X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-localio-deleg-v1-2-9dcb7d24e425@kernel.org> References: <20261204-localio-deleg-v1-0-9dcb7d24e425@kernel.org> In-Reply-To: <20261204-localio-deleg-v1-0-9dcb7d24e425@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Weston Andros Adamson , Mike Snitzer Cc: Anna Schumaker , linux-nfs@vger.kernel.org, Trond Myklebust , Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=9102; i=jlayton@kernel.org; h=from:subject:message-id; bh=7heBHIwkt43vwEUDwW06knEoQWXV1CXEC2vtEzvGK/Y=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBrEw+4QDFmfCVCurL2RtaQDM6LU2sS1+VHRxpfz /EYWtmFZHeJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaxMPuAAKCRAADmhBGVaC FTqeEADLM7JaufNuJ8hoH4tr+o3mYTTBrJDfcaM9xINbkcllI2oAM5VzsySf6JvfWQmIbZW/jtP r2zRtrnCh2TnQNkGN7CUXl7Pz5DwgG+SuWaBJRpq2Br0TMpzEZm1B46saMaraz7iiA+eadTiBYE rYG3uJzCGWYZXvKl4XVu3ol2zukXgtHDhpBjewU0yIpQ1bECHUixv2EGa6JYGDq37I3QqP0A8jc I2/DQE3SXvQtth3k6E9MF2S9ynhJYU7Fh6/dkabfZi9Rggz5PZLLnoQuaAqgs0HSZ8nA7AAlohT dG677N5i4s58SsFn1l0V7SXo4Wtgp5s1Euki7de3x1b5uSUTmJzhKobPi48hBHy7urpaI+MvPvv WUHD/IyhKe247qH6yZ9AoJFsxxlOIXazMR6tD9hdSD50MMzaA6hXMMuYIGTZlR4zGioASLT2mDg h6Ps/uqaykpttdsblir/tKRGSfjJ9glc/F5bTy8hfX/JNAPrTwSLDZV2NzbOSN9X+u/yWNb7tCj /xQuzcJoGqHFKhUv9HjhTubnpJ3TAvfJABlEE3D+w++yq5pk7XE2II4mc3FX0/bofNy1huBe/zk 9AsND4whb8WpEPTMftkf8kq0wAepK/R09+CZwANicb0lmeTrPJnu04LPwmcK/ZZ506qUNNwwHO2 Acycug/w+IIzkwA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Pass nfsd the NFSv4 client ID of the client whose open state covers a LOCALIO read, write or commit, so that opening the file doesn't recall that client's own delegations. nfs_local_open_fh() gets a second client argument for this. For ordinary I/O it is the client the I/O goes through; for NFSv3 mounts it yields no client ID, and nothing changes. nfs_open_local_fh() only passes the ID on if that client talks to the nfsd instance it has pinned for the open, since client IDs are only unique within a server. flexfilelayout passes NULL for now. Fixes: fa4983862e50 ("nfsd: add LOCALIO support") Signed-off-by: Jeff Layton --- fs/nfs/flexfilelayout/flexfilelayout.c | 3 ++- fs/nfs/internal.h | 7 +++--- fs/nfs/localio.c | 39 +++++++++++++++++++++++++++------- fs/nfs/pagelist.c | 2 +- fs/nfs/write.c | 3 ++- fs/nfs_common/nfslocalio.c | 13 ++++++++++-- include/linux/nfslocalio.h | 3 ++- 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 5c289737366f..8ed5f96e9706 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -173,7 +173,8 @@ ff_local_open_fh(struct pnfs_layout_segment *lseg, u32 ds_idx, u32 dss_id, #if IS_ENABLED(CONFIG_NFS_LOCALIO) struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx); - return nfs_local_open_fh(clp, cred, fh, &mirror->dss[dss_id].nfl, mode); + return nfs_local_open_fh(clp, NULL, cred, fh, &mirror->dss[dss_id].nfl, + mode); #else return NULL; #endif diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 5af6a032f145..415c5c4d0d8f 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -474,6 +474,7 @@ struct nfs_local_dio { extern void nfs_local_probe_async(struct nfs_client *); extern void nfs_local_probe_async_work(struct work_struct *); extern struct nfsd_file *nfs_local_open_fh(struct nfs_client *, + const struct nfs_client *, const struct cred *, struct nfs_fh *, struct nfs_file_localio *, @@ -491,9 +492,9 @@ extern bool nfs_server_is_local(const struct nfs_client *clp); static inline void nfs_local_probe(struct nfs_client *clp) {} static inline void nfs_local_probe_async(struct nfs_client *clp) {} static inline struct nfsd_file * -nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred, - struct nfs_fh *fh, struct nfs_file_localio *nfl, - const fmode_t mode) +nfs_local_open_fh(struct nfs_client *clp, const struct nfs_client *state_clp, + const struct cred *cred, struct nfs_fh *fh, + struct nfs_file_localio *nfl, const fmode_t mode) { return NULL; } diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c index 7f8d794581a3..c38476d1a8c8 100644 --- a/fs/nfs/localio.c +++ b/fs/nfs/localio.c @@ -334,6 +334,23 @@ static inline void nfs_local_file_put(struct nfsd_file *localio) nfs_to_nfsd_file_put_local(&nf); } +/* + * The NFSv4 client ID of @state_clp, so that nfsd doesn't recall that + * client's own delegations, or 0 if there is none. nfs_open_local_fh() + * only passes it on if @state_clp talks to the server it opens the file + * on, since client IDs are only unique within one server. + */ +static u64 nfs_local_clientid(const struct nfs_client *state_clp) +{ +#if IS_ENABLED(CONFIG_NFS_V4) + if (!state_clp || state_clp->rpc_ops->version != 4) + return 0; + return state_clp->cl_clientid; +#else + return 0; +#endif +} + /* * __nfs_local_open_fh - open a local filehandle in terms of nfsd_file. * @@ -341,16 +358,18 @@ static inline void nfs_local_file_put(struct nfsd_file *localio) * Caller must release returned nfsd_file with nfs_to_nfsd_file_put_local(). */ static struct nfsd_file * -__nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred, - struct nfs_fh *fh, struct nfs_file_localio *nfl, - struct nfsd_file __rcu **pnf, +__nfs_local_open_fh(struct nfs_client *clp, const struct nfs_client *state_clp, + const struct cred *cred, struct nfs_fh *fh, + struct nfs_file_localio *nfl, struct nfsd_file __rcu **pnf, const fmode_t mode) { int status = 0; struct nfsd_file *localio; localio = nfs_open_local_fh(&clp->cl_uuid, clp->cl_rpcclient, - cred, fh, nfl, pnf, mode); + cred, fh, nfl, pnf, mode, + state_clp ? &state_clp->cl_uuid : NULL, + nfs_local_clientid(state_clp)); if (IS_ERR(localio)) { status = PTR_ERR(localio); switch (status) { @@ -371,12 +390,16 @@ __nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred, * First checking if the open nfsd_file is already cached, otherwise * must __nfs_local_open_fh and insert the nfsd_file in nfs_file_localio. * + * @clp is the client the I/O is done through. @state_clp is the NFSv4 + * client whose open state covers it, if any: the same client for NFSv4 + * I/O, the metadata server's client for pNFS I/O to a data server. + * * Returns a pointer to a struct nfsd_file or NULL. */ struct nfsd_file * -nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred, - struct nfs_fh *fh, struct nfs_file_localio *nfl, - const fmode_t mode) +nfs_local_open_fh(struct nfs_client *clp, const struct nfs_client *state_clp, + const struct cred *cred, struct nfs_fh *fh, + struct nfs_file_localio *nfl, const fmode_t mode) { struct nfsd_file *nf, __rcu **pnf; @@ -390,7 +413,7 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred, else pnf = &nfl->ro_file; - nf = __nfs_local_open_fh(clp, cred, fh, nfl, pnf, mode); + nf = __nfs_local_open_fh(clp, state_clp, cred, fh, nfl, pnf, mode); if (IS_ERR(nf)) return NULL; return nf; diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index 71f0ce2bc4ea..2219c0595083 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -1009,7 +1009,7 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc) struct nfs_client *clp = NFS_SERVER(hdr->inode)->nfs_client; struct nfsd_file *localio = - nfs_local_open_fh(clp, hdr->cred, hdr->args.fh, + nfs_local_open_fh(clp, clp, hdr->cred, hdr->args.fh, &hdr->args.context->nfl, hdr->args.context->mode); diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 0b42d31f7a75..6f70bcb6775e 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -1782,7 +1782,8 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how, if (NFS_SERVER(inode)->nfs_client->cl_minorversion) task_flags = RPC_TASK_MOVEABLE; - localio = nfs_local_open_fh(NFS_SERVER(inode)->nfs_client, data->cred, + localio = nfs_local_open_fh(NFS_SERVER(inode)->nfs_client, + NFS_SERVER(inode)->nfs_client, data->cred, data->args.fh, &data->context->nfl, data->context->mode); return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode), diff --git a/fs/nfs_common/nfslocalio.c b/fs/nfs_common/nfslocalio.c index e77e42c2d567..676cd350a82b 100644 --- a/fs/nfs_common/nfslocalio.c +++ b/fs/nfs_common/nfslocalio.c @@ -335,7 +335,8 @@ struct nfsd_file *nfs_open_local_fh(nfs_uuid_t *uuid, struct rpc_clnt *rpc_clnt, const struct cred *cred, const struct nfs_fh *nfs_fh, struct nfs_file_localio *nfl, struct nfsd_file __rcu **pnf, - const fmode_t fmode) + const fmode_t fmode, const nfs_uuid_t *state_uuid, + u64 clientid) { struct net *net; struct auth_domain *dom; @@ -362,10 +363,18 @@ struct nfsd_file *nfs_open_local_fh(nfs_uuid_t *uuid, dom = uuid->dom; kref_get(&dom->ref); spin_unlock(&uuid->lock); + /* + * @clientid belongs to the client that @state_uuid is for. Client IDs + * are only unique within one server, so drop it unless that client + * talks to the server just pinned. + */ + if (state_uuid != uuid && + (!state_uuid || rcu_access_pointer(state_uuid->net) != net)) + clientid = 0; rcu_read_unlock(); /* We have an implied reference to net thanks to nfsd_net_try_get */ localio = nfs_to->nfsd_open_local_fh(net, dom, rpc_clnt, cred, - nfs_fh, pnf, fmode, 0); + nfs_fh, pnf, fmode, clientid); if (!IS_ERR(localio) && nfs_uuid_add_file(uuid, nfl) < 0) { /* * Delete the cached file when racing with nfs_uuid_put(). diff --git a/include/linux/nfslocalio.h b/include/linux/nfslocalio.h index 6b4746dde88a..5a92a0ca955b 100644 --- a/include/linux/nfslocalio.h +++ b/include/linux/nfslocalio.h @@ -92,7 +92,8 @@ struct nfsd_file *nfs_open_local_fh(nfs_uuid_t *, struct rpc_clnt *, const struct cred *, const struct nfs_fh *, struct nfs_file_localio *, struct nfsd_file __rcu **pnf, - const fmode_t); + const fmode_t, const nfs_uuid_t *state_uuid, + u64 clientid); static inline void nfs_to_nfsd_net_put(struct net *net) { -- 2.56.1