main.c 3.5 KB

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