Commit | Line | Data |
---|---|---|
b3b94faa DT |
1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | |
3a8a9a10 | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
b3b94faa DT |
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 | |
e9fc2aa0 | 7 | * of the GNU General Public License version 2. |
b3b94faa DT |
8 | */ |
9 | ||
b3b94faa DT |
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> | |
5c676f6d | 16 | #include <linux/gfs2_ondisk.h> |
7d308590 | 17 | #include <linux/lm_interface.h> |
ec45d9f5 | 18 | #include <asm/atomic.h> |
b3b94faa DT |
19 | |
20 | #include "gfs2.h" | |
5c676f6d | 21 | #include "incore.h" |
b2760583 | 22 | #include "super.h" |
b3b94faa | 23 | #include "sys.h" |
5c676f6d | 24 | #include "util.h" |
85d1da67 | 25 | #include "glock.h" |
b3b94faa | 26 | |
51cc5068 | 27 | static void gfs2_init_inode_once(void *foo) |
320dd101 SW |
28 | { |
29 | struct gfs2_inode *ip = foo; | |
a35afb83 CL |
30 | |
31 | inode_init_once(&ip->i_inode); | |
a35afb83 | 32 | init_rwsem(&ip->i_rw_mutex); |
813e0c46 | 33 | INIT_LIST_HEAD(&ip->i_trunc_list); |
6dbd8224 | 34 | ip->i_alloc = NULL; |
320dd101 SW |
35 | } |
36 | ||
51cc5068 | 37 | static void gfs2_init_glock_once(void *foo) |
ec45d9f5 SW |
38 | { |
39 | struct gfs2_glock *gl = foo; | |
a35afb83 CL |
40 | |
41 | INIT_HLIST_NODE(&gl->gl_list); | |
42 | spin_lock_init(&gl->gl_spin); | |
43 | INIT_LIST_HEAD(&gl->gl_holders); | |
a35afb83 CL |
44 | gl->gl_lvb = NULL; |
45 | atomic_set(&gl->gl_lvb_count, 0); | |
97cc1025 | 46 | INIT_LIST_HEAD(&gl->gl_lru); |
a35afb83 CL |
47 | INIT_LIST_HEAD(&gl->gl_ail_list); |
48 | atomic_set(&gl->gl_ail_count, 0); | |
ec45d9f5 SW |
49 | } |
50 | ||
b3b94faa DT |
51 | /** |
52 | * init_gfs2_fs - Register GFS2 as a filesystem | |
53 | * | |
54 | * Returns: 0 on success, error code on failure | |
55 | */ | |
56 | ||
57 | static int __init init_gfs2_fs(void) | |
58 | { | |
59 | int error; | |
60 | ||
b3b94faa DT |
61 | error = gfs2_sys_init(); |
62 | if (error) | |
63 | return error; | |
64 | ||
85d1da67 SW |
65 | error = gfs2_glock_init(); |
66 | if (error) | |
67 | goto fail; | |
b3b94faa | 68 | |
85d1da67 | 69 | error = -ENOMEM; |
b3b94faa DT |
70 | gfs2_glock_cachep = kmem_cache_create("gfs2_glock", |
71 | sizeof(struct gfs2_glock), | |
907b9bce | 72 | 0, 0, |
20c2df83 | 73 | gfs2_init_glock_once); |
b3b94faa DT |
74 | if (!gfs2_glock_cachep) |
75 | goto fail; | |
76 | ||
77 | gfs2_inode_cachep = kmem_cache_create("gfs2_inode", | |
78 | sizeof(struct gfs2_inode), | |
eb1dc33a AD |
79 | 0, SLAB_RECLAIM_ACCOUNT| |
80 | SLAB_MEM_SPREAD, | |
20c2df83 | 81 | gfs2_init_inode_once); |
b3b94faa DT |
82 | if (!gfs2_inode_cachep) |
83 | goto fail; | |
84 | ||
85 | gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata", | |
86 | sizeof(struct gfs2_bufdata), | |
20c2df83 | 87 | 0, 0, NULL); |
b3b94faa DT |
88 | if (!gfs2_bufdata_cachep) |
89 | goto fail; | |
90 | ||
6bdd9be6 BP |
91 | gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd", |
92 | sizeof(struct gfs2_rgrpd), | |
93 | 0, 0, NULL); | |
94 | if (!gfs2_rgrpd_cachep) | |
95 | goto fail; | |
96 | ||
37b2c837 SW |
97 | gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad", |
98 | sizeof(struct gfs2_quota_data), | |
99 | 0, 0, NULL); | |
100 | if (!gfs2_quotad_cachep) | |
101 | goto fail; | |
102 | ||
b3b94faa DT |
103 | error = register_filesystem(&gfs2_fs_type); |
104 | if (error) | |
105 | goto fail; | |
106 | ||
419c93e0 SW |
107 | error = register_filesystem(&gfs2meta_fs_type); |
108 | if (error) | |
109 | goto fail_unregister; | |
110 | ||
7c52b166 RP |
111 | gfs2_register_debugfs(); |
112 | ||
b3b94faa DT |
113 | printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__); |
114 | ||
115 | return 0; | |
116 | ||
419c93e0 SW |
117 | fail_unregister: |
118 | unregister_filesystem(&gfs2_fs_type); | |
119 | fail: | |
8fbbfd21 SW |
120 | gfs2_glock_exit(); |
121 | ||
37b2c837 SW |
122 | if (gfs2_quotad_cachep) |
123 | kmem_cache_destroy(gfs2_quotad_cachep); | |
124 | ||
6bdd9be6 BP |
125 | if (gfs2_rgrpd_cachep) |
126 | kmem_cache_destroy(gfs2_rgrpd_cachep); | |
127 | ||
b3b94faa DT |
128 | if (gfs2_bufdata_cachep) |
129 | kmem_cache_destroy(gfs2_bufdata_cachep); | |
130 | ||
131 | if (gfs2_inode_cachep) | |
132 | kmem_cache_destroy(gfs2_inode_cachep); | |
133 | ||
134 | if (gfs2_glock_cachep) | |
135 | kmem_cache_destroy(gfs2_glock_cachep); | |
136 | ||
137 | gfs2_sys_uninit(); | |
138 | return error; | |
139 | } | |
140 | ||
141 | /** | |
142 | * exit_gfs2_fs - Unregister the file system | |
143 | * | |
144 | */ | |
145 | ||
146 | static void __exit exit_gfs2_fs(void) | |
147 | { | |
8fbbfd21 | 148 | gfs2_glock_exit(); |
7c52b166 | 149 | gfs2_unregister_debugfs(); |
b3b94faa | 150 | unregister_filesystem(&gfs2_fs_type); |
419c93e0 | 151 | unregister_filesystem(&gfs2meta_fs_type); |
b3b94faa | 152 | |
37b2c837 | 153 | kmem_cache_destroy(gfs2_quotad_cachep); |
6bdd9be6 | 154 | kmem_cache_destroy(gfs2_rgrpd_cachep); |
b3b94faa DT |
155 | kmem_cache_destroy(gfs2_bufdata_cachep); |
156 | kmem_cache_destroy(gfs2_inode_cachep); | |
157 | kmem_cache_destroy(gfs2_glock_cachep); | |
158 | ||
159 | gfs2_sys_uninit(); | |
160 | } | |
161 | ||
162 | MODULE_DESCRIPTION("Global File System"); | |
163 | MODULE_AUTHOR("Red Hat, Inc."); | |
164 | MODULE_LICENSE("GPL"); | |
165 | ||
166 | module_init(init_gfs2_fs); | |
167 | module_exit(exit_gfs2_fs); | |
168 |