main.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. struct workqueue_struct *gfs2_control_wq;
  29. static struct shrinker qd_shrinker = {
  30. .shrink = gfs2_shrink_qd_memory,
  31. .seeks = DEFAULT_SEEKS,
  32. };
  33. static void gfs2_init_inode_once(void *foo)
  34. {
  35. struct gfs2_inode *ip = foo;
  36. inode_init_once(&ip->i_inode);
  37. init_rwsem(&ip->i_rw_mutex);
  38. INIT_LIST_HEAD(&ip->i_trunc_list);
  39. ip->i_qadata = NULL;
  40. ip->i_res = NULL;
  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_spin);
  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. error = gfs2_sys_init();
  72. if (error)
  73. return error;
  74. error = gfs2_glock_init();
  75. if (error)
  76. goto fail;
  77. error = -ENOMEM;
  78. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  79. sizeof(struct gfs2_glock),
  80. 0, 0,
  81. gfs2_init_glock_once);
  82. if (!gfs2_glock_cachep)
  83. goto fail;
  84. gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
  85. sizeof(struct gfs2_glock) +
  86. sizeof(struct address_space),
  87. 0, 0, gfs2_init_gl_aspace_once);
  88. if (!gfs2_glock_aspace_cachep)
  89. goto fail;
  90. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  91. sizeof(struct gfs2_inode),
  92. 0, SLAB_RECLAIM_ACCOUNT|
  93. SLAB_MEM_SPREAD,
  94. gfs2_init_inode_once);
  95. if (!gfs2_inode_cachep)
  96. goto fail;
  97. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  98. sizeof(struct gfs2_bufdata),
  99. 0, 0, NULL);
  100. if (!gfs2_bufdata_cachep)
  101. goto fail;
  102. gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  103. sizeof(struct gfs2_rgrpd),
  104. 0, 0, NULL);
  105. if (!gfs2_rgrpd_cachep)
  106. goto fail;
  107. gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  108. sizeof(struct gfs2_quota_data),
  109. 0, 0, NULL);
  110. if (!gfs2_quotad_cachep)
  111. goto fail;
  112. register_shrinker(&qd_shrinker);
  113. error = register_filesystem(&gfs2_fs_type);
  114. if (error)
  115. goto fail;
  116. error = register_filesystem(&gfs2meta_fs_type);
  117. if (error)
  118. goto fail_unregister;
  119. error = -ENOMEM;
  120. gfs_recovery_wq = alloc_workqueue("gfs_recovery",
  121. WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
  122. if (!gfs_recovery_wq)
  123. goto fail_wq;
  124. gfs2_control_wq = alloc_workqueue("gfs2_control",
  125. WQ_NON_REENTRANT | WQ_UNBOUND | WQ_FREEZABLE, 0);
  126. if (!gfs2_control_wq)
  127. goto fail_control;
  128. gfs2_register_debugfs();
  129. printk("GFS2 installed\n");
  130. return 0;
  131. fail_control:
  132. destroy_workqueue(gfs_recovery_wq);
  133. fail_wq:
  134. unregister_filesystem(&gfs2meta_fs_type);
  135. fail_unregister:
  136. unregister_filesystem(&gfs2_fs_type);
  137. fail:
  138. unregister_shrinker(&qd_shrinker);
  139. gfs2_glock_exit();
  140. if (gfs2_quotad_cachep)
  141. kmem_cache_destroy(gfs2_quotad_cachep);
  142. if (gfs2_rgrpd_cachep)
  143. kmem_cache_destroy(gfs2_rgrpd_cachep);
  144. if (gfs2_bufdata_cachep)
  145. kmem_cache_destroy(gfs2_bufdata_cachep);
  146. if (gfs2_inode_cachep)
  147. kmem_cache_destroy(gfs2_inode_cachep);
  148. if (gfs2_glock_aspace_cachep)
  149. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  150. if (gfs2_glock_cachep)
  151. kmem_cache_destroy(gfs2_glock_cachep);
  152. gfs2_sys_uninit();
  153. return error;
  154. }
  155. /**
  156. * exit_gfs2_fs - Unregister the file system
  157. *
  158. */
  159. static void __exit exit_gfs2_fs(void)
  160. {
  161. unregister_shrinker(&qd_shrinker);
  162. gfs2_glock_exit();
  163. gfs2_unregister_debugfs();
  164. unregister_filesystem(&gfs2_fs_type);
  165. unregister_filesystem(&gfs2meta_fs_type);
  166. destroy_workqueue(gfs_recovery_wq);
  167. destroy_workqueue(gfs2_control_wq);
  168. rcu_barrier();
  169. kmem_cache_destroy(gfs2_quotad_cachep);
  170. kmem_cache_destroy(gfs2_rgrpd_cachep);
  171. kmem_cache_destroy(gfs2_bufdata_cachep);
  172. kmem_cache_destroy(gfs2_inode_cachep);
  173. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  174. kmem_cache_destroy(gfs2_glock_cachep);
  175. gfs2_sys_uninit();
  176. }
  177. MODULE_DESCRIPTION("Global File System");
  178. MODULE_AUTHOR("Red Hat, Inc.");
  179. MODULE_LICENSE("GPL");
  180. module_init(init_gfs2_fs);
  181. module_exit(exit_gfs2_fs);