main.c 3.6 KB

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