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