]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nfsd: expose /proc/net/sunrpc/nfsd in net namespaces
authorJosef Bacik <josef@toxicpanda.com>
Thu, 5 Sep 2024 15:30:58 +0000 (11:30 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Sep 2024 09:06:45 +0000 (11:06 +0200)
[ Upstream commit 93483ac5fec62cc1de166051b219d953bb5e4ef4 ]

We are running nfsd servers inside of containers with their own network
namespace, and we want to monitor these services using the stats found
in /proc.  However these are not exposed in the proc inside of the
container, so we have to bind mount the host /proc into our containers
to get at this information.

Separate out the stat counters init and the proc registration, and move
the proc registration into the pernet operations entry and exit points
so that these stats can be exposed inside of network namespaces.

This is an intermediate step, this just exposes the global counters in
the network namespace.  Subsequent patches will move these counters into
the per-network namespace container.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfsd/nfsctl.c
fs/nfsd/stats.c
fs/nfsd/stats.h

index cc538b8c028730ba7dd90ca11ffb336f17126df6..e49a778e18155d2ec410ac81126a2d4fadcd2d01 100644 (file)
@@ -1466,6 +1466,7 @@ static __net_init int nfsd_init_net(struct net *net)
        nfsd4_init_leases_net(nn);
        get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key));
        seqlock_init(&nn->writeverf_lock);
+       nfsd_proc_stat_init(net);
 
        return 0;
 
@@ -1481,6 +1482,7 @@ static __net_exit void nfsd_exit_net(struct net *net)
 {
        struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
+       nfsd_proc_stat_shutdown(net);
        nfsd_net_reply_cache_destroy(nn);
        nfsd_idmap_shutdown(net);
        nfsd_export_shutdown(net);
@@ -1504,7 +1506,7 @@ static int __init init_nfsd(void)
        retval = nfsd4_init_pnfs();
        if (retval)
                goto out_free_slabs;
-       retval = nfsd_stat_init();      /* Statistics */
+       retval = nfsd_stat_counters_init();     /* Statistics */
        if (retval)
                goto out_free_pnfs;
        retval = nfsd_drc_slab_create();
@@ -1540,7 +1542,7 @@ out_free_lockd:
        nfsd_lockd_shutdown();
        nfsd_drc_slab_free();
 out_free_stat:
-       nfsd_stat_shutdown();
+       nfsd_stat_counters_destroy();
 out_free_pnfs:
        nfsd4_exit_pnfs();
 out_free_slabs:
@@ -1557,7 +1559,7 @@ static void __exit exit_nfsd(void)
        nfsd_drc_slab_free();
        remove_proc_entry("fs/nfs/exports", NULL);
        remove_proc_entry("fs/nfs", NULL);
-       nfsd_stat_shutdown();
+       nfsd_stat_counters_destroy();
        nfsd_lockd_shutdown();
        nfsd4_free_slabs();
        nfsd4_exit_pnfs();
index 1fe6488a1cf968c13498d4f62d7a555a08319531..22d57f92187e10fb802243a0bc3b6aa703612eb4 100644 (file)
@@ -106,31 +106,22 @@ void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num)
                percpu_counter_destroy(&counters[i]);
 }
 
-static int nfsd_stat_counters_init(void)
+int nfsd_stat_counters_init(void)
 {
        return nfsd_percpu_counters_init(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM);
 }
 
-static void nfsd_stat_counters_destroy(void)
+void nfsd_stat_counters_destroy(void)
 {
        nfsd_percpu_counters_destroy(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM);
 }
 
-int nfsd_stat_init(void)
+void nfsd_proc_stat_init(struct net *net)
 {
-       int err;
-
-       err = nfsd_stat_counters_init();
-       if (err)
-               return err;
-
-       svc_proc_register(&init_net, &nfsd_svcstats, &nfsd_proc_ops);
-
-       return 0;
+       svc_proc_register(net, &nfsd_svcstats, &nfsd_proc_ops);
 }
 
-void nfsd_stat_shutdown(void)
+void nfsd_proc_stat_shutdown(struct net *net)
 {
-       nfsd_stat_counters_destroy();
-       svc_proc_unregister(&init_net, "nfsd");
+       svc_proc_unregister(net, "nfsd");
 }
index a660f0fb799f7983dea9d6d5865dbf45ba55eaf6..31756a9a8a0ac471a9a65f95962b36d03ae14e3a 100644 (file)
@@ -39,8 +39,10 @@ extern struct svc_stat               nfsd_svcstats;
 int nfsd_percpu_counters_init(struct percpu_counter *counters, int num);
 void nfsd_percpu_counters_reset(struct percpu_counter *counters, int num);
 void nfsd_percpu_counters_destroy(struct percpu_counter *counters, int num);
-int nfsd_stat_init(void);
-void nfsd_stat_shutdown(void);
+int nfsd_stat_counters_init(void);
+void nfsd_stat_counters_destroy(void);
+void nfsd_proc_stat_init(struct net *net);
+void nfsd_proc_stat_shutdown(struct net *net);
 
 static inline void nfsd_stats_rc_hits_inc(void)
 {