main.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. static struct shrinker qd_shrinker = {
  25. .shrink = gfs2_shrink_qd_memory,
  26. .seeks = DEFAULT_SEEKS,
  27. };
  28. static void gfs2_init_inode_once(void *foo)
  29. {
  30. struct gfs2_inode *ip = foo;
  31. inode_init_once(&ip->i_inode);
  32. init_rwsem(&ip->i_rw_mutex);
  33. INIT_LIST_HEAD(&ip->i_trunc_list);
  34. ip->i_alloc = NULL;
  35. }
  36. static void gfs2_init_glock_once(void *foo)
  37. {
  38. struct gfs2_glock *gl = foo;
  39. INIT_HLIST_NODE(&gl->gl_list);
  40. spin_lock_init(&gl->gl_spin);
  41. INIT_LIST_HEAD(&gl->gl_holders);
  42. INIT_LIST_HEAD(&gl->gl_lru);
  43. INIT_LIST_HEAD(&gl->gl_ail_list);
  44. atomic_set(&gl->gl_ail_count, 0);
  45. }
  46. /**
  47. * init_gfs2_fs - Register GFS2 as a filesystem
  48. *
  49. * Returns: 0 on success, error code on failure
  50. */
  51. static int __init init_gfs2_fs(void)
  52. {
  53. int error;
  54. error = gfs2_sys_init();
  55. if (error)
  56. return error;
  57. error = gfs2_glock_init();
  58. if (error)
  59. goto fail;
  60. error = -ENOMEM;
  61. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  62. sizeof(struct gfs2_glock),
  63. 0, 0,
  64. gfs2_init_glock_once);
  65. if (!gfs2_glock_cachep)
  66. goto fail;
  67. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  68. sizeof(struct gfs2_inode),
  69. 0, SLAB_RECLAIM_ACCOUNT|
  70. SLAB_MEM_SPREAD,
  71. gfs2_init_inode_once);
  72. if (!gfs2_inode_cachep)
  73. goto fail;
  74. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  75. sizeof(struct gfs2_bufdata),
  76. 0, 0, NULL);
  77. if (!gfs2_bufdata_cachep)
  78. goto fail;
  79. gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  80. sizeof(struct gfs2_rgrpd),
  81. 0, 0, NULL);
  82. if (!gfs2_rgrpd_cachep)
  83. goto fail;
  84. gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  85. sizeof(struct gfs2_quota_data),
  86. 0, 0, NULL);
  87. if (!gfs2_quotad_cachep)
  88. goto fail;
  89. register_shrinker(&qd_shrinker);
  90. error = register_filesystem(&gfs2_fs_type);
  91. if (error)
  92. goto fail;
  93. error = register_filesystem(&gfs2meta_fs_type);
  94. if (error)
  95. goto fail_unregister;
  96. gfs2_register_debugfs();
  97. printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
  98. return 0;
  99. fail_unregister:
  100. unregister_filesystem(&gfs2_fs_type);
  101. fail:
  102. unregister_shrinker(&qd_shrinker);
  103. gfs2_glock_exit();
  104. if (gfs2_quotad_cachep)
  105. kmem_cache_destroy(gfs2_quotad_cachep);
  106. if (gfs2_rgrpd_cachep)
  107. kmem_cache_destroy(gfs2_rgrpd_cachep);
  108. if (gfs2_bufdata_cachep)
  109. kmem_cache_destroy(gfs2_bufdata_cachep);
  110. if (gfs2_inode_cachep)
  111. kmem_cache_destroy(gfs2_inode_cachep);
  112. if (gfs2_glock_cachep)
  113. kmem_cache_destroy(gfs2_glock_cachep);
  114. gfs2_sys_uninit();
  115. return error;
  116. }
  117. /**
  118. * exit_gfs2_fs - Unregister the file system
  119. *
  120. */
  121. static void __exit exit_gfs2_fs(void)
  122. {
  123. unregister_shrinker(&qd_shrinker);
  124. gfs2_glock_exit();
  125. gfs2_unregister_debugfs();
  126. unregister_filesystem(&gfs2_fs_type);
  127. unregister_filesystem(&gfs2meta_fs_type);
  128. kmem_cache_destroy(gfs2_quotad_cachep);
  129. kmem_cache_destroy(gfs2_rgrpd_cachep);
  130. kmem_cache_destroy(gfs2_bufdata_cachep);
  131. kmem_cache_destroy(gfs2_inode_cachep);
  132. kmem_cache_destroy(gfs2_glock_cachep);
  133. gfs2_sys_uninit();
  134. }
  135. MODULE_DESCRIPTION("Global File System");
  136. MODULE_AUTHOR("Red Hat, Inc.");
  137. MODULE_LICENSE("GPL");
  138. module_init(init_gfs2_fs);
  139. module_exit(exit_gfs2_fs);