Blame view

fs/gfs2/main.c 5.08 KB
b3b94faa5   David Teigland   [GFS2] The core o...
1
2
  /*
   * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3a8a9a103   Steven Whitehouse   [GFS2] Update cop...
3
   * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
b3b94faa5   David Teigland   [GFS2] The core o...
4
5
6
   *
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
e9fc2aa09   Steven Whitehouse   [GFS2] Update cop...
7
   * of the GNU General Public License version 2.
b3b94faa5   David Teigland   [GFS2] The core o...
8
   */
b3b94faa5   David Teigland   [GFS2] The core o...
9
10
11
12
13
14
  #include <linux/slab.h>
  #include <linux/spinlock.h>
  #include <linux/completion.h>
  #include <linux/buffer_head.h>
  #include <linux/module.h>
  #include <linux/init.h>
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
15
  #include <linux/gfs2_ondisk.h>
bc015cb84   Steven Whitehouse   GFS2: Use RCU for...
16
17
  #include <linux/rcupdate.h>
  #include <linux/rculist_bl.h>
60063497a   Arun Sharma   atomic: use <linu...
18
  #include <linux/atomic.h>
b3b94faa5   David Teigland   [GFS2] The core o...
19
20
  
  #include "gfs2.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
21
  #include "incore.h"
b27605837   Steven Whitehouse   GFS2: Rationalise...
22
  #include "super.h"
b3b94faa5   David Teigland   [GFS2] The core o...
23
  #include "sys.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
24
  #include "util.h"
85d1da67f   Steven Whitehouse   [GFS2] Move glock...
25
  #include "glock.h"
0a7ab79c5   Abhijith Das   GFS2: change gfs2...
26
  #include "quota.h"
6ecd7c2dd   Tejun Heo   gfs2: use workque...
27
  #include "recovery.h"
8d1235852   Steven Whitehouse   GFS2: Make . and ...
28
  #include "dir.h"
0a7ab79c5   Abhijith Das   GFS2: change gfs2...
29

e0c2a9aa1   David Teigland   GFS2: dlm based r...
30
  struct workqueue_struct *gfs2_control_wq;
0a7ab79c5   Abhijith Das   GFS2: change gfs2...
31
32
33
34
  static struct shrinker qd_shrinker = {
  	.shrink = gfs2_shrink_qd_memory,
  	.seeks = DEFAULT_SEEKS,
  };
b3b94faa5   David Teigland   [GFS2] The core o...
35

51cc50685   Alexey Dobriyan   SL*B: drop kmem c...
36
  static void gfs2_init_inode_once(void *foo)
320dd101e   Steven Whitehouse   [GFS2] glock debu...
37
38
  {
  	struct gfs2_inode *ip = foo;
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
39
40
  
  	inode_init_once(&ip->i_inode);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
41
  	init_rwsem(&ip->i_rw_mutex);
813e0c46c   Steven Whitehouse   GFS2: Fix "trunca...
42
  	INIT_LIST_HEAD(&ip->i_trunc_list);
564e12b11   Bob Peterson   GFS2: decouple qu...
43
44
  	ip->i_qadata = NULL;
  	ip->i_res = NULL;
17d539f04   Steven Whitehouse   GFS2: Cache dir h...
45
  	ip->i_hash_cache = NULL;
320dd101e   Steven Whitehouse   [GFS2] glock debu...
46
  }
51cc50685   Alexey Dobriyan   SL*B: drop kmem c...
47
  static void gfs2_init_glock_once(void *foo)
ec45d9f58   Steven Whitehouse   [GFS2] Use slab p...
48
49
  {
  	struct gfs2_glock *gl = foo;
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
50

bc015cb84   Steven Whitehouse   GFS2: Use RCU for...
51
  	INIT_HLIST_BL_NODE(&gl->gl_list);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
52
53
  	spin_lock_init(&gl->gl_spin);
  	INIT_LIST_HEAD(&gl->gl_holders);
97cc1025b   Steven Whitehouse   GFS2: Kill two da...
54
  	INIT_LIST_HEAD(&gl->gl_lru);
a35afb830   Christoph Lameter   Remove SLAB_CTOR_...
55
56
  	INIT_LIST_HEAD(&gl->gl_ail_list);
  	atomic_set(&gl->gl_ail_count, 0);
f42ab0852   Steven Whitehouse   GFS2: Optimise gl...
57
  	atomic_set(&gl->gl_revokes, 0);
ec45d9f58   Steven Whitehouse   [GFS2] Use slab p...
58
  }
