main.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  4. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  7. #include <linux/slab.h>
  8. #include <linux/spinlock.h>
  9. #include <linux/completion.h>
  10. #include <linux/buffer_head.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/gfs2_ondisk.h>
  14. #include <linux/rcupdate.h>
  15. #include <linux/rculist_bl.h>
  16. #include <linux/atomic.h>
  17. #include <linux/mempool.h>
  18. #include "gfs2.h"
  19. #include "incore.h"
  20. #include "super.h"
  21. #include "sys.h"
  22. #include "util.h"
  23. #include "glock.h"
  24. #include "quota.h"
  25. #include "recovery.h"
  26. #include "dir.h"
  27. #include "glops.h"
  28. struct workqueue_struct *gfs2_control_wq;
  29. static void gfs2_init_inode_once(void *foo)
  30. {
  31. struct gfs2_inode *ip = foo;
  32. inode_init_once(&ip->i_inode);
  33. atomic_set(&ip->i_sizehint, 0);
  34. init_rwsem(&ip->i_rw_mutex);
  35. INIT_LIST_HEAD(&ip->i_ordered);
  36. ip->i_qadata = NULL;
  37. gfs2_holder_mark_uninitialized(&ip->i_rgd_gh);
  38. memset(&ip->i_res, 0, sizeof(ip->i_res));
  39. RB_CLEAR_NODE(&ip->i_res.rs_node);
  40. ip->i_hash_cache = NULL;
  41. gfs2_holder_mark_uninitialized(&ip->i_iopen_gh);
  42. }
  43. static void gfs2_init_glock_once(void *foo)
  44. {
  45. struct gfs2_glock *gl = foo;
  46. spin_lock_init(&gl->gl_lockref.lock);
  47. INIT_LIST_HEAD(&gl->gl_holders);
  48. INIT_LIST_HEAD(&gl->gl_lru);
  49. INIT_LIST_HEAD(&gl->gl_ail_list);
  50. atomic_set(&gl->gl_ail_count, 0);
  51. atomic_set(&gl->gl_revokes, 0);
  52. }
  53. static void gfs2_init_gl_aspace_once(void *foo)
  54. {
  55. struct gfs2_glock_aspace *gla = foo;
  56. gfs2_init_glock_once(&gla->glock);
  57. address_space_init_once(&gla->mapping);
  58. }
  59. /**
  60. * init_gfs2_fs - Register GFS2 as a filesystem
  61. *
  62. * Returns: 0 on success, error code on failure
  63. */
  64. static int __init init_gfs2_fs(void)
  65. {
  66. int error;
  67. gfs2_str2qstr(&gfs2_qdot, ".");
  68. gfs2_str2qstr(&gfs2_qdotdot, "..");
  69. gfs2_quota_hash_init();
  70. error = gfs2_sys_init();
  71. if (error)
  72. return error;
  73. error = list_lru_init(&gfs2_qd_lru);
  74. if (error)
  75. goto fail_lru;
  76. error = gfs2_glock_init();
  77. if (error)
  78. goto fail_glock;
  79. error = -ENOMEM;
  80. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  81. sizeof(struct gfs2_glock),
  82. 0, SLAB_RECLAIM_ACCOUNT,
  83. gfs2_init_glock_once);
  84. if (!gfs2_glock_cachep)
  85. goto fail_cachep1;
  86. gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
  87. sizeof(struct gfs2_glock_aspace),
  88. 0, 0, gfs2_init_gl_aspace_once);
  89. if (!gfs2_glock_aspace_cachep)
  90. goto fail_cachep2;
  91. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  92. sizeof(struct gfs2_inode),
  93. 0, SLAB_RECLAIM_ACCOUNT|
  94. SLAB_MEM_SPREAD|
  95. SLAB_ACCOUNT,
  96. gfs2_init_inode_once);
  97. if (!gfs2_inode_cachep)
  98. goto fail_cachep3;
  99. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  100. sizeof(struct gfs2_bufdata),
  101. 0, 0, NULL);
  102. if (!gfs2_bufdata_cachep)
  103. goto fail_cachep4;
  104. gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  105. sizeof(struct gfs2_rgrpd),
  106. 0, 0, NULL);
  107. if (!gfs2_rgrpd_cachep)
  108. goto fail_cachep5;
  109. gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  110. sizeof(struct gfs2_quota_data),
  111. 0, SLAB_RECLAIM_ACCOUNT, NULL);
  112. if (!gfs2_quotad_cachep)
  113. goto fail_cachep6;
  114. gfs2_qadata_cachep = kmem_cache_create("gfs2_qadata",
  115. sizeof(struct gfs2_qadata),
  116. 0, 0, NULL);
  117. if (!gfs2_qadata_cachep)
  118. goto fail_cachep7;
  119. gfs2_trans_cachep = kmem_cache_create("gfs2_trans",
  120. sizeof(struct gfs2_trans),
  121. 0, 0, NULL);
  122. if (!gfs2_trans_cachep)
  123. goto fail_cachep8;
  124. error = register_shrinker(&gfs2_qd_shrinker, "gfs2-qd");
  125. if (error)
  126. goto fail_shrinker;
  127. error = -ENOMEM;
  128. gfs_recovery_wq = alloc_workqueue("gfs_recovery",
  129. WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
  130. if (!gfs_recovery_wq)
  131. goto fail_wq1;
  132. gfs2_control_wq = alloc_workqueue("gfs2_control",
  133. WQ_UNBOUND | WQ_FREEZABLE, 0);
  134. if (!gfs2_control_wq)
  135. goto fail_wq2;
  136. gfs2_freeze_wq = alloc_workqueue("freeze_workqueue", 0, 0);
  137. if (!gfs2_freeze_wq)
  138. goto fail_wq3;
  139. gfs2_page_pool = mempool_create_page_pool(64, 0);
  140. if (!gfs2_page_pool)
  141. goto fail_mempool;
  142. gfs2_register_debugfs();
  143. error = register_filesystem(&gfs2_fs_type);
  144. if (error)
  145. goto fail_fs1;
  146. error = register_filesystem(&gfs2meta_fs_type);
  147. if (error)
  148. goto fail_fs2;
  149. pr_info("GFS2 installed\n");
  150. return 0;
  151. fail_fs2:
  152. unregister_filesystem(&gfs2_fs_type);
  153. fail_fs1:
  154. mempool_destroy(gfs2_page_pool);
  155. fail_mempool:
  156. destroy_workqueue(gfs2_freeze_wq);
  157. fail_wq3:
  158. destroy_workqueue(gfs2_control_wq);
  159. fail_wq2:
  160. destroy_workqueue(gfs_recovery_wq);
  161. fail_wq1:
  162. unregister_shrinker(&gfs2_qd_shrinker);
  163. fail_shrinker:
  164. kmem_cache_destroy(gfs2_trans_cachep);
  165. fail_cachep8:
  166. kmem_cache_destroy(gfs2_qadata_cachep);
  167. fail_cachep7:
  168. kmem_cache_destroy(gfs2_quotad_cachep);
  169. fail_cachep6:
  170. kmem_cache_destroy(gfs2_rgrpd_cachep);
  171. fail_cachep5:
  172. kmem_cache_destroy(gfs2_bufdata_cachep);
  173. fail_cachep4:
  174. kmem_cache_destroy(gfs2_inode_cachep);
  175. fail_cachep3:
  176. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  177. fail_cachep2:
  178. kmem_cache_destroy(gfs2_glock_cachep);
  179. fail_cachep1:
  180. gfs2_glock_exit();
  181. fail_glock:
  182. list_lru_destroy(&gfs2_qd_lru);
  183. fail_lru:
  184. gfs2_sys_uninit();
  185. return error;
  186. }
  187. /**
  188. * exit_gfs2_fs - Unregister the file system
  189. *
  190. */
  191. static void __exit exit_gfs2_fs(void)
  192. {
  193. unregister_shrinker(&gfs2_qd_shrinker);
  194. gfs2_glock_exit();
  195. gfs2_unregister_debugfs();
  196. unregister_filesystem(&gfs2_fs_type);
  197. unregister_filesystem(&gfs2meta_fs_type);
  198. destroy_workqueue(gfs_recovery_wq);
  199. destroy_workqueue(gfs2_control_wq);
  200. destroy_workqueue(gfs2_freeze_wq);
  201. list_lru_destroy(&gfs2_qd_lru);
  202. rcu_barrier();
  203. mempool_destroy(gfs2_page_pool);
  204. kmem_cache_destroy(gfs2_trans_cachep);
  205. kmem_cache_destroy(gfs2_qadata_cachep);
  206. kmem_cache_destroy(gfs2_quotad_cachep);
  207. kmem_cache_destroy(gfs2_rgrpd_cachep);
  208. kmem_cache_destroy(gfs2_bufdata_cachep);
  209. kmem_cache_destroy(gfs2_inode_cachep);
  210. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  211. kmem_cache_destroy(gfs2_glock_cachep);
  212. gfs2_sys_uninit();
  213. }
  214. MODULE_DESCRIPTION("Global File System");
  215. MODULE_AUTHOR("Red Hat, Inc.");
  216. MODULE_LICENSE("GPL");
  217. module_init(init_gfs2_fs);
  218. module_exit(exit_gfs2_fs);