1 // SPDX-License-Identifier: GPL-2.0
3 * procfs-based user access to knfsd statistics
8 * rc <hits> <misses> <nocache>
9 * Statistsics for the reply cache
10 * fh <stale> <deprecated filehandle cache stats>
11 * statistics for filehandle lookup
12 * io <bytes-read> <bytes-written>
13 * statistics for IO throughput
14 * th <threads> <deprecated thread usage histogram stats>
16 * ra <deprecated ra-cache stats>
18 * plus generic RPC stats (see net/sunrpc/stats.c)
23 #include <linux/seq_file.h>
24 #include <linux/module.h>
25 #include <linux/sunrpc/stats.h>
26 #include <net/net_namespace.h>
30 static int nfsd_show(struct seq_file *seq, void *v)
32 struct net *net = pde_data(file_inode(seq->file));
33 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
36 seq_printf(seq, "rc %lld %lld %lld\nfh %lld 0 0 0 0\nio %lld %lld\n",
37 percpu_counter_sum_positive(&nn->counter[NFSD_STATS_RC_HITS]),
38 percpu_counter_sum_positive(&nn->counter[NFSD_STATS_RC_MISSES]),
39 percpu_counter_sum_positive(&nn->counter[NFSD_STATS_RC_NOCACHE]),
40 percpu_counter_sum_positive(&nn->counter[NFSD_STATS_FH_STALE]),
41 percpu_counter_sum_positive(&nn->counter[NFSD_STATS_IO_READ]),
42 percpu_counter_sum_positive(&nn->counter[NFSD_STATS_IO_WRITE]));
45 seq_printf(seq, "th %u 0", atomic_read(&nfsd_th_cnt));
47 /* deprecated thread usage histogram stats */
48 for (i = 0; i < 10; i++)
49 seq_puts(seq, " 0.000");
51 /* deprecated ra-cache stats */
52 seq_puts(seq, "\nra 0 0 0 0 0 0 0 0 0 0 0 0\n");
54 /* show my rpc info */
55 svc_seq_show(seq, &nn->nfsd_svcstats);
58 /* Show count for individual nfsv4 operations */
59 /* Writing operation numbers 0 1 2 also for maintaining uniformity */
60 seq_printf(seq, "proc4ops %u", LAST_NFS4_OP + 1);
61 for (i = 0; i <= LAST_NFS4_OP; i++) {
62 seq_printf(seq, " %lld",
63 percpu_counter_sum_positive(&nn->counter[NFSD_STATS_NFS4_OP(i)]));
65 seq_printf(seq, "\nwdeleg_getattr %lld",
66 percpu_counter_sum_positive(&nn->counter[NFSD_STATS_WDELEG_GETATTR]));
74 DEFINE_PROC_SHOW_ATTRIBUTE(nfsd);
76 int nfsd_percpu_counters_init(struct percpu_counter *counters, int num)
80 for (i = 0; !err && i < num; i++)
81 err = percpu_counter_init(&counters[i], 0, GFP_KERNEL);
87 percpu_counter_destroy(&counters[i-1]);
92 void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num)
96 for (i = 0; i < num; i++)
97 percpu_counter_set(&counters[i], 0);
100 void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num)
104 for (i = 0; i < num; i++)
105 percpu_counter_destroy(&counters[i]);
108 int nfsd_stat_counters_init(struct nfsd_net *nn)
110 return nfsd_percpu_counters_init(nn->counter, NFSD_STATS_COUNTERS_NUM);
113 void nfsd_stat_counters_destroy(struct nfsd_net *nn)
115 nfsd_percpu_counters_destroy(nn->counter, NFSD_STATS_COUNTERS_NUM);
118 void nfsd_proc_stat_init(struct net *net)
120 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
122 svc_proc_register(net, &nn->nfsd_svcstats, &nfsd_proc_ops);
125 void nfsd_proc_stat_shutdown(struct net *net)
127 svc_proc_unregister(net, "nfsd");