sysctl.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * Sysctl operations for Coda filesystem
  3. * Original version: (C) 1996 P. Braam and M. Callahan
  4. * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
  5. *
  6. * Carnegie Mellon encourages users to contribute improvements to
  7. * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
  8. *
  9. * CODA operation statistics
  10. * (c) March, 1998 Zhanyong Wan <zhanyong.wan@yale.edu>
  11. *
  12. */
  13. #include <linux/time.h>
  14. #include <linux/mm.h>
  15. #include <linux/sysctl.h>
  16. #include <linux/proc_fs.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/slab.h>
  19. #include <linux/stat.h>
  20. #include <linux/ctype.h>
  21. #include <linux/bitops.h>
  22. #include <asm/uaccess.h>
  23. #include <linux/utsname.h>
  24. #include <linux/module.h>
  25. #include <linux/coda.h>
  26. #include <linux/coda_linux.h>
  27. #include <linux/coda_fs_i.h>
  28. #include <linux/coda_psdev.h>
  29. #include <linux/coda_cache.h>
  30. #include <linux/coda_proc.h>
  31. static struct ctl_table_header *fs_table_header;
  32. #define CODA_TIMEOUT 3 /* timeout on upcalls to become intrble */
  33. #define CODA_HARD 5 /* mount type "hard" or "soft" */
  34. #define CODA_VFS 6 /* vfs statistics */
  35. #define CODA_CACHE_INV 9 /* cache invalidation statistics */
  36. #define CODA_FAKE_STATFS 10 /* don't query venus for actual cache usage */
  37. struct coda_vfs_stats coda_vfs_stat;
  38. static struct coda_cache_inv_stats coda_cache_inv_stat;
  39. static void reset_coda_vfs_stats( void )
  40. {
  41. memset( &coda_vfs_stat, 0, sizeof( coda_vfs_stat ) );
  42. }
  43. static void reset_coda_cache_inv_stats( void )
  44. {
  45. memset( &coda_cache_inv_stat, 0, sizeof( coda_cache_inv_stat ) );
  46. }
  47. static int do_reset_coda_vfs_stats( ctl_table * table, int write,
  48. struct file * filp, void __user * buffer,
  49. size_t * lenp, loff_t * ppos )
  50. {
  51. if ( write ) {
  52. reset_coda_vfs_stats();
  53. *ppos += *lenp;
  54. } else {
  55. *lenp = 0;
  56. }
  57. return 0;
  58. }
  59. static int do_reset_coda_cache_inv_stats( ctl_table * table, int write,
  60. struct file * filp,
  61. void __user * buffer,
  62. size_t * lenp, loff_t * ppos )
  63. {
  64. if ( write ) {
  65. reset_coda_cache_inv_stats();
  66. *ppos += *lenp;
  67. } else {
  68. *lenp = 0;
  69. }
  70. return 0;
  71. }
  72. static int proc_vfs_stats_show(struct seq_file *m, void *v)
  73. {
  74. struct coda_vfs_stats * ps = & coda_vfs_stat;
  75. seq_printf(m,
  76. "Coda VFS statistics\n"
  77. "===================\n\n"
  78. "File Operations:\n"
  79. "\topen\t\t%9d\n"
  80. "\tflush\t\t%9d\n"
  81. "\trelease\t\t%9d\n"
  82. "\tfsync\t\t%9d\n\n"
  83. "Dir Operations:\n"
  84. "\treaddir\t\t%9d\n\n"
  85. "Inode Operations\n"
  86. "\tcreate\t\t%9d\n"
  87. "\tlookup\t\t%9d\n"
  88. "\tlink\t\t%9d\n"
  89. "\tunlink\t\t%9d\n"
  90. "\tsymlink\t\t%9d\n"
  91. "\tmkdir\t\t%9d\n"
  92. "\trmdir\t\t%9d\n"
  93. "\trename\t\t%9d\n"
  94. "\tpermission\t%9d\n",
  95. /* file operations */
  96. ps->open,
  97. ps->flush,
  98. ps->release,
  99. ps->fsync,
  100. /* dir operations */
  101. ps->readdir,
  102. /* inode operations */
  103. ps->create,
  104. ps->lookup,
  105. ps->link,
  106. ps->unlink,
  107. ps->symlink,
  108. ps->mkdir,
  109. ps->rmdir,
  110. ps->rename,
  111. ps->permission);
  112. return 0;
  113. }
  114. static int proc_cache_inv_stats_show(struct seq_file *m, void *v)
  115. {
  116. struct coda_cache_inv_stats * ps = & coda_cache_inv_stat;
  117. seq_printf(m,
  118. "Coda cache invalidation statistics\n"
  119. "==================================\n\n"
  120. "flush\t\t%9d\n"
  121. "purge user\t%9d\n"
  122. "zap_dir\t\t%9d\n"
  123. "zap_file\t%9d\n"
  124. "zap_vnode\t%9d\n"
  125. "purge_fid\t%9d\n"
  126. "replace\t\t%9d\n",
  127. ps->flush,
  128. ps->purge_user,
  129. ps->zap_dir,
  130. ps->zap_file,
  131. ps->zap_vnode,
  132. ps->purge_fid,
  133. ps->replace );
  134. return 0;
  135. }
  136. static int proc_vfs_stats_open(struct inode *inode, struct file *file)
  137. {
  138. return single_open(file, proc_vfs_stats_show, NULL);
  139. }
  140. static int proc_cache_inv_stats_open(struct inode *inode, struct file *file)
  141. {
  142. return single_open(file, proc_cache_inv_stats_show, NULL);
  143. }
  144. static const struct file_operations proc_vfs_stats_fops = {
  145. .owner = THIS_MODULE,
  146. .open = proc_vfs_stats_open,
  147. .read = seq_read,
  148. .llseek = seq_lseek,
  149. .release = single_release,
  150. };
  151. static const struct file_operations proc_cache_inv_stats_fops = {
  152. .owner = THIS_MODULE,
  153. .open = proc_cache_inv_stats_open,
  154. .read = seq_read,
  155. .llseek = seq_lseek,
  156. .release = single_release,
  157. };
  158. static ctl_table coda_table[] = {
  159. {
  160. .ctl_name = CTL_UNNUMBERED,
  161. .procname = "timeout",
  162. .data = &coda_timeout,
  163. .maxlen = sizeof(int),
  164. .mode = 0644,
  165. .proc_handler = &proc_dointvec
  166. },
  167. {
  168. .ctl_name = CTL_UNNUMBERED,
  169. .procname = "hard",
  170. .data = &coda_hard,
  171. .maxlen = sizeof(int),
  172. .mode = 0644,
  173. .proc_handler = &proc_dointvec
  174. },
  175. {
  176. .ctl_name = CTL_UNNUMBERED,
  177. .procname = "vfs_stats",
  178. .data = NULL,
  179. .maxlen = 0,
  180. .mode = 0644,
  181. .proc_handler = &do_reset_coda_vfs_stats
  182. },
  183. {
  184. .ctl_name = CTL_UNNUMBERED,
  185. .procname = "cache_inv_stats",
  186. .data = NULL,
  187. .maxlen = 0,
  188. .mode = 0644,
  189. .proc_handler = &do_reset_coda_cache_inv_stats
  190. },
  191. {
  192. .ctl_name = CTL_UNNUMBERED,
  193. .procname = "fake_statfs",
  194. .data = &coda_fake_statfs,
  195. .maxlen = sizeof(int),
  196. .mode = 0600,
  197. .proc_handler = &proc_dointvec
  198. },
  199. {}
  200. };
  201. static ctl_table fs_table[] = {
  202. {
  203. .ctl_name = CTL_UNNUMBERED,
  204. .procname = "coda",
  205. .mode = 0555,
  206. .child = coda_table
  207. },
  208. {}
  209. };
  210. #ifdef CONFIG_PROC_FS
  211. /*
  212. target directory structure:
  213. /proc/fs (see linux/fs/proc/root.c)
  214. /proc/fs/coda
  215. /proc/fs/coda/{vfs_stats,
  216. */
  217. static struct proc_dir_entry* proc_fs_coda;
  218. #endif
  219. void coda_sysctl_init(void)
  220. {
  221. reset_coda_vfs_stats();
  222. reset_coda_cache_inv_stats();
  223. #ifdef CONFIG_PROC_FS
  224. proc_fs_coda = proc_mkdir("coda", proc_root_fs);
  225. if (proc_fs_coda) {
  226. struct proc_dir_entry *pde;
  227. proc_fs_coda->owner = THIS_MODULE;
  228. pde = create_proc_entry("vfs_stats", 0, proc_fs_coda);
  229. if (pde)
  230. pde->proc_fops = &proc_vfs_stats_fops;
  231. pde = create_proc_entry("cache_inv_stats", 0, proc_fs_coda);
  232. if (pde)
  233. pde->proc_fops = &proc_cache_inv_stats_fops;
  234. }
  235. #endif
  236. #ifdef CONFIG_SYSCTL
  237. if ( !fs_table_header )
  238. fs_table_header = register_sysctl_table(fs_table);
  239. #endif
  240. }
  241. void coda_sysctl_clean(void)
  242. {
  243. #ifdef CONFIG_SYSCTL
  244. if ( fs_table_header ) {
  245. unregister_sysctl_table(fs_table_header);
  246. fs_table_header = NULL;
  247. }
  248. #endif
  249. #ifdef CONFIG_PROC_FS
  250. remove_proc_entry("cache_inv_stats", proc_fs_coda);
  251. remove_proc_entry("vfs_stats", proc_fs_coda);
  252. remove_proc_entry("coda", proc_root_fs);
  253. #endif
  254. }