main.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 "gfs2.h"
  20. #include "incore.h"
  21. #include "super.h"
  22. #include "sys.h"
  23. #include "util.h"
  24. #include "glock.h"
  25. #include "quota.h"
  26. #include "recovery.h"
  27. #include "dir.h"
  28. static struct shrinker qd_shrinker = {
  29. .shrink = gfs2_shrink_qd_memory,
  30. .seeks = DEFAULT_SEEKS,
  31. };
  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. ip->i_res = NULL;
  40. ip->i_hash_cache = NULL;
  41. }
  42. static void gfs2_init_glock_once(void *foo)
  43. {
  44. struct gfs2_glock *gl = foo;
  45. INIT_HLIST_BL_NODE(&gl->gl_list);
  46. spin_lock_init(&gl->gl_spin);
  47. INIT_LIST_HEAD(&gl->gl_holders);
  48. INIT_LIST_HEAD(&gl->gl_lru);
  49. INIT_LIST_HEAD(&gl->gl_ail_list);
  50. atomic_set(&gl->gl_ail_count, 0);
  51. atomic_set(&gl->gl_revokes, 0);
  52. }
  53. static void gfs2_init_gl_aspace_once(void *foo)
  54. {
  55. struct gfs2_glock *gl = foo;
  56. struct address_space *mapping = (struct address_space *)(gl + 1);
  57. gfs2_init_glock_once(gl);
  58. address_space_init_once(mapping);
  59. }
  60. /**
  61. * init_gfs2_fs - Register GFS2 as a filesystem
  62. *
  63. * Returns: 0 on success, error code on failure
  64. */
  65. static int __init init_gfs2_fs(void)
  66. {
  67. int error;
  68. gfs2_str2qstr(&gfs2_qdot, ".");
  69. gfs2_str2qstr(&gfs2_qdotdot, "..");
  70. error = gfs2_sys_init();
  71. if (error)
  72. return error;
  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. register_shrinker(&qd_shrinker);
  112. error = register_filesystem(&gfs2_fs_type);
  113. if (error)
  114. goto fail;
  115. error = register_filesystem(&gfs2meta_fs_type);
  116. if (error)
  117. goto fail_unregister;
  118. error = -ENOMEM;
  119. gfs_recovery_wq = alloc_workqueue("gfs_recovery",
  120. WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
  121. if (!gfs_recovery_wq)
  122. goto fail_wq;
  123. gfs2_register_debugfs();
  124. printk("GFS2 installed\n");
  125. return 0;
  126. fail_wq:
  127. unregister_filesystem(&gfs2meta_fs_type);
  128. fail_unregister:
  129. unregister_filesystem(&gfs2_fs_type);
  130. fail:
  131. unregister_shrinker(&qd_shrinker);
  132. gfs2_glock_exit();
  133. if (gfs2_quotad_cachep)
  134. kmem_cache_destroy(gfs2_quotad_cachep);
  135. if (gfs2_rgrpd_cachep)
  136. kmem_cache_destroy(gfs2_rgrpd_cachep);
  137. if (gfs2_bufdata_cachep)
  138. kmem_cache_destroy(gfs2_bufdata_cachep);
  139. if (gfs2_inode_cachep)
  140. kmem_cache_destroy(gfs2_inode_cachep);
  141. if (gfs2_glock_aspace_cachep)
  142. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  143. if (gfs2_glock_cachep)
  144. kmem_cache_destroy(gfs2_glock_cachep);
  145. gfs2_sys_uninit();
  146. return error;
  147. }
  148. /**
  149. * exit_gfs2_fs - Unregister the file system
  150. *
  151. */
  152. static void __exit exit_gfs2_fs(void)
  153. {
  154. unregister_shrinker(&qd_shrinker);
  155. gfs2_glock_exit();
  156. gfs2_unregister_debugfs();
  157. unregister_filesystem(&gfs2_fs_type);
  158. unregister_filesystem(&gfs2meta_fs_type);
  159. destroy_workqueue(gfs_recovery_wq);
  160. rcu_barrier();
  161. kmem_cache_destroy(gfs2_quotad_cachep);
  162. kmem_cache_destroy(gfs2_rgrpd_cachep);
  163. kmem_cache_destroy(gfs2_bufdata_cachep);
  164. kmem_cache_destroy(gfs2_inode_cachep);
  165. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  166. kmem_cache_destroy(gfs2_glock_cachep);
  167. gfs2_sys_uninit();
  168. }
  169. MODULE_DESCRIPTION("Global File System");
  170. MODULE_AUTHOR("Red Hat, Inc.");
  171. MODULE_LICENSE("GPL");
  172. module_init(init_gfs2_fs);
  173. module_exit(exit_gfs2_fs);