009d85183   Steven Whitehouse   GFS2: Metadata ad...
59
60
61
62
63
64
  static void gfs2_init_gl_aspace_once(void *foo)
  {
  	struct gfs2_glock *gl = foo;
  	struct address_space *mapping = (struct address_space *)(gl + 1);
  
  	gfs2_init_glock_once(gl);
2aa15890f   Miklos Szeredi   mm: prevent concu...
65
  	address_space_init_once(mapping);
009d85183   Steven Whitehouse   GFS2: Metadata ad...
66
  }
b3b94faa5   David Teigland   [GFS2] The core o...
67
68
69
70
71
72
73
74
75
  /**
   * init_gfs2_fs - Register GFS2 as a filesystem
   *
   * Returns: 0 on success, error code on failure
   */
  
  static int __init init_gfs2_fs(void)
  {
  	int error;
8d1235852   Steven Whitehouse   GFS2: Make . and ...
76
77
  	gfs2_str2qstr(&gfs2_qdot, ".");
  	gfs2_str2qstr(&gfs2_qdotdot, "..");
b3b94faa5   David Teigland   [GFS2] The core o...
78
79
80
  	error = gfs2_sys_init();
  	if (error)
  		return error;
85d1da67f   Steven Whitehouse   [GFS2] Move glock...
81
82
83
  	error = gfs2_glock_init();
  	if (error)
  		goto fail;
b3b94faa5   David Teigland   [GFS2] The core o...
84

85d1da67f   Steven Whitehouse   [GFS2] Move glock...
85
  	error = -ENOMEM;
b3b94faa5   David Teigland   [GFS2] The core o...
86
87
  	gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  					      sizeof(struct gfs2_glock),
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
88
  					      0, 0,
20c2df83d   Paul Mundt   mm: Remove slab d...
89
  					      gfs2_init_glock_once);
b3b94faa5   David Teigland   [GFS2] The core o...
90
91
  	if (!gfs2_glock_cachep)
  		goto fail;
7c9a84a57   Steven Whitehouse   GFS2: Remove spac...
92
  	gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
009d85183   Steven Whitehouse   GFS2: Metadata ad...
93
94
95
96
97
98
  					sizeof(struct gfs2_glock) +
  					sizeof(struct address_space),
  					0, 0, gfs2_init_gl_aspace_once);
  
  	if (!gfs2_glock_aspace_cachep)
  		goto fail;
b3b94faa5   David Teigland   [GFS2] The core o...
99
100
  	gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  					      sizeof(struct gfs2_inode),
eb1dc33aa   Alexey Dobriyan   [GFS2] don't pani...
101
102
  					      0,  SLAB_RECLAIM_ACCOUNT|
  					          SLAB_MEM_SPREAD,
20c2df83d   Paul Mundt   mm: Remove slab d...
103
  					      gfs2_init_inode_once);
b3b94faa5   David Teigland   [GFS2] The core o...
104
105
106
107
108
  	if (!gfs2_inode_cachep)
  		goto fail;
  
  	gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  						sizeof(struct gfs2_bufdata),
20c2df83d   Paul Mundt   mm: Remove slab d...
109
  					        0, 0, NULL);
b3b94faa5   David Teigland   [GFS2] The core o...
110
111
  	if (!gfs2_bufdata_cachep)
  		goto fail;
6bdd9be62   Bob Peterson   [GFS2] Allocate g...
112
113
114
115
116
  	gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  					      sizeof(struct gfs2_rgrpd),
  					      0, 0, NULL);
  	if (!gfs2_rgrpd_cachep)
  		goto fail;
37b2c8377   Steven Whitehouse   GFS2: Clean up & ...
117
118
119
120
121
  	gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  					       sizeof(struct gfs2_quota_data),
  					       0, 0, NULL);
  	if (!gfs2_quotad_cachep)
  		goto fail;
0a7ab79c5   Abhijith Das   GFS2: change gfs2...
122
  	register_shrinker(&qd_shrinker);
b3b94faa5   David Teigland   [GFS2] The core o...
123
124
125
  	error = register_filesystem(&gfs2_fs_type);
  	if (error)
  		goto fail;
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
126
127
128
  	error = register_filesystem(&gfs2meta_fs_type);
  	if (error)
  		goto fail_unregister;
