]> Pileus Git - ~andy/linux/blob - fs/gfs2/main.c
GFS2: Use RCU for glock hash table
[~andy/linux] / fs / gfs2 / main.c
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
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>
20
21 #include "gfs2.h"
22 #include "incore.h"
23 #include "super.h"
24 #include "sys.h"
25 #include "util.h"
26 #include "glock.h"
27 #include "quota.h"
28 #include "recovery.h"
29 #include "dir.h"
30
31 static struct shrinker qd_shrinker = {
32         .shrink = gfs2_shrink_qd_memory,
33         .seeks = DEFAULT_SEEKS,
34 };
35
36 static void gfs2_init_inode_once(void *foo)
37 {
38         struct gfs2_inode *ip = foo;
39
40         inode_init_once(&ip->i_inode);
41         init_rwsem(&ip->i_rw_mutex);
42         INIT_LIST_HEAD(&ip->i_trunc_list);
43         ip->i_alloc = NULL;
44 }
45
46 static void gfs2_init_glock_once(void *foo)
47 {
48         struct gfs2_glock *gl = foo;
49
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);
56 }
57
58 static void gfs2_init_gl_aspace_once(void *foo)
59 {
60         struct gfs2_glock *gl = foo;
61         struct address_space *mapping = (struct address_space *)(gl + 1);
62
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);
72 }
73
74 /**
75  * init_gfs2_fs - Register GFS2 as a filesystem
76  *
77  * Returns: 0 on success, error code on failure
78  */
79
80 static int __init init_gfs2_fs(void)
81 {
82         int error;
83
84         gfs2_str2qstr(&gfs2_qdot, ".");
85         gfs2_str2qstr(&gfs2_qdotdot, "..");
86
87         error = gfs2_sys_init();
88         if (error)
89                 return error;
90
91         error = gfs2_glock_init();
92         if (error)
93                 goto fail;
94
95         error = -ENOMEM;
96         gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
97                                               sizeof(struct gfs2_glock),
98                                               0, 0,
99                                               gfs2_init_glock_once);
100         if (!gfs2_glock_cachep)
101                 goto fail;
102
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);
107
108         if (!gfs2_glock_aspace_cachep)
109                 goto fail;
110
111         gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
112                                               sizeof(struct gfs2_inode),
113                                               0,  SLAB_RECLAIM_ACCOUNT|
114                                                   SLAB_MEM_SPREAD,
115                                               gfs2_init_inode_once);
116         if (!gfs2_inode_cachep)
117                 goto fail;
118
119         gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
120                                                 sizeof(struct gfs2_bufdata),
121                                                 0, 0, NULL);
122         if (!gfs2_bufdata_cachep)
123                 goto fail;
124
125         gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
126                                               sizeof(struct gfs2_rgrpd),
127                                               0, 0, NULL);
128         if (!gfs2_rgrpd_cachep)
129                 goto fail;
130
131         gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
132                                                sizeof(struct gfs2_quota_data),
133                                                0, 0, NULL);
134         if (!gfs2_quotad_cachep)
135                 goto fail;
136
137         register_shrinker(&qd_shrinker);
138
139         error = register_filesystem(&gfs2_fs_type);
140         if (error)
141                 goto fail;
142
143         error = register_filesystem(&gfs2meta_fs_type);
144         if (error)
145                 goto fail_unregister;
146
147         error = -ENOMEM;
148         gfs_recovery_wq = alloc_workqueue("gfs_recovery",
149                                           WQ_MEM_RECLAIM | WQ_FREEZEABLE, 0);
150         if (!gfs_recovery_wq)
151                 goto fail_wq;
152
153         gfs2_register_debugfs();
154
155         printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
156
157         return 0;
158
159 fail_wq:
160         unregister_filesystem(&gfs2meta_fs_type);
161 fail_unregister:
162         unregister_filesystem(&gfs2_fs_type);
163 fail:
164         unregister_shrinker(&qd_shrinker);
165         gfs2_glock_exit();
166
167         if (gfs2_quotad_cachep)
168                 kmem_cache_destroy(gfs2_quotad_cachep);
169
170         if (gfs2_rgrpd_cachep)
171                 kmem_cache_destroy(gfs2_rgrpd_cachep);
172
173         if (gfs2_bufdata_cachep)
174                 kmem_cache_destroy(gfs2_bufdata_cachep);
175
176         if (gfs2_inode_cachep)
177                 kmem_cache_destroy(gfs2_inode_cachep);
178
179         if (gfs2_glock_aspace_cachep)
180                 kmem_cache_destroy(gfs2_glock_aspace_cachep);
181
182         if (gfs2_glock_cachep)
183                 kmem_cache_destroy(gfs2_glock_cachep);
184
185         gfs2_sys_uninit();
186         return error;
187 }
188
189 /**
190  * exit_gfs2_fs - Unregister the file system
191  *
192  */
193
194 static void __exit exit_gfs2_fs(void)
195 {
196         unregister_shrinker(&qd_shrinker);
197         gfs2_glock_exit();
198         gfs2_unregister_debugfs();
199         unregister_filesystem(&gfs2_fs_type);
200         unregister_filesystem(&gfs2meta_fs_type);
201         destroy_workqueue(gfs_recovery_wq);
202
203         rcu_barrier();
204
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);
211
212         gfs2_sys_uninit();
213 }
214
215 MODULE_DESCRIPTION("Global File System");
216 MODULE_AUTHOR("Red Hat, Inc.");
217 MODULE_LICENSE("GPL");
218
219 module_init(init_gfs2_fs);
220 module_exit(exit_gfs2_fs);
221