main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 v.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 "gfs2.h"
  18. #include "lm_interface.h"
  19. #include "incore.h"
  20. #include "ops_fstype.h"
  21. #include "sys.h"
  22. #include "util.h"
  23. static void gfs2_init_inode_once(void *foo, kmem_cache_t *cachep, unsigned long flags)
  24. {
  25. struct gfs2_inode *ip = foo;
  26. if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
  27. 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. /**
  35. * init_gfs2_fs - Register GFS2 as a filesystem
  36. *
  37. * Returns: 0 on success, error code on failure
  38. */
  39. static int __init init_gfs2_fs(void)
  40. {
  41. int error;
  42. gfs2_init_lmh();
  43. error = gfs2_sys_init();
  44. if (error)
  45. return error;
  46. error = -ENOMEM;
  47. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  48. sizeof(struct gfs2_glock),
  49. 0, 0, NULL, NULL);
  50. if (!gfs2_glock_cachep)
  51. goto fail;
  52. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  53. sizeof(struct gfs2_inode),
  54. 0, (SLAB_RECLAIM_ACCOUNT|
  55. SLAB_PANIC|SLAB_MEM_SPREAD),
  56. gfs2_init_inode_once, NULL);
  57. if (!gfs2_inode_cachep)
  58. goto fail;
  59. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  60. sizeof(struct gfs2_bufdata),
  61. 0, 0, NULL, NULL);
  62. if (!gfs2_bufdata_cachep)
  63. goto fail;
  64. error = register_filesystem(&gfs2_fs_type);
  65. if (error)
  66. goto fail;
  67. error = register_filesystem(&gfs2meta_fs_type);
  68. if (error)
  69. goto fail_unregister;
  70. printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
  71. return 0;
  72. fail_unregister:
  73. unregister_filesystem(&gfs2_fs_type);
  74. fail:
  75. if (gfs2_bufdata_cachep)
  76. kmem_cache_destroy(gfs2_bufdata_cachep);
  77. if (gfs2_inode_cachep)
  78. kmem_cache_destroy(gfs2_inode_cachep);
  79. if (gfs2_glock_cachep)
  80. kmem_cache_destroy(gfs2_glock_cachep);
  81. gfs2_sys_uninit();
  82. return error;
  83. }
  84. /**
  85. * exit_gfs2_fs - Unregister the file system
  86. *
  87. */
  88. static void __exit exit_gfs2_fs(void)
  89. {
  90. unregister_filesystem(&gfs2_fs_type);
  91. unregister_filesystem(&gfs2meta_fs_type);
  92. kmem_cache_destroy(gfs2_bufdata_cachep);
  93. kmem_cache_destroy(gfs2_inode_cachep);
  94. kmem_cache_destroy(gfs2_glock_cachep);
  95. gfs2_sys_uninit();
  96. }
  97. MODULE_DESCRIPTION("Global File System");
  98. MODULE_AUTHOR("Red Hat, Inc.");
  99. MODULE_LICENSE("GPL");
  100. module_init(init_gfs2_fs);
  101. module_exit(exit_gfs2_fs);