orangefs-mod.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * (C) 2001 Clemson University and The University of Chicago
  3. *
  4. * Changes by Acxiom Corporation to add proc file handler for pvfs2 client
  5. * parameters, Copyright Acxiom Corporation, 2005.
  6. *
  7. * See COPYING in top-level directory.
  8. */
  9. #include "protocol.h"
  10. #include "orangefs-kernel.h"
  11. #include "orangefs-debugfs.h"
  12. #include "orangefs-sysfs.h"
  13. /* ORANGEFS_VERSION is a ./configure define */
  14. #ifndef ORANGEFS_VERSION
  15. #define ORANGEFS_VERSION "upstream"
  16. #endif
  17. /*
  18. * global variables declared here
  19. */
  20. struct orangefs_stats orangefs_stats;
  21. /* the size of the hash tables for ops in progress */
  22. int hash_table_size = 509;
  23. static ulong module_parm_debug_mask;
  24. __u64 orangefs_gossip_debug_mask;
  25. int op_timeout_secs = ORANGEFS_DEFAULT_OP_TIMEOUT_SECS;
  26. int slot_timeout_secs = ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS;
  27. int orangefs_dcache_timeout_msecs = 50;
  28. int orangefs_getattr_timeout_msecs = 50;
  29. MODULE_LICENSE("GPL");
  30. MODULE_AUTHOR("ORANGEFS Development Team");
  31. MODULE_DESCRIPTION("The Linux Kernel VFS interface to ORANGEFS");
  32. MODULE_PARM_DESC(module_parm_debug_mask, "debugging level (see orangefs-debug.h for values)");
  33. MODULE_PARM_DESC(op_timeout_secs, "Operation timeout in seconds");
  34. MODULE_PARM_DESC(slot_timeout_secs, "Slot timeout in seconds");
  35. MODULE_PARM_DESC(hash_table_size,
  36. "size of hash table for operations in progress");
  37. static struct file_system_type orangefs_fs_type = {
  38. .name = "pvfs2",
  39. .mount = orangefs_mount,
  40. .kill_sb = orangefs_kill_sb,
  41. .owner = THIS_MODULE,
  42. };
  43. module_param(hash_table_size, int, 0);
  44. module_param(module_parm_debug_mask, ulong, 0644);
  45. module_param(op_timeout_secs, int, 0);
  46. module_param(slot_timeout_secs, int, 0);
  47. /*
  48. * Blocks non-priority requests from being queued for servicing. This
  49. * could be used for protecting the request list data structure, but
  50. * for now it's only being used to stall the op addition to the request
  51. * list
  52. */
  53. DEFINE_MUTEX(orangefs_request_mutex);
  54. /* hash table for storing operations waiting for matching downcall */
  55. struct list_head *orangefs_htable_ops_in_progress;
  56. DEFINE_SPINLOCK(orangefs_htable_ops_in_progress_lock);
  57. /* list for queueing upcall operations */
  58. LIST_HEAD(orangefs_request_list);
  59. /* used to protect the above orangefs_request_list */
  60. DEFINE_SPINLOCK(orangefs_request_list_lock);
  61. /* used for incoming request notification */
  62. DECLARE_WAIT_QUEUE_HEAD(orangefs_request_list_waitq);
  63. static int __init orangefs_init(void)
  64. {
  65. int ret = -1;
  66. __u32 i = 0;
  67. if (op_timeout_secs < 0)
  68. op_timeout_secs = 0;
  69. if (slot_timeout_secs < 0)
  70. slot_timeout_secs = 0;
  71. /* initialize global book keeping data structures */
  72. ret = op_cache_initialize();
  73. if (ret < 0)
  74. goto out;
  75. ret = orangefs_inode_cache_initialize();
  76. if (ret < 0)
  77. goto cleanup_op;
  78. orangefs_htable_ops_in_progress =
  79. kcalloc(hash_table_size, sizeof(struct list_head), GFP_KERNEL);
  80. if (!orangefs_htable_ops_in_progress) {
  81. ret = -ENOMEM;
  82. goto cleanup_inode;
  83. }
  84. /* initialize a doubly linked at each hash table index */
  85. for (i = 0; i < hash_table_size; i++)
  86. INIT_LIST_HEAD(&orangefs_htable_ops_in_progress[i]);
  87. ret = fsid_key_table_initialize();
  88. if (ret < 0)
  89. goto cleanup_progress_table;
  90. /*
  91. * Build the contents of /sys/kernel/debug/orangefs/debug-help
  92. * from the keywords in the kernel keyword/mask array.
  93. *
  94. * The keywords in the client keyword/mask array are
  95. * unknown at boot time.
  96. *
  97. * orangefs_prepare_debugfs_help_string will be used again
  98. * later to rebuild the debug-help-string after the client starts
  99. * and passes along the needed info. The argument signifies
  100. * which time orangefs_prepare_debugfs_help_string is being
  101. * called.
  102. */
  103. ret = orangefs_prepare_debugfs_help_string(1);
  104. if (ret)
  105. goto cleanup_key_table;
  106. ret = orangefs_debugfs_init(module_parm_debug_mask);
  107. if (ret)
  108. goto debugfs_init_failed;
  109. ret = orangefs_sysfs_init();
  110. if (ret)
  111. goto sysfs_init_failed;
  112. /* Initialize the orangefsdev subsystem. */
  113. ret = orangefs_dev_init();
  114. if (ret < 0) {
  115. gossip_err("%s: could not initialize device subsystem %d!\n",
  116. __func__,
  117. ret);
  118. goto cleanup_device;
  119. }
  120. ret = register_filesystem(&orangefs_fs_type);
  121. if (ret == 0) {
  122. pr_info("%s: module version %s loaded\n",
  123. __func__,
  124. ORANGEFS_VERSION);
  125. ret = 0;
  126. goto out;
  127. }
  128. orangefs_sysfs_exit();
  129. cleanup_device:
  130. orangefs_dev_cleanup();
  131. sysfs_init_failed:
  132. debugfs_init_failed:
  133. orangefs_debugfs_cleanup();
  134. cleanup_key_table:
  135. fsid_key_table_finalize();
  136. cleanup_progress_table:
  137. kfree(orangefs_htable_ops_in_progress);
  138. cleanup_inode:
  139. orangefs_inode_cache_finalize();
  140. cleanup_op:
  141. op_cache_finalize();
  142. out:
  143. return ret;
  144. }
  145. static void __exit orangefs_exit(void)
  146. {
  147. int i = 0;
  148. gossip_debug(GOSSIP_INIT_DEBUG, "orangefs: orangefs_exit called\n");
  149. unregister_filesystem(&orangefs_fs_type);
  150. orangefs_debugfs_cleanup();
  151. orangefs_sysfs_exit();
  152. fsid_key_table_finalize();
  153. orangefs_dev_cleanup();
  154. BUG_ON(!list_empty(&orangefs_request_list));
  155. for (i = 0; i < hash_table_size; i++)
  156. BUG_ON(!list_empty(&orangefs_htable_ops_in_progress[i]));
  157. orangefs_inode_cache_finalize();
  158. op_cache_finalize();
  159. kfree(orangefs_htable_ops_in_progress);
  160. pr_info("orangefs: module version %s unloaded\n", ORANGEFS_VERSION);
  161. }
  162. /*
  163. * What we do in this function is to walk the list of operations
  164. * that are in progress in the hash table and mark them as purged as well.
  165. */
  166. void purge_inprogress_ops(void)
  167. {
  168. int i;
  169. for (i = 0; i < hash_table_size; i++) {
  170. struct orangefs_kernel_op_s *op;
  171. struct orangefs_kernel_op_s *next;
  172. spin_lock(&orangefs_htable_ops_in_progress_lock);
  173. list_for_each_entry_safe(op,
  174. next,
  175. &orangefs_htable_ops_in_progress[i],
  176. list) {
  177. set_op_state_purged(op);
  178. gossip_debug(GOSSIP_DEV_DEBUG,
  179. "%s: op:%s: op_state:%d: process:%s:\n",
  180. __func__,
  181. get_opname_string(op),
  182. op->op_state,
  183. current->comm);
  184. }
  185. spin_unlock(&orangefs_htable_ops_in_progress_lock);
  186. }
  187. }
  188. module_init(orangefs_init);
  189. module_exit(orangefs_exit);