main.c 4.8 KB

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