]>
Commit | Line | Data |
---|---|---|
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 | ||
10 | #include <linux/sched.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/spinlock.h> | |
13 | #include <linux/completion.h> | |
14 | #include <linux/buffer_head.h> | |
b3b94faa DT |
15 | #include <linux/blkdev.h> |
16 | #include <linux/kthread.h> | |
86384605 AD |
17 | #include <linux/namei.h> |
18 | #include <linux/mount.h> | |
5c676f6d | 19 | #include <linux/gfs2_ondisk.h> |
7d308590 | 20 | #include <linux/lm_interface.h> |
b3b94faa DT |
21 | |
22 | #include "gfs2.h" | |
5c676f6d | 23 | #include "incore.h" |
b3b94faa DT |
24 | #include "daemon.h" |
25 | #include "glock.h" | |
26 | #include "glops.h" | |
27 | #include "inode.h" | |
28 | #include "lm.h" | |
29 | #include "mount.h" | |
b3b94faa DT |
30 | #include "ops_fstype.h" |
31 | #include "ops_super.h" | |
32 | #include "recovery.h" | |
33 | #include "rgrp.h" | |
34 | #include "super.h" | |
b3b94faa | 35 | #include "sys.h" |
5c676f6d | 36 | #include "util.h" |
b3b94faa DT |
37 | |
38 | #define DO 0 | |
39 | #define UNDO 1 | |
40 | ||
5bb76af1 RP |
41 | extern struct dentry_operations gfs2_dops; |
42 | ||
b3b94faa DT |
43 | static struct gfs2_sbd *init_sbd(struct super_block *sb) |
44 | { | |
45 | struct gfs2_sbd *sdp; | |
b3b94faa | 46 | |
85d1da67 | 47 | sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); |
b3b94faa DT |
48 | if (!sdp) |
49 | return NULL; | |
50 | ||
5c676f6d | 51 | sb->s_fs_info = sdp; |
b3b94faa DT |
52 | sdp->sd_vfs = sb; |
53 | ||
54 | gfs2_tune_init(&sdp->sd_tune); | |
55 | ||
b3b94faa DT |
56 | INIT_LIST_HEAD(&sdp->sd_reclaim_list); |
57 | spin_lock_init(&sdp->sd_reclaim_lock); | |
58 | init_waitqueue_head(&sdp->sd_reclaim_wq); | |
b3b94faa | 59 | |
f55ab26a | 60 | mutex_init(&sdp->sd_inum_mutex); |
b3b94faa | 61 | spin_lock_init(&sdp->sd_statfs_spin); |
f55ab26a | 62 | mutex_init(&sdp->sd_statfs_mutex); |
b3b94faa DT |
63 | |
64 | spin_lock_init(&sdp->sd_rindex_spin); | |
f55ab26a | 65 | mutex_init(&sdp->sd_rindex_mutex); |
b3b94faa DT |
66 | INIT_LIST_HEAD(&sdp->sd_rindex_list); |
67 | INIT_LIST_HEAD(&sdp->sd_rindex_mru_list); | |
68 | INIT_LIST_HEAD(&sdp->sd_rindex_recent_list); | |
69 | ||
70 | INIT_LIST_HEAD(&sdp->sd_jindex_list); | |
71 | spin_lock_init(&sdp->sd_jindex_spin); | |
f55ab26a | 72 | mutex_init(&sdp->sd_jindex_mutex); |
b3b94faa | 73 | |
b3b94faa DT |
74 | INIT_LIST_HEAD(&sdp->sd_quota_list); |
75 | spin_lock_init(&sdp->sd_quota_spin); | |
f55ab26a | 76 | mutex_init(&sdp->sd_quota_mutex); |
b3b94faa DT |
77 | |
78 | spin_lock_init(&sdp->sd_log_lock); | |
b3b94faa DT |
79 | |
80 | INIT_LIST_HEAD(&sdp->sd_log_le_gl); | |
81 | INIT_LIST_HEAD(&sdp->sd_log_le_buf); | |
82 | INIT_LIST_HEAD(&sdp->sd_log_le_revoke); | |
83 | INIT_LIST_HEAD(&sdp->sd_log_le_rg); | |
84 | INIT_LIST_HEAD(&sdp->sd_log_le_databuf); | |
85 | ||
71b86f56 | 86 | mutex_init(&sdp->sd_log_reserve_mutex); |
b3b94faa DT |
87 | INIT_LIST_HEAD(&sdp->sd_ail1_list); |
88 | INIT_LIST_HEAD(&sdp->sd_ail2_list); | |
89 | ||
484adff8 | 90 | init_rwsem(&sdp->sd_log_flush_lock); |
b3b94faa DT |
91 | INIT_LIST_HEAD(&sdp->sd_log_flush_list); |
92 | ||
93 | INIT_LIST_HEAD(&sdp->sd_revoke_list); | |
94 | ||
f55ab26a | 95 | mutex_init(&sdp->sd_freeze_lock); |
b3b94faa DT |
96 | |
97 | return sdp; | |
98 | } | |
99 | ||
419c93e0 | 100 | static void init_vfs(struct super_block *sb, unsigned noatime) |
b3b94faa | 101 | { |
419c93e0 | 102 | struct gfs2_sbd *sdp = sb->s_fs_info; |
b3b94faa DT |
103 | |
104 | sb->s_magic = GFS2_MAGIC; | |
105 | sb->s_op = &gfs2_super_ops; | |
106 | sb->s_export_op = &gfs2_export_ops; | |
4bd91ba1 | 107 | sb->s_time_gran = 1; |
b3b94faa DT |
108 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
109 | ||
110 | if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME)) | |
419c93e0 | 111 | set_bit(noatime, &sdp->sd_flags); |
b3b94faa DT |
112 | |
113 | /* Don't let the VFS update atimes. GFS2 handles this itself. */ | |
114 | sb->s_flags |= MS_NOATIME | MS_NODIRATIME; | |
b3b94faa DT |
115 | } |
116 | ||
117 | static int init_names(struct gfs2_sbd *sdp, int silent) | |
118 | { | |
b3b94faa DT |
119 | char *proto, *table; |
120 | int error = 0; | |
121 | ||
122 | proto = sdp->sd_args.ar_lockproto; | |
123 | table = sdp->sd_args.ar_locktable; | |
124 | ||
125 | /* Try to autodetect */ | |
126 | ||
127 | if (!proto[0] || !table[0]) { | |
bb8d8a6f SW |
128 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); |
129 | if (error) | |
130 | return error; | |
3cf1e7be SW |
131 | |
132 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); | |
b3b94faa DT |
133 | if (error) |
134 | goto out; | |
135 | ||
136 | if (!proto[0]) | |
3cf1e7be | 137 | proto = sdp->sd_sb.sb_lockproto; |
b3b94faa | 138 | if (!table[0]) |
3cf1e7be | 139 | table = sdp->sd_sb.sb_locktable; |
b3b94faa DT |
140 | } |
141 | ||
142 | if (!table[0]) | |
143 | table = sdp->sd_vfs->s_id; | |
144 | ||
145 | snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto); | |
146 | snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table); | |
147 | ||
a91ea69f | 148 | out: |
b3b94faa DT |
149 | return error; |
150 | } | |
151 | ||
152 | static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, | |
153 | int undo) | |
154 | { | |
155 | struct task_struct *p; | |
156 | int error = 0; | |
157 | ||
158 | if (undo) | |
159 | goto fail_trans; | |
160 | ||
161 | p = kthread_run(gfs2_scand, sdp, "gfs2_scand"); | |
162 | error = IS_ERR(p); | |
163 | if (error) { | |
164 | fs_err(sdp, "can't start scand thread: %d\n", error); | |
165 | return error; | |
166 | } | |
167 | sdp->sd_scand_process = p; | |
168 | ||
169 | for (sdp->sd_glockd_num = 0; | |
170 | sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd; | |
171 | sdp->sd_glockd_num++) { | |
172 | p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd"); | |
173 | error = IS_ERR(p); | |
174 | if (error) { | |
175 | fs_err(sdp, "can't start glockd thread: %d\n", error); | |
176 | goto fail; | |
177 | } | |
178 | sdp->sd_glockd_process[sdp->sd_glockd_num] = p; | |
179 | } | |
180 | ||
181 | error = gfs2_glock_nq_num(sdp, | |
182 | GFS2_MOUNT_LOCK, &gfs2_nondisk_glops, | |
183 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE, | |
184 | mount_gh); | |
185 | if (error) { | |
186 | fs_err(sdp, "can't acquire mount glock: %d\n", error); | |
187 | goto fail; | |
188 | } | |
189 | ||
190 | error = gfs2_glock_nq_num(sdp, | |
191 | GFS2_LIVE_LOCK, &gfs2_nondisk_glops, | |
192 | LM_ST_SHARED, | |
579b78a4 | 193 | LM_FLAG_NOEXP | GL_EXACT, |
b3b94faa DT |
194 | &sdp->sd_live_gh); |
195 | if (error) { | |
196 | fs_err(sdp, "can't acquire live glock: %d\n", error); | |
197 | goto fail_mount; | |
198 | } | |
199 | ||
200 | error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops, | |
201 | CREATE, &sdp->sd_rename_gl); | |
202 | if (error) { | |
203 | fs_err(sdp, "can't create rename glock: %d\n", error); | |
204 | goto fail_live; | |
205 | } | |
206 | ||
207 | error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops, | |
208 | CREATE, &sdp->sd_trans_gl); | |
209 | if (error) { | |
210 | fs_err(sdp, "can't create transaction glock: %d\n", error); | |
211 | goto fail_rename; | |
212 | } | |
213 | set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags); | |
214 | ||
215 | return 0; | |
216 | ||
feaa7bba | 217 | fail_trans: |
b3b94faa | 218 | gfs2_glock_put(sdp->sd_trans_gl); |
feaa7bba | 219 | fail_rename: |
b3b94faa | 220 | gfs2_glock_put(sdp->sd_rename_gl); |
feaa7bba | 221 | fail_live: |
b3b94faa | 222 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
feaa7bba | 223 | fail_mount: |
b3b94faa | 224 | gfs2_glock_dq_uninit(mount_gh); |
feaa7bba | 225 | fail: |
b3b94faa DT |
226 | while (sdp->sd_glockd_num--) |
227 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); | |
228 | ||
229 | kthread_stop(sdp->sd_scand_process); | |
b3b94faa DT |
230 | return error; |
231 | } | |
232 | ||
dbb7cae2 SW |
233 | static inline struct inode *gfs2_lookup_root(struct super_block *sb, |
234 | u64 no_addr) | |
f42faf4f | 235 | { |
dbb7cae2 | 236 | return gfs2_inode_lookup(sb, no_addr, DT_DIR); |
f42faf4f SW |
237 | } |
238 | ||
b3b94faa DT |
239 | static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) |
240 | { | |
241 | struct super_block *sb = sdp->sd_vfs; | |
242 | struct gfs2_holder sb_gh; | |
dbb7cae2 | 243 | u64 no_addr; |
f42faf4f | 244 | struct inode *inode; |
b3b94faa DT |
245 | int error = 0; |
246 | ||
247 | if (undo) { | |
88721877 RC |
248 | if (sb->s_root) { |
249 | dput(sb->s_root); | |
250 | sb->s_root = NULL; | |
251 | } | |
b3b94faa DT |
252 | return 0; |
253 | } | |
907b9bce | 254 | |
feaa7bba | 255 | error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops, |
b3b94faa DT |
256 | LM_ST_SHARED, 0, &sb_gh); |
257 | if (error) { | |
258 | fs_err(sdp, "can't acquire superblock glock: %d\n", error); | |
259 | return error; | |
260 | } | |
261 | ||
262 | error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); | |
263 | if (error) { | |
264 | fs_err(sdp, "can't read superblock: %d\n", error); | |
265 | goto out; | |
266 | } | |
267 | ||
268 | /* Set up the buffer cache and SB for real */ | |
b3b94faa | 269 | if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { |
419c93e0 | 270 | error = -EINVAL; |
b3b94faa DT |
271 | fs_err(sdp, "FS block size (%u) is too small for device " |
272 | "block size (%u)\n", | |
273 | sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); | |
274 | goto out; | |
275 | } | |
276 | if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { | |
419c93e0 | 277 | error = -EINVAL; |
b3b94faa DT |
278 | fs_err(sdp, "FS block size (%u) is too big for machine " |
279 | "page size (%u)\n", | |
280 | sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); | |
281 | goto out; | |
282 | } | |
b3b94faa DT |
283 | sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); |
284 | ||
f42faf4f | 285 | /* Get the root inode */ |
dbb7cae2 | 286 | no_addr = sdp->sd_sb.sb_root_dir.no_addr; |
419c93e0 | 287 | if (sb->s_type == &gfs2meta_fs_type) |
dbb7cae2 SW |
288 | no_addr = sdp->sd_sb.sb_master_dir.no_addr; |
289 | inode = gfs2_lookup_root(sb, no_addr); | |
c9fd4307 SW |
290 | if (IS_ERR(inode)) { |
291 | error = PTR_ERR(inode); | |
f42faf4f SW |
292 | fs_err(sdp, "can't read in root inode: %d\n", error); |
293 | goto out; | |
294 | } | |
b3b94faa | 295 | |
f42faf4f SW |
296 | sb->s_root = d_alloc_root(inode); |
297 | if (!sb->s_root) { | |
298 | fs_err(sdp, "can't get root dentry\n"); | |
299 | error = -ENOMEM; | |
c9fd4307 | 300 | iput(inode); |
f42faf4f | 301 | } |
5bb76af1 | 302 | sb->s_root->d_op = &gfs2_dops; |
f42faf4f | 303 | out: |
b3b94faa | 304 | gfs2_glock_dq_uninit(&sb_gh); |
b3b94faa DT |
305 | return error; |
306 | } | |
307 | ||
308 | static int init_journal(struct gfs2_sbd *sdp, int undo) | |
309 | { | |
310 | struct gfs2_holder ji_gh; | |
311 | struct task_struct *p; | |
5c676f6d | 312 | struct gfs2_inode *ip; |
b3b94faa DT |
313 | int jindex = 1; |
314 | int error = 0; | |
315 | ||
316 | if (undo) { | |
317 | jindex = 0; | |
318 | goto fail_recoverd; | |
319 | } | |
320 | ||
c752666c SW |
321 | sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex"); |
322 | if (IS_ERR(sdp->sd_jindex)) { | |
b3b94faa | 323 | fs_err(sdp, "can't lookup journal index: %d\n", error); |
c752666c | 324 | return PTR_ERR(sdp->sd_jindex); |
b3b94faa | 325 | } |
feaa7bba | 326 | ip = GFS2_I(sdp->sd_jindex); |
5c676f6d | 327 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
b3b94faa DT |
328 | |
329 | /* Load in the journal index special file */ | |
330 | ||
331 | error = gfs2_jindex_hold(sdp, &ji_gh); | |
332 | if (error) { | |
333 | fs_err(sdp, "can't read journal index: %d\n", error); | |
334 | goto fail; | |
335 | } | |
336 | ||
337 | error = -EINVAL; | |
338 | if (!gfs2_jindex_size(sdp)) { | |
339 | fs_err(sdp, "no journals!\n"); | |
907b9bce | 340 | goto fail_jindex; |
b3b94faa DT |
341 | } |
342 | ||
343 | if (sdp->sd_args.ar_spectator) { | |
344 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); | |
345 | sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; | |
346 | } else { | |
347 | if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { | |
348 | fs_err(sdp, "can't mount journal #%u\n", | |
349 | sdp->sd_lockstruct.ls_jid); | |
350 | fs_err(sdp, "there are only %u journals (0 - %u)\n", | |
351 | gfs2_jindex_size(sdp), | |
352 | gfs2_jindex_size(sdp) - 1); | |
353 | goto fail_jindex; | |
354 | } | |
355 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); | |
356 | ||
feaa7bba | 357 | error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid, |
b3b94faa DT |
358 | &gfs2_journal_glops, |
359 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, | |
360 | &sdp->sd_journal_gh); | |
361 | if (error) { | |
362 | fs_err(sdp, "can't acquire journal glock: %d\n", error); | |
363 | goto fail_jindex; | |
364 | } | |
365 | ||
feaa7bba SW |
366 | ip = GFS2_I(sdp->sd_jdesc->jd_inode); |
367 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, | |
b3b94faa DT |
368 | LM_FLAG_NOEXP | GL_EXACT, |
369 | &sdp->sd_jinode_gh); | |
370 | if (error) { | |
371 | fs_err(sdp, "can't acquire journal inode glock: %d\n", | |
372 | error); | |
373 | goto fail_journal_gh; | |
374 | } | |
375 | ||
376 | error = gfs2_jdesc_check(sdp->sd_jdesc); | |
377 | if (error) { | |
378 | fs_err(sdp, "my journal (%u) is bad: %d\n", | |
379 | sdp->sd_jdesc->jd_jid, error); | |
380 | goto fail_jinode_gh; | |
381 | } | |
382 | sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; | |
383 | } | |
384 | ||
385 | if (sdp->sd_lockstruct.ls_first) { | |
386 | unsigned int x; | |
387 | for (x = 0; x < sdp->sd_journals; x++) { | |
c63e31c2 | 388 | error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x)); |
b3b94faa DT |
389 | if (error) { |
390 | fs_err(sdp, "error recovering journal %u: %d\n", | |
391 | x, error); | |
392 | goto fail_jinode_gh; | |
393 | } | |
394 | } | |
395 | ||
396 | gfs2_lm_others_may_mount(sdp); | |
397 | } else if (!sdp->sd_args.ar_spectator) { | |
c63e31c2 | 398 | error = gfs2_recover_journal(sdp->sd_jdesc); |
b3b94faa DT |
399 | if (error) { |
400 | fs_err(sdp, "error recovering my journal: %d\n", error); | |
401 | goto fail_jinode_gh; | |
402 | } | |
403 | } | |
404 | ||
405 | set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags); | |
406 | gfs2_glock_dq_uninit(&ji_gh); | |
407 | jindex = 0; | |
408 | ||
b3b94faa DT |
409 | p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd"); |
410 | error = IS_ERR(p); | |
411 | if (error) { | |
412 | fs_err(sdp, "can't start recoverd thread: %d\n", error); | |
413 | goto fail_jinode_gh; | |
414 | } | |
415 | sdp->sd_recoverd_process = p; | |
416 | ||
417 | return 0; | |
418 | ||
a91ea69f | 419 | fail_recoverd: |
b3b94faa | 420 | kthread_stop(sdp->sd_recoverd_process); |
a91ea69f | 421 | fail_jinode_gh: |
b3b94faa DT |
422 | if (!sdp->sd_args.ar_spectator) |
423 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); | |
a91ea69f | 424 | fail_journal_gh: |
b3b94faa DT |
425 | if (!sdp->sd_args.ar_spectator) |
426 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); | |
a91ea69f | 427 | fail_jindex: |
b3b94faa DT |
428 | gfs2_jindex_free(sdp); |
429 | if (jindex) | |
430 | gfs2_glock_dq_uninit(&ji_gh); | |
a91ea69f | 431 | fail: |
f42faf4f | 432 | iput(sdp->sd_jindex); |
b3b94faa DT |
433 | return error; |
434 | } | |
435 | ||
b3b94faa DT |
436 | |
437 | static int init_inodes(struct gfs2_sbd *sdp, int undo) | |
438 | { | |
b3b94faa | 439 | int error = 0; |
5c676f6d | 440 | struct gfs2_inode *ip; |
c9fd4307 | 441 | struct inode *inode; |
b3b94faa DT |
442 | |
443 | if (undo) | |
f42faf4f SW |
444 | goto fail_qinode; |
445 | ||
dbb7cae2 | 446 | inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr); |
c9fd4307 SW |
447 | if (IS_ERR(inode)) { |
448 | error = PTR_ERR(inode); | |
f42faf4f SW |
449 | fs_err(sdp, "can't read in master directory: %d\n", error); |
450 | goto fail; | |
451 | } | |
c9fd4307 | 452 | sdp->sd_master_dir = inode; |
f42faf4f SW |
453 | |
454 | error = init_journal(sdp, undo); | |
455 | if (error) | |
456 | goto fail_master; | |
b3b94faa DT |
457 | |
458 | /* Read in the master inode number inode */ | |
c752666c SW |
459 | sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum"); |
460 | if (IS_ERR(sdp->sd_inum_inode)) { | |
461 | error = PTR_ERR(sdp->sd_inum_inode); | |
b3b94faa | 462 | fs_err(sdp, "can't read in inum inode: %d\n", error); |
f42faf4f | 463 | goto fail_journal; |
b3b94faa DT |
464 | } |
465 | ||
f42faf4f | 466 | |
b3b94faa | 467 | /* Read in the master statfs inode */ |
c752666c SW |
468 | sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs"); |
469 | if (IS_ERR(sdp->sd_statfs_inode)) { | |
470 | error = PTR_ERR(sdp->sd_statfs_inode); | |
b3b94faa | 471 | fs_err(sdp, "can't read in statfs inode: %d\n", error); |
f42faf4f | 472 | goto fail_inum; |
b3b94faa DT |
473 | } |
474 | ||
475 | /* Read in the resource index inode */ | |
c752666c SW |
476 | sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex"); |
477 | if (IS_ERR(sdp->sd_rindex)) { | |
478 | error = PTR_ERR(sdp->sd_rindex); | |
b3b94faa DT |
479 | fs_err(sdp, "can't get resource index inode: %d\n", error); |
480 | goto fail_statfs; | |
481 | } | |
feaa7bba | 482 | ip = GFS2_I(sdp->sd_rindex); |
5c676f6d SW |
483 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
484 | sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1; | |
b3b94faa DT |
485 | |
486 | /* Read in the quota inode */ | |
c752666c SW |
487 | sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota"); |
488 | if (IS_ERR(sdp->sd_quota_inode)) { | |
489 | error = PTR_ERR(sdp->sd_quota_inode); | |
b3b94faa DT |
490 | fs_err(sdp, "can't get quota file inode: %d\n", error); |
491 | goto fail_rindex; | |
492 | } | |
b3b94faa DT |
493 | return 0; |
494 | ||
f42faf4f SW |
495 | fail_qinode: |
496 | iput(sdp->sd_quota_inode); | |
f42faf4f | 497 | fail_rindex: |
b3b94faa | 498 | gfs2_clear_rgrpd(sdp); |
f42faf4f | 499 | iput(sdp->sd_rindex); |
f42faf4f SW |
500 | fail_statfs: |
501 | iput(sdp->sd_statfs_inode); | |
f42faf4f SW |
502 | fail_inum: |
503 | iput(sdp->sd_inum_inode); | |
504 | fail_journal: | |
505 | init_journal(sdp, UNDO); | |
506 | fail_master: | |
507 | iput(sdp->sd_master_dir); | |
508 | fail: | |
b3b94faa DT |
509 | return error; |
510 | } | |
511 | ||
512 | static int init_per_node(struct gfs2_sbd *sdp, int undo) | |
513 | { | |
f42faf4f | 514 | struct inode *pn = NULL; |
b3b94faa DT |
515 | char buf[30]; |
516 | int error = 0; | |
5c676f6d | 517 | struct gfs2_inode *ip; |
b3b94faa DT |
518 | |
519 | if (sdp->sd_args.ar_spectator) | |
520 | return 0; | |
521 | ||
522 | if (undo) | |
523 | goto fail_qc_gh; | |
524 | ||
c752666c SW |
525 | pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node"); |
526 | if (IS_ERR(pn)) { | |
527 | error = PTR_ERR(pn); | |
b3b94faa DT |
528 | fs_err(sdp, "can't find per_node directory: %d\n", error); |
529 | return error; | |
530 | } | |
531 | ||
532 | sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid); | |
c752666c SW |
533 | sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf); |
534 | if (IS_ERR(sdp->sd_ir_inode)) { | |
535 | error = PTR_ERR(sdp->sd_ir_inode); | |
b3b94faa DT |
536 | fs_err(sdp, "can't find local \"ir\" file: %d\n", error); |
537 | goto fail; | |
538 | } | |
539 | ||
540 | sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid); | |
c752666c SW |
541 | sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf); |
542 | if (IS_ERR(sdp->sd_sc_inode)) { | |
543 | error = PTR_ERR(sdp->sd_sc_inode); | |
b3b94faa DT |
544 | fs_err(sdp, "can't find local \"sc\" file: %d\n", error); |
545 | goto fail_ir_i; | |
546 | } | |
547 | ||
b3b94faa | 548 | sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); |
c752666c SW |
549 | sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); |
550 | if (IS_ERR(sdp->sd_qc_inode)) { | |
551 | error = PTR_ERR(sdp->sd_qc_inode); | |
b3b94faa DT |
552 | fs_err(sdp, "can't find local \"qc\" file: %d\n", error); |
553 | goto fail_ut_i; | |
554 | } | |
555 | ||
f42faf4f | 556 | iput(pn); |
b3b94faa DT |
557 | pn = NULL; |
558 | ||
feaa7bba | 559 | ip = GFS2_I(sdp->sd_ir_inode); |
5c676f6d | 560 | error = gfs2_glock_nq_init(ip->i_gl, |
579b78a4 | 561 | LM_ST_EXCLUSIVE, 0, |
b3b94faa DT |
562 | &sdp->sd_ir_gh); |
563 | if (error) { | |
564 | fs_err(sdp, "can't lock local \"ir\" file: %d\n", error); | |
565 | goto fail_qc_i; | |
566 | } | |
567 | ||
feaa7bba | 568 | ip = GFS2_I(sdp->sd_sc_inode); |
5c676f6d | 569 | error = gfs2_glock_nq_init(ip->i_gl, |
579b78a4 | 570 | LM_ST_EXCLUSIVE, 0, |
b3b94faa DT |
571 | &sdp->sd_sc_gh); |
572 | if (error) { | |
573 | fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); | |
574 | goto fail_ir_gh; | |
575 | } | |
576 | ||
feaa7bba | 577 | ip = GFS2_I(sdp->sd_qc_inode); |
5c676f6d | 578 | error = gfs2_glock_nq_init(ip->i_gl, |
579b78a4 | 579 | LM_ST_EXCLUSIVE, 0, |
b3b94faa DT |
580 | &sdp->sd_qc_gh); |
581 | if (error) { | |
582 | fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); | |
583 | goto fail_ut_gh; | |
584 | } | |
585 | ||
586 | return 0; | |
587 | ||
a91ea69f | 588 | fail_qc_gh: |
b3b94faa | 589 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
a91ea69f | 590 | fail_ut_gh: |
b3b94faa | 591 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
a91ea69f | 592 | fail_ir_gh: |
b3b94faa | 593 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
a91ea69f | 594 | fail_qc_i: |
f42faf4f | 595 | iput(sdp->sd_qc_inode); |
a91ea69f | 596 | fail_ut_i: |
f42faf4f | 597 | iput(sdp->sd_sc_inode); |
a91ea69f | 598 | fail_ir_i: |
f42faf4f | 599 | iput(sdp->sd_ir_inode); |
a91ea69f | 600 | fail: |
b3b94faa | 601 | if (pn) |
f42faf4f | 602 | iput(pn); |
b3b94faa DT |
603 | return error; |
604 | } | |
605 | ||
606 | static int init_threads(struct gfs2_sbd *sdp, int undo) | |
607 | { | |
608 | struct task_struct *p; | |
609 | int error = 0; | |
610 | ||
611 | if (undo) | |
feaa7bba | 612 | goto fail_quotad; |
b3b94faa DT |
613 | |
614 | sdp->sd_log_flush_time = jiffies; | |
615 | sdp->sd_jindex_refresh_time = jiffies; | |
616 | ||
617 | p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); | |
618 | error = IS_ERR(p); | |
619 | if (error) { | |
620 | fs_err(sdp, "can't start logd thread: %d\n", error); | |
621 | return error; | |
622 | } | |
623 | sdp->sd_logd_process = p; | |
624 | ||
625 | sdp->sd_statfs_sync_time = jiffies; | |
626 | sdp->sd_quota_sync_time = jiffies; | |
627 | ||
628 | p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); | |
629 | error = IS_ERR(p); | |
630 | if (error) { | |
631 | fs_err(sdp, "can't start quotad thread: %d\n", error); | |
632 | goto fail; | |
633 | } | |
634 | sdp->sd_quotad_process = p; | |
635 | ||
b3b94faa DT |
636 | return 0; |
637 | ||
b3b94faa | 638 | |
feaa7bba | 639 | fail_quotad: |
b3b94faa | 640 | kthread_stop(sdp->sd_quotad_process); |
feaa7bba | 641 | fail: |
b3b94faa | 642 | kthread_stop(sdp->sd_logd_process); |
b3b94faa DT |
643 | return error; |
644 | } | |
645 | ||
646 | /** | |
647 | * fill_super - Read in superblock | |
648 | * @sb: The VFS superblock | |
649 | * @data: Mount options | |
650 | * @silent: Don't complain if it's not a GFS2 filesystem | |
651 | * | |
652 | * Returns: errno | |
653 | */ | |
654 | ||
655 | static int fill_super(struct super_block *sb, void *data, int silent) | |
656 | { | |
657 | struct gfs2_sbd *sdp; | |
658 | struct gfs2_holder mount_gh; | |
659 | int error; | |
660 | ||
661 | sdp = init_sbd(sb); | |
662 | if (!sdp) { | |
d92a8d48 | 663 | printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n"); |
b3b94faa DT |
664 | return -ENOMEM; |
665 | } | |
666 | ||
667 | error = gfs2_mount_args(sdp, (char *)data, 0); | |
668 | if (error) { | |
d92a8d48 | 669 | printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); |
b3b94faa DT |
670 | goto fail; |
671 | } | |
672 | ||
419c93e0 SW |
673 | init_vfs(sb, SDF_NOATIME); |
674 | ||
675 | /* Set up the buffer cache and fill in some fake block size values | |
676 | to allow us to read-in the on-disk superblock. */ | |
677 | sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); | |
678 | sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; | |
679 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - | |
680 | GFS2_BASIC_BLOCK_SHIFT; | |
681 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; | |
b3b94faa DT |
682 | |
683 | error = init_names(sdp, silent); | |
684 | if (error) | |
685 | goto fail; | |
686 | ||
7c52b166 RP |
687 | gfs2_create_debugfs_file(sdp); |
688 | ||
b3b94faa DT |
689 | error = gfs2_sys_fs_add(sdp); |
690 | if (error) | |
691 | goto fail; | |
692 | ||
693 | error = gfs2_lm_mount(sdp, silent); | |
694 | if (error) | |
695 | goto fail_sys; | |
696 | ||
697 | error = init_locking(sdp, &mount_gh, DO); | |
698 | if (error) | |
699 | goto fail_lm; | |
700 | ||
701 | error = init_sb(sdp, silent, DO); | |
702 | if (error) | |
703 | goto fail_locking; | |
b3b94faa DT |
704 | |
705 | error = init_inodes(sdp, DO); | |
706 | if (error) | |
f42faf4f | 707 | goto fail_sb; |
b3b94faa DT |
708 | |
709 | error = init_per_node(sdp, DO); | |
710 | if (error) | |
711 | goto fail_inodes; | |
712 | ||
713 | error = gfs2_statfs_init(sdp); | |
714 | if (error) { | |
715 | fs_err(sdp, "can't initialize statfs subsystem: %d\n", error); | |
716 | goto fail_per_node; | |
717 | } | |
718 | ||
719 | error = init_threads(sdp, DO); | |
720 | if (error) | |
721 | goto fail_per_node; | |
722 | ||
723 | if (!(sb->s_flags & MS_RDONLY)) { | |
724 | error = gfs2_make_fs_rw(sdp); | |
725 | if (error) { | |
726 | fs_err(sdp, "can't make FS RW: %d\n", error); | |
727 | goto fail_threads; | |
728 | } | |
729 | } | |
730 | ||
731 | gfs2_glock_dq_uninit(&mount_gh); | |
732 | ||
733 | return 0; | |
734 | ||
a91ea69f | 735 | fail_threads: |
b3b94faa | 736 | init_threads(sdp, UNDO); |
a91ea69f | 737 | fail_per_node: |
b3b94faa | 738 | init_per_node(sdp, UNDO); |
a91ea69f | 739 | fail_inodes: |
b3b94faa | 740 | init_inodes(sdp, UNDO); |
a91ea69f | 741 | fail_sb: |
b3b94faa | 742 | init_sb(sdp, 0, UNDO); |
a91ea69f | 743 | fail_locking: |
b3b94faa | 744 | init_locking(sdp, &mount_gh, UNDO); |
a91ea69f | 745 | fail_lm: |
b3b94faa DT |
746 | gfs2_gl_hash_clear(sdp, WAIT); |
747 | gfs2_lm_unmount(sdp); | |
748 | while (invalidate_inodes(sb)) | |
749 | yield(); | |
a91ea69f | 750 | fail_sys: |
b3b94faa | 751 | gfs2_sys_fs_del(sdp); |
a91ea69f | 752 | fail: |
5f882096 | 753 | gfs2_delete_debugfs_file(sdp); |
a2c45807 | 754 | kfree(sdp); |
5c676f6d | 755 | sb->s_fs_info = NULL; |
b3b94faa DT |
756 | return error; |
757 | } | |
758 | ||
ccd6efd0 AM |
759 | static int gfs2_get_sb(struct file_system_type *fs_type, int flags, |
760 | const char *dev_name, void *data, struct vfsmount *mnt) | |
b3b94faa | 761 | { |
86384605 AD |
762 | struct super_block *sb; |
763 | struct gfs2_sbd *sdp; | |
764 | int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); | |
765 | if (error) | |
766 | goto out; | |
767 | sb = mnt->mnt_sb; | |
26c1a574 | 768 | sdp = sb->s_fs_info; |
86384605 AD |
769 | sdp->sd_gfs2mnt = mnt; |
770 | out: | |
771 | return error; | |
772 | } | |
773 | ||
907b9bce | 774 | static int fill_super_meta(struct super_block *sb, struct super_block *new, |
86384605 AD |
775 | void *data, int silent) |
776 | { | |
777 | struct gfs2_sbd *sdp = sb->s_fs_info; | |
778 | struct inode *inode; | |
779 | int error = 0; | |
780 | ||
781 | new->s_fs_info = sdp; | |
782 | sdp->sd_vfs_meta = sb; | |
783 | ||
784 | init_vfs(new, SDF_NOATIME); | |
785 | ||
786 | /* Get the master inode */ | |
787 | inode = igrab(sdp->sd_master_dir); | |
788 | ||
789 | new->s_root = d_alloc_root(inode); | |
790 | if (!new->s_root) { | |
791 | fs_err(sdp, "can't get root dentry\n"); | |
792 | error = -ENOMEM; | |
793 | iput(inode); | |
bbbe4512 AB |
794 | } else |
795 | new->s_root->d_op = &gfs2_dops; | |
86384605 AD |
796 | |
797 | return error; | |
798 | } | |
a91ea69f | 799 | |
86384605 AD |
800 | static int set_bdev_super(struct super_block *s, void *data) |
801 | { | |
802 | s->s_bdev = data; | |
803 | s->s_dev = s->s_bdev->bd_dev; | |
804 | return 0; | |
805 | } | |
907b9bce | 806 | |
86384605 AD |
807 | static int test_bdev_super(struct super_block *s, void *data) |
808 | { | |
26c1a574 | 809 | return s->s_bdev == data; |
86384605 AD |
810 | } |
811 | ||
812 | static struct super_block* get_gfs2_sb(const char *dev_name) | |
813 | { | |
814 | struct kstat stat; | |
815 | struct nameidata nd; | |
816 | struct file_system_type *fstype; | |
817 | struct super_block *sb = NULL, *s; | |
818 | struct list_head *l; | |
819 | int error; | |
907b9bce | 820 | |
86384605 AD |
821 | error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); |
822 | if (error) { | |
907b9bce | 823 | printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n", |
86384605 AD |
824 | dev_name); |
825 | goto out; | |
826 | } | |
827 | error = vfs_getattr(nd.mnt, nd.dentry, &stat); | |
828 | ||
829 | fstype = get_fs_type("gfs2"); | |
830 | list_for_each(l, &fstype->fs_supers) { | |
831 | s = list_entry(l, struct super_block, s_instances); | |
832 | if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) || | |
833 | (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) { | |
834 | sb = s; | |
835 | goto free_nd; | |
836 | } | |
837 | } | |
838 | ||
839 | printk(KERN_WARNING "GFS2: Unrecognized block device or " | |
d5a6751b | 840 | "mount point %s\n", dev_name); |
86384605 AD |
841 | |
842 | free_nd: | |
843 | path_release(&nd); | |
844 | out: | |
845 | return sb; | |
846 | } | |
847 | ||
848 | static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags, | |
849 | const char *dev_name, void *data, struct vfsmount *mnt) | |
850 | { | |
851 | int error = 0; | |
852 | struct super_block *sb = NULL, *new; | |
853 | struct gfs2_sbd *sdp; | |
86384605 AD |
854 | |
855 | sb = get_gfs2_sb(dev_name); | |
856 | if (!sb) { | |
857 | printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n"); | |
858 | error = -ENOENT; | |
859 | goto error; | |
860 | } | |
861 | sdp = (struct gfs2_sbd*) sb->s_fs_info; | |
862 | if (sdp->sd_vfs_meta) { | |
863 | printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n"); | |
864 | error = -EBUSY; | |
865 | goto error; | |
866 | } | |
f73ca1b7 | 867 | down(&sb->s_bdev->bd_mount_sem); |
86384605 | 868 | new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev); |
f73ca1b7 | 869 | up(&sb->s_bdev->bd_mount_sem); |
86384605 AD |
870 | if (IS_ERR(new)) { |
871 | error = PTR_ERR(new); | |
872 | goto error; | |
873 | } | |
874 | module_put(fs_type->owner); | |
875 | new->s_flags = flags; | |
876 | strlcpy(new->s_id, sb->s_id, sizeof(new->s_id)); | |
877 | sb_set_blocksize(new, sb->s_blocksize); | |
878 | error = fill_super_meta(sb, new, data, flags & MS_SILENT ? 1 : 0); | |
879 | if (error) { | |
880 | up_write(&new->s_umount); | |
881 | deactivate_super(new); | |
882 | goto error; | |
883 | } | |
907b9bce | 884 | |
86384605 | 885 | new->s_flags |= MS_ACTIVE; |
907b9bce | 886 | |
86384605 AD |
887 | /* Grab a reference to the gfs2 mount point */ |
888 | atomic_inc(&sdp->sd_gfs2mnt->mnt_count); | |
889 | return simple_set_mnt(mnt, new); | |
890 | error: | |
86384605 | 891 | return error; |
b3b94faa DT |
892 | } |
893 | ||
419c93e0 SW |
894 | static void gfs2_kill_sb(struct super_block *sb) |
895 | { | |
7c52b166 | 896 | gfs2_delete_debugfs_file(sb->s_fs_info); |
419c93e0 SW |
897 | kill_block_super(sb); |
898 | } | |
899 | ||
86384605 AD |
900 | static void gfs2_kill_sb_meta(struct super_block *sb) |
901 | { | |
902 | struct gfs2_sbd *sdp = sb->s_fs_info; | |
903 | generic_shutdown_super(sb); | |
904 | sdp->sd_vfs_meta = NULL; | |
905 | atomic_dec(&sdp->sd_gfs2mnt->mnt_count); | |
906 | } | |
907 | ||
b3b94faa DT |
908 | struct file_system_type gfs2_fs_type = { |
909 | .name = "gfs2", | |
910 | .fs_flags = FS_REQUIRES_DEV, | |
911 | .get_sb = gfs2_get_sb, | |
419c93e0 SW |
912 | .kill_sb = gfs2_kill_sb, |
913 | .owner = THIS_MODULE, | |
914 | }; | |
915 | ||
916 | struct file_system_type gfs2meta_fs_type = { | |
917 | .name = "gfs2meta", | |
918 | .fs_flags = FS_REQUIRES_DEV, | |
86384605 AD |
919 | .get_sb = gfs2_get_sb_meta, |
920 | .kill_sb = gfs2_kill_sb_meta, | |
b3b94faa DT |
921 | .owner = THIS_MODULE, |
922 | }; | |
923 |