main.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. static struct shrinker qd_shrinker = {
  26. .shrink = gfs2_shrink_qd_memory,
  27. .seeks = DEFAULT_SEEKS,
  28. };
  29. static void gfs2_init_inode_once(void *foo)
  30. {
  31. struct gfs2_inode *ip = foo;
  32. inode_init_once(&ip->i_inode);
  33. init_rwsem(&ip->i_rw_mutex);
  34. INIT_LIST_HEAD(&ip->i_trunc_list);
  35. ip->i_alloc = NULL;
  36. }
  37. static void gfs2_init_glock_once(void *foo)
  38. {
  39. struct gfs2_glock *gl = foo;
  40. INIT_HLIST_NODE(&gl->gl_list);
  41. spin_lock_init(&gl->gl_spin);
  42. INIT_LIST_HEAD(&gl->gl_holders);
  43. INIT_LIST_HEAD(&gl->gl_lru);
  44. INIT_LIST_HEAD(&gl->gl_ail_list);
  45. atomic_set(&gl->gl_ail_count, 0);
  46. }
  47. static void gfs2_init_gl_aspace_once(void *foo)
  48. {
  49. struct gfs2_glock *gl = foo;
  50. struct address_space *mapping = (struct address_space *)(gl + 1);
  51. gfs2_init_glock_once(gl);
  52. memset(mapping, 0, sizeof(*mapping));
  53. INIT_RADIX_TREE(&mapping->page_tree, GFP_ATOMIC);
  54. spin_lock_init(&mapping->tree_lock);
  55. spin_lock_init(&mapping->i_mmap_lock);
  56. INIT_LIST_HEAD(&mapping->private_list);
  57. spin_lock_init(&mapping->private_lock);
  58. INIT_RAW_PRIO_TREE_ROOT(&mapping->i_mmap);
  59. INIT_LIST_HEAD(&mapping->i_mmap_nonlinear);
  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. error = gfs2_sys_init();
  70. if (error)
  71. return error;
  72. error = gfs2_glock_init();
  73. if (error)
  74. goto fail;
  75. error = -ENOMEM;
  76. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  77. sizeof(struct gfs2_glock),
  78. 0, 0,
  79. gfs2_init_glock_once);
  80. if (!gfs2_glock_cachep)
  81. goto fail;
  82. gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
  83. sizeof(struct gfs2_glock) +
  84. sizeof(struct address_space),
  85. 0, 0, gfs2_init_gl_aspace_once);
  86. if (!gfs2_glock_aspace_cachep)
  87. goto fail;
  88. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  89. sizeof(struct gfs2_inode),
  90. 0, SLAB_RECLAIM_ACCOUNT|
  91. SLAB_MEM_SPREAD,
  92. gfs2_init_inode_once);
  93. if (!gfs2_inode_cachep)
  94. goto fail;
  95. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  96. sizeof(struct gfs2_bufdata),
  97. 0, 0, NULL);
  98. if (!gfs2_bufdata_cachep)
  99. goto fail;
  100. gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  101. sizeof(struct gfs2_rgrpd),
  102. 0, 0, NULL);
  103. if (!gfs2_rgrpd_cachep)
  104. goto fail;
  105. gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  106. sizeof(struct gfs2_quota_data),
  107. 0, 0, NULL);
  108. if (!gfs2_quotad_cachep)
  109. goto fail;
  110. register_shrinker(&qd_shrinker);
  111. error = register_filesystem(&gfs2_fs_type);
  112. if (error)
  113. goto fail;
  114. error = register_filesystem(&gfs2meta_fs_type);
  115. if (error)
  116. goto fail_unregister;
  117. error = -ENOMEM;
  118. gfs_recovery_wq = alloc_workqueue("gfs_recovery",
  119. WQ_NON_REENTRANT | WQ_RESCUER, 0);
  120. if (!gfs_recovery_wq)
  121. goto fail_wq;
  122. gfs2_register_debugfs();
  123. printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
  124. return 0;
  125. fail_wq:
  126. unregister_filesystem(&gfs2meta_fs_type);
  127. fail_unregister:
  128. unregister_filesystem(&gfs2_fs_type);
  129. fail:
  130. unregister_shrinker(&qd_shrinker);
  131. gfs2_glock_exit();
  132. if (gfs2_quotad_cachep)
  133. kmem_cache_destroy(gfs2_quotad_cachep);
  134. if (gfs2_rgrpd_cachep)
  135. kmem_cache_destroy(gfs2_rgrpd_cachep);
  136. if (gfs2_bufdata_cachep)
  137. kmem_cache_destroy(gfs2_bufdata_cachep);
  138. if (gfs2_inode_cachep)
  139. kmem_cache_destroy(gfs2_inode_cachep);
  140. if (gfs2_glock_aspace_cachep)
  141. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  142. if (gfs2_glock_cachep)
  143. kmem_cache_destroy(gfs2_glock_cachep);
  144. gfs2_sys_uninit();
  145. return error;
  146. }
  147. /**
  148. * exit_gfs2_fs - Unregister the file system
  149. *
  150. */
  151. static void __exit exit_gfs2_fs(void)
  152. {
  153. unregister_shrinker(&qd_shrinker);
  154. gfs2_glock_exit();
  155. gfs2_unregister_debugfs();
  156. unregister_filesystem(&gfs2_fs_type);
  157. unregister_filesystem(&gfs2meta_fs_type);
  158. destroy_workqueue(gfs_recovery_wq);
  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);