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