sysctl.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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/config.h>
  14. #include <linux/time.h>
  15. #include <linux/mm.h>
  16. #include <linux/sysctl.h>
  17. #include <linux/proc_fs.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 coda_vfs_stats_get_info( char * buffer, char ** start,
  74. off_t offset, int length)
  75. {
  76. int len=0;
  77. off_t begin;
  78. struct coda_vfs_stats * ps = & coda_vfs_stat;
  79. /* this works as long as we are below 1024 characters! */
  80. len += sprintf( buffer,
  81. "Coda VFS statistics\n"
  82. "===================\n\n"
  83. "File Operations:\n"
  84. "\topen\t\t%9d\n"
  85. "\tflush\t\t%9d\n"
  86. "\trelease\t\t%9d\n"
  87. "\tfsync\t\t%9d\n\n"
  88. "Dir Operations:\n"
  89. "\treaddir\t\t%9d\n\n"
  90. "Inode Operations\n"
  91. "\tcreate\t\t%9d\n"
  92. "\tlookup\t\t%9d\n"
  93. "\tlink\t\t%9d\n"
  94. "\tunlink\t\t%9d\n"
  95. "\tsymlink\t\t%9d\n"
  96. "\tmkdir\t\t%9d\n"
  97. "\trmdir\t\t%9d\n"
  98. "\trename\t\t%9d\n"
  99. "\tpermission\t%9d\n",
  100. /* file operations */
  101. ps->open,
  102. ps->flush,
  103. ps->release,
  104. ps->fsync,
  105. /* dir operations */
  106. ps->readdir,
  107. /* inode operations */
  108. ps->create,
  109. ps->lookup,
  110. ps->link,
  111. ps->unlink,
  112. ps->symlink,
  113. ps->mkdir,
  114. ps->rmdir,
  115. ps->rename,
  116. ps->permission);
  117. begin = offset;
  118. *start = buffer + begin;
  119. len -= begin;
  120. if ( len > length )
  121. len = length;
  122. if ( len < 0 )
  123. len = 0;
  124. return len;
  125. }
  126. static int coda_cache_inv_stats_get_info( char * buffer, char ** start,
  127. off_t offset, int length)
  128. {
  129. int len=0;
  130. off_t begin;
  131. struct coda_cache_inv_stats * ps = & coda_cache_inv_stat;
  132. /* this works as long as we are below 1024 characters! */
  133. len += sprintf( buffer,
  134. "Coda cache invalidation statistics\n"
  135. "==================================\n\n"
  136. "flush\t\t%9d\n"
  137. "purge user\t%9d\n"
  138. "zap_dir\t\t%9d\n"
  139. "zap_file\t%9d\n"
  140. "zap_vnode\t%9d\n"
  141. "purge_fid\t%9d\n"
  142. "replace\t\t%9d\n",
  143. ps->flush,
  144. ps->purge_user,
  145. ps->zap_dir,
  146. ps->zap_file,
  147. ps->zap_vnode,
  148. ps->purge_fid,
  149. ps->replace );
  150. begin = offset;
  151. *start = buffer + begin;
  152. len -= begin;
  153. if ( len > length )
  154. len = length;
  155. if ( len < 0 )
  156. len = 0;
  157. return len;
  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. #define coda_proc_create(name,get_info) \
  181. create_proc_info_entry(name, 0, proc_fs_coda, get_info)
  182. void coda_sysctl_init(void)
  183. {
  184. reset_coda_vfs_stats();
  185. reset_coda_cache_inv_stats();
  186. #ifdef CONFIG_PROC_FS
  187. proc_fs_coda = proc_mkdir("coda", proc_root_fs);
  188. if (proc_fs_coda) {
  189. proc_fs_coda->owner = THIS_MODULE;
  190. coda_proc_create("vfs_stats", coda_vfs_stats_get_info);
  191. coda_proc_create("cache_inv_stats", coda_cache_inv_stats_get_info);
  192. }
  193. #endif
  194. #ifdef CONFIG_SYSCTL
  195. if ( !fs_table_header )
  196. fs_table_header = register_sysctl_table(fs_table, 0);
  197. #endif
  198. }
  199. void coda_sysctl_clean(void)
  200. {
  201. #ifdef CONFIG_SYSCTL
  202. if ( fs_table_header ) {
  203. unregister_sysctl_table(fs_table_header);
  204. fs_table_header = NULL;
  205. }
  206. #endif
  207. #ifdef CONFIG_PROC_FS
  208. remove_proc_entry("cache_inv_stats", proc_fs_coda);
  209. remove_proc_entry("vfs_stats", proc_fs_coda);
  210. remove_proc_entry("coda", proc_root_fs);
  211. #endif
  212. }