main.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 <asm/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_alloc = NULL;
  39. }
  40. static void gfs2_init_glock_once(void *foo)
  41. {
  42. struct gfs2_glock *gl = foo;
  43. INIT_HLIST_BL_NODE(&gl->gl_list);
  44. spin_lock_init(&gl->gl_spin);
  45. INIT_LIST_HEAD(&gl->gl_holders);
  46. INIT_LIST_HEAD(&gl->gl_lru);
  47. INIT_LIST_HEAD(&gl->gl_ail_list);
  48. atomic_set(&gl->gl_ail_count, 0);
  49. }
  50. static void gfs2_init_gl_aspace_once(void *foo)
  51. {
  52. struct gfs2_glock *gl = foo;
  53. struct address_space *mapping = (struct address_space *)(gl + 1);
  54. gfs2_init_glock_once(gl);
  55. address_space_init_once(mapping);
  56. }
  57. /**
  58. * init_gfs2_fs - Register GFS2 as a filesystem
  59. *
  60. * Returns: 0 on success, error code on failure
  61. */
  62. static int __init init_gfs2_fs(void)
  63. {
  64. int error;
  65. gfs2_str2qstr(&gfs2_qdot, ".");
  66. gfs2_str2qstr(&gfs2_qdotdot, "..");
  67. error = gfs2_sys_init();
  68. if (error)
  69. return error;
  70. error = gfs2_glock_init();
  71. if (error)
  72. goto fail;
  73. error = -ENOMEM;
  74. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  75. sizeof(struct gfs2_glock),
  76. 0, 0,
  77. gfs2_init_glock_once);
  78. if (!gfs2_glock_cachep)
  79. goto fail;
  80. gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
  81. sizeof(struct gfs2_glock) +
  82. sizeof(struct address_space),
  83. 0, 0, gfs2_init_gl_aspace_once);
  84. if (!gfs2_glock_aspace_cachep)
  85. goto fail;
  86. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  87. sizeof(struct gfs2_inode),
  88. 0, SLAB_RECLAIM_ACCOUNT|
  89. SLAB_MEM_SPREAD,
  90. gfs2_init_inode_once);
  91. if (!gfs2_inode_cachep)
  92. goto fail;
  93. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  94. sizeof(struct gfs2_bufdata),
  95. 0, 0, NULL);
  96. if (!gfs2_bufdata_cachep)
  97. goto fail;
  98. gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  99. sizeof(struct gfs2_rgrpd),
  100. 0, 0, NULL);
  101. if (!gfs2_rgrpd_cachep)
  102. goto fail;
  103. gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  104. sizeof(struct gfs2_quota_data),
  105. 0, 0, NULL);
  106. if (!gfs2_quotad_cachep)
  107. goto fail;
  108. register_shrinker(&qd_shrinker);
  109. error = register_filesystem(&gfs2_fs_type);
  110. if (error)
  111. goto fail;
  112. error = register_filesystem(&gfs2meta_fs_type);
  113. if (error)
  114. goto fail_unregister;
  115. error = -ENOMEM;
  116. gfs_recovery_wq = alloc_workqueue("gfs_recovery",
  117. WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
  118. if (!gfs_recovery_wq)
  119. goto fail_wq;
  120. gfs2_register_debugfs();
  121. printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
  122. return 0;
  123. fail_wq:
  124. unregister_filesystem(&gfs2meta_fs_type);
  125. fail_unregister:
  126. unregister_filesystem(&gfs2_fs_type);
  127. fail:
  128. unregister_shrinker(&qd_shrinker);
  129. gfs2_glock_exit();
  130. if (gfs2_quotad_cachep)
  131. kmem_cache_destroy(gfs2_quotad_cachep);
  132. if (gfs2_rgrpd_cachep)
  133. kmem_cache_destroy(gfs2_rgrpd_cachep);
  134. if (gfs2_bufdata_cachep)
  135. kmem_cache_destroy(gfs2_bufdata_cachep);
  136. if (gfs2_inode_cachep)
  137. kmem_cache_destroy(gfs2_inode_cachep);
  138. if (gfs2_glock_aspace_cachep)
  139. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  140. if (gfs2_glock_cachep)
  141. kmem_cache_destroy(gfs2_glock_cachep);
  142. gfs2_sys_uninit();
  143. return error;
  144. }
  145. /**
  146. * exit_gfs2_fs - Unregister the file system
  147. *
  148. */
  149. static void __exit exit_gfs2_fs(void)
  150. {
  151. unregister_shrinker(&qd_shrinker);
  152. gfs2_glock_exit();
  153. gfs2_unregister_debugfs();
  154. unregister_filesystem(&gfs2_fs_type);
  155. unregister_filesystem(&gfs2meta_fs_type);
  156. destroy_workqueue(gfs_recovery_wq);
  157. rcu_barrier();
  158. kmem_cache_destroy(gfs2_quotad_cachep);
  159. kmem_cache_destroy(gfs2_rgrpd_cachep);
  160. kmem_cache_destroy(gfs2_bufdata_cachep);
  161. kmem_cache_destroy(gfs2_inode_cachep);
  162. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  163. kmem_cache_destroy(gfs2_glock_cachep);
  164. gfs2_sys_uninit();
  165. }
  166. MODULE_DESCRIPTION("Global File System");
  167. MODULE_AUTHOR("Red Hat, Inc.");
  168. MODULE_LICENSE("GPL");
  169. module_init(init_gfs2_fs);
  170. module_exit(exit_gfs2_fs);