2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
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.
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/slab.h>
13 #include <linux/spinlock.h>
14 #include <linux/completion.h>
15 #include <linux/buffer_head.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/gfs2_ondisk.h>
19 #include <linux/rcupdate.h>
20 #include <linux/rculist_bl.h>
21 #include <linux/atomic.h>
22 #include <linux/mempool.h>
35 struct workqueue_struct *gfs2_control_wq;
37 static void gfs2_init_inode_once(void *foo)
39 struct gfs2_inode *ip = foo;
41 inode_init_once(&ip->i_inode);
42 init_rwsem(&ip->i_rw_mutex);
43 INIT_LIST_HEAD(&ip->i_trunc_list);
46 ip->i_hash_cache = NULL;
49 static void gfs2_init_glock_once(void *foo)
51 struct gfs2_glock *gl = foo;
53 INIT_HLIST_BL_NODE(&gl->gl_list);
54 spin_lock_init(&gl->gl_lockref.lock);
55 INIT_LIST_HEAD(&gl->gl_holders);
56 INIT_LIST_HEAD(&gl->gl_lru);
57 INIT_LIST_HEAD(&gl->gl_ail_list);
58 atomic_set(&gl->gl_ail_count, 0);
59 atomic_set(&gl->gl_revokes, 0);
62 static void gfs2_init_gl_aspace_once(void *foo)
64 struct gfs2_glock *gl = foo;
65 struct address_space *mapping = (struct address_space *)(gl + 1);
67 gfs2_init_glock_once(gl);
68 address_space_init_once(mapping);
72 * init_gfs2_fs - Register GFS2 as a filesystem
74 * Returns: 0 on success, error code on failure
77 static int __init init_gfs2_fs(void)
81 gfs2_str2qstr(&gfs2_qdot, ".");
82 gfs2_str2qstr(&gfs2_qdotdot, "..");
83 gfs2_quota_hash_init();
85 error = gfs2_sys_init();
89 error = list_lru_init(&gfs2_qd_lru);
93 error = gfs2_glock_init();
98 gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
99 sizeof(struct gfs2_glock),
101 gfs2_init_glock_once);
102 if (!gfs2_glock_cachep)
105 gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
106 sizeof(struct gfs2_glock) +
107 sizeof(struct address_space),
108 0, 0, gfs2_init_gl_aspace_once);
110 if (!gfs2_glock_aspace_cachep)
113 gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
114 sizeof(struct gfs2_inode),
115 0, SLAB_RECLAIM_ACCOUNT|
117 gfs2_init_inode_once);
118 if (!gfs2_inode_cachep)
121 gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
122 sizeof(struct gfs2_bufdata),
124 if (!gfs2_bufdata_cachep)
127 gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
128 sizeof(struct gfs2_rgrpd),
130 if (!gfs2_rgrpd_cachep)
133 gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
134 sizeof(struct gfs2_quota_data),
136 if (!gfs2_quotad_cachep)
139 gfs2_qadata_cachep = kmem_cache_create("gfs2_qadata",
140 sizeof(struct gfs2_qadata),
142 if (!gfs2_qadata_cachep)
145 gfs2_rsrv_cachep = kmem_cache_create("gfs2_mblk",
146 sizeof(struct gfs2_blkreserv),
148 if (!gfs2_rsrv_cachep)
151 register_shrinker(&gfs2_qd_shrinker);
153 error = register_filesystem(&gfs2_fs_type);
157 error = register_filesystem(&gfs2meta_fs_type);
159 goto fail_unregister;
162 gfs_recovery_wq = alloc_workqueue("gfs_recovery",
163 WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
164 if (!gfs_recovery_wq)
167 gfs2_control_wq = alloc_workqueue("gfs2_control",
168 WQ_UNBOUND | WQ_FREEZABLE, 0);
169 if (!gfs2_control_wq)
172 gfs2_freeze_wq = alloc_workqueue("freeze_workqueue", 0, 0);
177 gfs2_page_pool = mempool_create_page_pool(64, 0);
181 gfs2_register_debugfs();
183 pr_info("GFS2 installed\n");
188 destroy_workqueue(gfs2_freeze_wq);
190 destroy_workqueue(gfs2_control_wq);
192 destroy_workqueue(gfs_recovery_wq);
194 unregister_filesystem(&gfs2meta_fs_type);
196 unregister_filesystem(&gfs2_fs_type);
198 list_lru_destroy(&gfs2_qd_lru);
200 unregister_shrinker(&gfs2_qd_shrinker);
203 if (gfs2_rsrv_cachep)
204 kmem_cache_destroy(gfs2_rsrv_cachep);
206 if (gfs2_qadata_cachep)
207 kmem_cache_destroy(gfs2_qadata_cachep);
209 if (gfs2_quotad_cachep)
210 kmem_cache_destroy(gfs2_quotad_cachep);
212 if (gfs2_rgrpd_cachep)
213 kmem_cache_destroy(gfs2_rgrpd_cachep);
215 if (gfs2_bufdata_cachep)
216 kmem_cache_destroy(gfs2_bufdata_cachep);
218 if (gfs2_inode_cachep)
219 kmem_cache_destroy(gfs2_inode_cachep);
221 if (gfs2_glock_aspace_cachep)
222 kmem_cache_destroy(gfs2_glock_aspace_cachep);
224 if (gfs2_glock_cachep)
225 kmem_cache_destroy(gfs2_glock_cachep);
232 * exit_gfs2_fs - Unregister the file system
236 static void __exit exit_gfs2_fs(void)
238 unregister_shrinker(&gfs2_qd_shrinker);
240 gfs2_unregister_debugfs();
241 unregister_filesystem(&gfs2_fs_type);
242 unregister_filesystem(&gfs2meta_fs_type);
243 destroy_workqueue(gfs_recovery_wq);
244 destroy_workqueue(gfs2_control_wq);
245 destroy_workqueue(gfs2_freeze_wq);
246 list_lru_destroy(&gfs2_qd_lru);
250 mempool_destroy(gfs2_page_pool);
251 kmem_cache_destroy(gfs2_rsrv_cachep);
252 kmem_cache_destroy(gfs2_qadata_cachep);
253 kmem_cache_destroy(gfs2_quotad_cachep);
254 kmem_cache_destroy(gfs2_rgrpd_cachep);
255 kmem_cache_destroy(gfs2_bufdata_cachep);
256 kmem_cache_destroy(gfs2_inode_cachep);
257 kmem_cache_destroy(gfs2_glock_aspace_cachep);
258 kmem_cache_destroy(gfs2_glock_cachep);
263 MODULE_DESCRIPTION("Global File System");
264 MODULE_AUTHOR("Red Hat, Inc.");
265 MODULE_LICENSE("GPL");
267 module_init(init_gfs2_fs);
268 module_exit(exit_gfs2_fs);