main.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. gfs2_holder_mark_uninitialized(&ip->i_iopen_gh);
  43. }
  44. static void gfs2_init_glock_once(void *foo)
  45. {
  46. struct gfs2_glock *gl = foo;
  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_glock;
  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_cachep1;
  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_cachep2;
  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_cachep3;
  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_cachep4;
  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_cachep5;
  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_cachep6;
  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_cachep7;
  122. error = register_shrinker(&gfs2_qd_shrinker);
  123. if (error)
  124. goto fail_shrinker;
  125. error = register_filesystem(&gfs2_fs_type);
  126. if (error)
  127. goto fail_fs1;
  128. error = register_filesystem(&gfs2meta_fs_type);
  129. if (error)
  130. goto fail_fs2;
  131. error = -ENOMEM;
  132. gfs_recovery_wq = alloc_workqueue("gfs_recovery",
  133. WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
  134. if (!gfs_recovery_wq)
  135. goto fail_wq1;
  136. gfs2_control_wq = alloc_workqueue("gfs2_control",
  137. WQ_UNBOUND | WQ_FREEZABLE, 0);
  138. if (!gfs2_control_wq)
  139. goto fail_wq2;
  140. gfs2_freeze_wq = alloc_workqueue("freeze_workqueue", 0, 0);
  141. if (!gfs2_freeze_wq)
  142. goto fail_wq3;
  143. gfs2_page_pool = mempool_create_page_pool(64, 0);
  144. if (!gfs2_page_pool)
  145. goto fail_mempool;
  146. error = gfs2_register_debugfs();
  147. if (error)
  148. goto fail_debugfs;
  149. pr_info("GFS2 installed\n");
  150. return 0;
  151. fail_debugfs:
  152. mempool_destroy(gfs2_page_pool);
  153. fail_mempool:
  154. destroy_workqueue(gfs2_freeze_wq);
  155. fail_wq3:
  156. destroy_workqueue(gfs2_control_wq);
  157. fail_wq2:
  158. destroy_workqueue(gfs_recovery_wq);
  159. fail_wq1:
  160. unregister_filesystem(&gfs2meta_fs_type);
  161. fail_fs2:
  162. unregister_filesystem(&gfs2_fs_type);
  163. fail_fs1:
  164. unregister_shrinker(&gfs2_qd_shrinker);
  165. fail_shrinker:
  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_qadata_cachep);
  205. kmem_cache_destroy(gfs2_quotad_cachep);
  206. kmem_cache_destroy(gfs2_rgrpd_cachep);
  207. kmem_cache_destroy(gfs2_bufdata_cachep);
  208. kmem_cache_destroy(gfs2_inode_cachep);
  209. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  210. kmem_cache_destroy(gfs2_glock_cachep);
  211. gfs2_sys_uninit();
  212. }
  213. MODULE_DESCRIPTION("Global File System");
  214. MODULE_AUTHOR("Red Hat, Inc.");
  215. MODULE_LICENSE("GPL");
  216. module_init(init_gfs2_fs);
  217. module_exit(exit_gfs2_fs);