blob: 8a139ff1919f922bdf20b3f2d933316a1560b5f8 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
David Teiglandb3b94fa2006-01-16 16:50:04 +000010#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>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050016#include <linux/gfs2_ondisk.h>
Steven Whitehousebc015cb2011-01-19 09:30:01 +000017#include <linux/rcupdate.h>
18#include <linux/rculist_bl.h>
Arun Sharma60063492011-07-26 16:09:06 -070019#include <linux/atomic.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000020
21#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050022#include "incore.h"
Steven Whitehouseb2760582008-10-14 16:05:55 +010023#include "super.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000024#include "sys.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050025#include "util.h"
Steven Whitehouse85d1da62006-09-07 14:40:21 -040026#include "glock.h"
Abhijith Das0a7ab792009-01-07 16:03:37 -060027#include "quota.h"
Tejun Heo6ecd7c22010-07-20 22:09:02 +020028#include "recovery.h"
Steven Whitehouse8d123582010-09-17 12:30:23 +010029#include "dir.h"
Abhijith Das0a7ab792009-01-07 16:03:37 -060030
31static struct shrinker qd_shrinker = {
32 .shrink = gfs2_shrink_qd_memory,
33 .seeks = DEFAULT_SEEKS,
34};
David Teiglandb3b94fa2006-01-16 16:50:04 +000035
Alexey Dobriyan51cc5062008-07-25 19:45:34 -070036static void gfs2_init_inode_once(void *foo)
Steven Whitehouse320dd102006-05-18 16:25:27 -040037{
38 struct gfs2_inode *ip = foo;
Christoph Lametera35afb82007-05-16 22:10:57 -070039
40 inode_init_once(&ip->i_inode);
Christoph Lametera35afb82007-05-16 22:10:57 -070041 init_rwsem(&ip->i_rw_mutex);
Steven Whitehouse813e0c42008-11-18 13:38:48 +000042 INIT_LIST_HEAD(&ip->i_trunc_list);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +000043 ip->i_alloc = NULL;
Steven Whitehouse17d539f2011-06-15 10:29:37 +010044 ip->i_hash_cache = NULL;
Steven Whitehouse320dd102006-05-18 16:25:27 -040045}
46
Alexey Dobriyan51cc5062008-07-25 19:45:34 -070047static void gfs2_init_glock_once(void *foo)
Steven Whitehouseec45d9f2006-08-30 10:36:52 -040048{
49 struct gfs2_glock *gl = foo;
Christoph Lametera35afb82007-05-16 22:10:57 -070050
Steven Whitehousebc015cb2011-01-19 09:30:01 +000051 INIT_HLIST_BL_NODE(&gl->gl_list);
Christoph Lametera35afb82007-05-16 22:10:57 -070052 spin_lock_init(&gl->gl_spin);
53 INIT_LIST_HEAD(&gl->gl_holders);
Steven Whitehouse97cc1022008-11-20 13:39:47 +000054 INIT_LIST_HEAD(&gl->gl_lru);
Christoph Lametera35afb82007-05-16 22:10:57 -070055 INIT_LIST_HEAD(&gl->gl_ail_list);
56 atomic_set(&gl->gl_ail_count, 0);
Steven Whitehousef42ab082011-04-14 16:50:31 +010057 atomic_set(&gl->gl_revokes, 0);
Steven Whitehouseec45d9f2006-08-30 10:36:52 -040058}
59
Steven Whitehouse009d8512009-12-08 12:12:13 +000060static void gfs2_init_gl_aspace_once(void *foo)
61{
62 struct gfs2_glock *gl = foo;
63 struct address_space *mapping = (struct address_space *)(gl + 1);
64
65 gfs2_init_glock_once(gl);
Miklos Szeredi2aa15892011-02-23 13:49:47 +010066 address_space_init_once(mapping);
Steven Whitehouse009d8512009-12-08 12:12:13 +000067}
68
David Teiglandb3b94fa2006-01-16 16:50:04 +000069/**
70 * init_gfs2_fs - Register GFS2 as a filesystem
71 *
72 * Returns: 0 on success, error code on failure
73 */
74
75static int __init init_gfs2_fs(void)
76{
77 int error;
78
Steven Whitehouse8d123582010-09-17 12:30:23 +010079 gfs2_str2qstr(&gfs2_qdot, ".");
80 gfs2_str2qstr(&gfs2_qdotdot, "..");
81
David Teiglandb3b94fa2006-01-16 16:50:04 +000082 error = gfs2_sys_init();
83 if (error)
84 return error;
85
Steven Whitehouse85d1da62006-09-07 14:40:21 -040086 error = gfs2_glock_init();
87 if (error)
88 goto fail;
David Teiglandb3b94fa2006-01-16 16:50:04 +000089
Steven Whitehouse85d1da62006-09-07 14:40:21 -040090 error = -ENOMEM;
David Teiglandb3b94fa2006-01-16 16:50:04 +000091 gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
92 sizeof(struct gfs2_glock),
Steven Whitehouse907b9bc2006-09-25 09:26:04 -040093 0, 0,
Paul Mundt20c2df82007-07-20 10:11:58 +090094 gfs2_init_glock_once);
David Teiglandb3b94fa2006-01-16 16:50:04 +000095 if (!gfs2_glock_cachep)
96 goto fail;
97
Steven Whitehouse7c9a84a2010-03-12 17:05:31 +000098 gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
Steven Whitehouse009d8512009-12-08 12:12:13 +000099 sizeof(struct gfs2_glock) +
100 sizeof(struct address_space),
101 0, 0, gfs2_init_gl_aspace_once);
102
103 if (!gfs2_glock_aspace_cachep)
104 goto fail;
105
David Teiglandb3b94fa2006-01-16 16:50:04 +0000106 gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
107 sizeof(struct gfs2_inode),
Alexey Dobriyaneb1dc332006-10-28 03:03:48 +0400108 0, SLAB_RECLAIM_ACCOUNT|
109 SLAB_MEM_SPREAD,
Paul Mundt20c2df82007-07-20 10:11:58 +0900110 gfs2_init_inode_once);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000111 if (!gfs2_inode_cachep)
112 goto fail;
113
114 gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
115 sizeof(struct gfs2_bufdata),
Paul Mundt20c2df82007-07-20 10:11:58 +0900116 0, 0, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000117 if (!gfs2_bufdata_cachep)
118 goto fail;
119
Bob Peterson6bdd9be2008-01-28 17:20:26 -0600120 gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
121 sizeof(struct gfs2_rgrpd),
122 0, 0, NULL);
123 if (!gfs2_rgrpd_cachep)
124 goto fail;
125
Steven Whitehouse37b2c832008-11-17 14:25:37 +0000126 gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
127 sizeof(struct gfs2_quota_data),
128 0, 0, NULL);
129 if (!gfs2_quotad_cachep)
130 goto fail;
131
Abhijith Das0a7ab792009-01-07 16:03:37 -0600132 register_shrinker(&qd_shrinker);
133
David Teiglandb3b94fa2006-01-16 16:50:04 +0000134 error = register_filesystem(&gfs2_fs_type);
135 if (error)
136 goto fail;
137
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500138 error = register_filesystem(&gfs2meta_fs_type);
139 if (error)
140 goto fail_unregister;
141
Tejun Heo6ecd7c22010-07-20 22:09:02 +0200142 error = -ENOMEM;
143 gfs_recovery_wq = alloc_workqueue("gfs_recovery",
Tejun Heo58a69cb2011-02-16 09:25:31 +0100144 WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
Tejun Heo6ecd7c22010-07-20 22:09:02 +0200145 if (!gfs_recovery_wq)
146 goto fail_wq;
Steven Whitehousefe64d512009-05-19 10:01:18 +0100147
Robert Peterson7c52b162007-03-16 10:26:37 +0000148 gfs2_register_debugfs();
149
Michal Marek8d2c50e2011-04-01 12:41:20 +0200150 printk("GFS2 installed\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000151
152 return 0;
153
Tejun Heo6ecd7c22010-07-20 22:09:02 +0200154fail_wq:
Steven Whitehousefe64d512009-05-19 10:01:18 +0100155 unregister_filesystem(&gfs2meta_fs_type);
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500156fail_unregister:
157 unregister_filesystem(&gfs2_fs_type);
158fail:
Abhijith Das0a7ab792009-01-07 16:03:37 -0600159 unregister_shrinker(&qd_shrinker);
Steven Whitehouse8fbbfd22007-08-01 13:57:10 +0100160 gfs2_glock_exit();
161
Steven Whitehouse37b2c832008-11-17 14:25:37 +0000162 if (gfs2_quotad_cachep)
163 kmem_cache_destroy(gfs2_quotad_cachep);
164
Bob Peterson6bdd9be2008-01-28 17:20:26 -0600165 if (gfs2_rgrpd_cachep)
166 kmem_cache_destroy(gfs2_rgrpd_cachep);
167
David Teiglandb3b94fa2006-01-16 16:50:04 +0000168 if (gfs2_bufdata_cachep)
169 kmem_cache_destroy(gfs2_bufdata_cachep);
170
171 if (gfs2_inode_cachep)
172 kmem_cache_destroy(gfs2_inode_cachep);
173
Steven Whitehouse009d8512009-12-08 12:12:13 +0000174 if (gfs2_glock_aspace_cachep)
175 kmem_cache_destroy(gfs2_glock_aspace_cachep);
176
David Teiglandb3b94fa2006-01-16 16:50:04 +0000177 if (gfs2_glock_cachep)
178 kmem_cache_destroy(gfs2_glock_cachep);
179
180 gfs2_sys_uninit();
181 return error;
182}
183
184/**
185 * exit_gfs2_fs - Unregister the file system
186 *
187 */
188
189static void __exit exit_gfs2_fs(void)
190{
Abhijith Das0a7ab792009-01-07 16:03:37 -0600191 unregister_shrinker(&qd_shrinker);
Steven Whitehouse8fbbfd22007-08-01 13:57:10 +0100192 gfs2_glock_exit();
Robert Peterson7c52b162007-03-16 10:26:37 +0000193 gfs2_unregister_debugfs();
David Teiglandb3b94fa2006-01-16 16:50:04 +0000194 unregister_filesystem(&gfs2_fs_type);
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500195 unregister_filesystem(&gfs2meta_fs_type);
Tejun Heo6ecd7c22010-07-20 22:09:02 +0200196 destroy_workqueue(gfs_recovery_wq);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000197
Steven Whitehousebc015cb2011-01-19 09:30:01 +0000198 rcu_barrier();
199
Steven Whitehouse37b2c832008-11-17 14:25:37 +0000200 kmem_cache_destroy(gfs2_quotad_cachep);
Bob Peterson6bdd9be2008-01-28 17:20:26 -0600201 kmem_cache_destroy(gfs2_rgrpd_cachep);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000202 kmem_cache_destroy(gfs2_bufdata_cachep);
203 kmem_cache_destroy(gfs2_inode_cachep);
Steven Whitehouse009d8512009-12-08 12:12:13 +0000204 kmem_cache_destroy(gfs2_glock_aspace_cachep);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000205 kmem_cache_destroy(gfs2_glock_cachep);
206
207 gfs2_sys_uninit();
208}
209
210MODULE_DESCRIPTION("Global File System");
211MODULE_AUTHOR("Red Hat, Inc.");
212MODULE_LICENSE("GPL");
213
214module_init(init_gfs2_fs);
215module_exit(exit_gfs2_fs);
216