Skip to content

Commit 93483ac

Browse files
josefbacikchucklever
authored andcommitted
nfsd: expose /proc/net/sunrpc/nfsd in net namespaces
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>
1 parent d98416c commit 93483ac

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

fs/nfsd/nfsctl.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ static __net_init int nfsd_net_init(struct net *net)
16791679
nfsd4_init_leases_net(nn);
16801680
get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key));
16811681
seqlock_init(&nn->writeverf_lock);
1682+
nfsd_proc_stat_init(net);
16821683

16831684
return 0;
16841685

@@ -1699,6 +1700,7 @@ static __net_exit void nfsd_net_exit(struct net *net)
16991700
{
17001701
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
17011702

1703+
nfsd_proc_stat_shutdown(net);
17021704
nfsd_net_reply_cache_destroy(nn);
17031705
nfsd_idmap_shutdown(net);
17041706
nfsd_export_shutdown(net);
@@ -1722,7 +1724,7 @@ static int __init init_nfsd(void)
17221724
retval = nfsd4_init_pnfs();
17231725
if (retval)
17241726
goto out_free_slabs;
1725-
retval = nfsd_stat_init(); /* Statistics */
1727+
retval = nfsd_stat_counters_init(); /* Statistics */
17261728
if (retval)
17271729
goto out_free_pnfs;
17281730
retval = nfsd_drc_slab_create();
@@ -1762,7 +1764,7 @@ static int __init init_nfsd(void)
17621764
nfsd_lockd_shutdown();
17631765
nfsd_drc_slab_free();
17641766
out_free_stat:
1765-
nfsd_stat_shutdown();
1767+
nfsd_stat_counters_destroy();
17661768
out_free_pnfs:
17671769
nfsd4_exit_pnfs();
17681770
out_free_slabs:
@@ -1780,7 +1782,7 @@ static void __exit exit_nfsd(void)
17801782
nfsd_drc_slab_free();
17811783
remove_proc_entry("fs/nfs/exports", NULL);
17821784
remove_proc_entry("fs/nfs", NULL);
1783-
nfsd_stat_shutdown();
1785+
nfsd_stat_counters_destroy();
17841786
nfsd_lockd_shutdown();
17851787
nfsd4_free_slabs();
17861788
nfsd4_exit_pnfs();

fs/nfsd/stats.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,31 +108,22 @@ void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num)
108108
percpu_counter_destroy(&counters[i]);
109109
}
110110

111-
static int nfsd_stat_counters_init(void)
111+
int nfsd_stat_counters_init(void)
112112
{
113113
return nfsd_percpu_counters_init(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM);
114114
}
115115

116-
static void nfsd_stat_counters_destroy(void)
116+
void nfsd_stat_counters_destroy(void)
117117
{
118118
nfsd_percpu_counters_destroy(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM);
119119
}
120120

121-
int nfsd_stat_init(void)
121+
void nfsd_proc_stat_init(struct net *net)
122122
{
123-
int err;
124-
125-
err = nfsd_stat_counters_init();
126-
if (err)
127-
return err;
128-
129-
svc_proc_register(&init_net, &nfsd_svcstats, &nfsd_proc_ops);
130-
131-
return 0;
123+
svc_proc_register(net, &nfsd_svcstats, &nfsd_proc_ops);
132124
}
133125

134-
void nfsd_stat_shutdown(void)
126+
void nfsd_proc_stat_shutdown(struct net *net)
135127
{
136-
nfsd_stat_counters_destroy();
137-
svc_proc_unregister(&init_net, "nfsd");
128+
svc_proc_unregister(net, "nfsd");
138129
}

fs/nfsd/stats.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ extern struct svc_stat nfsd_svcstats;
4040
int nfsd_percpu_counters_init(struct percpu_counter *counters, int num);
4141
void nfsd_percpu_counters_reset(struct percpu_counter *counters, int num);
4242
void nfsd_percpu_counters_destroy(struct percpu_counter *counters, int num);
43-
int nfsd_stat_init(void);
44-
void nfsd_stat_shutdown(void);
43+
int nfsd_stat_counters_init(void);
44+
void nfsd_stat_counters_destroy(void);
45+
void nfsd_proc_stat_init(struct net *net);
46+
void nfsd_proc_stat_shutdown(struct net *net);
4547

4648
static inline void nfsd_stats_rc_hits_inc(void)
4749
{

0 commit comments

Comments
 (0)