stats.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * linux/net/sunrpc/stats.c
  3. *
  4. * procfs-based user access to generic RPC statistics. The stats files
  5. * reside in /proc/net/rpc.
  6. *
  7. * The read routines assume that the buffer passed in is just big enough.
  8. * If you implement an RPC service that has its own stats routine which
  9. * appends the generic RPC stats, make sure you don't exceed the PAGE_SIZE
  10. * limit.
  11. *
  12. * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/proc_fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/sunrpc/clnt.h>
  21. #include <linux/sunrpc/svcsock.h>
  22. #define RPCDBG_FACILITY RPCDBG_MISC
  23. struct proc_dir_entry *proc_net_rpc = NULL;
  24. /*
  25. * Get RPC client stats
  26. */
  27. static int rpc_proc_show(struct seq_file *seq, void *v) {
  28. const struct rpc_stat *statp = seq->private;
  29. const struct rpc_program *prog = statp->program;
  30. int i, j;
  31. seq_printf(seq,
  32. "net %u %u %u %u\n",
  33. statp->netcnt,
  34. statp->netudpcnt,
  35. statp->nettcpcnt,
  36. statp->nettcpconn);
  37. seq_printf(seq,
  38. "rpc %u %u %u\n",
  39. statp->rpccnt,
  40. statp->rpcretrans,
  41. statp->rpcauthrefresh);
  42. for (i = 0; i < prog->nrvers; i++) {
  43. const struct rpc_version *vers = prog->version[i];
  44. if (!vers)
  45. continue;
  46. seq_printf(seq, "proc%u %u",
  47. vers->number, vers->nrprocs);
  48. for (j = 0; j < vers->nrprocs; j++)
  49. seq_printf(seq, " %u",
  50. vers->procs[j].p_count);
  51. seq_putc(seq, '\n');
  52. }
  53. return 0;
  54. }
  55. static int rpc_proc_open(struct inode *inode, struct file *file)
  56. {
  57. return single_open(file, rpc_proc_show, PDE(inode)->data);
  58. }
  59. static struct file_operations rpc_proc_fops = {
  60. .owner = THIS_MODULE,
  61. .open = rpc_proc_open,
  62. .read = seq_read,
  63. .llseek = seq_lseek,
  64. .release = single_release,
  65. };
  66. /*
  67. * Get RPC server stats
  68. */
  69. void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp) {
  70. const struct svc_program *prog = statp->program;
  71. const struct svc_procedure *proc;
  72. const struct svc_version *vers;
  73. int i, j;
  74. seq_printf(seq,
  75. "net %u %u %u %u\n",
  76. statp->netcnt,
  77. statp->netudpcnt,
  78. statp->nettcpcnt,
  79. statp->nettcpconn);
  80. seq_printf(seq,
  81. "rpc %u %u %u %u %u\n",
  82. statp->rpccnt,
  83. statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt,
  84. statp->rpcbadfmt,
  85. statp->rpcbadauth,
  86. statp->rpcbadclnt);
  87. for (i = 0; i < prog->pg_nvers; i++) {
  88. if (!(vers = prog->pg_vers[i]) || !(proc = vers->vs_proc))
  89. continue;
  90. seq_printf(seq, "proc%d %u", i, vers->vs_nproc);
  91. for (j = 0; j < vers->vs_nproc; j++, proc++)
  92. seq_printf(seq, " %u", proc->pc_count);
  93. seq_putc(seq, '\n');
  94. }
  95. }
  96. /*
  97. * Register/unregister RPC proc files
  98. */
  99. static inline struct proc_dir_entry *
  100. do_register(const char *name, void *data, struct file_operations *fops)
  101. {
  102. struct proc_dir_entry *ent;
  103. rpc_proc_init();
  104. dprintk("RPC: registering /proc/net/rpc/%s\n", name);
  105. ent = create_proc_entry(name, 0, proc_net_rpc);
  106. if (ent) {
  107. ent->proc_fops = fops;
  108. ent->data = data;
  109. }
  110. return ent;
  111. }
  112. struct proc_dir_entry *
  113. rpc_proc_register(struct rpc_stat *statp)
  114. {
  115. return do_register(statp->program->name, statp, &rpc_proc_fops);
  116. }
  117. void
  118. rpc_proc_unregister(const char *name)
  119. {
  120. remove_proc_entry(name, proc_net_rpc);
  121. }
  122. struct proc_dir_entry *
  123. svc_proc_register(struct svc_stat *statp, struct file_operations *fops)
  124. {
  125. return do_register(statp->program->pg_name, statp, fops);
  126. }
  127. void
  128. svc_proc_unregister(const char *name)
  129. {
  130. remove_proc_entry(name, proc_net_rpc);
  131. }
  132. void
  133. rpc_proc_init(void)
  134. {
  135. dprintk("RPC: registering /proc/net/rpc\n");
  136. if (!proc_net_rpc) {
  137. struct proc_dir_entry *ent;
  138. ent = proc_mkdir("rpc", proc_net);
  139. if (ent) {
  140. ent->owner = THIS_MODULE;
  141. proc_net_rpc = ent;
  142. }
  143. }
  144. }
  145. void
  146. rpc_proc_exit(void)
  147. {
  148. dprintk("RPC: unregistering /proc/net/rpc\n");
  149. if (proc_net_rpc) {
  150. proc_net_rpc = NULL;
  151. remove_proc_entry("net/rpc", NULL);
  152. }
  153. }