main.c 5.5 KB

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