main.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 <linux/slow-work.h>
  18. #include "gfs2.h"
  19. #include "incore.h"
  20. #include "super.h"
  21. #include "sys.h"
  22. #include "util.h"
  23. #include "glock.h"
  24. #include "quota.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. /**
  48. * init_gfs2_fs - Register GFS2 as a filesystem
  49. *
  50. * Returns: 0 on success, error code on failure
  51. */
  52. static int __init init_gfs2_fs(void)
  53. {
  54. int error;
  55. error = gfs2_sys_init();
  56. if (error)
  57. return error;
  58. error = gfs2_glock_init();
  59. if (error)
  60. goto fail;
  61. error = -ENOMEM;
  62. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  63. sizeof(struct gfs2_glock),
  64. 0, 0,
  65. gfs2_init_glock_once);
  66. if (!gfs2_glock_cachep)
  67. goto fail;
  68. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  69. sizeof(struct gfs2_inode),
  70. 0, SLAB_RECLAIM_ACCOUNT|
  71. SLAB_MEM_SPREAD,
  72. gfs2_init_inode_once);
  73. if (!gfs2_inode_cachep)
  74. goto fail;
  75. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  76. sizeof(struct gfs2_bufdata),
  77. 0, 0, NULL);
  78. if (!gfs2_bufdata_cachep)
  79. goto fail;
  80. gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  81. sizeof(struct gfs2_rgrpd),
  82. 0, 0, NULL);
  83. if (!gfs2_rgrpd_cachep)
  84. goto fail;
  85. gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  86. sizeof(struct gfs2_quota_data),
  87. 0, 0, NULL);
  88. if (!gfs2_quotad_cachep)
  89. goto fail;
  90. register_shrinker(&qd_shrinker);
  91. error = register_filesystem(&gfs2_fs_type);
  92. if (error)
  93. goto fail;
  94. error = register_filesystem(&gfs2meta_fs_type);
  95. if (error)
  96. goto fail_unregister;
  97. error = slow_work_register_user();
  98. if (error)
  99. goto fail_slow;
  100. gfs2_register_debugfs();
  101. printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
  102. return 0;
  103. fail_slow:
  104. unregister_filesystem(&gfs2meta_fs_type);
  105. fail_unregister:
  106. unregister_filesystem(&gfs2_fs_type);
  107. fail:
  108. unregister_shrinker(&qd_shrinker);
  109. gfs2_glock_exit();
  110. if (gfs2_quotad_cachep)
  111. kmem_cache_destroy(gfs2_quotad_cachep);
  112. if (gfs2_rgrpd_cachep)
  113. kmem_cache_destroy(gfs2_rgrpd_cachep);
  114. if (gfs2_bufdata_cachep)
  115. kmem_cache_destroy(gfs2_bufdata_cachep);
  116. if (gfs2_inode_cachep)
  117. kmem_cache_destroy(gfs2_inode_cachep);
  118. if (gfs2_glock_cachep)
  119. kmem_cache_destroy(gfs2_glock_cachep);
  120. gfs2_sys_uninit();
  121. return error;
  122. }
  123. /**
  124. * exit_gfs2_fs - Unregister the file system
  125. *
  126. */
  127. static void __exit exit_gfs2_fs(void)
  128. {
  129. unregister_shrinker(&qd_shrinker);
  130. gfs2_glock_exit();
  131. gfs2_unregister_debugfs();
  132. unregister_filesystem(&gfs2_fs_type);
  133. unregister_filesystem(&gfs2meta_fs_type);
  134. slow_work_unregister_user();
  135. kmem_cache_destroy(gfs2_quotad_cachep);
  136. kmem_cache_destroy(gfs2_rgrpd_cachep);
  137. kmem_cache_destroy(gfs2_bufdata_cachep);
  138. kmem_cache_destroy(gfs2_inode_cachep);
  139. kmem_cache_destroy(gfs2_glock_cachep);
  140. gfs2_sys_uninit();
  141. }
  142. MODULE_DESCRIPTION("Global File System");
  143. MODULE_AUTHOR("Red Hat, Inc.");
  144. MODULE_LICENSE("GPL");
  145. module_init(init_gfs2_fs);
  146. module_exit(exit_gfs2_fs);