0001
0002
0003
0004
0005
0006
0007 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0008
0009 #include <linux/slab.h>
0010 #include <linux/spinlock.h>
0011 #include <linux/completion.h>
0012 #include <linux/buffer_head.h>
0013 #include <linux/module.h>
0014 #include <linux/init.h>
0015 #include <linux/gfs2_ondisk.h>
0016 #include <linux/rcupdate.h>
0017 #include <linux/rculist_bl.h>
0018 #include <linux/atomic.h>
0019 #include <linux/mempool.h>
0020
0021 #include "gfs2.h"
0022 #include "incore.h"
0023 #include "super.h"
0024 #include "sys.h"
0025 #include "util.h"
0026 #include "glock.h"
0027 #include "quota.h"
0028 #include "recovery.h"
0029 #include "dir.h"
0030 #include "glops.h"
0031
0032 struct workqueue_struct *gfs2_control_wq;
0033
0034 static void gfs2_init_inode_once(void *foo)
0035 {
0036 struct gfs2_inode *ip = foo;
0037
0038 inode_init_once(&ip->i_inode);
0039 atomic_set(&ip->i_sizehint, 0);
0040 init_rwsem(&ip->i_rw_mutex);
0041 INIT_LIST_HEAD(&ip->i_ordered);
0042 ip->i_qadata = NULL;
0043 gfs2_holder_mark_uninitialized(&ip->i_rgd_gh);
0044 memset(&ip->i_res, 0, sizeof(ip->i_res));
0045 RB_CLEAR_NODE(&ip->i_res.rs_node);
0046 ip->i_hash_cache = NULL;
0047 gfs2_holder_mark_uninitialized(&ip->i_iopen_gh);
0048 }
0049
0050 static void gfs2_init_glock_once(void *foo)
0051 {
0052 struct gfs2_glock *gl = foo;
0053
0054 spin_lock_init(&gl->gl_lockref.lock);
0055 INIT_LIST_HEAD(&gl->gl_holders);
0056 INIT_LIST_HEAD(&gl->gl_lru);
0057 INIT_LIST_HEAD(&gl->gl_ail_list);
0058 atomic_set(&gl->gl_ail_count, 0);
0059 atomic_set(&gl->gl_revokes, 0);
0060 }
0061
0062 static void gfs2_init_gl_aspace_once(void *foo)
0063 {
0064 struct gfs2_glock_aspace *gla = foo;
0065
0066 gfs2_init_glock_once(&gla->glock);
0067 address_space_init_once(&gla->mapping);
0068 }
0069
0070
0071
0072
0073
0074
0075
0076 static int __init init_gfs2_fs(void)
0077 {
0078 int error;
0079
0080 gfs2_str2qstr(&gfs2_qdot, ".");
0081 gfs2_str2qstr(&gfs2_qdotdot, "..");
0082 gfs2_quota_hash_init();
0083
0084 error = gfs2_sys_init();
0085 if (error)
0086 return error;
0087
0088 error = list_lru_init(&gfs2_qd_lru);
0089 if (error)
0090 goto fail_lru;
0091
0092 error = gfs2_glock_init();
0093 if (error)
0094 goto fail_glock;
0095
0096 error = -ENOMEM;
0097 gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
0098 sizeof(struct gfs2_glock),
0099 0, SLAB_RECLAIM_ACCOUNT,
0100 gfs2_init_glock_once);
0101 if (!gfs2_glock_cachep)
0102 goto fail_cachep1;
0103
0104 gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
0105 sizeof(struct gfs2_glock_aspace),
0106 0, 0, gfs2_init_gl_aspace_once);
0107
0108 if (!gfs2_glock_aspace_cachep)
0109 goto fail_cachep2;
0110
0111 gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
0112 sizeof(struct gfs2_inode),
0113 0, SLAB_RECLAIM_ACCOUNT|
0114 SLAB_MEM_SPREAD|
0115 SLAB_ACCOUNT,
0116 gfs2_init_inode_once);
0117 if (!gfs2_inode_cachep)
0118 goto fail_cachep3;
0119
0120 gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
0121 sizeof(struct gfs2_bufdata),
0122 0, 0, NULL);
0123 if (!gfs2_bufdata_cachep)
0124 goto fail_cachep4;
0125
0126 gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
0127 sizeof(struct gfs2_rgrpd),
0128 0, 0, NULL);
0129 if (!gfs2_rgrpd_cachep)
0130 goto fail_cachep5;
0131
0132 gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
0133 sizeof(struct gfs2_quota_data),
0134 0, SLAB_RECLAIM_ACCOUNT, NULL);
0135 if (!gfs2_quotad_cachep)
0136 goto fail_cachep6;
0137
0138 gfs2_qadata_cachep = kmem_cache_create("gfs2_qadata",
0139 sizeof(struct gfs2_qadata),
0140 0, 0, NULL);
0141 if (!gfs2_qadata_cachep)
0142 goto fail_cachep7;
0143
0144 gfs2_trans_cachep = kmem_cache_create("gfs2_trans",
0145 sizeof(struct gfs2_trans),
0146 0, 0, NULL);
0147 if (!gfs2_trans_cachep)
0148 goto fail_cachep8;
0149
0150 error = register_shrinker(&gfs2_qd_shrinker, "gfs2-qd");
0151 if (error)
0152 goto fail_shrinker;
0153
0154 error = register_filesystem(&gfs2_fs_type);
0155 if (error)
0156 goto fail_fs1;
0157
0158 error = register_filesystem(&gfs2meta_fs_type);
0159 if (error)
0160 goto fail_fs2;
0161
0162 error = -ENOMEM;
0163 gfs_recovery_wq = alloc_workqueue("gfs_recovery",
0164 WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
0165 if (!gfs_recovery_wq)
0166 goto fail_wq1;
0167
0168 gfs2_control_wq = alloc_workqueue("gfs2_control",
0169 WQ_UNBOUND | WQ_FREEZABLE, 0);
0170 if (!gfs2_control_wq)
0171 goto fail_wq2;
0172
0173 gfs2_freeze_wq = alloc_workqueue("freeze_workqueue", 0, 0);
0174
0175 if (!gfs2_freeze_wq)
0176 goto fail_wq3;
0177
0178 gfs2_page_pool = mempool_create_page_pool(64, 0);
0179 if (!gfs2_page_pool)
0180 goto fail_mempool;
0181
0182 gfs2_register_debugfs();
0183
0184 pr_info("GFS2 installed\n");
0185
0186 return 0;
0187
0188 fail_mempool:
0189 destroy_workqueue(gfs2_freeze_wq);
0190 fail_wq3:
0191 destroy_workqueue(gfs2_control_wq);
0192 fail_wq2:
0193 destroy_workqueue(gfs_recovery_wq);
0194 fail_wq1:
0195 unregister_filesystem(&gfs2meta_fs_type);
0196 fail_fs2:
0197 unregister_filesystem(&gfs2_fs_type);
0198 fail_fs1:
0199 unregister_shrinker(&gfs2_qd_shrinker);
0200 fail_shrinker:
0201 kmem_cache_destroy(gfs2_trans_cachep);
0202 fail_cachep8:
0203 kmem_cache_destroy(gfs2_qadata_cachep);
0204 fail_cachep7:
0205 kmem_cache_destroy(gfs2_quotad_cachep);
0206 fail_cachep6:
0207 kmem_cache_destroy(gfs2_rgrpd_cachep);
0208 fail_cachep5:
0209 kmem_cache_destroy(gfs2_bufdata_cachep);
0210 fail_cachep4:
0211 kmem_cache_destroy(gfs2_inode_cachep);
0212 fail_cachep3:
0213 kmem_cache_destroy(gfs2_glock_aspace_cachep);
0214 fail_cachep2:
0215 kmem_cache_destroy(gfs2_glock_cachep);
0216 fail_cachep1:
0217 gfs2_glock_exit();
0218 fail_glock:
0219 list_lru_destroy(&gfs2_qd_lru);
0220 fail_lru:
0221 gfs2_sys_uninit();
0222 return error;
0223 }
0224
0225
0226
0227
0228
0229
0230 static void __exit exit_gfs2_fs(void)
0231 {
0232 unregister_shrinker(&gfs2_qd_shrinker);
0233 gfs2_glock_exit();
0234 gfs2_unregister_debugfs();
0235 unregister_filesystem(&gfs2_fs_type);
0236 unregister_filesystem(&gfs2meta_fs_type);
0237 destroy_workqueue(gfs_recovery_wq);
0238 destroy_workqueue(gfs2_control_wq);
0239 destroy_workqueue(gfs2_freeze_wq);
0240 list_lru_destroy(&gfs2_qd_lru);
0241
0242 rcu_barrier();
0243
0244 mempool_destroy(gfs2_page_pool);
0245 kmem_cache_destroy(gfs2_trans_cachep);
0246 kmem_cache_destroy(gfs2_qadata_cachep);
0247 kmem_cache_destroy(gfs2_quotad_cachep);
0248 kmem_cache_destroy(gfs2_rgrpd_cachep);
0249 kmem_cache_destroy(gfs2_bufdata_cachep);
0250 kmem_cache_destroy(gfs2_inode_cachep);
0251 kmem_cache_destroy(gfs2_glock_aspace_cachep);
0252 kmem_cache_destroy(gfs2_glock_cachep);
0253
0254 gfs2_sys_uninit();
0255 }
0256
0257 MODULE_DESCRIPTION("Global File System");
0258 MODULE_AUTHOR("Red Hat, Inc.");
0259 MODULE_LICENSE("GPL");
0260
0261 module_init(init_gfs2_fs);
0262 module_exit(exit_gfs2_fs);
0263