orangefs-mod.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. ret = bdi_init(&orangefs_backing_dev_info);
  68. if (ret)
  69. return ret;
  70. if (op_timeout_secs < 0)
  71. op_timeout_secs = 0;
  72. if (slot_timeout_secs < 0)
  73. slot_timeout_secs = 0;
  74. /* initialize global book keeping data structures */
  75. ret = op_cache_initialize();
  76. if (ret < 0)
  77. goto err;
  78. ret = orangefs_inode_cache_initialize();
  79. if (ret < 0)
  80. goto cleanup_op;
  81. orangefs_htable_ops_in_progress =
  82. kcalloc(hash_table_size, sizeof(struct list_head), GFP_KERNEL);
  83. if (!orangefs_htable_ops_in_progress) {
  84. gossip_err("Failed to initialize op hashtable");
  85. ret = -ENOMEM;
  86. goto cleanup_inode;
  87. }
  88. /* initialize a doubly linked at each hash table index */
  89. for (i = 0; i < hash_table_size; i++)
  90. INIT_LIST_HEAD(&orangefs_htable_ops_in_progress[i]);
  91. ret = fsid_key_table_initialize();
  92. if (ret < 0)
  93. goto cleanup_progress_table;
  94. /*
  95. * Build the contents of /sys/kernel/debug/orangefs/debug-help
  96. * from the keywords in the kernel keyword/mask array.
  97. *
  98. * The keywords in the client keyword/mask array are
  99. * unknown at boot time.
  100. *
  101. * orangefs_prepare_debugfs_help_string will be used again
  102. * later to rebuild the debug-help-string after the client starts
  103. * and passes along the needed info. The argument signifies
  104. * which time orangefs_prepare_debugfs_help_string is being
  105. * called.
  106. */
  107. ret = orangefs_prepare_debugfs_help_string(1);
  108. if (ret)
  109. goto cleanup_key_table;
  110. ret = orangefs_debugfs_init(module_parm_debug_mask);
  111. if (ret)
  112. goto debugfs_init_failed;
  113. ret = orangefs_sysfs_init();
  114. if (ret)
  115. goto sysfs_init_failed;
  116. /* Initialize the orangefsdev subsystem. */
  117. ret = orangefs_dev_init();
  118. if (ret < 0) {
  119. gossip_err("%s: could not initialize device subsystem %d!\n",
  120. __func__,
  121. ret);
  122. goto cleanup_device;
  123. }
  124. ret = register_filesystem(&orangefs_fs_type);
  125. if (ret == 0) {
  126. pr_info("%s: module version %s loaded\n",
  127. __func__,
  128. ORANGEFS_VERSION);
  129. ret = 0;
  130. goto out;
  131. }
  132. orangefs_sysfs_exit();
  133. cleanup_device:
  134. orangefs_dev_cleanup();
  135. sysfs_init_failed:
  136. debugfs_init_failed:
  137. orangefs_debugfs_cleanup();
  138. cleanup_key_table:
  139. fsid_key_table_finalize();
  140. cleanup_progress_table:
  141. kfree(orangefs_htable_ops_in_progress);
  142. cleanup_inode:
  143. orangefs_inode_cache_finalize();
  144. cleanup_op:
  145. op_cache_finalize();
  146. err:
  147. bdi_destroy(&orangefs_backing_dev_info);
  148. out:
  149. return ret;
  150. }
  151. static void __exit orangefs_exit(void)
  152. {
  153. int i = 0;
  154. gossip_debug(GOSSIP_INIT_DEBUG, "orangefs: orangefs_exit called\n");
  155. unregister_filesystem(&orangefs_fs_type);
  156. orangefs_debugfs_cleanup();
  157. orangefs_sysfs_exit();
  158. fsid_key_table_finalize();
  159. orangefs_dev_cleanup();
  160. BUG_ON(!list_empty(&orangefs_request_list));
  161. for (i = 0; i < hash_table_size; i++)
  162. BUG_ON(!list_empty(&orangefs_htable_ops_in_progress[i]));
  163. orangefs_inode_cache_finalize();
  164. op_cache_finalize();
  165. kfree(orangefs_htable_ops_in_progress);
  166. bdi_destroy(&orangefs_backing_dev_info);
  167. pr_info("orangefs: module version %s unloaded\n", ORANGEFS_VERSION);
  168. }
  169. /*
  170. * What we do in this function is to walk the list of operations
  171. * that are in progress in the hash table and mark them as purged as well.
  172. */
  173. void purge_inprogress_ops(void)
  174. {
  175. int i;
  176. for (i = 0; i < hash_table_size; i++) {
  177. struct orangefs_kernel_op_s *op;
  178. struct orangefs_kernel_op_s *next;
  179. spin_lock(&orangefs_htable_ops_in_progress_lock);
  180. list_for_each_entry_safe(op,
  181. next,
  182. &orangefs_htable_ops_in_progress[i],
  183. list) {
  184. set_op_state_purged(op);
  185. gossip_debug(GOSSIP_DEV_DEBUG,
  186. "%s: op:%s: op_state:%d: process:%s:\n",
  187. __func__,
  188. get_opname_string(op),
  189. op->op_state,
  190. current->comm);
  191. }
  192. spin_unlock(&orangefs_htable_ops_in_progress_lock);
  193. }
  194. }
  195. module_init(orangefs_init);
  196. module_exit(orangefs_exit);