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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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>
18 #include <linux/gfs2_ondisk.h>
19 #include <linux/rcupdate.h>
20 #include <linux/rculist_bl.h>
21 #include <linux/atomic.h>
22 #include <linux/mempool.h>
35 struct workqueue_struct
*gfs2_control_wq
;
37 static void gfs2_init_inode_once(void *foo
)
39 struct gfs2_inode
*ip
= foo
;
41 inode_init_once(&ip
->i_inode
);
42 init_rwsem(&ip
->i_rw_mutex
);
43 INIT_LIST_HEAD(&ip
->i_trunc_list
);
45 ip
->i_hash_cache
= NULL
;
48 static void gfs2_init_glock_once(void *foo
)
50 struct gfs2_glock
*gl
= foo
;
52 INIT_HLIST_BL_NODE(&gl
->gl_list
);
53 spin_lock_init(&gl
->gl_lockref
.lock
);
54 INIT_LIST_HEAD(&gl
->gl_holders
);
55 INIT_LIST_HEAD(&gl
->gl_lru
);
56 INIT_LIST_HEAD(&gl
->gl_ail_list
);
57 atomic_set(&gl
->gl_ail_count
, 0);
58 atomic_set(&gl
->gl_revokes
, 0);
61 static void gfs2_init_gl_aspace_once(void *foo
)
63 struct gfs2_glock
*gl
= foo
;
64 struct address_space
*mapping
= (struct address_space
*)(gl
+ 1);
66 gfs2_init_glock_once(gl
);
67 address_space_init_once(mapping
);
71 * init_gfs2_fs - Register GFS2 as a filesystem
73 * Returns: 0 on success, error code on failure
76 static int __init
init_gfs2_fs(void)
80 gfs2_str2qstr(&gfs2_qdot
, ".");
81 gfs2_str2qstr(&gfs2_qdotdot
, "..");
82 gfs2_quota_hash_init();
84 error
= gfs2_sys_init();
88 error
= list_lru_init(&gfs2_qd_lru
);
92 error
= gfs2_glock_init();
97 gfs2_glock_cachep
= kmem_cache_create("gfs2_glock",
98 sizeof(struct gfs2_glock
),
100 gfs2_init_glock_once
);
101 if (!gfs2_glock_cachep
)
104 gfs2_glock_aspace_cachep
= kmem_cache_create("gfs2_glock(aspace)",
105 sizeof(struct gfs2_glock
) +
106 sizeof(struct address_space
),
107 0, 0, gfs2_init_gl_aspace_once
);
109 if (!gfs2_glock_aspace_cachep
)
112 gfs2_inode_cachep
= kmem_cache_create("gfs2_inode",
113 sizeof(struct gfs2_inode
),
114 0, SLAB_RECLAIM_ACCOUNT
|
116 gfs2_init_inode_once
);
117 if (!gfs2_inode_cachep
)
120 gfs2_bufdata_cachep
= kmem_cache_create("gfs2_bufdata",
121 sizeof(struct gfs2_bufdata
),
123 if (!gfs2_bufdata_cachep
)
126 gfs2_rgrpd_cachep
= kmem_cache_create("gfs2_rgrpd",
127 sizeof(struct gfs2_rgrpd
),
129 if (!gfs2_rgrpd_cachep
)
132 gfs2_quotad_cachep
= kmem_cache_create("gfs2_quotad",
133 sizeof(struct gfs2_quota_data
),
135 if (!gfs2_quotad_cachep
)
138 gfs2_rsrv_cachep
= kmem_cache_create("gfs2_mblk",
139 sizeof(struct gfs2_blkreserv
),
141 if (!gfs2_rsrv_cachep
)
144 register_shrinker(&gfs2_qd_shrinker
);
146 error
= register_filesystem(&gfs2_fs_type
);
150 error
= register_filesystem(&gfs2meta_fs_type
);
152 goto fail_unregister
;
155 gfs_recovery_wq
= alloc_workqueue("gfs_recovery",
156 WQ_MEM_RECLAIM
| WQ_FREEZABLE
, 0);
157 if (!gfs_recovery_wq
)
160 gfs2_control_wq
= alloc_workqueue("gfs2_control",
161 WQ_UNBOUND
| WQ_FREEZABLE
, 0);
162 if (!gfs2_control_wq
)
165 gfs2_freeze_wq
= alloc_workqueue("freeze_workqueue", 0, 0);
170 gfs2_page_pool
= mempool_create_page_pool(64, 0);
174 gfs2_register_debugfs();
176 pr_info("GFS2 installed\n");
181 destroy_workqueue(gfs2_freeze_wq
);
183 destroy_workqueue(gfs2_control_wq
);
185 destroy_workqueue(gfs_recovery_wq
);
187 unregister_filesystem(&gfs2meta_fs_type
);
189 unregister_filesystem(&gfs2_fs_type
);
191 list_lru_destroy(&gfs2_qd_lru
);
193 unregister_shrinker(&gfs2_qd_shrinker
);
196 if (gfs2_rsrv_cachep
)
197 kmem_cache_destroy(gfs2_rsrv_cachep
);
199 if (gfs2_quotad_cachep
)
200 kmem_cache_destroy(gfs2_quotad_cachep
);
202 if (gfs2_rgrpd_cachep
)
203 kmem_cache_destroy(gfs2_rgrpd_cachep
);
205 if (gfs2_bufdata_cachep
)
206 kmem_cache_destroy(gfs2_bufdata_cachep
);
208 if (gfs2_inode_cachep
)
209 kmem_cache_destroy(gfs2_inode_cachep
);
211 if (gfs2_glock_aspace_cachep
)
212 kmem_cache_destroy(gfs2_glock_aspace_cachep
);
214 if (gfs2_glock_cachep
)
215 kmem_cache_destroy(gfs2_glock_cachep
);
222 * exit_gfs2_fs - Unregister the file system
226 static void __exit
exit_gfs2_fs(void)
228 unregister_shrinker(&gfs2_qd_shrinker
);
230 gfs2_unregister_debugfs();
231 unregister_filesystem(&gfs2_fs_type
);
232 unregister_filesystem(&gfs2meta_fs_type
);
233 destroy_workqueue(gfs_recovery_wq
);
234 destroy_workqueue(gfs2_control_wq
);
235 destroy_workqueue(gfs2_freeze_wq
);
236 list_lru_destroy(&gfs2_qd_lru
);
240 mempool_destroy(gfs2_page_pool
);
241 kmem_cache_destroy(gfs2_rsrv_cachep
);
242 kmem_cache_destroy(gfs2_quotad_cachep
);
243 kmem_cache_destroy(gfs2_rgrpd_cachep
);
244 kmem_cache_destroy(gfs2_bufdata_cachep
);
245 kmem_cache_destroy(gfs2_inode_cachep
);
246 kmem_cache_destroy(gfs2_glock_aspace_cachep
);
247 kmem_cache_destroy(gfs2_glock_cachep
);
252 MODULE_DESCRIPTION("Global File System");
253 MODULE_AUTHOR("Red Hat, Inc.");
254 MODULE_LICENSE("GPL");
256 module_init(init_gfs2_fs
);
257 module_exit(exit_gfs2_fs
);