main.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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(void *foo, struct kmem_cache *cachep, unsigned long flags)
  25. {
  26. struct gfs2_inode *ip = foo;
  27. if (flags & SLAB_CTOR_CONSTRUCTOR) {
  28. inode_init_once(&ip->i_inode);
  29. spin_lock_init(&ip->i_spin);
  30. init_rwsem(&ip->i_rw_mutex);
  31. memset(ip->i_cache, 0, sizeof(ip->i_cache));
  32. }
  33. }
  34. static void gfs2_init_glock_once(void *foo, struct kmem_cache *cachep, unsigned long flags)
  35. {
  36. struct gfs2_glock *gl = foo;
  37. if (flags & SLAB_CTOR_CONSTRUCTOR) {
  38. INIT_HLIST_NODE(&gl->gl_list);
  39. spin_lock_init(&gl->gl_spin);
  40. INIT_LIST_HEAD(&gl->gl_holders);
  41. INIT_LIST_HEAD(&gl->gl_waiters1);
  42. INIT_LIST_HEAD(&gl->gl_waiters3);
  43. gl->gl_lvb = NULL;
  44. atomic_set(&gl->gl_lvb_count, 0);
  45. INIT_LIST_HEAD(&gl->gl_reclaim);
  46. INIT_LIST_HEAD(&gl->gl_ail_list);
  47. atomic_set(&gl->gl_ail_count, 0);
  48. }
  49. }
  50. /**
  51. * init_gfs2_fs - Register GFS2 as a filesystem
  52. *
  53. * Returns: 0 on success, error code on failure
  54. */
  55. static int __init init_gfs2_fs(void)
  56. {
  57. int error;
  58. error = gfs2_sys_init();
  59. if (error)
  60. return error;
  61. error = gfs2_glock_init();
  62. if (error)
  63. goto fail;
  64. error = -ENOMEM;
  65. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  66. sizeof(struct gfs2_glock),
  67. 0, 0,
  68. gfs2_init_glock_once, NULL);
  69. if (!gfs2_glock_cachep)
  70. goto fail;
  71. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  72. sizeof(struct gfs2_inode),
  73. 0, SLAB_RECLAIM_ACCOUNT|
  74. SLAB_MEM_SPREAD,
  75. gfs2_init_inode_once, NULL);
  76. if (!gfs2_inode_cachep)
  77. goto fail;
  78. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  79. sizeof(struct gfs2_bufdata),
  80. 0, 0, NULL, NULL);
  81. if (!gfs2_bufdata_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. if (gfs2_bufdata_cachep)
  96. kmem_cache_destroy(gfs2_bufdata_cachep);
  97. if (gfs2_inode_cachep)
  98. kmem_cache_destroy(gfs2_inode_cachep);
  99. if (gfs2_glock_cachep)
  100. kmem_cache_destroy(gfs2_glock_cachep);
  101. gfs2_sys_uninit();
  102. return error;
  103. }
  104. /**
  105. * exit_gfs2_fs - Unregister the file system
  106. *
  107. */
  108. static void __exit exit_gfs2_fs(void)
  109. {
  110. gfs2_unregister_debugfs();
  111. unregister_filesystem(&gfs2_fs_type);
  112. unregister_filesystem(&gfs2meta_fs_type);
  113. kmem_cache_destroy(gfs2_bufdata_cachep);
  114. kmem_cache_destroy(gfs2_inode_cachep);
  115. kmem_cache_destroy(gfs2_glock_cachep);
  116. gfs2_sys_uninit();
  117. }
  118. MODULE_DESCRIPTION("Global File System");
  119. MODULE_AUTHOR("Red Hat, Inc.");
  120. MODULE_LICENSE("GPL");
  121. module_init(init_gfs2_fs);
  122. module_exit(exit_gfs2_fs);