main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/gfs2_ondisk.h>
  17. #include <linux/lm_interface.h>
  18. #include <asm/atomic.h>
  19. #include "gfs2.h"
  20. #include "incore.h"
  21. #include "ops_fstype.h"
  22. #include "sys.h"
  23. #include "util.h"
  24. #include "glock.h"
  25. static void gfs2_init_inode_once(void *foo, kmem_cache_t *cachep, unsigned long flags)
  26. {
  27. struct gfs2_inode *ip = foo;
  28. if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
  29. SLAB_CTOR_CONSTRUCTOR) {
  30. inode_init_once(&ip->i_inode);
  31. spin_lock_init(&ip->i_spin);
  32. init_rwsem(&ip->i_rw_mutex);
  33. memset(ip->i_cache, 0, sizeof(ip->i_cache));
  34. }
  35. }
  36. static void gfs2_init_glock_once(void *foo, kmem_cache_t *cachep, unsigned long flags)
  37. {
  38. struct gfs2_glock *gl = foo;
  39. if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
  40. SLAB_CTOR_CONSTRUCTOR) {
  41. INIT_HLIST_NODE(&gl->gl_list);
  42. spin_lock_init(&gl->gl_spin);
  43. INIT_LIST_HEAD(&gl->gl_holders);
  44. INIT_LIST_HEAD(&gl->gl_waiters1);
  45. INIT_LIST_HEAD(&gl->gl_waiters2);
  46. INIT_LIST_HEAD(&gl->gl_waiters3);
  47. gl->gl_lvb = NULL;
  48. atomic_set(&gl->gl_lvb_count, 0);
  49. INIT_LIST_HEAD(&gl->gl_reclaim);
  50. INIT_LIST_HEAD(&gl->gl_ail_list);
  51. atomic_set(&gl->gl_ail_count, 0);
  52. }
  53. }
  54. /**
  55. * init_gfs2_fs - Register GFS2 as a filesystem
  56. *
  57. * Returns: 0 on success, error code on failure
  58. */
  59. static int __init init_gfs2_fs(void)
  60. {
  61. int error;
  62. error = gfs2_sys_init();
  63. if (error)
  64. return error;
  65. error = gfs2_glock_init();
  66. if (error)
  67. goto fail;
  68. error = -ENOMEM;
  69. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  70. sizeof(struct gfs2_glock),
  71. 0, 0,
  72. gfs2_init_glock_once, NULL);
  73. if (!gfs2_glock_cachep)
  74. goto fail;
  75. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  76. sizeof(struct gfs2_inode),
  77. 0, (SLAB_RECLAIM_ACCOUNT|
  78. SLAB_PANIC|SLAB_MEM_SPREAD),
  79. gfs2_init_inode_once, NULL);
  80. if (!gfs2_inode_cachep)
  81. goto fail;
  82. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  83. sizeof(struct gfs2_bufdata),
  84. 0, 0, NULL, NULL);
  85. if (!gfs2_bufdata_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. printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
  94. return 0;
  95. fail_unregister:
  96. unregister_filesystem(&gfs2_fs_type);
  97. fail:
  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. unregister_filesystem(&gfs2_fs_type);
  114. unregister_filesystem(&gfs2meta_fs_type);
  115. kmem_cache_destroy(gfs2_bufdata_cachep);
  116. kmem_cache_destroy(gfs2_inode_cachep);
  117. kmem_cache_destroy(gfs2_glock_cachep);
  118. gfs2_sys_uninit();
  119. }
  120. MODULE_DESCRIPTION("Global File System");
  121. MODULE_AUTHOR("Red Hat, Inc.");
  122. MODULE_LICENSE("GPL");
  123. module_init(init_gfs2_fs);
  124. module_exit(exit_gfs2_fs);