main.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/gfs2_ondisk.h>
  17. #include <linux/rcupdate.h>
  18. #include <linux/rculist_bl.h>
  19. #include <linux/atomic.h>
  20. #include <linux/mempool.h>
  21. #include "gfs2.h"
  22. #include "incore.h"
  23. #include "super.h"
  24. #include "sys.h"
  25. #include "util.h"
  26. #include "glock.h"
  27. #include "quota.h"
  28. #include "recovery.h"
  29. #include "dir.h"
  30. struct workqueue_struct *gfs2_control_wq;
  31. static void gfs2_init_inode_once(void *foo)
  32. {
  33. struct gfs2_inode *ip = foo;
  34. inode_init_once(&ip->i_inode);
  35. init_rwsem(&ip->i_rw_mutex);
  36. INIT_LIST_HEAD(&ip->i_trunc_list);
  37. ip->i_res = NULL;
  38. ip->i_hash_cache = NULL;
  39. }
  40. static void gfs2_init_glock_once(void *foo)
  41. {
  42. struct gfs2_glock *gl = foo;
  43. INIT_HLIST_BL_NODE(&gl->gl_list);
  44. spin_lock_init(&gl->gl_spin);
  45. INIT_LIST_HEAD(&gl->gl_holders);
  46. INIT_LIST_HEAD(&gl->gl_lru);
  47. INIT_LIST_HEAD(&gl->gl_ail_list);
  48. atomic_set(&gl->gl_ail_count, 0);
  49. atomic_set(&gl->gl_revokes, 0);
  50. }
  51. static void gfs2_init_gl_aspace_once(void *foo)
  52. {
  53. struct gfs2_glock *gl = foo;
  54. struct address_space *mapping = (struct address_space *)(gl + 1);
  55. gfs2_init_glock_once(gl);
  56. address_space_init_once(mapping);
  57. }
  58. /**
  59. * init_gfs2_fs - Register GFS2 as a filesystem
  60. *
  61. * Returns: 0 on success, error code on failure
  62. */
  63. static int __init init_gfs2_fs(void)
  64. {
  65. int error;
  66. gfs2_str2qstr(&gfs2_qdot, ".");
  67. gfs2_str2qstr(&gfs2_qdotdot, "..");
  68. gfs2_quota_hash_init();
  69. error = gfs2_sys_init();
  70. if (error)
  71. return error;
  72. error = list_lru_init(&gfs2_qd_lru);
  73. if (error)
  74. goto fail_lru;
  75. error = gfs2_glock_init();
  76. if (error)
  77. goto fail;
  78. error = -ENOMEM;
  79. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  80. sizeof(struct gfs2_glock),
  81. 0, 0,
  82. gfs2_init_glock_once);
  83. if (!gfs2_glock_cachep)
  84. goto fail;
  85. gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
  86. sizeof(struct gfs2_glock) +
  87. sizeof(struct address_space),
  88. 0, 0, gfs2_init_gl_aspace_once);
  89. if (!gfs2_glock_aspace_cachep)
  90. goto fail;
  91. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  92. sizeof(struct gfs2_inode),
  93. 0, SLAB_RECLAIM_ACCOUNT|
  94. SLAB_MEM_SPREAD,
  95. gfs2_init_inode_once);
  96. if (!gfs2_inode_cachep)
  97. goto fail;
  98. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  99. sizeof(struct gfs2_bufdata),
  100. 0, 0, NULL);
  101. if (!gfs2_bufdata_cachep)
  102. goto fail;
  103. gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  104. sizeof(struct gfs2_rgrpd),
  105. 0, 0, NULL);
  106. if (!gfs2_rgrpd_cachep)
  107. goto fail;
  108. gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  109. sizeof(struct gfs2_quota_data),
  110. 0, 0, NULL);
  111. if (!gfs2_quotad_cachep)
  112. goto fail;
  113. gfs2_rsrv_cachep = kmem_cache_create("gfs2_mblk",
  114. sizeof(struct gfs2_blkreserv),
  115. 0, 0, NULL);
  116. if (!gfs2_rsrv_cachep)
  117. goto fail;
  118. register_shrinker(&gfs2_qd_shrinker);
  119. error = register_filesystem(&gfs2_fs_type);
  120. if (error)
  121. goto fail;
  122. error = register_filesystem(&gfs2meta_fs_type);
  123. if (error)
  124. goto fail_unregister;
  125. error = -ENOMEM;
  126. gfs_recovery_wq = alloc_workqueue("gfs_recovery",
  127. WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
  128. if (!gfs_recovery_wq)
  129. goto fail_wq;
  130. gfs2_control_wq = alloc_workqueue("gfs2_control",
  131. WQ_UNBOUND | WQ_FREEZABLE, 0);
  132. if (!gfs2_control_wq)
  133. goto fail_recovery;
  134. gfs2_page_pool = mempool_create_page_pool(64, 0);
  135. if (!gfs2_page_pool)
  136. goto fail_control;
  137. gfs2_register_debugfs();
  138. pr_info("GFS2 installed\n");
  139. return 0;
  140. fail_control:
  141. destroy_workqueue(gfs2_control_wq);
  142. fail_recovery:
  143. destroy_workqueue(gfs_recovery_wq);
  144. fail_wq:
  145. unregister_filesystem(&gfs2meta_fs_type);
  146. fail_unregister:
  147. unregister_filesystem(&gfs2_fs_type);
  148. fail:
  149. list_lru_destroy(&gfs2_qd_lru);
  150. fail_lru:
  151. unregister_shrinker(&gfs2_qd_shrinker);
  152. gfs2_glock_exit();
  153. if (gfs2_rsrv_cachep)
  154. kmem_cache_destroy(gfs2_rsrv_cachep);
  155. if (gfs2_quotad_cachep)
  156. kmem_cache_destroy(gfs2_quotad_cachep);
  157. if (gfs2_rgrpd_cachep)
  158. kmem_cache_destroy(gfs2_rgrpd_cachep);
  159. if (gfs2_bufdata_cachep)
  160. kmem_cache_destroy(gfs2_bufdata_cachep);
  161. if (gfs2_inode_cachep)
  162. kmem_cache_destroy(gfs2_inode_cachep);
  163. if (gfs2_glock_aspace_cachep)
  164. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  165. if (gfs2_glock_cachep)
  166. kmem_cache_destroy(gfs2_glock_cachep);
  167. gfs2_sys_uninit();
  168. return error;
  169. }
  170. /**
  171. * exit_gfs2_fs - Unregister the file system
  172. *
  173. */
  174. static void __exit exit_gfs2_fs(void)
  175. {
  176. unregister_shrinker(&gfs2_qd_shrinker);
  177. gfs2_glock_exit();
  178. gfs2_unregister_debugfs();
  179. unregister_filesystem(&gfs2_fs_type);
  180. unregister_filesystem(&gfs2meta_fs_type);
  181. destroy_workqueue(gfs_recovery_wq);
  182. destroy_workqueue(gfs2_control_wq);
  183. list_lru_destroy(&gfs2_qd_lru);
  184. rcu_barrier();
  185. mempool_destroy(gfs2_page_pool);
  186. kmem_cache_destroy(gfs2_rsrv_cachep);
  187. kmem_cache_destroy(gfs2_quotad_cachep);
  188. kmem_cache_destroy(gfs2_rgrpd_cachep);
  189. kmem_cache_destroy(gfs2_bufdata_cachep);
  190. kmem_cache_destroy(gfs2_inode_cachep);
  191. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  192. kmem_cache_destroy(gfs2_glock_cachep);
  193. gfs2_sys_uninit();
  194. }
  195. MODULE_DESCRIPTION("Global File System");
  196. MODULE_AUTHOR("Red Hat, Inc.");
  197. MODULE_LICENSE("GPL");
  198. module_init(init_gfs2_fs);
  199. module_exit(exit_gfs2_fs);