2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
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 version 2.
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/blkdev.h>
16 #include <linux/kthread.h>
17 #include <linux/namei.h>
18 #include <linux/mount.h>
19 #include <linux/gfs2_ondisk.h>
20 #include <linux/lm_interface.h>
30 #include "ops_fstype.h"
31 #include "ops_dentry.h"
32 #include "ops_super.h"
43 static struct gfs2_sbd
*init_sbd(struct super_block
*sb
)
47 sdp
= kzalloc(sizeof(struct gfs2_sbd
), GFP_KERNEL
);
54 gfs2_tune_init(&sdp
->sd_tune
);
56 INIT_LIST_HEAD(&sdp
->sd_reclaim_list
);
57 spin_lock_init(&sdp
->sd_reclaim_lock
);
58 init_waitqueue_head(&sdp
->sd_reclaim_wq
);
60 mutex_init(&sdp
->sd_inum_mutex
);
61 spin_lock_init(&sdp
->sd_statfs_spin
);
63 spin_lock_init(&sdp
->sd_rindex_spin
);
64 mutex_init(&sdp
->sd_rindex_mutex
);
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
);
69 INIT_LIST_HEAD(&sdp
->sd_jindex_list
);
70 spin_lock_init(&sdp
->sd_jindex_spin
);
71 mutex_init(&sdp
->sd_jindex_mutex
);
73 INIT_LIST_HEAD(&sdp
->sd_quota_list
);
74 spin_lock_init(&sdp
->sd_quota_spin
);
75 mutex_init(&sdp
->sd_quota_mutex
);
77 spin_lock_init(&sdp
->sd_log_lock
);
79 INIT_LIST_HEAD(&sdp
->sd_log_le_buf
);
80 INIT_LIST_HEAD(&sdp
->sd_log_le_revoke
);
81 INIT_LIST_HEAD(&sdp
->sd_log_le_rg
);
82 INIT_LIST_HEAD(&sdp
->sd_log_le_databuf
);
83 INIT_LIST_HEAD(&sdp
->sd_log_le_ordered
);
85 mutex_init(&sdp
->sd_log_reserve_mutex
);
86 INIT_LIST_HEAD(&sdp
->sd_ail1_list
);
87 INIT_LIST_HEAD(&sdp
->sd_ail2_list
);
89 init_rwsem(&sdp
->sd_log_flush_lock
);
90 atomic_set(&sdp
->sd_log_in_flight
, 0);
91 init_waitqueue_head(&sdp
->sd_log_flush_wait
);
93 INIT_LIST_HEAD(&sdp
->sd_revoke_list
);
95 mutex_init(&sdp
->sd_freeze_lock
);
100 static void init_vfs(struct super_block
*sb
, unsigned noatime
)
102 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
104 sb
->s_magic
= GFS2_MAGIC
;
105 sb
->s_op
= &gfs2_super_ops
;
106 sb
->s_export_op
= &gfs2_export_ops
;
108 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
110 if (sb
->s_flags
& (MS_NOATIME
| MS_NODIRATIME
))
111 set_bit(noatime
, &sdp
->sd_flags
);
113 /* Don't let the VFS update atimes. GFS2 handles this itself. */
114 sb
->s_flags
|= MS_NOATIME
| MS_NODIRATIME
;
117 static int init_names(struct gfs2_sbd
*sdp
, int silent
)
122 proto
= sdp
->sd_args
.ar_lockproto
;
123 table
= sdp
->sd_args
.ar_locktable
;
125 /* Try to autodetect */
127 if (!proto
[0] || !table
[0]) {
128 error
= gfs2_read_super(sdp
, GFS2_SB_ADDR
>> sdp
->sd_fsb2bb_shift
);
132 error
= gfs2_check_sb(sdp
, &sdp
->sd_sb
, silent
);
137 proto
= sdp
->sd_sb
.sb_lockproto
;
139 table
= sdp
->sd_sb
.sb_locktable
;
143 table
= sdp
->sd_vfs
->s_id
;
145 strlcpy(sdp
->sd_proto_name
, proto
, GFS2_FSNAME_LEN
);
146 strlcpy(sdp
->sd_table_name
, table
, GFS2_FSNAME_LEN
);
148 table
= sdp
->sd_table_name
;
149 while ((table
= strchr(table
, '/')))
156 static int init_locking(struct gfs2_sbd
*sdp
, struct gfs2_holder
*mount_gh
,
159 struct task_struct
*p
;
165 for (sdp
->sd_glockd_num
= 0;
166 sdp
->sd_glockd_num
< sdp
->sd_args
.ar_num_glockd
;
167 sdp
->sd_glockd_num
++) {
168 p
= kthread_run(gfs2_glockd
, sdp
, "gfs2_glockd");
171 fs_err(sdp
, "can't start glockd thread: %d\n", error
);
174 sdp
->sd_glockd_process
[sdp
->sd_glockd_num
] = p
;
177 error
= gfs2_glock_nq_num(sdp
,
178 GFS2_MOUNT_LOCK
, &gfs2_nondisk_glops
,
179 LM_ST_EXCLUSIVE
, LM_FLAG_NOEXP
| GL_NOCACHE
,
182 fs_err(sdp
, "can't acquire mount glock: %d\n", error
);
186 error
= gfs2_glock_nq_num(sdp
,
187 GFS2_LIVE_LOCK
, &gfs2_nondisk_glops
,
189 LM_FLAG_NOEXP
| GL_EXACT
,
192 fs_err(sdp
, "can't acquire live glock: %d\n", error
);
196 error
= gfs2_glock_get(sdp
, GFS2_RENAME_LOCK
, &gfs2_nondisk_glops
,
197 CREATE
, &sdp
->sd_rename_gl
);
199 fs_err(sdp
, "can't create rename glock: %d\n", error
);
203 error
= gfs2_glock_get(sdp
, GFS2_TRANS_LOCK
, &gfs2_trans_glops
,
204 CREATE
, &sdp
->sd_trans_gl
);
206 fs_err(sdp
, "can't create transaction glock: %d\n", error
);
209 set_bit(GLF_STICKY
, &sdp
->sd_trans_gl
->gl_flags
);
214 gfs2_glock_put(sdp
->sd_trans_gl
);
216 gfs2_glock_put(sdp
->sd_rename_gl
);
218 gfs2_glock_dq_uninit(&sdp
->sd_live_gh
);
220 gfs2_glock_dq_uninit(mount_gh
);
222 while (sdp
->sd_glockd_num
--)
223 kthread_stop(sdp
->sd_glockd_process
[sdp
->sd_glockd_num
]);
228 static inline struct inode
*gfs2_lookup_root(struct super_block
*sb
,
231 return gfs2_inode_lookup(sb
, DT_DIR
, no_addr
, 0, 0);
234 static int init_sb(struct gfs2_sbd
*sdp
, int silent
, int undo
)
236 struct super_block
*sb
= sdp
->sd_vfs
;
237 struct gfs2_holder sb_gh
;
250 error
= gfs2_glock_nq_num(sdp
, GFS2_SB_LOCK
, &gfs2_meta_glops
,
251 LM_ST_SHARED
, 0, &sb_gh
);
253 fs_err(sdp
, "can't acquire superblock glock: %d\n", error
);
257 error
= gfs2_read_sb(sdp
, sb_gh
.gh_gl
, silent
);
259 fs_err(sdp
, "can't read superblock: %d\n", error
);
263 /* Set up the buffer cache and SB for real */
264 if (sdp
->sd_sb
.sb_bsize
< bdev_hardsect_size(sb
->s_bdev
)) {
266 fs_err(sdp
, "FS block size (%u) is too small for device "
268 sdp
->sd_sb
.sb_bsize
, bdev_hardsect_size(sb
->s_bdev
));
271 if (sdp
->sd_sb
.sb_bsize
> PAGE_SIZE
) {
273 fs_err(sdp
, "FS block size (%u) is too big for machine "
275 sdp
->sd_sb
.sb_bsize
, (unsigned int)PAGE_SIZE
);
278 sb_set_blocksize(sb
, sdp
->sd_sb
.sb_bsize
);
280 /* Get the root inode */
281 no_addr
= sdp
->sd_sb
.sb_root_dir
.no_addr
;
282 if (sb
->s_type
== &gfs2meta_fs_type
)
283 no_addr
= sdp
->sd_sb
.sb_master_dir
.no_addr
;
284 inode
= gfs2_lookup_root(sb
, no_addr
);
286 error
= PTR_ERR(inode
);
287 fs_err(sdp
, "can't read in root inode: %d\n", error
);
291 sb
->s_root
= d_alloc_root(inode
);
293 fs_err(sdp
, "can't get root dentry\n");
297 sb
->s_root
->d_op
= &gfs2_dops
;
300 gfs2_glock_dq_uninit(&sb_gh
);
305 * map_journal_extents - create a reusable "extent" mapping from all logical
306 * blocks to all physical blocks for the given journal. This will save
307 * us time when writing journal blocks. Most journals will have only one
308 * extent that maps all their logical blocks. That's because gfs2.mkfs
309 * arranges the journal blocks sequentially to maximize performance.
310 * So the extent would map the first block for the entire file length.
311 * However, gfs2_jadd can happen while file activity is happening, so
312 * those journals may not be sequential. Less likely is the case where
313 * the users created their own journals by mounting the metafs and
314 * laying it out. But it's still possible. These journals might have
317 * TODO: This should be done in bigger chunks rather than one block at a time,
318 * but since it's only done at mount time, I'm not worried about the
321 static int map_journal_extents(struct gfs2_sbd
*sdp
)
323 struct gfs2_jdesc
*jd
= sdp
->sd_jdesc
;
325 u64 db
, prev_db
; /* logical block, disk block, prev disk block */
326 struct gfs2_inode
*ip
= GFS2_I(jd
->jd_inode
);
327 struct gfs2_journal_extent
*jext
= NULL
;
328 struct buffer_head bh
;
333 for (lb
= 0; lb
< ip
->i_di
.di_size
>> sdp
->sd_sb
.sb_bsize_shift
; lb
++) {
336 bh
.b_size
= 1 << ip
->i_inode
.i_blkbits
;
337 rc
= gfs2_block_map(jd
->jd_inode
, lb
, &bh
, 0);
340 printk(KERN_INFO
"GFS2 journal mapping error %d: lb="
341 "%u db=%llu\n", rc
, lb
, (unsigned long long)db
);
344 if (!prev_db
|| db
!= prev_db
+ 1) {
345 jext
= kzalloc(sizeof(struct gfs2_journal_extent
),
348 printk(KERN_INFO
"GFS2 error: out of memory "
349 "mapping journal extents.\n");
356 list_add_tail(&jext
->extent_list
, &jd
->extent_list
);
365 static void gfs2_lm_others_may_mount(struct gfs2_sbd
*sdp
)
367 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
368 sdp
->sd_lockstruct
.ls_ops
->lm_others_may_mount(
369 sdp
->sd_lockstruct
.ls_lockspace
);
372 static int init_journal(struct gfs2_sbd
*sdp
, int undo
)
374 struct gfs2_holder ji_gh
;
375 struct task_struct
*p
;
376 struct gfs2_inode
*ip
;
385 sdp
->sd_jindex
= gfs2_lookup_simple(sdp
->sd_master_dir
, "jindex");
386 if (IS_ERR(sdp
->sd_jindex
)) {
387 fs_err(sdp
, "can't lookup journal index: %d\n", error
);
388 return PTR_ERR(sdp
->sd_jindex
);
390 ip
= GFS2_I(sdp
->sd_jindex
);
391 set_bit(GLF_STICKY
, &ip
->i_gl
->gl_flags
);
393 /* Load in the journal index special file */
395 error
= gfs2_jindex_hold(sdp
, &ji_gh
);
397 fs_err(sdp
, "can't read journal index: %d\n", error
);
402 if (!gfs2_jindex_size(sdp
)) {
403 fs_err(sdp
, "no journals!\n");
407 if (sdp
->sd_args
.ar_spectator
) {
408 sdp
->sd_jdesc
= gfs2_jdesc_find(sdp
, 0);
409 atomic_set(&sdp
->sd_log_blks_free
, sdp
->sd_jdesc
->jd_blocks
);
411 if (sdp
->sd_lockstruct
.ls_jid
>= gfs2_jindex_size(sdp
)) {
412 fs_err(sdp
, "can't mount journal #%u\n",
413 sdp
->sd_lockstruct
.ls_jid
);
414 fs_err(sdp
, "there are only %u journals (0 - %u)\n",
415 gfs2_jindex_size(sdp
),
416 gfs2_jindex_size(sdp
) - 1);
419 sdp
->sd_jdesc
= gfs2_jdesc_find(sdp
, sdp
->sd_lockstruct
.ls_jid
);
421 error
= gfs2_glock_nq_num(sdp
, sdp
->sd_lockstruct
.ls_jid
,
423 LM_ST_EXCLUSIVE
, LM_FLAG_NOEXP
,
424 &sdp
->sd_journal_gh
);
426 fs_err(sdp
, "can't acquire journal glock: %d\n", error
);
430 ip
= GFS2_I(sdp
->sd_jdesc
->jd_inode
);
431 error
= gfs2_glock_nq_init(ip
->i_gl
, LM_ST_SHARED
,
432 LM_FLAG_NOEXP
| GL_EXACT
| GL_NOCACHE
,
435 fs_err(sdp
, "can't acquire journal inode glock: %d\n",
437 goto fail_journal_gh
;
440 error
= gfs2_jdesc_check(sdp
->sd_jdesc
);
442 fs_err(sdp
, "my journal (%u) is bad: %d\n",
443 sdp
->sd_jdesc
->jd_jid
, error
);
446 atomic_set(&sdp
->sd_log_blks_free
, sdp
->sd_jdesc
->jd_blocks
);
448 /* Map the extents for this journal's blocks */
449 map_journal_extents(sdp
);
452 if (sdp
->sd_lockstruct
.ls_first
) {
454 for (x
= 0; x
< sdp
->sd_journals
; x
++) {
455 error
= gfs2_recover_journal(gfs2_jdesc_find(sdp
, x
));
457 fs_err(sdp
, "error recovering journal %u: %d\n",
463 gfs2_lm_others_may_mount(sdp
);
464 } else if (!sdp
->sd_args
.ar_spectator
) {
465 error
= gfs2_recover_journal(sdp
->sd_jdesc
);
467 fs_err(sdp
, "error recovering my journal: %d\n", error
);
472 set_bit(SDF_JOURNAL_CHECKED
, &sdp
->sd_flags
);
473 gfs2_glock_dq_uninit(&ji_gh
);
476 p
= kthread_run(gfs2_recoverd
, sdp
, "gfs2_recoverd");
479 fs_err(sdp
, "can't start recoverd thread: %d\n", error
);
482 sdp
->sd_recoverd_process
= p
;
487 kthread_stop(sdp
->sd_recoverd_process
);
489 if (!sdp
->sd_args
.ar_spectator
)
490 gfs2_glock_dq_uninit(&sdp
->sd_jinode_gh
);
492 if (!sdp
->sd_args
.ar_spectator
)
493 gfs2_glock_dq_uninit(&sdp
->sd_journal_gh
);
495 gfs2_jindex_free(sdp
);
497 gfs2_glock_dq_uninit(&ji_gh
);
499 iput(sdp
->sd_jindex
);
504 static int init_inodes(struct gfs2_sbd
*sdp
, int undo
)
507 struct gfs2_inode
*ip
;
513 inode
= gfs2_lookup_root(sdp
->sd_vfs
, sdp
->sd_sb
.sb_master_dir
.no_addr
);
515 error
= PTR_ERR(inode
);
516 fs_err(sdp
, "can't read in master directory: %d\n", error
);
519 sdp
->sd_master_dir
= inode
;
521 error
= init_journal(sdp
, undo
);
525 /* Read in the master inode number inode */
526 sdp
->sd_inum_inode
= gfs2_lookup_simple(sdp
->sd_master_dir
, "inum");
527 if (IS_ERR(sdp
->sd_inum_inode
)) {
528 error
= PTR_ERR(sdp
->sd_inum_inode
);
529 fs_err(sdp
, "can't read in inum inode: %d\n", error
);
534 /* Read in the master statfs inode */
535 sdp
->sd_statfs_inode
= gfs2_lookup_simple(sdp
->sd_master_dir
, "statfs");
536 if (IS_ERR(sdp
->sd_statfs_inode
)) {
537 error
= PTR_ERR(sdp
->sd_statfs_inode
);
538 fs_err(sdp
, "can't read in statfs inode: %d\n", error
);
542 /* Read in the resource index inode */
543 sdp
->sd_rindex
= gfs2_lookup_simple(sdp
->sd_master_dir
, "rindex");
544 if (IS_ERR(sdp
->sd_rindex
)) {
545 error
= PTR_ERR(sdp
->sd_rindex
);
546 fs_err(sdp
, "can't get resource index inode: %d\n", error
);
549 ip
= GFS2_I(sdp
->sd_rindex
);
550 set_bit(GLF_STICKY
, &ip
->i_gl
->gl_flags
);
551 sdp
->sd_rindex_uptodate
= 0;
553 /* Read in the quota inode */
554 sdp
->sd_quota_inode
= gfs2_lookup_simple(sdp
->sd_master_dir
, "quota");
555 if (IS_ERR(sdp
->sd_quota_inode
)) {
556 error
= PTR_ERR(sdp
->sd_quota_inode
);
557 fs_err(sdp
, "can't get quota file inode: %d\n", error
);
563 iput(sdp
->sd_quota_inode
);
565 gfs2_clear_rgrpd(sdp
);
566 iput(sdp
->sd_rindex
);
568 iput(sdp
->sd_statfs_inode
);
570 iput(sdp
->sd_inum_inode
);
572 init_journal(sdp
, UNDO
);
574 iput(sdp
->sd_master_dir
);
579 static int init_per_node(struct gfs2_sbd
*sdp
, int undo
)
581 struct inode
*pn
= NULL
;
584 struct gfs2_inode
*ip
;
586 if (sdp
->sd_args
.ar_spectator
)
592 pn
= gfs2_lookup_simple(sdp
->sd_master_dir
, "per_node");
595 fs_err(sdp
, "can't find per_node directory: %d\n", error
);
599 sprintf(buf
, "inum_range%u", sdp
->sd_jdesc
->jd_jid
);
600 sdp
->sd_ir_inode
= gfs2_lookup_simple(pn
, buf
);
601 if (IS_ERR(sdp
->sd_ir_inode
)) {
602 error
= PTR_ERR(sdp
->sd_ir_inode
);
603 fs_err(sdp
, "can't find local \"ir\" file: %d\n", error
);
607 sprintf(buf
, "statfs_change%u", sdp
->sd_jdesc
->jd_jid
);
608 sdp
->sd_sc_inode
= gfs2_lookup_simple(pn
, buf
);
609 if (IS_ERR(sdp
->sd_sc_inode
)) {
610 error
= PTR_ERR(sdp
->sd_sc_inode
);
611 fs_err(sdp
, "can't find local \"sc\" file: %d\n", error
);
615 sprintf(buf
, "quota_change%u", sdp
->sd_jdesc
->jd_jid
);
616 sdp
->sd_qc_inode
= gfs2_lookup_simple(pn
, buf
);
617 if (IS_ERR(sdp
->sd_qc_inode
)) {
618 error
= PTR_ERR(sdp
->sd_qc_inode
);
619 fs_err(sdp
, "can't find local \"qc\" file: %d\n", error
);
626 ip
= GFS2_I(sdp
->sd_ir_inode
);
627 error
= gfs2_glock_nq_init(ip
->i_gl
,
631 fs_err(sdp
, "can't lock local \"ir\" file: %d\n", error
);
635 ip
= GFS2_I(sdp
->sd_sc_inode
);
636 error
= gfs2_glock_nq_init(ip
->i_gl
,
640 fs_err(sdp
, "can't lock local \"sc\" file: %d\n", error
);
644 ip
= GFS2_I(sdp
->sd_qc_inode
);
645 error
= gfs2_glock_nq_init(ip
->i_gl
,
649 fs_err(sdp
, "can't lock local \"qc\" file: %d\n", error
);
656 gfs2_glock_dq_uninit(&sdp
->sd_qc_gh
);
658 gfs2_glock_dq_uninit(&sdp
->sd_sc_gh
);
660 gfs2_glock_dq_uninit(&sdp
->sd_ir_gh
);
662 iput(sdp
->sd_qc_inode
);
664 iput(sdp
->sd_sc_inode
);
666 iput(sdp
->sd_ir_inode
);
673 static int init_threads(struct gfs2_sbd
*sdp
, int undo
)
675 struct task_struct
*p
;
681 sdp
->sd_log_flush_time
= jiffies
;
682 sdp
->sd_jindex_refresh_time
= jiffies
;
684 p
= kthread_run(gfs2_logd
, sdp
, "gfs2_logd");
687 fs_err(sdp
, "can't start logd thread: %d\n", error
);
690 sdp
->sd_logd_process
= p
;
692 sdp
->sd_statfs_sync_time
= jiffies
;
693 sdp
->sd_quota_sync_time
= jiffies
;
695 p
= kthread_run(gfs2_quotad
, sdp
, "gfs2_quotad");
698 fs_err(sdp
, "can't start quotad thread: %d\n", error
);
701 sdp
->sd_quotad_process
= p
;
707 kthread_stop(sdp
->sd_quotad_process
);
709 kthread_stop(sdp
->sd_logd_process
);
714 * gfs2_lm_mount - mount a locking protocol
715 * @sdp: the filesystem
716 * @args: mount arguements
717 * @silent: if 1, don't complain if the FS isn't a GFS2 fs
722 static int gfs2_lm_mount(struct gfs2_sbd
*sdp
, int silent
)
724 char *proto
= sdp
->sd_proto_name
;
725 char *table
= sdp
->sd_table_name
;
726 int flags
= LM_MFLAG_CONV_NODROP
;
729 if (sdp
->sd_args
.ar_spectator
)
730 flags
|= LM_MFLAG_SPECTATOR
;
732 fs_info(sdp
, "Trying to join cluster \"%s\", \"%s\"\n", proto
, table
);
734 error
= gfs2_mount_lockproto(proto
, table
, sdp
->sd_args
.ar_hostdata
,
736 GFS2_MIN_LVB_SIZE
, flags
,
737 &sdp
->sd_lockstruct
, &sdp
->sd_kobj
);
739 fs_info(sdp
, "can't mount proto=%s, table=%s, hostdata=%s\n",
740 proto
, table
, sdp
->sd_args
.ar_hostdata
);
744 if (gfs2_assert_warn(sdp
, sdp
->sd_lockstruct
.ls_lockspace
) ||
745 gfs2_assert_warn(sdp
, sdp
->sd_lockstruct
.ls_ops
) ||
746 gfs2_assert_warn(sdp
, sdp
->sd_lockstruct
.ls_lvb_size
>=
747 GFS2_MIN_LVB_SIZE
)) {
748 gfs2_unmount_lockproto(&sdp
->sd_lockstruct
);
752 if (sdp
->sd_args
.ar_spectator
)
753 snprintf(sdp
->sd_fsname
, GFS2_FSNAME_LEN
, "%s.s", table
);
755 snprintf(sdp
->sd_fsname
, GFS2_FSNAME_LEN
, "%s.%u", table
,
756 sdp
->sd_lockstruct
.ls_jid
);
758 fs_info(sdp
, "Joined cluster. Now mounting FS...\n");
760 if ((sdp
->sd_lockstruct
.ls_flags
& LM_LSFLAG_LOCAL
) &&
761 !sdp
->sd_args
.ar_ignore_local_fs
) {
762 sdp
->sd_args
.ar_localflocks
= 1;
763 sdp
->sd_args
.ar_localcaching
= 1;
770 void gfs2_lm_unmount(struct gfs2_sbd
*sdp
)
772 if (likely(!test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
)))
773 gfs2_unmount_lockproto(&sdp
->sd_lockstruct
);
777 * fill_super - Read in superblock
778 * @sb: The VFS superblock
779 * @data: Mount options
780 * @silent: Don't complain if it's not a GFS2 filesystem
785 static int fill_super(struct super_block
*sb
, void *data
, int silent
)
787 struct gfs2_sbd
*sdp
;
788 struct gfs2_holder mount_gh
;
793 printk(KERN_WARNING
"GFS2: can't alloc struct gfs2_sbd\n");
797 error
= gfs2_mount_args(sdp
, (char *)data
, 0);
799 printk(KERN_WARNING
"GFS2: can't parse mount arguments\n");
803 init_vfs(sb
, SDF_NOATIME
);
805 /* Set up the buffer cache and fill in some fake block size values
806 to allow us to read-in the on-disk superblock. */
807 sdp
->sd_sb
.sb_bsize
= sb_min_blocksize(sb
, GFS2_BASIC_BLOCK
);
808 sdp
->sd_sb
.sb_bsize_shift
= sb
->s_blocksize_bits
;
809 sdp
->sd_fsb2bb_shift
= sdp
->sd_sb
.sb_bsize_shift
-
810 GFS2_BASIC_BLOCK_SHIFT
;
811 sdp
->sd_fsb2bb
= 1 << sdp
->sd_fsb2bb_shift
;
813 error
= init_names(sdp
, silent
);
817 gfs2_create_debugfs_file(sdp
);
819 error
= gfs2_sys_fs_add(sdp
);
823 error
= gfs2_lm_mount(sdp
, silent
);
827 error
= init_locking(sdp
, &mount_gh
, DO
);
831 error
= init_sb(sdp
, silent
, DO
);
835 error
= init_inodes(sdp
, DO
);
839 error
= init_per_node(sdp
, DO
);
843 error
= gfs2_statfs_init(sdp
);
845 fs_err(sdp
, "can't initialize statfs subsystem: %d\n", error
);
849 error
= init_threads(sdp
, DO
);
853 if (!(sb
->s_flags
& MS_RDONLY
)) {
854 error
= gfs2_make_fs_rw(sdp
);
856 fs_err(sdp
, "can't make FS RW: %d\n", error
);
861 gfs2_glock_dq_uninit(&mount_gh
);
866 init_threads(sdp
, UNDO
);
868 init_per_node(sdp
, UNDO
);
870 init_inodes(sdp
, UNDO
);
872 init_sb(sdp
, 0, UNDO
);
874 init_locking(sdp
, &mount_gh
, UNDO
);
876 gfs2_gl_hash_clear(sdp
, WAIT
);
877 gfs2_lm_unmount(sdp
);
878 while (invalidate_inodes(sb
))
881 gfs2_sys_fs_del(sdp
);
883 gfs2_delete_debugfs_file(sdp
);
885 sb
->s_fs_info
= NULL
;
889 static int gfs2_get_sb(struct file_system_type
*fs_type
, int flags
,
890 const char *dev_name
, void *data
, struct vfsmount
*mnt
)
892 struct super_block
*sb
;
893 struct gfs2_sbd
*sdp
;
894 int error
= get_sb_bdev(fs_type
, flags
, dev_name
, data
, fill_super
, mnt
);
899 sdp
->sd_gfs2mnt
= mnt
;
904 static int fill_super_meta(struct super_block
*sb
, struct super_block
*new,
905 void *data
, int silent
)
907 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
911 new->s_fs_info
= sdp
;
912 sdp
->sd_vfs_meta
= sb
;
914 init_vfs(new, SDF_NOATIME
);
916 /* Get the master inode */
917 inode
= igrab(sdp
->sd_master_dir
);
919 new->s_root
= d_alloc_root(inode
);
921 fs_err(sdp
, "can't get root dentry\n");
925 new->s_root
->d_op
= &gfs2_dops
;
930 static int set_bdev_super(struct super_block
*s
, void *data
)
933 s
->s_dev
= s
->s_bdev
->bd_dev
;
937 static int test_bdev_super(struct super_block
*s
, void *data
)
939 return s
->s_bdev
== data
;
942 static struct super_block
* get_gfs2_sb(const char *dev_name
)
946 struct super_block
*sb
= NULL
, *s
;
949 error
= path_lookup(dev_name
, LOOKUP_FOLLOW
, &nd
);
951 printk(KERN_WARNING
"GFS2: path_lookup on %s returned error\n",
955 error
= vfs_getattr(nd
.path
.mnt
, nd
.path
.dentry
, &stat
);
957 list_for_each_entry(s
, &gfs2_fs_type
.fs_supers
, s_instances
) {
958 if ((S_ISBLK(stat
.mode
) && s
->s_dev
== stat
.rdev
) ||
959 (S_ISDIR(stat
.mode
) &&
960 s
== nd
.path
.dentry
->d_inode
->i_sb
)) {
966 printk(KERN_WARNING
"GFS2: Unrecognized block device or "
967 "mount point %s\n", dev_name
);
975 static int gfs2_get_sb_meta(struct file_system_type
*fs_type
, int flags
,
976 const char *dev_name
, void *data
, struct vfsmount
*mnt
)
979 struct super_block
*sb
= NULL
, *new;
980 struct gfs2_sbd
*sdp
;
982 sb
= get_gfs2_sb(dev_name
);
984 printk(KERN_WARNING
"GFS2: gfs2 mount does not exist\n");
989 if (sdp
->sd_vfs_meta
) {
990 printk(KERN_WARNING
"GFS2: gfs2meta mount already exists\n");
994 down(&sb
->s_bdev
->bd_mount_sem
);
995 new = sget(fs_type
, test_bdev_super
, set_bdev_super
, sb
->s_bdev
);
996 up(&sb
->s_bdev
->bd_mount_sem
);
998 error
= PTR_ERR(new);
1001 new->s_flags
= flags
;
1002 strlcpy(new->s_id
, sb
->s_id
, sizeof(new->s_id
));
1003 sb_set_blocksize(new, sb
->s_blocksize
);
1004 error
= fill_super_meta(sb
, new, data
, flags
& MS_SILENT
? 1 : 0);
1006 up_write(&new->s_umount
);
1007 deactivate_super(new);
1011 new->s_flags
|= MS_ACTIVE
;
1013 /* Grab a reference to the gfs2 mount point */
1014 atomic_inc(&sdp
->sd_gfs2mnt
->mnt_count
);
1015 return simple_set_mnt(mnt
, new);
1020 static void gfs2_kill_sb(struct super_block
*sb
)
1022 if (sb
->s_fs_info
) {
1023 gfs2_delete_debugfs_file(sb
->s_fs_info
);
1024 gfs2_meta_syncfs(sb
->s_fs_info
);
1026 kill_block_super(sb
);
1029 static void gfs2_kill_sb_meta(struct super_block
*sb
)
1031 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
1032 generic_shutdown_super(sb
);
1033 sdp
->sd_vfs_meta
= NULL
;
1034 atomic_dec(&sdp
->sd_gfs2mnt
->mnt_count
);
1037 struct file_system_type gfs2_fs_type
= {
1039 .fs_flags
= FS_REQUIRES_DEV
,
1040 .get_sb
= gfs2_get_sb
,
1041 .kill_sb
= gfs2_kill_sb
,
1042 .owner
= THIS_MODULE
,
1045 struct file_system_type gfs2meta_fs_type
= {
1047 .fs_flags
= FS_REQUIRES_DEV
,
1048 .get_sb
= gfs2_get_sb_meta
,
1049 .kill_sb
= gfs2_kill_sb_meta
,
1050 .owner
= THIS_MODULE
,