sysctl.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 FS_CODA 1 /* Coda file system */
  33. #define CODA_TIMEOUT 3 /* timeout on upcalls to become intrble */
  34. #define CODA_HARD 5 /* mount type "hard" or "soft" */
  35. #define CODA_VFS 6 /* vfs statistics */
  36. #define CODA_CACHE_INV 9 /* cache invalidation statistics */
  37. #define CODA_FAKE_STATFS 10 /* don't query venus for actual cache usage */
  38. struct coda_vfs_stats coda_vfs_stat;
  39. static struct coda_cache_inv_stats coda_cache_inv_stat;
  40. static void reset_coda_vfs_stats( void )
  41. {
  42. memset( &coda_vfs_stat, 0, sizeof( coda_vfs_stat ) );
  43. }
  44. static void reset_coda_cache_inv_stats( void )
  45. {
  46. memset( &coda_cache_inv_stat, 0, sizeof( coda_cache_inv_stat ) );
  47. }
  48. static int do_reset_coda_vfs_stats( ctl_table * table, int write,
  49. struct file * filp, void __user * buffer,
  50. size_t * lenp, loff_t * ppos )
  51. {
  52. if ( write ) {
  53. reset_coda_vfs_stats();
  54. *ppos += *lenp;
  55. } else {
  56. *lenp = 0;
  57. }
  58. return 0;
  59. }
  60. static int do_reset_coda_cache_inv_stats( ctl_table * table, int write,
  61. struct file * filp,
  62. void __user * buffer,
  63. size_t * lenp, loff_t * ppos )
  64. {
  65. if ( write ) {
  66. reset_coda_cache_inv_stats();
  67. *ppos += *lenp;
  68. } else {
  69. *lenp = 0;
  70. }
  71. return 0;
  72. }
  73. static int proc_vfs_stats_show(struct seq_file *m, void *v)
  74. {
  75. struct coda_vfs_stats * ps = & coda_vfs_stat;
  76. seq_printf(m,
  77. "Coda VFS statistics\n"
  78. "===================\n\n"
  79. "File Operations:\n"
  80. "\topen\t\t%9d\n"
  81. "\tflush\t\t%9d\n"
  82. "\trelease\t\t%9d\n"
  83. "\tfsync\t\t%9d\n\n"
  84. "Dir Operations:\n"
  85. "\treaddir\t\t%9d\n\n"
  86. "Inode Operations\n"
  87. "\tcreate\t\t%9d\n"
  88. "\tlookup\t\t%9d\n"
  89. "\tlink\t\t%9d\n"
  90. "\tunlink\t\t%9d\n"
  91. "\tsymlink\t\t%9d\n"
  92. "\tmkdir\t\t%9d\n"
  93. "\trmdir\t\t%9d\n"
  94. "\trename\t\t%9d\n"
  95. "\tpermission\t%9d\n",
  96. /* file operations */
  97. ps->open,
  98. ps->flush,
  99. ps->release,
  100. ps->fsync,
  101. /* dir operations */
  102. ps->readdir,
  103. /* inode operations */
  104. ps->create,
  105. ps->lookup,
  106. ps->link,
  107. ps->unlink,
  108. ps->symlink,
  109. ps->mkdir,
  110. ps->rmdir,
  111. ps->rename,
  112. ps->permission);
  113. return 0;
  114. }
  115. static int proc_cache_inv_stats_show(struct seq_file *m, void *v)
  116. {
  117. struct coda_cache_inv_stats * ps = & coda_cache_inv_stat;
  118. seq_printf(m,
  119. "Coda cache invalidation statistics\n"
  120. "==================================\n\n"
  121. "flush\t\t%9d\n"
  122. "purge user\t%9d\n"
  123. "zap_dir\t\t%9d\n"
  124. "zap_file\t%9d\n"
  125. "zap_vnode\t%9d\n"
  126. "purge_fid\t%9d\n"
  127. "replace\t\t%9d\n",
  128. ps->flush,
  129. ps->purge_user,
  130. ps->zap_dir,
  131. ps->zap_file,
  132. ps->zap_vnode,
  133. ps->purge_fid,
  134. ps->replace );
  135. return 0;
  136. }
  137. static int proc_vfs_stats_open(struct inode *inode, struct file *file)
  138. {
  139. return single_open(file, proc_vfs_stats_show, NULL);
  140. }
  141. static int proc_cache_inv_stats_open(struct inode *inode, struct file *file)
  142. {
  143. return single_open(file, proc_cache_inv_stats_show, NULL);
  144. }
  145. static const struct file_operations proc_vfs_stats_fops = {
  146. .owner = THIS_MODULE,
  147. .open = proc_vfs_stats_open,
  148. .read = seq_read,
  149. .llseek = seq_lseek,
  150. .release = single_release,
  151. };
  152. static const struct file_operations proc_cache_inv_stats_fops = {
  153. .owner = THIS_MODULE,
  154. .open = proc_cache_inv_stats_open,
  155. .read = seq_read,
  156. .llseek = seq_lseek,
  157. .release = single_release,
  158. };
  159. static ctl_table coda_table[] = {
  160. {CODA_TIMEOUT, "timeout", &coda_timeout, sizeof(int), 0644, NULL, &proc_dointvec},
  161. {CODA_HARD, "hard", &coda_hard, sizeof(int), 0644, NULL, &proc_dointvec},
  162. {CODA_VFS, "vfs_stats", NULL, 0, 0644, NULL, &do_reset_coda_vfs_stats},
  163. {CODA_CACHE_INV, "cache_inv_stats", NULL, 0, 0644, NULL, &do_reset_coda_cache_inv_stats},
  164. {CODA_FAKE_STATFS, "fake_statfs", &coda_fake_statfs, sizeof(int), 0600, NULL, &proc_dointvec},
  165. { 0 }
  166. };
  167. static ctl_table fs_table[] = {
  168. {FS_CODA, "coda", NULL, 0, 0555, coda_table},
  169. {0}
  170. };
  171. #ifdef CONFIG_PROC_FS
  172. /*
  173. target directory structure:
  174. /proc/fs (see linux/fs/proc/root.c)
  175. /proc/fs/coda
  176. /proc/fs/coda/{vfs_stats,
  177. */
  178. static struct proc_dir_entry* proc_fs_coda;
  179. #endif
  180. void coda_sysctl_init(void)
  181. {
  182. reset_coda_vfs_stats();
  183. reset_coda_cache_inv_stats();
  184. #ifdef CONFIG_PROC_FS
  185. proc_fs_coda = proc_mkdir("coda", proc_root_fs);
  186. if (proc_fs_coda) {
  187. struct proc_dir_entry *pde;
  188. proc_fs_coda->owner = THIS_MODULE;
  189. pde = create_proc_entry("vfs_stats", 0, proc_fs_coda);
  190. if (pde)
  191. pde->proc_fops = &proc_vfs_stats_fops;
  192. pde = create_proc_entry("cache_inv_stats", 0, proc_fs_coda);
  193. if (pde)
  194. pde->proc_fops = &proc_cache_inv_stats_fops;
  195. }
  196. #endif
  197. #ifdef CONFIG_SYSCTL
  198. if ( !fs_table_header )
  199. fs_table_header = register_sysctl_table(fs_table, 0);
  200. #endif
  201. }
  202. void coda_sysctl_clean(void)
  203. {
  204. #ifdef CONFIG_SYSCTL
  205. if ( fs_table_header ) {
  206. unregister_sysctl_table(fs_table_header);
  207. fs_table_header = NULL;
  208. }
  209. #endif
  210. #ifdef CONFIG_PROC_FS
  211. remove_proc_entry("cache_inv_stats", proc_fs_coda);
  212. remove_proc_entry("vfs_stats", proc_fs_coda);
  213. remove_proc_entry("coda", proc_root_fs);
  214. #endif
  215. }