sysctl.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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/slab.h>
  18. #include <linux/stat.h>
  19. #include <linux/ctype.h>
  20. #include <linux/bitops.h>
  21. #include <asm/uaccess.h>
  22. #include <linux/utsname.h>
  23. #include <linux/module.h>
  24. #include <linux/coda.h>
  25. #include <linux/coda_linux.h>
  26. #include <linux/coda_fs_i.h>
  27. #include <linux/coda_psdev.h>
  28. #include <linux/coda_cache.h>
  29. #include <linux/coda_proc.h>
  30. static struct ctl_table_header *fs_table_header;
  31. #define FS_CODA 1 /* Coda file system */
  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 coda_vfs_stats_get_info( char * buffer, char ** start,
  73. off_t offset, int length)
  74. {
  75. int len=0;
  76. off_t begin;
  77. struct coda_vfs_stats * ps = & coda_vfs_stat;
  78. /* this works as long as we are below 1024 characters! */
  79. len += sprintf( buffer,
  80. "Coda VFS statistics\n"
  81. "===================\n\n"
  82. "File Operations:\n"
  83. "\topen\t\t%9d\n"
  84. "\tflush\t\t%9d\n"
  85. "\trelease\t\t%9d\n"
  86. "\tfsync\t\t%9d\n\n"
  87. "Dir Operations:\n"
  88. "\treaddir\t\t%9d\n\n"
  89. "Inode Operations\n"
  90. "\tcreate\t\t%9d\n"
  91. "\tlookup\t\t%9d\n"
  92. "\tlink\t\t%9d\n"
  93. "\tunlink\t\t%9d\n"
  94. "\tsymlink\t\t%9d\n"
  95. "\tmkdir\t\t%9d\n"
  96. "\trmdir\t\t%9d\n"
  97. "\trename\t\t%9d\n"
  98. "\tpermission\t%9d\n",
  99. /* file operations */
  100. ps->open,
  101. ps->flush,
  102. ps->release,
  103. ps->fsync,
  104. /* dir operations */
  105. ps->readdir,
  106. /* inode operations */
  107. ps->create,
  108. ps->lookup,
  109. ps->link,
  110. ps->unlink,
  111. ps->symlink,
  112. ps->mkdir,
  113. ps->rmdir,
  114. ps->rename,
  115. ps->permission);
  116. begin = offset;
  117. *start = buffer + begin;
  118. len -= begin;
  119. if ( len > length )
  120. len = length;
  121. if ( len < 0 )
  122. len = 0;
  123. return len;
  124. }
  125. static int coda_cache_inv_stats_get_info( char * buffer, char ** start,
  126. off_t offset, int length)
  127. {
  128. int len=0;
  129. off_t begin;
  130. struct coda_cache_inv_stats * ps = & coda_cache_inv_stat;
  131. /* this works as long as we are below 1024 characters! */
  132. len += sprintf( buffer,
  133. "Coda cache invalidation statistics\n"
  134. "==================================\n\n"
  135. "flush\t\t%9d\n"
  136. "purge user\t%9d\n"
  137. "zap_dir\t\t%9d\n"
  138. "zap_file\t%9d\n"
  139. "zap_vnode\t%9d\n"
  140. "purge_fid\t%9d\n"
  141. "replace\t\t%9d\n",
  142. ps->flush,
  143. ps->purge_user,
  144. ps->zap_dir,
  145. ps->zap_file,
  146. ps->zap_vnode,
  147. ps->purge_fid,
  148. ps->replace );
  149. begin = offset;
  150. *start = buffer + begin;
  151. len -= begin;
  152. if ( len > length )
  153. len = length;
  154. if ( len < 0 )
  155. len = 0;
  156. return len;
  157. }
  158. static ctl_table coda_table[] = {
  159. {CODA_TIMEOUT, "timeout", &coda_timeout, sizeof(int), 0644, NULL, &proc_dointvec},
  160. {CODA_HARD, "hard", &coda_hard, sizeof(int), 0644, NULL, &proc_dointvec},
  161. {CODA_VFS, "vfs_stats", NULL, 0, 0644, NULL, &do_reset_coda_vfs_stats},
  162. {CODA_CACHE_INV, "cache_inv_stats", NULL, 0, 0644, NULL, &do_reset_coda_cache_inv_stats},
  163. {CODA_FAKE_STATFS, "fake_statfs", &coda_fake_statfs, sizeof(int), 0600, NULL, &proc_dointvec},
  164. { 0 }
  165. };
  166. static ctl_table fs_table[] = {
  167. {FS_CODA, "coda", NULL, 0, 0555, coda_table},
  168. {0}
  169. };
  170. #ifdef CONFIG_PROC_FS
  171. /*
  172. target directory structure:
  173. /proc/fs (see linux/fs/proc/root.c)
  174. /proc/fs/coda
  175. /proc/fs/coda/{vfs_stats,
  176. */
  177. static struct proc_dir_entry* proc_fs_coda;
  178. #endif
  179. #define coda_proc_create(name,get_info) \
  180. create_proc_info_entry(name, 0, proc_fs_coda, get_info)
  181. void coda_sysctl_init(void)
  182. {
  183. reset_coda_vfs_stats();
  184. reset_coda_cache_inv_stats();
  185. #ifdef CONFIG_PROC_FS
  186. proc_fs_coda = proc_mkdir("coda", proc_root_fs);
  187. if (proc_fs_coda) {
  188. proc_fs_coda->owner = THIS_MODULE;
  189. coda_proc_create("vfs_stats", coda_vfs_stats_get_info);
  190. coda_proc_create("cache_inv_stats", coda_cache_inv_stats_get_info);
  191. }
  192. #endif
  193. #ifdef CONFIG_SYSCTL
  194. if ( !fs_table_header )
  195. fs_table_header = register_sysctl_table(fs_table, 0);
  196. #endif
  197. }
  198. void coda_sysctl_clean(void)
  199. {
  200. #ifdef CONFIG_SYSCTL
  201. if ( fs_table_header ) {
  202. unregister_sysctl_table(fs_table_header);
  203. fs_table_header = NULL;
  204. }
  205. #endif
  206. #ifdef CONFIG_PROC_FS
  207. remove_proc_entry("cache_inv_stats", proc_fs_coda);
  208. remove_proc_entry("vfs_stats", proc_fs_coda);
  209. remove_proc_entry("coda", proc_root_fs);
  210. #endif
  211. }