orangefs-mod.c 5.9 KB

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