[PATCH] nfs: add a refcount tracker for struct net as held by the nfs_client

From: Jeff Layton
Date: Tue Mar 25 2025 - 07:45:12 EST


Eric added refcount trackers to several long-held netns references in
the sunrpc layer in 2022. Add a tracker to the netns reference held by
the nfs_client as well.

Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/nfs/client.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 3b0918ade53cd331d76baaa86fd2adec5d945b78..2ce58f2d6bf50924c38962ddedb7f0ca68752a8a 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -180,7 +180,7 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
clp->cl_proto = cl_init->proto;
clp->cl_nconnect = cl_init->nconnect;
clp->cl_max_connect = cl_init->max_connect ? cl_init->max_connect : 1;
- clp->cl_net = get_net(cl_init->net);
+ clp->cl_net = get_net_track(cl_init->net, &clp->cl_ns_tracker, GFP_KERNEL);

#if IS_ENABLED(CONFIG_NFS_LOCALIO)
seqlock_init(&clp->cl_boot_lock);
@@ -250,7 +250,7 @@ void nfs_free_client(struct nfs_client *clp)
if (!IS_ERR(clp->cl_rpcclient))
rpc_shutdown_client(clp->cl_rpcclient);

- put_net(clp->cl_net);
+ put_net_track(clp->cl_net, &clp->cl_ns_track);
put_nfs_version(clp->cl_nfs_mod);
kfree(clp->cl_hostname);
kfree(clp->cl_acceptor);

---
base-commit: 38fec10eb60d687e30c8c6b5420d86e8149f7557
change-id: 20250325-nfs-net-nef-fc2709b4efda

Best regards,
--
Jeff Layton <jlayton@xxxxxxxxxx>