main.c 5.9 KB

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