main.c 4.7 KB

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