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