orangefs-mod.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 = 50;
  29. int orangefs_dcache_timeout_msecs = 50;
  30. int orangefs_getattr_timeout_msecs = 50;
  31. MODULE_LICENSE("GPL");
  32. MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
  33. MODULE_AUTHOR("ORANGEFS Development Team");
  34. MODULE_DESCRIPTION("The Linux Kernel VFS interface to ORANGEFS");
  35. MODULE_PARM_DESC(module_parm_debug_mask, "debugging level (see orangefs-debug.h for values)");
  36. MODULE_PARM_DESC(op_timeout_secs, "Operation timeout in seconds");
  37. MODULE_PARM_DESC(slot_timeout_secs, "Slot timeout in seconds");
  38. MODULE_PARM_DESC(hash_table_size,
  39. "size of hash table for operations in progress");
  40. static struct file_system_type orangefs_fs_type = {
  41. .name = "pvfs2",
  42. .mount = orangefs_mount,
  43. .kill_sb = orangefs_kill_sb,
  44. .owner = THIS_MODULE,
  45. };
  46. module_param(hash_table_size, int, 0);
  47. module_param(module_parm_debug_mask, ulong, 0644);
  48. module_param(op_timeout_secs, int, 0);
  49. module_param(slot_timeout_secs, int, 0);
  50. /*
  51. * Blocks non-priority requests from being queued for servicing. This
  52. * could be used for protecting the request list data structure, but
  53. * for now it's only being used to stall the op addition to the request
  54. * list
  55. */
  56. DEFINE_MUTEX(orangefs_request_mutex);
  57. /* hash table for storing operations waiting for matching downcall */
  58. struct list_head *orangefs_htable_ops_in_progress;
  59. DEFINE_SPINLOCK(orangefs_htable_ops_in_progress_lock);
  60. /* list for queueing upcall operations */
  61. LIST_HEAD(orangefs_request_list);
  62. /* used to protect the above orangefs_request_list */
  63. DEFINE_SPINLOCK(orangefs_request_list_lock);
  64. /* used for incoming request notification */
  65. DECLARE_WAIT_QUEUE_HEAD(orangefs_request_list_waitq);
  66. static int __init orangefs_init(void)
  67. {
  68. int ret;
  69. __u32 i = 0;
  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 out;
  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. ret = -ENOMEM;
  85. goto cleanup_inode;
  86. }
  87. /* initialize a doubly linked at each hash table index */
  88. for (i = 0; i < hash_table_size; i++)
  89. INIT_LIST_HEAD(&orangefs_htable_ops_in_progress[i]);
  90. ret = fsid_key_table_initialize();
  91. if (ret < 0)
  92. goto cleanup_progress_table;
  93. /*
  94. * Build the contents of /sys/kernel/debug/orangefs/debug-help
  95. * from the keywords in the kernel keyword/mask array.
  96. *
  97. * The keywords in the client keyword/mask array are
  98. * unknown at boot time.
  99. *
  100. * orangefs_prepare_debugfs_help_string will be used again
  101. * later to rebuild the debug-help-string after the client starts
  102. * and passes along the needed info. The argument signifies
  103. * which time orangefs_prepare_debugfs_help_string is being
  104. * called.
  105. */
  106. ret = orangefs_prepare_debugfs_help_string(1);
  107. if (ret)
  108. goto cleanup_key_table;
  109. orangefs_debugfs_init(module_parm_debug_mask);
  110. ret = orangefs_sysfs_init();
  111. if (ret)
  112. goto sysfs_init_failed;
  113. /* Initialize the orangefsdev subsystem. */
  114. ret = orangefs_dev_init();
  115. if (ret < 0) {
  116. gossip_err("%s: could not initialize device subsystem %d!\n",
  117. __func__,
  118. ret);
  119. goto cleanup_device;
  120. }
  121. ret = register_filesystem(&orangefs_fs_type);
  122. if (ret == 0) {
  123. pr_info("%s: module version %s loaded\n",
  124. __func__,
  125. ORANGEFS_VERSION);
  126. goto out;
  127. }
  128. orangefs_sysfs_exit();
  129. cleanup_device:
  130. orangefs_dev_cleanup();
  131. sysfs_init_failed:
  132. orangefs_debugfs_cleanup();
  133. cleanup_key_table:
  134. fsid_key_table_finalize();
  135. cleanup_progress_table:
  136. kfree(orangefs_htable_ops_in_progress);
  137. cleanup_inode:
  138. orangefs_inode_cache_finalize();
  139. cleanup_op:
  140. op_cache_finalize();
  141. out:
  142. return ret;
  143. }
  144. static void __exit orangefs_exit(void)
  145. {
  146. int i = 0;
  147. gossip_debug(GOSSIP_INIT_DEBUG, "orangefs: orangefs_exit called\n");
  148. unregister_filesystem(&orangefs_fs_type);
  149. orangefs_debugfs_cleanup();
  150. orangefs_sysfs_exit();
  151. fsid_key_table_finalize();
  152. orangefs_dev_cleanup();
  153. BUG_ON(!list_empty(&orangefs_request_list));
  154. for (i = 0; i < hash_table_size; i++)
  155. BUG_ON(!list_empty(&orangefs_htable_ops_in_progress[i]));
  156. orangefs_inode_cache_finalize();
  157. op_cache_finalize();
  158. kfree(orangefs_htable_ops_in_progress);
  159. pr_info("orangefs: module version %s unloaded\n", ORANGEFS_VERSION);
  160. }
  161. /*
  162. * What we do in this function is to walk the list of operations
  163. * that are in progress in the hash table and mark them as purged as well.
  164. */
  165. void purge_inprogress_ops(void)
  166. {
  167. int i;
  168. for (i = 0; i < hash_table_size; i++) {
  169. struct orangefs_kernel_op_s *op;
  170. struct orangefs_kernel_op_s *next;
  171. spin_lock(&orangefs_htable_ops_in_progress_lock);
  172. list_for_each_entry_safe(op,
  173. next,
  174. &orangefs_htable_ops_in_progress[i],
  175. list) {
  176. set_op_state_purged(op);
  177. gossip_debug(GOSSIP_DEV_DEBUG,
  178. "%s: op:%s: op_state:%d: process:%s:\n",
  179. __func__,
  180. get_opname_string(op),
  181. op->op_state,
  182. current->comm);
  183. }
  184. spin_unlock(&orangefs_htable_ops_in_progress_lock);
  185. }
  186. }
  187. module_init(orangefs_init);
  188. module_exit(orangefs_exit);