main.c 5.7 KB

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