6ecd7c2dd   Tejun Heo   gfs2: use workque...
129
130
  	error = -ENOMEM;
  	gfs_recovery_wq = alloc_workqueue("gfs_recovery",
58a69cb47   Tejun Heo   workqueue, freeze...
131
  					  WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
6ecd7c2dd   Tejun Heo   gfs2: use workque...
132
133
  	if (!gfs_recovery_wq)
  		goto fail_wq;
fe64d517d   Steven Whitehouse   GFS2: Umount reco...
134

e0c2a9aa1   David Teigland   GFS2: dlm based r...
135
136
137
138
  	gfs2_control_wq = alloc_workqueue("gfs2_control",
  			       WQ_NON_REENTRANT | WQ_UNBOUND | WQ_FREEZABLE, 0);
  	if (!gfs2_control_wq)
  		goto fail_control;
7c52b166c   Robert Peterson   [GFS2] Add gfs2_t...
139
  	gfs2_register_debugfs();
8d2c50e3b   Michal Marek   gfs2: Drop __TIME...
140
141
  	printk("GFS2 installed
  ");
b3b94faa5   David Teigland   [GFS2] The core o...
142
143
  
  	return 0;
e0c2a9aa1   David Teigland   GFS2: dlm based r...
144
145
  fail_control:
  	destroy_workqueue(gfs_recovery_wq);
6ecd7c2dd   Tejun Heo   gfs2: use workque...
146
  fail_wq:
fe64d517d   Steven Whitehouse   GFS2: Umount reco...
147
  	unregister_filesystem(&gfs2meta_fs_type);
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
148
149
150
  fail_unregister:
  	unregister_filesystem(&gfs2_fs_type);
  fail:
0a7ab79c5   Abhijith Das   GFS2: change gfs2...
151
  	unregister_shrinker(&qd_shrinker);
8fbbfd214   Steven Whitehouse   [GFS2] Reduce num...
152
  	gfs2_glock_exit();
37b2c8377   Steven Whitehouse   GFS2: Clean up & ...
153
154
  	if (gfs2_quotad_cachep)
  		kmem_cache_destroy(gfs2_quotad_cachep);
6bdd9be62   Bob Peterson   [GFS2] Allocate g...
155
156
  	if (gfs2_rgrpd_cachep)
  		kmem_cache_destroy(gfs2_rgrpd_cachep);
b3b94faa5   David Teigland   [GFS2] The core o...
157
158
159
160
161
  	if (gfs2_bufdata_cachep)
  		kmem_cache_destroy(gfs2_bufdata_cachep);
  
  	if (gfs2_inode_cachep)
  		kmem_cache_destroy(gfs2_inode_cachep);
009d85183   Steven Whitehouse   GFS2: Metadata ad...
162
163
  	if (gfs2_glock_aspace_cachep)
  		kmem_cache_destroy(gfs2_glock_aspace_cachep);
b3b94faa5   David Teigland   [GFS2] The core o...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
  	if (gfs2_glock_cachep)
  		kmem_cache_destroy(gfs2_glock_cachep);
  
  	gfs2_sys_uninit();
  	return error;
  }
  
  /**
   * exit_gfs2_fs - Unregister the file system
   *
   */
  
  static void __exit exit_gfs2_fs(void)
  {
0a7ab79c5   Abhijith Das   GFS2: change gfs2...
178
  	unregister_shrinker(&qd_shrinker);
8fbbfd214   Steven Whitehouse   [GFS2] Reduce num...
179
  	gfs2_glock_exit();
7c52b166c   Robert Peterson   [GFS2] Add gfs2_t...
180
  	gfs2_unregister_debugfs();
b3b94faa5   David Teigland   [GFS2] The core o...
181
  	unregister_filesystem(&gfs2_fs_type);
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
182
  	unregister_filesystem(&gfs2meta_fs_type);
6ecd7c2dd   Tejun Heo   gfs2: use workque...
183
  	destroy_workqueue(gfs_recovery_wq);
e0c2a9aa1   David Teigland   GFS2: dlm based r...
184
  	destroy_workqueue(gfs2_control_wq);
b3b94faa5   David Teigland   [GFS2] The core o...
185

bc015cb84   Steven Whitehouse   GFS2: Use RCU for...
186
  	rcu_barrier();
37b2c8377   Steven Whitehouse   GFS2: Clean up & ...
187
  	kmem_cache_destroy(gfs2_quotad_cachep);
6bdd9be62   Bob Peterson   [GFS2] Allocate g...
188
  	kmem_cache_destroy(gfs2_rgrpd_cachep);
b3b94faa5   David Teigland   [GFS2] The core o...
189
190
  	kmem_cache_destroy(gfs2_bufdata_cachep);
  	kmem_cache_destroy(gfs2_inode_cachep);
009d85183   Steven Whitehouse   GFS2: Metadata ad...
191
  	kmem_cache_destroy(gfs2_glock_aspace_cachep);
b3b94faa5   David Teigland   [GFS2] The core o...
192
193
194
195
196
197
198
199
200
201
202
  	kmem_cache_destroy(gfs2_glock_cachep);
  
  	gfs2_sys_uninit();
  }
  
  MODULE_DESCRIPTION("Global File System");
  MODULE_AUTHOR("Red Hat, Inc.");
  MODULE_LICENSE("GPL");
  
  module_init(init_gfs2_fs);
  module_exit(exit_gfs2_fs);