2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2007 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>
31 #include "ops_fstype.h"
32 #include "ops_dentry.h"
33 #include "ops_super.h"
44 static struct gfs2_sbd *init_sbd(struct super_block *sb)
48 sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
55 gfs2_tune_init(&sdp->sd_tune);
57 INIT_LIST_HEAD(&sdp->sd_reclaim_list);
58 spin_lock_init(&sdp->sd_reclaim_lock);
59 init_waitqueue_head(&sdp->sd_reclaim_wq);
61 mutex_init(&sdp->sd_inum_mutex);
62 spin_lock_init(&sdp->sd_statfs_spin);
64 spin_lock_init(&sdp->sd_rindex_spin);
65 mutex_init(&sdp->sd_rindex_mutex);
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);
70 INIT_LIST_HEAD(&sdp->sd_jindex_list);
71 spin_lock_init(&sdp->sd_jindex_spin);
72 mutex_init(&sdp->sd_jindex_mutex);
74 INIT_LIST_HEAD(&sdp->sd_quota_list);
75 spin_lock_init(&sdp->sd_quota_spin);
76 mutex_init(&sdp->sd_quota_mutex);
78 spin_lock_init(&sdp->sd_log_lock);
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 INIT_LIST_HEAD(&sdp->sd_log_le_ordered);
86 mutex_init(&sdp->sd_log_reserve_mutex);
87 INIT_LIST_HEAD(&sdp->sd_ail1_list);
88 INIT_LIST_HEAD(&sdp->sd_ail2_list);
90 init_rwsem(&sdp->sd_log_flush_lock);
91 atomic_set(&sdp->sd_log_in_flight, 0);
92 init_waitqueue_head(&sdp->sd_log_flush_wait);
94 INIT_LIST_HEAD(&sdp->sd_revoke_list);
96 mutex_init(&sdp->sd_freeze_lock);
101 static void init_vfs(struct super_block *sb, unsigned noatime)
103 struct gfs2_sbd *sdp = sb->s_fs_info;
105 sb->s_magic = GFS2_MAGIC;
106 sb->s_op = &gfs2_super_ops;
107 sb->s_export_op = &gfs2_export_ops;
109 sb->s_maxbytes = MAX_LFS_FILESIZE;
111 if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME))
112 set_bit(noatime, &sdp->sd_flags);
114 /* Don't let the VFS update atimes. GFS2 handles this itself. */
115 sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
118 static int init_names(struct gfs2_sbd *sdp, int silent)
123 proto = sdp->sd_args.ar_lockproto;
124 table = sdp->sd_args.ar_locktable;
126 /* Try to autodetect */
128 if (!proto[0] || !table[0]) {
129 error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
133 error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
138 proto = sdp->sd_sb.sb_lockproto;
140 table = sdp->sd_sb.sb_locktable;
144 table = sdp->sd_vfs->s_id;
146 snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto);
147 snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table);
149 table = sdp->sd_table_name;
150 while ((table = strchr(table, '/')))
157 static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
160 struct task_struct *p;
166 for (sdp->sd_glockd_num = 0;
167 sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd;
168 sdp->sd_glockd_num++) {
169 p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd");
172 fs_err(sdp, "can't start glockd thread: %d\n", error);
175 sdp->sd_glockd_process[sdp->sd_glockd_num] = p;
178 error = gfs2_glock_nq_num(sdp,
179 GFS2_MOUNT_LOCK, &gfs2_nondisk_glops,
180 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE,
183 fs_err(sdp, "can't acquire mount glock: %d\n", error);
187 error = gfs2_glock_nq_num(sdp,
188 GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
190 LM_FLAG_NOEXP | GL_EXACT,
193 fs_err(sdp, "can't acquire live glock: %d\n", error);
197 error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops,
198 CREATE, &sdp->sd_rename_gl);
200 fs_err(sdp, "can't create rename glock: %d\n", error);
204 error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops,
205 CREATE, &sdp->sd_trans_gl);
207 fs_err(sdp, "can't create transaction glock: %d\n", error);
210 set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags);
215 gfs2_glock_put(sdp->sd_trans_gl);
217 gfs2_glock_put(sdp->sd_rename_gl);
219 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
221 gfs2_glock_dq_uninit(mount_gh);
223 while (sdp->sd_glockd_num--)
224 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
229 static inline struct inode *gfs2_lookup_root(struct super_block *sb,
232 return gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0);
235 static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
237 struct super_block *sb = sdp->sd_vfs;
238 struct gfs2_holder sb_gh;
251 error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
252 LM_ST_SHARED, 0, &sb_gh);
254 fs_err(sdp, "can't acquire superblock glock: %d\n", error);
258 error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent);
260 fs_err(sdp, "can't read superblock: %d\n", error);
264 /* Set up the buffer cache and SB for real */
265 if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
267 fs_err(sdp, "FS block size (%u) is too small for device "
269 sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
272 if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
274 fs_err(sdp, "FS block size (%u) is too big for machine "
276 sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
279 sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
281 /* Get the root inode */
282 no_addr = sdp->sd_sb.sb_root_dir.no_addr;
283 if (sb->s_type == &gfs2meta_fs_type)
284 no_addr = sdp->sd_sb.sb_master_dir.no_addr;
285 inode = gfs2_lookup_root(sb, no_addr);
287 error = PTR_ERR(inode);
288 fs_err(sdp, "can't read in root inode: %d\n", error);
292 sb->s_root = d_alloc_root(inode);
294 fs_err(sdp, "can't get root dentry\n");
298 sb->s_root->d_op = &gfs2_dops;
301 gfs2_glock_dq_uninit(&sb_gh);
306 * map_journal_extents - create a reusable "extent" mapping from all logical
307 * blocks to all physical blocks for the given journal. This will save
308 * us time when writing journal blocks. Most journals will have only one
309 * extent that maps all their logical blocks. That's because gfs2.mkfs
310 * arranges the journal blocks sequentially to maximize performance.
311 * So the extent would map the first block for the entire file length.
312 * However, gfs2_jadd can happen while file activity is happening, so
313 * those journals may not be sequential. Less likely is the case where
314 * the users created their own journals by mounting the metafs and
315 * laying it out. But it's still possible. These journals might have
318 * TODO: This should be done in bigger chunks rather than one block at a time,
319 * but since it's only done at mount time, I'm not worried about the
322 static int map_journal_extents(struct gfs2_sbd *sdp)
324 struct gfs2_jdesc *jd = sdp->sd_jdesc;
326 u64 db, prev_db; /* logical block, disk block, prev disk block */
327 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
328 struct gfs2_journal_extent *jext = NULL;
329 struct buffer_head bh;
332 INIT_LIST_HEAD(&jd->extent_list);
335 for (lb = 0; lb < ip->i_di.di_size / sdp->sd_sb.sb_bsize; lb++) {
338 bh.b_size = 1 << ip->i_inode.i_blkbits;
339 rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0);
342 printk(KERN_INFO "GFS2 journal mapping error %d: lb="
343 "%u db=%llu\n", rc, lb, (unsigned long long)db);
346 if (!prev_db || db != prev_db + 1) {
347 jext = kzalloc(sizeof(struct gfs2_journal_extent),
350 printk(KERN_INFO "GFS2 error: out of memory "
351 "mapping journal extents.\n");
358 list_add_tail(&jext->extent_list, &jd->extent_list);
367 static int init_journal(struct gfs2_sbd *sdp, int undo)
369 struct gfs2_holder ji_gh;
370 struct task_struct *p;
371 struct gfs2_inode *ip;
380 sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex");
381 if (IS_ERR(sdp->sd_jindex)) {
382 fs_err(sdp, "can't lookup journal index: %d\n", error);
383 return PTR_ERR(sdp->sd_jindex);
385 ip = GFS2_I(sdp->sd_jindex);
386 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
388 /* Load in the journal index special file */
390 error = gfs2_jindex_hold(sdp, &ji_gh);
392 fs_err(sdp, "can't read journal index: %d\n", error);
397 if (!gfs2_jindex_size(sdp)) {
398 fs_err(sdp, "no journals!\n");
402 if (sdp->sd_args.ar_spectator) {
403 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
404 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
406 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
407 fs_err(sdp, "can't mount journal #%u\n",
408 sdp->sd_lockstruct.ls_jid);
409 fs_err(sdp, "there are only %u journals (0 - %u)\n",
410 gfs2_jindex_size(sdp),
411 gfs2_jindex_size(sdp) - 1);
414 sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
416 error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
418 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
419 &sdp->sd_journal_gh);
421 fs_err(sdp, "can't acquire journal glock: %d\n", error);
425 ip = GFS2_I(sdp->sd_jdesc->jd_inode);
426 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
427 LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE,
430 fs_err(sdp, "can't acquire journal inode glock: %d\n",
432 goto fail_journal_gh;
435 error = gfs2_jdesc_check(sdp->sd_jdesc);
437 fs_err(sdp, "my journal (%u) is bad: %d\n",
438 sdp->sd_jdesc->jd_jid, error);
441 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
443 /* Map the extents for this journal's blocks */
444 map_journal_extents(sdp);
447 if (sdp->sd_lockstruct.ls_first) {
449 for (x = 0; x < sdp->sd_journals; x++) {
450 error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
452 fs_err(sdp, "error recovering journal %u: %d\n",
458 gfs2_lm_others_may_mount(sdp);
459 } else if (!sdp->sd_args.ar_spectator) {
460 error = gfs2_recover_journal(sdp->sd_jdesc);
462 fs_err(sdp, "error recovering my journal: %d\n", error);
467 set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags);
468 gfs2_glock_dq_uninit(&ji_gh);
471 p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
474 fs_err(sdp, "can't start recoverd thread: %d\n", error);
477 sdp->sd_recoverd_process = p;
482 kthread_stop(sdp->sd_recoverd_process);
484 if (!sdp->sd_args.ar_spectator)
485 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
487 if (!sdp->sd_args.ar_spectator)
488 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
490 gfs2_jindex_free(sdp);
492 gfs2_glock_dq_uninit(&ji_gh);
494 iput(sdp->sd_jindex);
499 static int init_inodes(struct gfs2_sbd *sdp, int undo)
502 struct gfs2_inode *ip;
508 inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr);
510 error = PTR_ERR(inode);
511 fs_err(sdp, "can't read in master directory: %d\n", error);
514 sdp->sd_master_dir = inode;
516 error = init_journal(sdp, undo);
520 /* Read in the master inode number inode */
521 sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum");
522 if (IS_ERR(sdp->sd_inum_inode)) {
523 error = PTR_ERR(sdp->sd_inum_inode);
524 fs_err(sdp, "can't read in inum inode: %d\n", error);
529 /* Read in the master statfs inode */
530 sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs");
531 if (IS_ERR(sdp->sd_statfs_inode)) {
532 error = PTR_ERR(sdp->sd_statfs_inode);
533 fs_err(sdp, "can't read in statfs inode: %d\n", error);
537 /* Read in the resource index inode */
538 sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex");
539 if (IS_ERR(sdp->sd_rindex)) {
540 error = PTR_ERR(sdp->sd_rindex);
541 fs_err(sdp, "can't get resource index inode: %d\n", error);
544 ip = GFS2_I(sdp->sd_rindex);
545 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
546 sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1;
548 /* Read in the quota inode */
549 sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota");
550 if (IS_ERR(sdp->sd_quota_inode)) {
551 error = PTR_ERR(sdp->sd_quota_inode);
552 fs_err(sdp, "can't get quota file inode: %d\n", error);
558 iput(sdp->sd_quota_inode);
560 gfs2_clear_rgrpd(sdp);
561 iput(sdp->sd_rindex);
563 iput(sdp->sd_statfs_inode);
565 iput(sdp->sd_inum_inode);
567 init_journal(sdp, UNDO);
569 iput(sdp->sd_master_dir);
574 static int init_per_node(struct gfs2_sbd *sdp, int undo)
576 struct inode *pn = NULL;
579 struct gfs2_inode *ip;
581 if (sdp->sd_args.ar_spectator)
587 pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node");
590 fs_err(sdp, "can't find per_node directory: %d\n", error);
594 sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
595 sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
596 if (IS_ERR(sdp->sd_ir_inode)) {
597 error = PTR_ERR(sdp->sd_ir_inode);
598 fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
602 sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
603 sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
604 if (IS_ERR(sdp->sd_sc_inode)) {
605 error = PTR_ERR(sdp->sd_sc_inode);
606 fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
610 sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
611 sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
612 if (IS_ERR(sdp->sd_qc_inode)) {
613 error = PTR_ERR(sdp->sd_qc_inode);
614 fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
621 ip = GFS2_I(sdp->sd_ir_inode);
622 error = gfs2_glock_nq_init(ip->i_gl,
626 fs_err(sdp, "can't lock local \"ir\" file: %d\n", error);
630 ip = GFS2_I(sdp->sd_sc_inode);
631 error = gfs2_glock_nq_init(ip->i_gl,
635 fs_err(sdp, "can't lock local \"sc\" file: %d\n", error);
639 ip = GFS2_I(sdp->sd_qc_inode);
640 error = gfs2_glock_nq_init(ip->i_gl,
644 fs_err(sdp, "can't lock local \"qc\" file: %d\n", error);
651 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
653 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
655 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
657 iput(sdp->sd_qc_inode);
659 iput(sdp->sd_sc_inode);
661 iput(sdp->sd_ir_inode);
668 static int init_threads(struct gfs2_sbd *sdp, int undo)
670 struct task_struct *p;
676 sdp->sd_log_flush_time = jiffies;
677 sdp->sd_jindex_refresh_time = jiffies;
679 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
682 fs_err(sdp, "can't start logd thread: %d\n", error);
685 sdp->sd_logd_process = p;
687 sdp->sd_statfs_sync_time = jiffies;
688 sdp->sd_quota_sync_time = jiffies;
690 p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
693 fs_err(sdp, "can't start quotad thread: %d\n", error);
696 sdp->sd_quotad_process = p;
702 kthread_stop(sdp->sd_quotad_process);
704 kthread_stop(sdp->sd_logd_process);
709 * fill_super - Read in superblock
710 * @sb: The VFS superblock
711 * @data: Mount options
712 * @silent: Don't complain if it's not a GFS2 filesystem
717 static int fill_super(struct super_block *sb, void *data, int silent)
719 struct gfs2_sbd *sdp;
720 struct gfs2_holder mount_gh;
725 printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n");
729 error = gfs2_mount_args(sdp, (char *)data, 0);
731 printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
735 init_vfs(sb, SDF_NOATIME);
737 /* Set up the buffer cache and fill in some fake block size values
738 to allow us to read-in the on-disk superblock. */
739 sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
740 sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
741 sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
742 GFS2_BASIC_BLOCK_SHIFT;
743 sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
745 error = init_names(sdp, silent);
749 gfs2_create_debugfs_file(sdp);
751 error = gfs2_sys_fs_add(sdp);
755 error = gfs2_lm_mount(sdp, silent);
759 error = init_locking(sdp, &mount_gh, DO);
763 error = init_sb(sdp, silent, DO);
767 error = init_inodes(sdp, DO);
771 error = init_per_node(sdp, DO);
775 error = gfs2_statfs_init(sdp);
777 fs_err(sdp, "can't initialize statfs subsystem: %d\n", error);
781 error = init_threads(sdp, DO);
785 if (!(sb->s_flags & MS_RDONLY)) {
786 error = gfs2_make_fs_rw(sdp);
788 fs_err(sdp, "can't make FS RW: %d\n", error);
793 gfs2_glock_dq_uninit(&mount_gh);
798 init_threads(sdp, UNDO);
800 init_per_node(sdp, UNDO);
802 init_inodes(sdp, UNDO);
804 init_sb(sdp, 0, UNDO);
806 init_locking(sdp, &mount_gh, UNDO);
808 gfs2_gl_hash_clear(sdp, WAIT);
809 gfs2_lm_unmount(sdp);
810 while (invalidate_inodes(sb))
813 gfs2_sys_fs_del(sdp);
815 gfs2_delete_debugfs_file(sdp);
817 sb->s_fs_info = NULL;
821 static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
822 const char *dev_name, void *data, struct vfsmount *mnt)
824 struct super_block *sb;
825 struct gfs2_sbd *sdp;
826 int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
831 sdp->sd_gfs2mnt = mnt;
836 static int fill_super_meta(struct super_block *sb, struct super_block *new,
837 void *data, int silent)
839 struct gfs2_sbd *sdp = sb->s_fs_info;
843 new->s_fs_info = sdp;
844 sdp->sd_vfs_meta = sb;
846 init_vfs(new, SDF_NOATIME);
848 /* Get the master inode */
849 inode = igrab(sdp->sd_master_dir);
851 new->s_root = d_alloc_root(inode);
853 fs_err(sdp, "can't get root dentry\n");
857 new->s_root->d_op = &gfs2_dops;
862 static int set_bdev_super(struct super_block *s, void *data)
865 s->s_dev = s->s_bdev->bd_dev;
869 static int test_bdev_super(struct super_block *s, void *data)
871 return s->s_bdev == data;
874 static struct super_block* get_gfs2_sb(const char *dev_name)
878 struct file_system_type *fstype;
879 struct super_block *sb = NULL, *s;
882 error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
884 printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n",
888 error = vfs_getattr(nd.mnt, nd.dentry, &stat);
890 fstype = get_fs_type("gfs2");
891 list_for_each_entry(s, &fstype->fs_supers, s_instances) {
892 if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) ||
893 (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) {
899 printk(KERN_WARNING "GFS2: Unrecognized block device or "
900 "mount point %s\n", dev_name);
908 static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
909 const char *dev_name, void *data, struct vfsmount *mnt)
912 struct super_block *sb = NULL, *new;
913 struct gfs2_sbd *sdp;
915 sb = get_gfs2_sb(dev_name);
917 printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n");
922 if (sdp->sd_vfs_meta) {
923 printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n");
927 down(&sb->s_bdev->bd_mount_sem);
928 new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev);
929 up(&sb->s_bdev->bd_mount_sem);
931 error = PTR_ERR(new);
934 module_put(fs_type->owner);
935 new->s_flags = flags;
936 strlcpy(new->s_id, sb->s_id, sizeof(new->s_id));
937 sb_set_blocksize(new, sb->s_blocksize);
938 error = fill_super_meta(sb, new, data, flags & MS_SILENT ? 1 : 0);
940 up_write(&new->s_umount);
941 deactivate_super(new);
945 new->s_flags |= MS_ACTIVE;
947 /* Grab a reference to the gfs2 mount point */
948 atomic_inc(&sdp->sd_gfs2mnt->mnt_count);
949 return simple_set_mnt(mnt, new);
954 static void gfs2_kill_sb(struct super_block *sb)
957 gfs2_delete_debugfs_file(sb->s_fs_info);
958 gfs2_meta_syncfs(sb->s_fs_info);
960 kill_block_super(sb);
963 static void gfs2_kill_sb_meta(struct super_block *sb)
965 struct gfs2_sbd *sdp = sb->s_fs_info;
966 generic_shutdown_super(sb);
967 sdp->sd_vfs_meta = NULL;
968 atomic_dec(&sdp->sd_gfs2mnt->mnt_count);
971 struct file_system_type gfs2_fs_type = {
973 .fs_flags = FS_REQUIRES_DEV,
974 .get_sb = gfs2_get_sb,
975 .kill_sb = gfs2_kill_sb,
976 .owner = THIS_MODULE,
979 struct file_system_type gfs2meta_fs_type = {
981 .fs_flags = FS_REQUIRES_DEV,
982 .get_sb = gfs2_get_sb_meta,
983 .kill_sb = gfs2_kill_sb_meta,
984 .owner = THIS_MODULE,