Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * procfs-based user access to knfsd statistics
0004  *
0005  * /proc/net/rpc/nfsd
0006  *
0007  * Format:
0008  *  rc <hits> <misses> <nocache>
0009  *          Statistsics for the reply cache
0010  *  fh <stale> <deprecated filehandle cache stats>
0011  *          statistics for filehandle lookup
0012  *  io <bytes-read> <bytes-written>
0013  *          statistics for IO throughput
0014  *  th <threads> <deprecated thread usage histogram stats>
0015  *          number of threads
0016  *  ra <deprecated ra-cache stats>
0017  *
0018  *  plus generic RPC stats (see net/sunrpc/stats.c)
0019  *
0020  * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
0021  */
0022 
0023 #include <linux/seq_file.h>
0024 #include <linux/module.h>
0025 #include <linux/sunrpc/stats.h>
0026 #include <net/net_namespace.h>
0027 
0028 #include "nfsd.h"
0029 
0030 struct nfsd_stats   nfsdstats;
0031 struct svc_stat     nfsd_svcstats = {
0032     .program    = &nfsd_program,
0033 };
0034 
0035 static int nfsd_proc_show(struct seq_file *seq, void *v)
0036 {
0037     int i;
0038 
0039     seq_printf(seq, "rc %lld %lld %lld\nfh %lld 0 0 0 0\nio %lld %lld\n",
0040            percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_RC_HITS]),
0041            percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_RC_MISSES]),
0042            percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_RC_NOCACHE]),
0043            percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_FH_STALE]),
0044            percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_IO_READ]),
0045            percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_IO_WRITE]));
0046 
0047     /* thread usage: */
0048     seq_printf(seq, "th %u 0", atomic_read(&nfsdstats.th_cnt));
0049 
0050     /* deprecated thread usage histogram stats */
0051     for (i = 0; i < 10; i++)
0052         seq_puts(seq, " 0.000");
0053 
0054     /* deprecated ra-cache stats */
0055     seq_puts(seq, "\nra 0 0 0 0 0 0 0 0 0 0 0 0\n");
0056 
0057     /* show my rpc info */
0058     svc_seq_show(seq, &nfsd_svcstats);
0059 
0060 #ifdef CONFIG_NFSD_V4
0061     /* Show count for individual nfsv4 operations */
0062     /* Writing operation numbers 0 1 2 also for maintaining uniformity */
0063     seq_printf(seq,"proc4ops %u", LAST_NFS4_OP + 1);
0064     for (i = 0; i <= LAST_NFS4_OP; i++) {
0065         seq_printf(seq, " %lld",
0066                percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_NFS4_OP(i)]));
0067     }
0068 
0069     seq_putc(seq, '\n');
0070 #endif
0071 
0072     return 0;
0073 }
0074 
0075 static int nfsd_proc_open(struct inode *inode, struct file *file)
0076 {
0077     return single_open(file, nfsd_proc_show, NULL);
0078 }
0079 
0080 static const struct proc_ops nfsd_proc_ops = {
0081     .proc_open  = nfsd_proc_open,
0082     .proc_read  = seq_read,
0083     .proc_lseek = seq_lseek,
0084     .proc_release   = single_release,
0085 };
0086 
0087 int nfsd_percpu_counters_init(struct percpu_counter counters[], int num)
0088 {
0089     int i, err = 0;
0090 
0091     for (i = 0; !err && i < num; i++)
0092         err = percpu_counter_init(&counters[i], 0, GFP_KERNEL);
0093 
0094     if (!err)
0095         return 0;
0096 
0097     for (; i > 0; i--)
0098         percpu_counter_destroy(&counters[i-1]);
0099 
0100     return err;
0101 }
0102 
0103 void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num)
0104 {
0105     int i;
0106 
0107     for (i = 0; i < num; i++)
0108         percpu_counter_set(&counters[i], 0);
0109 }
0110 
0111 void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num)
0112 {
0113     int i;
0114 
0115     for (i = 0; i < num; i++)
0116         percpu_counter_destroy(&counters[i]);
0117 }
0118 
0119 static int nfsd_stat_counters_init(void)
0120 {
0121     return nfsd_percpu_counters_init(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM);
0122 }
0123 
0124 static void nfsd_stat_counters_destroy(void)
0125 {
0126     nfsd_percpu_counters_destroy(nfsdstats.counter, NFSD_STATS_COUNTERS_NUM);
0127 }
0128 
0129 int nfsd_stat_init(void)
0130 {
0131     int err;
0132 
0133     err = nfsd_stat_counters_init();
0134     if (err)
0135         return err;
0136 
0137     svc_proc_register(&init_net, &nfsd_svcstats, &nfsd_proc_ops);
0138 
0139     return 0;
0140 }
0141 
0142 void nfsd_stat_shutdown(void)
0143 {
0144     nfsd_stat_counters_destroy();
0145     svc_proc_unregister(&init_net, "nfsd");
0146 }