]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/gfs2/main.c
Merge branches 'for-4.4/upstream-fixes', 'for-4.5/async-suspend', 'for-4.5/container...
[mirror_ubuntu-artful-kernel.git] / fs / gfs2 / main.c
CommitLineData
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
d77d1b58
JP
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
b3b94faa
DT
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>
5c676f6d 18#include <linux/gfs2_ondisk.h>
bc015cb8
SW
19#include <linux/rcupdate.h>
20#include <linux/rculist_bl.h>
60063497 21#include <linux/atomic.h>
75ca61c1 22#include <linux/mempool.h>
b3b94faa
DT
23
24#include "gfs2.h"
5c676f6d 25#include "incore.h"
b2760583 26#include "super.h"
b3b94faa 27#include "sys.h"
5c676f6d 28#include "util.h"
85d1da67 29#include "glock.h"
0a7ab79c 30#include "quota.h"
6ecd7c2d 31#include "recovery.h"
8d123585 32#include "dir.h"
2e60d768 33#include "glops.h"
0a7ab79c 34
e0c2a9aa
DT
35struct workqueue_struct *gfs2_control_wq;
36
51cc5068 37static void gfs2_init_inode_once(void *foo)
320dd101
SW
38{
39 struct gfs2_inode *ip = foo;
a35afb83
CL
40
41 inode_init_once(&ip->i_inode);
a35afb83 42 init_rwsem(&ip->i_rw_mutex);
813e0c46 43 INIT_LIST_HEAD(&ip->i_trunc_list);
564e12b1 44 ip->i_res = NULL;
17d539f0 45 ip->i_hash_cache = NULL;
320dd101
SW
46}
47
51cc5068 48static void gfs2_init_glock_once(void *foo)
ec45d9f5
SW
49{
50 struct gfs2_glock *gl = foo;
a35afb83 51
bc015cb8 52 INIT_HLIST_BL_NODE(&gl->gl_list);
f3dd1649 53 spin_lock_init(&gl->gl_lockref.lock);
a35afb83 54 INIT_LIST_HEAD(&gl->gl_holders);
97cc1025 55 INIT_LIST_HEAD(&gl->gl_lru);
a35afb83
CL
56 INIT_LIST_HEAD(&gl->gl_ail_list);
57 atomic_set(&gl->gl_ail_count, 0);
f42ab085 58 atomic_set(&gl->gl_revokes, 0);
ec45d9f5
SW
59}
60
009d8518
SW
61static void gfs2_init_gl_aspace_once(void *foo)
62{
63 struct gfs2_glock *gl = foo;
64 struct address_space *mapping = (struct address_space *)(gl + 1);
65
66 gfs2_init_glock_once(gl);
2aa15890 67 address_space_init_once(mapping);
009d8518
SW
68}
69
b3b94faa
DT
70/**
71 * init_gfs2_fs - Register GFS2 as a filesystem
72 *
73 * Returns: 0 on success, error code on failure
74 */
75
76static int __init init_gfs2_fs(void)
77{
78 int error;
79
8d123585
SW
80 gfs2_str2qstr(&gfs2_qdot, ".");
81 gfs2_str2qstr(&gfs2_qdotdot, "..");
c754fbbb 82 gfs2_quota_hash_init();
8d123585 83
b3b94faa
DT
84 error = gfs2_sys_init();
85 if (error)
86 return error;
87
2147dbfd
SW
88 error = list_lru_init(&gfs2_qd_lru);
89 if (error)
90 goto fail_lru;
91
85d1da67
SW
92 error = gfs2_glock_init();
93 if (error)
94 goto fail;
b3b94faa 95
85d1da67 96 error = -ENOMEM;
b3b94faa
DT
97 gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
98 sizeof(struct gfs2_glock),
907b9bce 99 0, 0,
20c2df83 100 gfs2_init_glock_once);
b3b94faa
DT
101 if (!gfs2_glock_cachep)
102 goto fail;
103
7c9a84a5 104 gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
009d8518
SW
105 sizeof(struct gfs2_glock) +
106 sizeof(struct address_space),
107 0, 0, gfs2_init_gl_aspace_once);
108
109 if (!gfs2_glock_aspace_cachep)
110 goto fail;
111
b3b94faa
DT
112 gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
113 sizeof(struct gfs2_inode),
eb1dc33a
AD
114 0, SLAB_RECLAIM_ACCOUNT|
115 SLAB_MEM_SPREAD,
20c2df83 116 gfs2_init_inode_once);
b3b94faa
DT
117 if (!gfs2_inode_cachep)
118 goto fail;
119
120 gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
121 sizeof(struct gfs2_bufdata),
20c2df83 122 0, 0, NULL);
b3b94faa
DT
123 if (!gfs2_bufdata_cachep)
124 goto fail;
125
6bdd9be6
BP
126 gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
127 sizeof(struct gfs2_rgrpd),
128 0, 0, NULL);
129 if (!gfs2_rgrpd_cachep)
130 goto fail;
131
37b2c837
SW
132 gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
133 sizeof(struct gfs2_quota_data),
134 0, 0, NULL);
135 if (!gfs2_quotad_cachep)
136 goto fail;
137
36f5580b
BP
138 gfs2_rsrv_cachep = kmem_cache_create("gfs2_mblk",
139 sizeof(struct gfs2_blkreserv),
140 0, 0, NULL);
141 if (!gfs2_rsrv_cachep)
142 goto fail;
143
2147dbfd 144 register_shrinker(&gfs2_qd_shrinker);
0a7ab79c 145
b3b94faa
DT
146 error = register_filesystem(&gfs2_fs_type);
147 if (error)
148 goto fail;
149
419c93e0
SW
150 error = register_filesystem(&gfs2meta_fs_type);
151 if (error)
152 goto fail_unregister;
153
6ecd7c2d
TH
154 error = -ENOMEM;
155 gfs_recovery_wq = alloc_workqueue("gfs_recovery",
58a69cb4 156 WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
6ecd7c2d
TH
157 if (!gfs_recovery_wq)
158 goto fail_wq;
fe64d517 159
e0c2a9aa 160 gfs2_control_wq = alloc_workqueue("gfs2_control",
d08fa65a 161 WQ_UNBOUND | WQ_FREEZABLE, 0);
e0c2a9aa 162 if (!gfs2_control_wq)
75ca61c1
SW
163 goto fail_recovery;
164
2e60d768
BM
165 gfs2_freeze_wq = alloc_workqueue("freeze_workqueue", 0, 0);
166
167 if (!gfs2_freeze_wq)
168 goto fail_control;
169
e8c92ed7
SW
170 gfs2_page_pool = mempool_create_page_pool(64, 0);
171 if (!gfs2_page_pool)
2e60d768 172 goto fail_freeze;
e0c2a9aa 173
7c52b166
RP
174 gfs2_register_debugfs();
175
fc554ed3 176 pr_info("GFS2 installed\n");
b3b94faa
DT
177
178 return 0;
179
2e60d768
BM
180fail_freeze:
181 destroy_workqueue(gfs2_freeze_wq);
e0c2a9aa 182fail_control:
75ca61c1
SW
183 destroy_workqueue(gfs2_control_wq);
184fail_recovery:
e0c2a9aa 185 destroy_workqueue(gfs_recovery_wq);
6ecd7c2d 186fail_wq:
fe64d517 187 unregister_filesystem(&gfs2meta_fs_type);
419c93e0
SW
188fail_unregister:
189 unregister_filesystem(&gfs2_fs_type);
190fail:
2147dbfd
SW
191 list_lru_destroy(&gfs2_qd_lru);
192fail_lru:
193 unregister_shrinker(&gfs2_qd_shrinker);
8fbbfd21
SW
194 gfs2_glock_exit();
195
36f5580b
BP
196 if (gfs2_rsrv_cachep)
197 kmem_cache_destroy(gfs2_rsrv_cachep);
198
37b2c837
SW
199 if (gfs2_quotad_cachep)
200 kmem_cache_destroy(gfs2_quotad_cachep);
201
6bdd9be6
BP
202 if (gfs2_rgrpd_cachep)
203 kmem_cache_destroy(gfs2_rgrpd_cachep);
204
b3b94faa
DT
205 if (gfs2_bufdata_cachep)
206 kmem_cache_destroy(gfs2_bufdata_cachep);
207
208 if (gfs2_inode_cachep)
209 kmem_cache_destroy(gfs2_inode_cachep);
210
009d8518
SW
211 if (gfs2_glock_aspace_cachep)
212 kmem_cache_destroy(gfs2_glock_aspace_cachep);
213
b3b94faa
DT
214 if (gfs2_glock_cachep)
215 kmem_cache_destroy(gfs2_glock_cachep);
216
217 gfs2_sys_uninit();
218 return error;
219}
220
221/**
222 * exit_gfs2_fs - Unregister the file system
223 *
224 */
225
226static void __exit exit_gfs2_fs(void)
227{
2147dbfd 228 unregister_shrinker(&gfs2_qd_shrinker);
8fbbfd21 229 gfs2_glock_exit();
7c52b166 230 gfs2_unregister_debugfs();
b3b94faa 231 unregister_filesystem(&gfs2_fs_type);
419c93e0 232 unregister_filesystem(&gfs2meta_fs_type);
6ecd7c2d 233 destroy_workqueue(gfs_recovery_wq);
e0c2a9aa 234 destroy_workqueue(gfs2_control_wq);
2e60d768 235 destroy_workqueue(gfs2_freeze_wq);
2147dbfd 236 list_lru_destroy(&gfs2_qd_lru);
b3b94faa 237
bc015cb8
SW
238 rcu_barrier();
239
e8c92ed7 240 mempool_destroy(gfs2_page_pool);
36f5580b 241 kmem_cache_destroy(gfs2_rsrv_cachep);
37b2c837 242 kmem_cache_destroy(gfs2_quotad_cachep);
6bdd9be6 243 kmem_cache_destroy(gfs2_rgrpd_cachep);
b3b94faa
DT
244 kmem_cache_destroy(gfs2_bufdata_cachep);
245 kmem_cache_destroy(gfs2_inode_cachep);
009d8518 246 kmem_cache_destroy(gfs2_glock_aspace_cachep);
b3b94faa
DT
247 kmem_cache_destroy(gfs2_glock_cachep);
248
249 gfs2_sys_uninit();
250}
251
252MODULE_DESCRIPTION("Global File System");
253MODULE_AUTHOR("Red Hat, Inc.");
254MODULE_LICENSE("GPL");
255
256module_init(init_gfs2_fs);
257module_exit(exit_gfs2_fs);
258