3eb49edae542dd17cf9f4597e583bf6a91e744cd
[linux-2.6.git] / fs / gfs2 / ops_fstype.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2008 Red Hat, Inc.  All rights reserved.
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 version 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/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>
21
22 #include "gfs2.h"
23 #include "incore.h"
24 #include "bmap.h"
25 #include "glock.h"
26 #include "glops.h"
27 #include "inode.h"
28 #include "recovery.h"
29 #include "rgrp.h"
30 #include "super.h"
31 #include "sys.h"
32 #include "util.h"
33 #include "log.h"
34 #include "quota.h"
35 #include "dir.h"
36
37 #define DO 0
38 #define UNDO 1
39
40 static const u32 gfs2_old_fs_formats[] = {
41         0
42 };
43
44 static const u32 gfs2_old_multihost_formats[] = {
45         0
46 };
47
48 /**
49  * gfs2_tune_init - Fill a gfs2_tune structure with default values
50  * @gt: tune
51  *
52  */
53
54 static void gfs2_tune_init(struct gfs2_tune *gt)
55 {
56         spin_lock_init(&gt->gt_spin);
57
58         gt->gt_incore_log_blocks = 1024;
59         gt->gt_log_flush_secs = 60;
60         gt->gt_recoverd_secs = 60;
61         gt->gt_logd_secs = 1;
62         gt->gt_quota_simul_sync = 64;
63         gt->gt_quota_warn_period = 10;
64         gt->gt_quota_scale_num = 1;
65         gt->gt_quota_scale_den = 1;
66         gt->gt_quota_cache_secs = 300;
67         gt->gt_quota_quantum = 60;
68         gt->gt_new_files_jdata = 0;
69         gt->gt_max_readahead = 1 << 18;
70         gt->gt_stall_secs = 600;
71         gt->gt_complain_secs = 10;
72         gt->gt_statfs_quantum = 30;
73         gt->gt_statfs_slow = 0;
74 }
75
76 static struct gfs2_sbd *init_sbd(struct super_block *sb)
77 {
78         struct gfs2_sbd *sdp;
79
80         sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
81         if (!sdp)
82                 return NULL;
83
84         sb->s_fs_info = sdp;
85         sdp->sd_vfs = sb;
86
87         gfs2_tune_init(&sdp->sd_tune);
88
89         mutex_init(&sdp->sd_inum_mutex);
90         spin_lock_init(&sdp->sd_statfs_spin);
91
92         spin_lock_init(&sdp->sd_rindex_spin);
93         mutex_init(&sdp->sd_rindex_mutex);
94         INIT_LIST_HEAD(&sdp->sd_rindex_list);
95         INIT_LIST_HEAD(&sdp->sd_rindex_mru_list);
96
97         INIT_LIST_HEAD(&sdp->sd_jindex_list);
98         spin_lock_init(&sdp->sd_jindex_spin);
99         mutex_init(&sdp->sd_jindex_mutex);
100
101         INIT_LIST_HEAD(&sdp->sd_quota_list);
102         spin_lock_init(&sdp->sd_quota_spin);
103         mutex_init(&sdp->sd_quota_mutex);
104         init_waitqueue_head(&sdp->sd_quota_wait);
105         INIT_LIST_HEAD(&sdp->sd_trunc_list);
106         spin_lock_init(&sdp->sd_trunc_lock);
107
108         spin_lock_init(&sdp->sd_log_lock);
109
110         INIT_LIST_HEAD(&sdp->sd_log_le_buf);
111         INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
112         INIT_LIST_HEAD(&sdp->sd_log_le_rg);
113         INIT_LIST_HEAD(&sdp->sd_log_le_databuf);
114         INIT_LIST_HEAD(&sdp->sd_log_le_ordered);
115
116         mutex_init(&sdp->sd_log_reserve_mutex);
117         INIT_LIST_HEAD(&sdp->sd_ail1_list);
118         INIT_LIST_HEAD(&sdp->sd_ail2_list);
119
120         init_rwsem(&sdp->sd_log_flush_lock);
121         atomic_set(&sdp->sd_log_in_flight, 0);
122         init_waitqueue_head(&sdp->sd_log_flush_wait);
123
124         INIT_LIST_HEAD(&sdp->sd_revoke_list);
125
126         mutex_init(&sdp->sd_freeze_lock);
127
128         return sdp;
129 }
130
131
132 /**
133  * gfs2_check_sb - Check superblock
134  * @sdp: the filesystem
135  * @sb: The superblock
136  * @silent: Don't print a message if the check fails
137  *
138  * Checks the version code of the FS is one that we understand how to
139  * read and that the sizes of the various on-disk structures have not
140  * changed.
141  */
142
143 static int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb_host *sb, int silent)
144 {
145         unsigned int x;
146
147         if (sb->sb_magic != GFS2_MAGIC ||
148             sb->sb_type != GFS2_METATYPE_SB) {
149                 if (!silent)
150                         printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n");
151                 return -EINVAL;
152         }
153
154         /*  If format numbers match exactly, we're done.  */
155
156         if (sb->sb_fs_format == GFS2_FORMAT_FS &&
157             sb->sb_multihost_format == GFS2_FORMAT_MULTI)
158                 return 0;
159
160         if (sb->sb_fs_format != GFS2_FORMAT_FS) {
161                 for (x = 0; gfs2_old_fs_formats[x]; x++)
162                         if (gfs2_old_fs_formats[x] == sb->sb_fs_format)
163                                 break;
164
165                 if (!gfs2_old_fs_formats[x]) {
166                         printk(KERN_WARNING
167                                "GFS2: code version (%u, %u) is incompatible "
168                                "with ondisk format (%u, %u)\n",
169                                GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
170                                sb->sb_fs_format, sb->sb_multihost_format);
171                         printk(KERN_WARNING
172                                "GFS2: I don't know how to upgrade this FS\n");
173                         return -EINVAL;
174                 }
175         }
176
177         if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) {
178                 for (x = 0; gfs2_old_multihost_formats[x]; x++)
179                         if (gfs2_old_multihost_formats[x] ==
180                             sb->sb_multihost_format)
181                                 break;
182
183                 if (!gfs2_old_multihost_formats[x]) {
184                         printk(KERN_WARNING
185                                "GFS2: code version (%u, %u) is incompatible "
186                                "with ondisk format (%u, %u)\n",
187                                GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
188                                sb->sb_fs_format, sb->sb_multihost_format);
189                         printk(KERN_WARNING
190                                "GFS2: I don't know how to upgrade this FS\n");
191                         return -EINVAL;
192                 }
193         }
194
195         if (!sdp->sd_args.ar_upgrade) {
196                 printk(KERN_WARNING
197                        "GFS2: code version (%u, %u) is incompatible "
198                        "with ondisk format (%u, %u)\n",
199                        GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
200                        sb->sb_fs_format, sb->sb_multihost_format);
201                 printk(KERN_INFO
202                        "GFS2: Use the \"upgrade\" mount option to upgrade "
203                        "the FS\n");
204                 printk(KERN_INFO "GFS2: See the manual for more details\n");
205                 return -EINVAL;
206         }
207
208         return 0;
209 }
210
211 static void end_bio_io_page(struct bio *bio, int error)
212 {
213         struct page *page = bio->bi_private;
214
215         if (!error)
216                 SetPageUptodate(page);
217         else
218                 printk(KERN_WARNING "gfs2: error %d reading superblock\n", error);
219         unlock_page(page);
220 }
221
222 static void gfs2_sb_in(struct gfs2_sb_host *sb, const void *buf)
223 {
224         const struct gfs2_sb *str = buf;
225
226         sb->sb_magic = be32_to_cpu(str->sb_header.mh_magic);
227         sb->sb_type = be32_to_cpu(str->sb_header.mh_type);
228         sb->sb_format = be32_to_cpu(str->sb_header.mh_format);
229         sb->sb_fs_format = be32_to_cpu(str->sb_fs_format);
230         sb->sb_multihost_format = be32_to_cpu(str->sb_multihost_format);
231         sb->sb_bsize = be32_to_cpu(str->sb_bsize);
232         sb->sb_bsize_shift = be32_to_cpu(str->sb_bsize_shift);
233         sb->sb_master_dir.no_addr = be64_to_cpu(str->sb_master_dir.no_addr);
234         sb->sb_master_dir.no_formal_ino = be64_to_cpu(str->sb_master_dir.no_formal_ino);
235         sb->sb_root_dir.no_addr = be64_to_cpu(str->sb_root_dir.no_addr);
236         sb->sb_root_dir.no_formal_ino = be64_to_cpu(str->sb_root_dir.no_formal_ino);
237
238         memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN);
239         memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN);
240 }
241
242 /**
243  * gfs2_read_super - Read the gfs2 super block from disk
244  * @sdp: The GFS2 super block
245  * @sector: The location of the super block
246  * @error: The error code to return
247  *
248  * This uses the bio functions to read the super block from disk
249  * because we want to be 100% sure that we never read cached data.
250  * A super block is read twice only during each GFS2 mount and is
251  * never written to by the filesystem. The first time its read no
252  * locks are held, and the only details which are looked at are those
253  * relating to the locking protocol. Once locking is up and working,
254  * the sb is read again under the lock to establish the location of
255  * the master directory (contains pointers to journals etc) and the
256  * root directory.
257  *
258  * Returns: 0 on success or error
259  */
260
261 static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector)
262 {
263         struct super_block *sb = sdp->sd_vfs;
264         struct gfs2_sb *p;
265         struct page *page;
266         struct bio *bio;
267
268         page = alloc_page(GFP_NOFS);
269         if (unlikely(!page))
270                 return -ENOBUFS;
271
272         ClearPageUptodate(page);
273         ClearPageDirty(page);
274         lock_page(page);
275
276         bio = bio_alloc(GFP_NOFS, 1);
277         if (unlikely(!bio)) {
278                 __free_page(page);
279                 return -ENOBUFS;
280         }
281
282         bio->bi_sector = sector * (sb->s_blocksize >> 9);
283         bio->bi_bdev = sb->s_bdev;
284         bio_add_page(bio, page, PAGE_SIZE, 0);
285
286         bio->bi_end_io = end_bio_io_page;
287         bio->bi_private = page;
288         submit_bio(READ_SYNC | (1 << BIO_RW_META), bio);
289         wait_on_page_locked(page);
290         bio_put(bio);
291         if (!PageUptodate(page)) {
292                 __free_page(page);
293                 return -EIO;
294         }
295         p = kmap(page);
296         gfs2_sb_in(&sdp->sd_sb, p);
297         kunmap(page);
298         __free_page(page);
299         return 0;
300 }
301 /**
302  * gfs2_read_sb - Read super block
303  * @sdp: The GFS2 superblock
304  * @gl: the glock for the superblock (assumed to be held)
305  * @silent: Don't print message if mount fails
306  *
307  */
308
309 static int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent)
310 {
311         u32 hash_blocks, ind_blocks, leaf_blocks;
312         u32 tmp_blocks;
313         unsigned int x;
314         int error;
315
316         error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
317         if (error) {
318                 if (!silent)
319                         fs_err(sdp, "can't read superblock\n");
320                 return error;
321         }
322
323         error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
324         if (error)
325                 return error;
326
327         sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
328                                GFS2_BASIC_BLOCK_SHIFT;
329         sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
330         sdp->sd_diptrs = (sdp->sd_sb.sb_bsize -
331                           sizeof(struct gfs2_dinode)) / sizeof(u64);
332         sdp->sd_inptrs = (sdp->sd_sb.sb_bsize -
333                           sizeof(struct gfs2_meta_header)) / sizeof(u64);
334         sdp->sd_jbsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header);
335         sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2;
336         sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1;
337         sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(u64);
338         sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize -
339                                 sizeof(struct gfs2_meta_header)) /
340                                 sizeof(struct gfs2_quota_change);
341
342         /* Compute maximum reservation required to add a entry to a directory */
343
344         hash_blocks = DIV_ROUND_UP(sizeof(u64) * (1 << GFS2_DIR_MAX_DEPTH),
345                              sdp->sd_jbsize);
346
347         ind_blocks = 0;
348         for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) {
349                 tmp_blocks = DIV_ROUND_UP(tmp_blocks, sdp->sd_inptrs);
350                 ind_blocks += tmp_blocks;
351         }
352
353         leaf_blocks = 2 + GFS2_DIR_MAX_DEPTH;
354
355         sdp->sd_max_dirres = hash_blocks + ind_blocks + leaf_blocks;
356
357         sdp->sd_heightsize[0] = sdp->sd_sb.sb_bsize -
358                                 sizeof(struct gfs2_dinode);
359         sdp->sd_heightsize[1] = sdp->sd_sb.sb_bsize * sdp->sd_diptrs;
360         for (x = 2;; x++) {
361                 u64 space, d;
362                 u32 m;
363
364                 space = sdp->sd_heightsize[x - 1] * sdp->sd_inptrs;
365                 d = space;
366                 m = do_div(d, sdp->sd_inptrs);
367
368                 if (d != sdp->sd_heightsize[x - 1] || m)
369                         break;
370                 sdp->sd_heightsize[x] = space;
371         }
372         sdp->sd_max_height = x;
373         sdp->sd_heightsize[x] = ~0;
374         gfs2_assert(sdp, sdp->sd_max_height <= GFS2_MAX_META_HEIGHT);
375
376         sdp->sd_jheightsize[0] = sdp->sd_sb.sb_bsize -
377                                  sizeof(struct gfs2_dinode);
378         sdp->sd_jheightsize[1] = sdp->sd_jbsize * sdp->sd_diptrs;
379         for (x = 2;; x++) {
380                 u64 space, d;
381                 u32 m;
382
383                 space = sdp->sd_jheightsize[x - 1] * sdp->sd_inptrs;
384                 d = space;
385                 m = do_div(d, sdp->sd_inptrs);
386
387                 if (d != sdp->sd_jheightsize[x - 1] || m)
388                         break;
389                 sdp->sd_jheightsize[x] = space;
390         }
391         sdp->sd_max_jheight = x;
392         sdp->sd_jheightsize[x] = ~0;
393         gfs2_assert(sdp, sdp->sd_max_jheight <= GFS2_MAX_META_HEIGHT);
394
395         return 0;
396 }
397
398 static int init_names(struct gfs2_sbd *sdp, int silent)
399 {
400         char *proto, *table;
401         int error = 0;
402
403         proto = sdp->sd_args.ar_lockproto;
404         table = sdp->sd_args.ar_locktable;
405
406         /*  Try to autodetect  */
407
408         if (!proto[0] || !table[0]) {
409                 error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
410                 if (error)
411                         return error;
412
413                 error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
414                 if (error)
415                         goto out;
416
417                 if (!proto[0])
418                         proto = sdp->sd_sb.sb_lockproto;
419                 if (!table[0])
420                         table = sdp->sd_sb.sb_locktable;
421         }
422
423         if (!table[0])
424                 table = sdp->sd_vfs->s_id;
425
426         strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
427         strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
428
429         table = sdp->sd_table_name;
430         while ((table = strchr(table, '/')))
431                 *table = '_';
432
433 out:
434         return error;
435 }
436
437 static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
438                         int undo)
439 {
440         int error = 0;
441
442         if (undo)
443                 goto fail_trans;
444
445         error = gfs2_glock_nq_num(sdp,
446                                   GFS2_MOUNT_LOCK, &gfs2_nondisk_glops,
447                                   LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE,
448                                   mount_gh);
449         if (error) {
450                 fs_err(sdp, "can't acquire mount glock: %d\n", error);
451                 goto fail;
452         }
453
454         error = gfs2_glock_nq_num(sdp,
455                                   GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
456                                   LM_ST_SHARED,
457                                   LM_FLAG_NOEXP | GL_EXACT,
458                                   &sdp->sd_live_gh);
459         if (error) {
460                 fs_err(sdp, "can't acquire live glock: %d\n", error);
461                 goto fail_mount;
462         }
463
464         error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops,
465                                CREATE, &sdp->sd_rename_gl);
466         if (error) {
467                 fs_err(sdp, "can't create rename glock: %d\n", error);
468                 goto fail_live;
469         }
470
471         error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops,
472                                CREATE, &sdp->sd_trans_gl);
473         if (error) {
474                 fs_err(sdp, "can't create transaction glock: %d\n", error);
475                 goto fail_rename;
476         }
477
478         return 0;
479
480 fail_trans:
481         gfs2_glock_put(sdp->sd_trans_gl);
482 fail_rename:
483         gfs2_glock_put(sdp->sd_rename_gl);
484 fail_live:
485         gfs2_glock_dq_uninit(&sdp->sd_live_gh);
486 fail_mount:
487         gfs2_glock_dq_uninit(mount_gh);
488 fail:
489         return error;
490 }
491
492 static int gfs2_lookup_root(struct super_block *sb, struct dentry **dptr,
493                             u64 no_addr, const char *name)
494 {
495         struct gfs2_sbd *sdp = sb->s_fs_info;
496         struct dentry *dentry;
497         struct inode *inode;
498
499         inode = gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0);
500         if (IS_ERR(inode)) {
501                 fs_err(sdp, "can't read in %s inode: %ld\n", name, PTR_ERR(inode));
502                 return PTR_ERR(inode);
503         }
504         dentry = d_alloc_root(inode);
505         if (!dentry) {
506                 fs_err(sdp, "can't alloc %s dentry\n", name);
507                 iput(inode);
508                 return -ENOMEM;
509         }
510         dentry->d_op = &gfs2_dops;
511         *dptr = dentry;
512         return 0;
513 }
514
515 static int init_sb(struct gfs2_sbd *sdp, int silent)
516 {
517         struct super_block *sb = sdp->sd_vfs;
518         struct gfs2_holder sb_gh;
519         u64 no_addr;
520         int ret;
521
522         ret = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
523                                 LM_ST_SHARED, 0, &sb_gh);
524         if (ret) {
525                 fs_err(sdp, "can't acquire superblock glock: %d\n", ret);
526                 return ret;
527         }
528
529         ret = gfs2_read_sb(sdp, sb_gh.gh_gl, silent);
530         if (ret) {
531                 fs_err(sdp, "can't read superblock: %d\n", ret);
532                 goto out;
533         }
534
535         /* Set up the buffer cache and SB for real */
536         if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
537                 ret = -EINVAL;
538                 fs_err(sdp, "FS block size (%u) is too small for device "
539                        "block size (%u)\n",
540                        sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
541                 goto out;
542         }
543         if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
544                 ret = -EINVAL;
545                 fs_err(sdp, "FS block size (%u) is too big for machine "
546                        "page size (%u)\n",
547                        sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
548                 goto out;
549         }
550         sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
551
552         /* Get the root inode */
553         no_addr = sdp->sd_sb.sb_root_dir.no_addr;
554         ret = gfs2_lookup_root(sb, &sdp->sd_root_dir, no_addr, "root");
555         if (ret)
556                 goto out;
557
558         /* Get the master inode */
559         no_addr = sdp->sd_sb.sb_master_dir.no_addr;
560         ret = gfs2_lookup_root(sb, &sdp->sd_master_dir, no_addr, "master");
561         if (ret) {
562                 dput(sdp->sd_root_dir);
563                 goto out;
564         }
565         sb->s_root = dget(sdp->sd_args.ar_meta ? sdp->sd_master_dir : sdp->sd_root_dir);
566 out:
567         gfs2_glock_dq_uninit(&sb_gh);
568         return ret;
569 }
570
571 /**
572  * map_journal_extents - create a reusable "extent" mapping from all logical
573  * blocks to all physical blocks for the given journal.  This will save
574  * us time when writing journal blocks.  Most journals will have only one
575  * extent that maps all their logical blocks.  That's because gfs2.mkfs
576  * arranges the journal blocks sequentially to maximize performance.
577  * So the extent would map the first block for the entire file length.
578  * However, gfs2_jadd can happen while file activity is happening, so
579  * those journals may not be sequential.  Less likely is the case where
580  * the users created their own journals by mounting the metafs and
581  * laying it out.  But it's still possible.  These journals might have
582  * several extents.
583  *
584  * TODO: This should be done in bigger chunks rather than one block at a time,
585  *       but since it's only done at mount time, I'm not worried about the
586  *       time it takes.
587  */
588 static int map_journal_extents(struct gfs2_sbd *sdp)
589 {
590         struct gfs2_jdesc *jd = sdp->sd_jdesc;
591         unsigned int lb;
592         u64 db, prev_db; /* logical block, disk block, prev disk block */
593         struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
594         struct gfs2_journal_extent *jext = NULL;
595         struct buffer_head bh;
596         int rc = 0;
597
598         prev_db = 0;
599
600         for (lb = 0; lb < ip->i_disksize >> sdp->sd_sb.sb_bsize_shift; lb++) {
601                 bh.b_state = 0;
602                 bh.b_blocknr = 0;
603                 bh.b_size = 1 << ip->i_inode.i_blkbits;
604                 rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0);
605                 db = bh.b_blocknr;
606                 if (rc || !db) {
607                         printk(KERN_INFO "GFS2 journal mapping error %d: lb="
608                                "%u db=%llu\n", rc, lb, (unsigned long long)db);
609                         break;
610                 }
611                 if (!prev_db || db != prev_db + 1) {
612                         jext = kzalloc(sizeof(struct gfs2_journal_extent),
613                                        GFP_KERNEL);
614                         if (!jext) {
615                                 printk(KERN_INFO "GFS2 error: out of memory "
616                                        "mapping journal extents.\n");
617                                 rc = -ENOMEM;
618                                 break;
619                         }
620                         jext->dblock = db;
621                         jext->lblock = lb;
622                         jext->blocks = 1;
623                         list_add_tail(&jext->extent_list, &jd->extent_list);
624                 } else {
625                         jext->blocks++;
626                 }
627                 prev_db = db;
628         }
629         return rc;
630 }
631
632 static void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp)
633 {
634         if (!sdp->sd_lockstruct.ls_ops->lm_others_may_mount)
635                 return;
636         if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
637                 sdp->sd_lockstruct.ls_ops->lm_others_may_mount(
638                                         sdp->sd_lockstruct.ls_lockspace);
639 }
640
641 /**
642  * gfs2_jindex_hold - Grab a lock on the jindex
643  * @sdp: The GFS2 superblock
644  * @ji_gh: the holder for the jindex glock
645  *
646  * Returns: errno
647  */
648
649 static int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
650 {
651         struct gfs2_inode *dip = GFS2_I(sdp->sd_jindex);
652         struct qstr name;
653         char buf[20];
654         struct gfs2_jdesc *jd;
655         int error;
656
657         name.name = buf;
658
659         mutex_lock(&sdp->sd_jindex_mutex);
660
661         for (;;) {
662                 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, ji_gh);
663                 if (error)
664                         break;
665
666                 name.len = sprintf(buf, "journal%u", sdp->sd_journals);
667                 name.hash = gfs2_disk_hash(name.name, name.len);
668
669                 error = gfs2_dir_check(sdp->sd_jindex, &name, NULL);
670                 if (error == -ENOENT) {
671                         error = 0;
672                         break;
673                 }
674
675                 gfs2_glock_dq_uninit(ji_gh);
676
677                 if (error)
678                         break;
679
680                 error = -ENOMEM;
681                 jd = kzalloc(sizeof(struct gfs2_jdesc), GFP_KERNEL);
682                 if (!jd)
683                         break;
684
685                 INIT_LIST_HEAD(&jd->extent_list);
686                 jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1);
687                 if (!jd->jd_inode || IS_ERR(jd->jd_inode)) {
688                         if (!jd->jd_inode)
689                                 error = -ENOENT;
690                         else
691                                 error = PTR_ERR(jd->jd_inode);
692                         kfree(jd);
693                         break;
694                 }
695
696                 spin_lock(&sdp->sd_jindex_spin);
697                 jd->jd_jid = sdp->sd_journals++;
698                 list_add_tail(&jd->jd_list, &sdp->sd_jindex_list);
699                 spin_unlock(&sdp->sd_jindex_spin);
700         }
701
702         mutex_unlock(&sdp->sd_jindex_mutex);
703
704         return error;
705 }
706
707 static int init_journal(struct gfs2_sbd *sdp, int undo)
708 {
709         struct inode *master = sdp->sd_master_dir->d_inode;
710         struct gfs2_holder ji_gh;
711         struct task_struct *p;
712         struct gfs2_inode *ip;
713         int jindex = 1;
714         int error = 0;
715
716         if (undo) {
717                 jindex = 0;
718                 goto fail_recoverd;
719         }
720
721         sdp->sd_jindex = gfs2_lookup_simple(master, "jindex");
722         if (IS_ERR(sdp->sd_jindex)) {
723                 fs_err(sdp, "can't lookup journal index: %d\n", error);
724                 return PTR_ERR(sdp->sd_jindex);
725         }
726         ip = GFS2_I(sdp->sd_jindex);
727
728         /* Load in the journal index special file */
729
730         error = gfs2_jindex_hold(sdp, &ji_gh);
731         if (error) {
732                 fs_err(sdp, "can't read journal index: %d\n", error);
733                 goto fail;
734         }
735
736         error = -EINVAL;
737         if (!gfs2_jindex_size(sdp)) {
738                 fs_err(sdp, "no journals!\n");
739                 goto fail_jindex;
740         }
741
742         if (sdp->sd_args.ar_spectator) {
743                 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
744                 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
745         } else {
746                 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
747                         fs_err(sdp, "can't mount journal #%u\n",
748                                sdp->sd_lockstruct.ls_jid);
749                         fs_err(sdp, "there are only %u journals (0 - %u)\n",
750                                gfs2_jindex_size(sdp),
751                                gfs2_jindex_size(sdp) - 1);
752                         goto fail_jindex;
753                 }
754                 sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
755
756                 error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
757                                           &gfs2_journal_glops,
758                                           LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
759                                           &sdp->sd_journal_gh);
760                 if (error) {
761                         fs_err(sdp, "can't acquire journal glock: %d\n", error);
762                         goto fail_jindex;
763                 }
764
765                 ip = GFS2_I(sdp->sd_jdesc->jd_inode);
766                 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
767                                            LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE,
768                                            &sdp->sd_jinode_gh);
769                 if (error) {
770                         fs_err(sdp, "can't acquire journal inode glock: %d\n",
771                                error);
772                         goto fail_journal_gh;
773                 }
774
775                 error = gfs2_jdesc_check(sdp->sd_jdesc);
776                 if (error) {
777                         fs_err(sdp, "my journal (%u) is bad: %d\n",
778                                sdp->sd_jdesc->jd_jid, error);
779                         goto fail_jinode_gh;
780                 }
781                 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
782
783                 /* Map the extents for this journal's blocks */
784                 map_journal_extents(sdp);
785         }
786
787         if (sdp->sd_lockstruct.ls_first) {
788                 unsigned int x;
789                 for (x = 0; x < sdp->sd_journals; x++) {
790                         error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
791                         if (error) {
792                                 fs_err(sdp, "error recovering journal %u: %d\n",
793                                        x, error);
794                                 goto fail_jinode_gh;
795                         }
796                 }
797
798                 gfs2_lm_others_may_mount(sdp);
799         } else if (!sdp->sd_args.ar_spectator) {
800                 error = gfs2_recover_journal(sdp->sd_jdesc);
801                 if (error) {
802                         fs_err(sdp, "error recovering my journal: %d\n", error);
803                         goto fail_jinode_gh;
804                 }
805         }
806
807         set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags);
808         gfs2_glock_dq_uninit(&ji_gh);
809         jindex = 0;
810
811         p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
812         error = IS_ERR(p);
813         if (error) {
814                 fs_err(sdp, "can't start recoverd thread: %d\n", error);
815                 goto fail_jinode_gh;
816         }
817         sdp->sd_recoverd_process = p;
818
819         return 0;
820
821 fail_recoverd:
822         kthread_stop(sdp->sd_recoverd_process);
823 fail_jinode_gh:
824         if (!sdp->sd_args.ar_spectator)
825                 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
826 fail_journal_gh:
827         if (!sdp->sd_args.ar_spectator)
828                 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
829 fail_jindex:
830         gfs2_jindex_free(sdp);
831         if (jindex)
832                 gfs2_glock_dq_uninit(&ji_gh);
833 fail:
834         iput(sdp->sd_jindex);
835         return error;
836 }
837
838
839 static int init_inodes(struct gfs2_sbd *sdp, int undo)
840 {
841         int error = 0;
842         struct gfs2_inode *ip;
843         struct inode *master = sdp->sd_master_dir->d_inode;
844
845         if (undo)
846                 goto fail_qinode;
847
848         error = init_journal(sdp, undo);
849         if (error)
850                 goto fail;
851
852         /* Read in the master inode number inode */
853         sdp->sd_inum_inode = gfs2_lookup_simple(master, "inum");
854         if (IS_ERR(sdp->sd_inum_inode)) {
855                 error = PTR_ERR(sdp->sd_inum_inode);
856                 fs_err(sdp, "can't read in inum inode: %d\n", error);
857                 goto fail_journal;
858         }
859
860
861         /* Read in the master statfs inode */
862         sdp->sd_statfs_inode = gfs2_lookup_simple(master, "statfs");
863         if (IS_ERR(sdp->sd_statfs_inode)) {
864                 error = PTR_ERR(sdp->sd_statfs_inode);
865                 fs_err(sdp, "can't read in statfs inode: %d\n", error);
866                 goto fail_inum;
867         }
868
869         /* Read in the resource index inode */
870         sdp->sd_rindex = gfs2_lookup_simple(master, "rindex");
871         if (IS_ERR(sdp->sd_rindex)) {
872                 error = PTR_ERR(sdp->sd_rindex);
873                 fs_err(sdp, "can't get resource index inode: %d\n", error);
874                 goto fail_statfs;
875         }
876         ip = GFS2_I(sdp->sd_rindex);
877         sdp->sd_rindex_uptodate = 0;
878
879         /* Read in the quota inode */
880         sdp->sd_quota_inode = gfs2_lookup_simple(master, "quota");
881         if (IS_ERR(sdp->sd_quota_inode)) {
882                 error = PTR_ERR(sdp->sd_quota_inode);
883                 fs_err(sdp, "can't get quota file inode: %d\n", error);
884                 goto fail_rindex;
885         }
886         return 0;
887
888 fail_qinode:
889         iput(sdp->sd_quota_inode);
890 fail_rindex:
891         gfs2_clear_rgrpd(sdp);
892         iput(sdp->sd_rindex);
893 fail_statfs:
894         iput(sdp->sd_statfs_inode);
895 fail_inum:
896         iput(sdp->sd_inum_inode);
897 fail_journal:
898         init_journal(sdp, UNDO);
899 fail:
900         return error;
901 }
902
903 static int init_per_node(struct gfs2_sbd *sdp, int undo)
904 {
905         struct inode *pn = NULL;
906         char buf[30];
907         int error = 0;
908         struct gfs2_inode *ip;
909         struct inode *master = sdp->sd_master_dir->d_inode;
910
911         if (sdp->sd_args.ar_spectator)
912                 return 0;
913
914         if (undo)
915                 goto fail_qc_gh;
916
917         pn = gfs2_lookup_simple(master, "per_node");
918         if (IS_ERR(pn)) {
919                 error = PTR_ERR(pn);
920                 fs_err(sdp, "can't find per_node directory: %d\n", error);
921                 return error;
922         }
923
924         sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
925         sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
926         if (IS_ERR(sdp->sd_ir_inode)) {
927                 error = PTR_ERR(sdp->sd_ir_inode);
928                 fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
929                 goto fail;
930         }
931
932         sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
933         sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
934         if (IS_ERR(sdp->sd_sc_inode)) {
935                 error = PTR_ERR(sdp->sd_sc_inode);
936                 fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
937                 goto fail_ir_i;
938         }
939
940         sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
941         sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
942         if (IS_ERR(sdp->sd_qc_inode)) {
943                 error = PTR_ERR(sdp->sd_qc_inode);
944                 fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
945                 goto fail_ut_i;
946         }
947
948         iput(pn);
949         pn = NULL;
950
951         ip = GFS2_I(sdp->sd_ir_inode);
952         error = gfs2_glock_nq_init(ip->i_gl,
953                                    LM_ST_EXCLUSIVE, 0,
954                                    &sdp->sd_ir_gh);
955         if (error) {
956                 fs_err(sdp, "can't lock local \"ir\" file: %d\n", error);
957                 goto fail_qc_i;
958         }
959
960         ip = GFS2_I(sdp->sd_sc_inode);
961         error = gfs2_glock_nq_init(ip->i_gl,
962                                    LM_ST_EXCLUSIVE, 0,
963                                    &sdp->sd_sc_gh);
964         if (error) {
965                 fs_err(sdp, "can't lock local \"sc\" file: %d\n", error);
966                 goto fail_ir_gh;
967         }
968
969         ip = GFS2_I(sdp->sd_qc_inode);
970         error = gfs2_glock_nq_init(ip->i_gl,
971                                    LM_ST_EXCLUSIVE, 0,
972                                    &sdp->sd_qc_gh);
973         if (error) {
974                 fs_err(sdp, "can't lock local \"qc\" file: %d\n", error);
975                 goto fail_ut_gh;
976         }
977
978         return 0;
979
980 fail_qc_gh:
981         gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
982 fail_ut_gh:
983         gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
984 fail_ir_gh:
985         gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
986 fail_qc_i:
987         iput(sdp->sd_qc_inode);
988 fail_ut_i:
989         iput(sdp->sd_sc_inode);
990 fail_ir_i:
991         iput(sdp->sd_ir_inode);
992 fail:
993         if (pn)
994                 iput(pn);
995         return error;
996 }
997
998 static int init_threads(struct gfs2_sbd *sdp, int undo)
999 {
1000         struct task_struct *p;
1001         int error = 0;
1002
1003         if (undo)
1004                 goto fail_quotad;
1005
1006         sdp->sd_log_flush_time = jiffies;
1007         sdp->sd_jindex_refresh_time = jiffies;
1008
1009         p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
1010         error = IS_ERR(p);
1011         if (error) {
1012                 fs_err(sdp, "can't start logd thread: %d\n", error);
1013                 return error;
1014         }
1015         sdp->sd_logd_process = p;
1016
1017         p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
1018         error = IS_ERR(p);
1019         if (error) {
1020                 fs_err(sdp, "can't start quotad thread: %d\n", error);
1021                 goto fail;
1022         }
1023         sdp->sd_quotad_process = p;
1024
1025         return 0;
1026
1027
1028 fail_quotad:
1029         kthread_stop(sdp->sd_quotad_process);
1030 fail:
1031         kthread_stop(sdp->sd_logd_process);
1032         return error;
1033 }
1034
1035 /**
1036  * gfs2_lm_mount - mount a locking protocol
1037  * @sdp: the filesystem
1038  * @args: mount arguements
1039  * @silent: if 1, don't complain if the FS isn't a GFS2 fs
1040  *
1041  * Returns: errno
1042  */
1043
1044 static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
1045 {
1046         char *proto = sdp->sd_proto_name;
1047         char *table = sdp->sd_table_name;
1048         int flags = LM_MFLAG_CONV_NODROP;
1049         int error;
1050
1051         if (sdp->sd_args.ar_spectator)
1052                 flags |= LM_MFLAG_SPECTATOR;
1053
1054         fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
1055
1056         error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata,
1057                                      gfs2_glock_cb, sdp,
1058                                      GFS2_MIN_LVB_SIZE, flags,
1059                                      &sdp->sd_lockstruct, &sdp->sd_kobj);
1060         if (error) {
1061                 fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n",
1062                         proto, table, sdp->sd_args.ar_hostdata);
1063                 goto out;
1064         }
1065
1066         if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) ||
1067             gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >=
1068                                   GFS2_MIN_LVB_SIZE)) {
1069                 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
1070                 goto out;
1071         }
1072
1073         if (sdp->sd_args.ar_spectator)
1074                 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table);
1075         else
1076                 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
1077                          sdp->sd_lockstruct.ls_jid);
1078
1079         fs_info(sdp, "Joined cluster. Now mounting FS...\n");
1080
1081         if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) &&
1082             !sdp->sd_args.ar_ignore_local_fs) {
1083                 sdp->sd_args.ar_localflocks = 1;
1084                 sdp->sd_args.ar_localcaching = 1;
1085         }
1086
1087 out:
1088         return error;
1089 }
1090
1091 void gfs2_lm_unmount(struct gfs2_sbd *sdp)
1092 {
1093         if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
1094                 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
1095 }
1096
1097 /**
1098  * fill_super - Read in superblock
1099  * @sb: The VFS superblock
1100  * @data: Mount options
1101  * @silent: Don't complain if it's not a GFS2 filesystem
1102  *
1103  * Returns: errno
1104  */
1105
1106 static int fill_super(struct super_block *sb, void *data, int silent)
1107 {
1108         struct gfs2_sbd *sdp;
1109         struct gfs2_holder mount_gh;
1110         int error;
1111
1112         sdp = init_sbd(sb);
1113         if (!sdp) {
1114                 printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n");
1115                 return -ENOMEM;
1116         }
1117
1118         sdp->sd_args.ar_quota = GFS2_QUOTA_DEFAULT;
1119         sdp->sd_args.ar_data = GFS2_DATA_DEFAULT;
1120
1121         error = gfs2_mount_args(sdp, &sdp->sd_args, data);
1122         if (error) {
1123                 printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
1124                 goto fail;
1125         }
1126
1127         if (sdp->sd_args.ar_spectator)
1128                 sb->s_flags |= MS_RDONLY;
1129         if (sdp->sd_args.ar_posix_acl)
1130                 sb->s_flags |= MS_POSIXACL;
1131
1132         sb->s_magic = GFS2_MAGIC;
1133         sb->s_op = &gfs2_super_ops;
1134         sb->s_export_op = &gfs2_export_ops;
1135         sb->s_time_gran = 1;
1136         sb->s_maxbytes = MAX_LFS_FILESIZE;
1137
1138         /* Set up the buffer cache and fill in some fake block size values
1139            to allow us to read-in the on-disk superblock. */
1140         sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
1141         sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
1142         sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
1143                                GFS2_BASIC_BLOCK_SHIFT;
1144         sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
1145
1146         error = init_names(sdp, silent);
1147         if (error)
1148                 goto fail;
1149
1150         gfs2_create_debugfs_file(sdp);
1151
1152         error = gfs2_sys_fs_add(sdp);
1153         if (error)
1154                 goto fail;
1155
1156         error = gfs2_lm_mount(sdp, silent);
1157         if (error)
1158                 goto fail_sys;
1159
1160         error = init_locking(sdp, &mount_gh, DO);
1161         if (error)
1162                 goto fail_lm;
1163
1164         error = init_sb(sdp, silent);
1165         if (error)
1166                 goto fail_locking;
1167
1168         error = init_inodes(sdp, DO);
1169         if (error)
1170                 goto fail_sb;
1171
1172         error = init_per_node(sdp, DO);
1173         if (error)
1174                 goto fail_inodes;
1175
1176         error = gfs2_statfs_init(sdp);
1177         if (error) {
1178                 fs_err(sdp, "can't initialize statfs subsystem: %d\n", error);
1179                 goto fail_per_node;
1180         }
1181
1182         error = init_threads(sdp, DO);
1183         if (error)
1184                 goto fail_per_node;
1185
1186         if (!(sb->s_flags & MS_RDONLY)) {
1187                 error = gfs2_make_fs_rw(sdp);
1188                 if (error) {
1189                         fs_err(sdp, "can't make FS RW: %d\n", error);
1190                         goto fail_threads;
1191                 }
1192         }
1193
1194         gfs2_glock_dq_uninit(&mount_gh);
1195
1196         return 0;
1197
1198 fail_threads:
1199         init_threads(sdp, UNDO);
1200 fail_per_node:
1201         init_per_node(sdp, UNDO);
1202 fail_inodes:
1203         init_inodes(sdp, UNDO);
1204 fail_sb:
1205         if (sdp->sd_root_dir)
1206                 dput(sdp->sd_root_dir);
1207         if (sdp->sd_master_dir)
1208                 dput(sdp->sd_master_dir);
1209         sb->s_root = NULL;
1210 fail_locking:
1211         init_locking(sdp, &mount_gh, UNDO);
1212 fail_lm:
1213         gfs2_gl_hash_clear(sdp);
1214         gfs2_lm_unmount(sdp);
1215         while (invalidate_inodes(sb))
1216                 yield();
1217 fail_sys:
1218         gfs2_sys_fs_del(sdp);
1219 fail:
1220         gfs2_delete_debugfs_file(sdp);
1221         kfree(sdp);
1222         sb->s_fs_info = NULL;
1223         return error;
1224 }
1225
1226 static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
1227                        const char *dev_name, void *data, struct vfsmount *mnt)
1228 {
1229         return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
1230 }
1231
1232 static struct super_block *get_gfs2_sb(const char *dev_name)
1233 {
1234         struct super_block *sb;
1235         struct nameidata nd;
1236         int error;
1237
1238         error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
1239         if (error) {
1240                 printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n",
1241                        dev_name, error);
1242                 return NULL;
1243         }
1244         sb = nd.path.dentry->d_inode->i_sb;
1245         if (sb && (sb->s_type == &gfs2_fs_type))
1246                 atomic_inc(&sb->s_active);
1247         else
1248                 sb = NULL;
1249         path_put(&nd.path);
1250         return sb;
1251 }
1252
1253 static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
1254                             const char *dev_name, void *data, struct vfsmount *mnt)
1255 {
1256         struct super_block *sb = NULL;
1257         struct gfs2_sbd *sdp;
1258
1259         sb = get_gfs2_sb(dev_name);
1260         if (!sb) {
1261                 printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n");
1262                 return -ENOENT;
1263         }
1264         sdp = sb->s_fs_info;
1265         mnt->mnt_sb = sb;
1266         mnt->mnt_root = dget(sdp->sd_master_dir);
1267         return 0;
1268 }
1269
1270 static void gfs2_kill_sb(struct super_block *sb)
1271 {
1272         struct gfs2_sbd *sdp = sb->s_fs_info;
1273
1274         if (sdp == NULL) {
1275                 kill_block_super(sb);
1276                 return;
1277         }
1278
1279         gfs2_meta_syncfs(sdp);
1280         dput(sdp->sd_root_dir);
1281         dput(sdp->sd_master_dir);
1282         sdp->sd_root_dir = NULL;
1283         sdp->sd_master_dir = NULL;
1284         shrink_dcache_sb(sb);
1285         kill_block_super(sb);
1286         gfs2_delete_debugfs_file(sdp);
1287         kfree(sdp);
1288 }
1289
1290 struct file_system_type gfs2_fs_type = {
1291         .name = "gfs2",
1292         .fs_flags = FS_REQUIRES_DEV,
1293         .get_sb = gfs2_get_sb,
1294         .kill_sb = gfs2_kill_sb,
1295         .owner = THIS_MODULE,
1296 };
1297
1298 struct file_system_type gfs2meta_fs_type = {
1299         .name = "gfs2meta",
1300         .fs_flags = FS_REQUIRES_DEV,
1301         .get_sb = gfs2_get_sb_meta,
1302         .owner = THIS_MODULE,
1303 };
1304