Merge branch 'pending-misc' (early part) into devel
[linux-2.6-block.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
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>
ec45d9f5 17#include <asm/atomic.h>
fe64d517 18#include <linux/slow-work.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"
0a7ab79c
AD
26#include "quota.h"
27
28static struct shrinker qd_shrinker = {
29 .shrink = gfs2_shrink_qd_memory,
30 .seeks = DEFAULT_SEEKS,
31};
b3b94faa 32
51cc5068 33static void gfs2_init_inode_once(void *foo)
320dd101
SW
34{
35 struct gfs2_inode *ip = foo;
a35afb83
CL
36
37 inode_init_once(&ip->i_inode);
a35afb83 38 init_rwsem(&ip->i_rw_mutex);
813e0c46 39 INIT_LIST_HEAD(&ip->i_trunc_list);
6dbd8224 40 ip->i_alloc = NULL;
320dd101
SW
41}
42
51cc5068 43static void gfs2_init_glock_once(void *foo)
ec45d9f5
SW
44{
45 struct gfs2_glock *gl = foo;
a35afb83
CL
46
47 INIT_HLIST_NODE(&gl->gl_list);
48 spin_lock_init(&gl->gl_spin);
49 INIT_LIST_HEAD(&gl->gl_holders);
97cc1025 50 INIT_LIST_HEAD(&gl->gl_lru);
a35afb83
CL
51 INIT_LIST_HEAD(&gl->gl_ail_list);
52 atomic_set(&gl->gl_ail_count, 0);
ec45d9f5
SW
53}
54
b3b94faa
DT
55/**
56 * init_gfs2_fs - Register GFS2 as a filesystem
57 *
58 * Returns: 0 on success, error code on failure
59 */
60
61static int __init init_gfs2_fs(void)
62{
63 int error;
64
b3b94faa
DT
65 error = gfs2_sys_init();
66 if (error)
67 return error;
68
85d1da67
SW
69 error = gfs2_glock_init();
70 if (error)
71 goto fail;
b3b94faa 72
85d1da67 73 error = -ENOMEM;
b3b94faa
DT
74 gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
75 sizeof(struct gfs2_glock),
907b9bce 76 0, 0,
20c2df83 77 gfs2_init_glock_once);
b3b94faa
DT
78 if (!gfs2_glock_cachep)
79 goto fail;
80
81 gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
82 sizeof(struct gfs2_inode),
eb1dc33a
AD
83 0, SLAB_RECLAIM_ACCOUNT|
84 SLAB_MEM_SPREAD,
20c2df83 85 gfs2_init_inode_once);
b3b94faa
DT
86 if (!gfs2_inode_cachep)
87 goto fail;
88
89 gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
90 sizeof(struct gfs2_bufdata),
20c2df83 91 0, 0, NULL);
b3b94faa
DT
92 if (!gfs2_bufdata_cachep)
93 goto fail;
94
6bdd9be6
BP
95 gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
96 sizeof(struct gfs2_rgrpd),
97 0, 0, NULL);
98 if (!gfs2_rgrpd_cachep)
99 goto fail;
100
37b2c837
SW
101 gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
102 sizeof(struct gfs2_quota_data),
103 0, 0, NULL);
104 if (!gfs2_quotad_cachep)
105 goto fail;
106
0a7ab79c
AD
107 register_shrinker(&qd_shrinker);
108
b3b94faa
DT
109 error = register_filesystem(&gfs2_fs_type);
110 if (error)
111 goto fail;
112
419c93e0
SW
113 error = register_filesystem(&gfs2meta_fs_type);
114 if (error)
115 goto fail_unregister;
116
3d7a641e 117 error = slow_work_register_user(THIS_MODULE);
fe64d517
SW
118 if (error)
119 goto fail_slow;
120
7c52b166
RP
121 gfs2_register_debugfs();
122
b3b94faa
DT
123 printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
124
125 return 0;
126
fe64d517
SW
127fail_slow:
128 unregister_filesystem(&gfs2meta_fs_type);
419c93e0
SW
129fail_unregister:
130 unregister_filesystem(&gfs2_fs_type);
131fail:
0a7ab79c 132 unregister_shrinker(&qd_shrinker);
8fbbfd21
SW
133 gfs2_glock_exit();
134
37b2c837
SW
135 if (gfs2_quotad_cachep)
136 kmem_cache_destroy(gfs2_quotad_cachep);
137
6bdd9be6
BP
138 if (gfs2_rgrpd_cachep)
139 kmem_cache_destroy(gfs2_rgrpd_cachep);
140
b3b94faa
DT
141 if (gfs2_bufdata_cachep)
142 kmem_cache_destroy(gfs2_bufdata_cachep);
143
144 if (gfs2_inode_cachep)
145 kmem_cache_destroy(gfs2_inode_cachep);
146
147 if (gfs2_glock_cachep)
148 kmem_cache_destroy(gfs2_glock_cachep);
149
150 gfs2_sys_uninit();
151 return error;
152}
153
154/**
155 * exit_gfs2_fs - Unregister the file system
156 *
157 */
158
159static void __exit exit_gfs2_fs(void)
160{
0a7ab79c 161 unregister_shrinker(&qd_shrinker);
8fbbfd21 162 gfs2_glock_exit();
7c52b166 163 gfs2_unregister_debugfs();
b3b94faa 164 unregister_filesystem(&gfs2_fs_type);
419c93e0 165 unregister_filesystem(&gfs2meta_fs_type);
3d7a641e 166 slow_work_unregister_user(THIS_MODULE);
b3b94faa 167
37b2c837 168 kmem_cache_destroy(gfs2_quotad_cachep);
6bdd9be6 169 kmem_cache_destroy(gfs2_rgrpd_cachep);
b3b94faa
DT
170 kmem_cache_destroy(gfs2_bufdata_cachep);
171 kmem_cache_destroy(gfs2_inode_cachep);
172 kmem_cache_destroy(gfs2_glock_cachep);
173
174 gfs2_sys_uninit();
175}
176
177MODULE_DESCRIPTION("Global File System");
178MODULE_AUTHOR("Red Hat, Inc.");
179MODULE_LICENSE("GPL");
180
181module_init(init_gfs2_fs);
182module_exit(exit_gfs2_fs);
183