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 #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/rcupdate.h>
18 #include <linux/rculist_bl.h>
19 #include <asm/atomic.h>
31 static struct shrinker qd_shrinker = {
32 .shrink = gfs2_shrink_qd_memory,
33 .seeks = DEFAULT_SEEKS,
36 static void gfs2_init_inode_once(void *foo)
38 struct gfs2_inode *ip = foo;
40 inode_init_once(&ip->i_inode);
41 init_rwsem(&ip->i_rw_mutex);
42 INIT_LIST_HEAD(&ip->i_trunc_list);
46 static void gfs2_init_glock_once(void *foo)
48 struct gfs2_glock *gl = foo;
50 INIT_HLIST_BL_NODE(&gl->gl_list);
51 spin_lock_init(&gl->gl_spin);
52 INIT_LIST_HEAD(&gl->gl_holders);
53 INIT_LIST_HEAD(&gl->gl_lru);
54 INIT_LIST_HEAD(&gl->gl_ail_list);
55 atomic_set(&gl->gl_ail_count, 0);
58 static void gfs2_init_gl_aspace_once(void *foo)
60 struct gfs2_glock *gl = foo;
61 struct address_space *mapping = (struct address_space *)(gl + 1);
63 gfs2_init_glock_once(gl);
64 memset(mapping, 0, sizeof(*mapping));
65 INIT_RADIX_TREE(&mapping->page_tree, GFP_ATOMIC);
66 spin_lock_init(&mapping->tree_lock);
67 spin_lock_init(&mapping->i_mmap_lock);
68 INIT_LIST_HEAD(&mapping->private_list);
69 spin_lock_init(&mapping->private_lock);
70 INIT_RAW_PRIO_TREE_ROOT(&mapping->i_mmap);
71 INIT_LIST_HEAD(&mapping->i_mmap_nonlinear);
75 * init_gfs2_fs - Register GFS2 as a filesystem
77 * Returns: 0 on success, error code on failure
80 static int __init init_gfs2_fs(void)
84 gfs2_str2qstr(&gfs2_qdot, ".");
85 gfs2_str2qstr(&gfs2_qdotdot, "..");
87 error = gfs2_sys_init();
91 error = gfs2_glock_init();
96 gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
97 sizeof(struct gfs2_glock),
99 gfs2_init_glock_once);
100 if (!gfs2_glock_cachep)
103 gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
104 sizeof(struct gfs2_glock) +
105 sizeof(struct address_space),
106 0, 0, gfs2_init_gl_aspace_once);
108 if (!gfs2_glock_aspace_cachep)
111 gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
112 sizeof(struct gfs2_inode),
113 0, SLAB_RECLAIM_ACCOUNT|
115 gfs2_init_inode_once);
116 if (!gfs2_inode_cachep)
119 gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
120 sizeof(struct gfs2_bufdata),
122 if (!gfs2_bufdata_cachep)
125 gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
126 sizeof(struct gfs2_rgrpd),
128 if (!gfs2_rgrpd_cachep)
131 gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
132 sizeof(struct gfs2_quota_data),
134 if (!gfs2_quotad_cachep)
137 register_shrinker(&qd_shrinker);
139 error = register_filesystem(&gfs2_fs_type);
143 error = register_filesystem(&gfs2meta_fs_type);
145 goto fail_unregister;
148 gfs_recovery_wq = alloc_workqueue("gfs_recovery",
149 WQ_MEM_RECLAIM | WQ_FREEZEABLE, 0);
150 if (!gfs_recovery_wq)
153 gfs2_register_debugfs();
155 printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
160 unregister_filesystem(&gfs2meta_fs_type);
162 unregister_filesystem(&gfs2_fs_type);
164 unregister_shrinker(&qd_shrinker);
167 if (gfs2_quotad_cachep)
168 kmem_cache_destroy(gfs2_quotad_cachep);
170 if (gfs2_rgrpd_cachep)
171 kmem_cache_destroy(gfs2_rgrpd_cachep);
173 if (gfs2_bufdata_cachep)
174 kmem_cache_destroy(gfs2_bufdata_cachep);
176 if (gfs2_inode_cachep)
177 kmem_cache_destroy(gfs2_inode_cachep);
179 if (gfs2_glock_aspace_cachep)
180 kmem_cache_destroy(gfs2_glock_aspace_cachep);
182 if (gfs2_glock_cachep)
183 kmem_cache_destroy(gfs2_glock_cachep);
190 * exit_gfs2_fs - Unregister the file system
194 static void __exit exit_gfs2_fs(void)
196 unregister_shrinker(&qd_shrinker);
198 gfs2_unregister_debugfs();
199 unregister_filesystem(&gfs2_fs_type);
200 unregister_filesystem(&gfs2meta_fs_type);
201 destroy_workqueue(gfs_recovery_wq);
205 kmem_cache_destroy(gfs2_quotad_cachep);
206 kmem_cache_destroy(gfs2_rgrpd_cachep);
207 kmem_cache_destroy(gfs2_bufdata_cachep);
208 kmem_cache_destroy(gfs2_inode_cachep);
209 kmem_cache_destroy(gfs2_glock_aspace_cachep);
210 kmem_cache_destroy(gfs2_glock_cachep);
215 MODULE_DESCRIPTION("Global File System");
216 MODULE_AUTHOR("Red Hat, Inc.");
217 MODULE_LICENSE("GPL");
219 module_init(init_gfs2_fs);
220 module_exit(exit_gfs2_fs);