blob: b4d1d6490633dbbe6a0662824526c976ef091d28 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Bob Petersoncf45b752008-01-31 10:31:39 -06003 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
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>
David Teiglandb3b94fa2006-01-16 16:50:04 +000015#include <linux/blkdev.h>
16#include <linux/kthread.h>
Abhijith Das86384602006-08-25 11:13:37 -050017#include <linux/namei.h>
18#include <linux/mount.h>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050019#include <linux/gfs2_ondisk.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020020#include <linux/lm_interface.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000021
22#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050023#include "incore.h"
Bob Petersonda6dd402007-12-11 18:49:21 -060024#include "bmap.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000025#include "daemon.h"
26#include "glock.h"
27#include "glops.h"
28#include "inode.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000029#include "mount.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000030#include "ops_fstype.h"
Denis Chengca5a9392007-07-31 18:31:12 +080031#include "ops_dentry.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000032#include "ops_super.h"
33#include "recovery.h"
34#include "rgrp.h"
35#include "super.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000036#include "sys.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050037#include "util.h"
Steven Whitehousebb3b0e32007-08-16 16:03:57 +010038#include "log.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000039
40#define DO 0
41#define UNDO 1
42
43static struct gfs2_sbd *init_sbd(struct super_block *sb)
44{
45 struct gfs2_sbd *sdp;
David Teiglandb3b94fa2006-01-16 16:50:04 +000046
Steven Whitehouse85d1da62006-09-07 14:40:21 -040047 sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
David Teiglandb3b94fa2006-01-16 16:50:04 +000048 if (!sdp)
49 return NULL;
50
Steven Whitehouse5c676f62006-02-27 17:23:27 -050051 sb->s_fs_info = sdp;
David Teiglandb3b94fa2006-01-16 16:50:04 +000052 sdp->sd_vfs = sb;
53
54 gfs2_tune_init(&sdp->sd_tune);
55
David Teiglandb3b94fa2006-01-16 16:50:04 +000056 INIT_LIST_HEAD(&sdp->sd_reclaim_list);
57 spin_lock_init(&sdp->sd_reclaim_lock);
58 init_waitqueue_head(&sdp->sd_reclaim_wq);
David Teiglandb3b94fa2006-01-16 16:50:04 +000059
Steven Whitehousef55ab262006-02-21 12:51:39 +000060 mutex_init(&sdp->sd_inum_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000061 spin_lock_init(&sdp->sd_statfs_spin);
David Teiglandb3b94fa2006-01-16 16:50:04 +000062
63 spin_lock_init(&sdp->sd_rindex_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000064 mutex_init(&sdp->sd_rindex_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000065 INIT_LIST_HEAD(&sdp->sd_rindex_list);
66 INIT_LIST_HEAD(&sdp->sd_rindex_mru_list);
David Teiglandb3b94fa2006-01-16 16:50:04 +000067
68 INIT_LIST_HEAD(&sdp->sd_jindex_list);
69 spin_lock_init(&sdp->sd_jindex_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000070 mutex_init(&sdp->sd_jindex_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000071
David Teiglandb3b94fa2006-01-16 16:50:04 +000072 INIT_LIST_HEAD(&sdp->sd_quota_list);
73 spin_lock_init(&sdp->sd_quota_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000074 mutex_init(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000075
76 spin_lock_init(&sdp->sd_log_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000077
David Teiglandb3b94fa2006-01-16 16:50:04 +000078 INIT_LIST_HEAD(&sdp->sd_log_le_buf);
79 INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
80 INIT_LIST_HEAD(&sdp->sd_log_le_rg);
81 INIT_LIST_HEAD(&sdp->sd_log_le_databuf);
Steven Whitehoused7b616e2007-09-02 10:48:13 +010082 INIT_LIST_HEAD(&sdp->sd_log_le_ordered);
David Teiglandb3b94fa2006-01-16 16:50:04 +000083
Steven Whitehouse71b86f52006-03-28 14:14:04 -050084 mutex_init(&sdp->sd_log_reserve_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000085 INIT_LIST_HEAD(&sdp->sd_ail1_list);
86 INIT_LIST_HEAD(&sdp->sd_ail2_list);
87
Steven Whitehouse484adff2006-03-29 09:12:12 -050088 init_rwsem(&sdp->sd_log_flush_lock);
Steven Whitehouse16615be2007-09-17 10:59:52 +010089 atomic_set(&sdp->sd_log_in_flight, 0);
90 init_waitqueue_head(&sdp->sd_log_flush_wait);
David Teiglandb3b94fa2006-01-16 16:50:04 +000091
92 INIT_LIST_HEAD(&sdp->sd_revoke_list);
93
Steven Whitehousef55ab262006-02-21 12:51:39 +000094 mutex_init(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000095
96 return sdp;
97}
98
Steven Whitehouse419c93e2006-03-02 16:33:41 -050099static void init_vfs(struct super_block *sb, unsigned noatime)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000100{
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500101 struct gfs2_sbd *sdp = sb->s_fs_info;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000102
103 sb->s_magic = GFS2_MAGIC;
104 sb->s_op = &gfs2_super_ops;
105 sb->s_export_op = &gfs2_export_ops;
Steven Whitehouse4bd91ba2007-06-05 09:39:18 +0100106 sb->s_time_gran = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000107 sb->s_maxbytes = MAX_LFS_FILESIZE;
108
109 if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME))
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500110 set_bit(noatime, &sdp->sd_flags);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000111
112 /* Don't let the VFS update atimes. GFS2 handles this itself. */
113 sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000114}
115
116static int init_names(struct gfs2_sbd *sdp, int silent)
117{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000118 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]) {
Steven Whitehousebb8d8a62007-06-01 14:11:58 +0100127 error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
128 if (error)
129 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000130
Steven Whitehouse3cf1e7b2006-10-02 11:49:41 -0400131 error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000132 if (error)
133 goto out;
134
135 if (!proto[0])
Steven Whitehouse3cf1e7b2006-10-02 11:49:41 -0400136 proto = sdp->sd_sb.sb_lockproto;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000137 if (!table[0])
Steven Whitehouse3cf1e7b2006-10-02 11:49:41 -0400138 table = sdp->sd_sb.sb_locktable;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000139 }
140
141 if (!table[0])
142 table = sdp->sd_vfs->s_id;
143
Jean Delvare00377d82008-05-09 17:59:51 +0200144 strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
145 strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000146
Denis Cheng5d35e312007-08-13 11:01:58 +0800147 table = sdp->sd_table_name;
148 while ((table = strchr(table, '/')))
Robert Petersonb35997d2007-06-07 09:10:01 -0500149 *table = '_';
150
Steven Whitehousea91ea692006-09-04 12:04:26 -0400151out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000152 return error;
153}
154
155static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
156 int undo)
157{
158 struct task_struct *p;
159 int error = 0;
160
161 if (undo)
162 goto fail_trans;
163
David Teiglandb3b94fa2006-01-16 16:50:04 +0000164 for (sdp->sd_glockd_num = 0;
165 sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd;
166 sdp->sd_glockd_num++) {
167 p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd");
168 error = IS_ERR(p);
169 if (error) {
170 fs_err(sdp, "can't start glockd thread: %d\n", error);
171 goto fail;
172 }
173 sdp->sd_glockd_process[sdp->sd_glockd_num] = p;
174 }
175
176 error = gfs2_glock_nq_num(sdp,
177 GFS2_MOUNT_LOCK, &gfs2_nondisk_glops,
178 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE,
179 mount_gh);
180 if (error) {
181 fs_err(sdp, "can't acquire mount glock: %d\n", error);
182 goto fail;
183 }
184
185 error = gfs2_glock_nq_num(sdp,
186 GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
187 LM_ST_SHARED,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400188 LM_FLAG_NOEXP | GL_EXACT,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000189 &sdp->sd_live_gh);
190 if (error) {
191 fs_err(sdp, "can't acquire live glock: %d\n", error);
192 goto fail_mount;
193 }
194
195 error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops,
196 CREATE, &sdp->sd_rename_gl);
197 if (error) {
198 fs_err(sdp, "can't create rename glock: %d\n", error);
199 goto fail_live;
200 }
201
202 error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops,
203 CREATE, &sdp->sd_trans_gl);
204 if (error) {
205 fs_err(sdp, "can't create transaction glock: %d\n", error);
206 goto fail_rename;
207 }
208 set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags);
209
210 return 0;
211
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400212fail_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000213 gfs2_glock_put(sdp->sd_trans_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400214fail_rename:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000215 gfs2_glock_put(sdp->sd_rename_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400216fail_live:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000217 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400218fail_mount:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000219 gfs2_glock_dq_uninit(mount_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400220fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000221 while (sdp->sd_glockd_num--)
222 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
223
David Teiglandb3b94fa2006-01-16 16:50:04 +0000224 return error;
225}
226
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100227static inline struct inode *gfs2_lookup_root(struct super_block *sb,
228 u64 no_addr)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000229{
Benjamin Marzinski7a9f53b2007-09-18 13:33:18 -0500230 return gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000231}
232
David Teiglandb3b94fa2006-01-16 16:50:04 +0000233static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
234{
235 struct super_block *sb = sdp->sd_vfs;
236 struct gfs2_holder sb_gh;
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100237 u64 no_addr;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000238 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000239 int error = 0;
240
241 if (undo) {
Russell Cattelan88721872006-08-10 11:08:40 -0500242 if (sb->s_root) {
243 dput(sb->s_root);
244 sb->s_root = NULL;
245 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000246 return 0;
247 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400248
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400249 error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000250 LM_ST_SHARED, 0, &sb_gh);
251 if (error) {
252 fs_err(sdp, "can't acquire superblock glock: %d\n", error);
253 return error;
254 }
255
256 error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent);
257 if (error) {
258 fs_err(sdp, "can't read superblock: %d\n", error);
259 goto out;
260 }
261
262 /* Set up the buffer cache and SB for real */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000263 if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500264 error = -EINVAL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000265 fs_err(sdp, "FS block size (%u) is too small for device "
266 "block size (%u)\n",
267 sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
268 goto out;
269 }
270 if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500271 error = -EINVAL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000272 fs_err(sdp, "FS block size (%u) is too big for machine "
273 "page size (%u)\n",
274 sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
275 goto out;
276 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000277 sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
278
Steven Whitehousef42faf42006-01-30 18:34:10 +0000279 /* Get the root inode */
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100280 no_addr = sdp->sd_sb.sb_root_dir.no_addr;
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500281 if (sb->s_type == &gfs2meta_fs_type)
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100282 no_addr = sdp->sd_sb.sb_master_dir.no_addr;
283 inode = gfs2_lookup_root(sb, no_addr);
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500284 if (IS_ERR(inode)) {
285 error = PTR_ERR(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000286 fs_err(sdp, "can't read in root inode: %d\n", error);
287 goto out;
288 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000289
Steven Whitehousef42faf42006-01-30 18:34:10 +0000290 sb->s_root = d_alloc_root(inode);
291 if (!sb->s_root) {
292 fs_err(sdp, "can't get root dentry\n");
293 error = -ENOMEM;
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500294 iput(inode);
Denis Cheng34eaae32007-08-15 23:54:44 +0800295 } else
296 sb->s_root->d_op = &gfs2_dops;
297
Steven Whitehousef42faf42006-01-30 18:34:10 +0000298out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000299 gfs2_glock_dq_uninit(&sb_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000300 return error;
301}
302
Bob Petersonda6dd402007-12-11 18:49:21 -0600303/**
304 * map_journal_extents - create a reusable "extent" mapping from all logical
305 * blocks to all physical blocks for the given journal. This will save
306 * us time when writing journal blocks. Most journals will have only one
307 * extent that maps all their logical blocks. That's because gfs2.mkfs
308 * arranges the journal blocks sequentially to maximize performance.
309 * So the extent would map the first block for the entire file length.
310 * However, gfs2_jadd can happen while file activity is happening, so
311 * those journals may not be sequential. Less likely is the case where
312 * the users created their own journals by mounting the metafs and
313 * laying it out. But it's still possible. These journals might have
314 * several extents.
315 *
316 * TODO: This should be done in bigger chunks rather than one block at a time,
317 * but since it's only done at mount time, I'm not worried about the
318 * time it takes.
319 */
320static int map_journal_extents(struct gfs2_sbd *sdp)
321{
322 struct gfs2_jdesc *jd = sdp->sd_jdesc;
323 unsigned int lb;
324 u64 db, prev_db; /* logical block, disk block, prev disk block */
325 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
326 struct gfs2_journal_extent *jext = NULL;
327 struct buffer_head bh;
328 int rc = 0;
329
Bob Petersonda6dd402007-12-11 18:49:21 -0600330 prev_db = 0;
331
Bob Petersonfa3742f2007-12-12 17:52:13 -0600332 for (lb = 0; lb < ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; lb++) {
Bob Petersonda6dd402007-12-11 18:49:21 -0600333 bh.b_state = 0;
334 bh.b_blocknr = 0;
335 bh.b_size = 1 << ip->i_inode.i_blkbits;
336 rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0);
337 db = bh.b_blocknr;
338 if (rc || !db) {
339 printk(KERN_INFO "GFS2 journal mapping error %d: lb="
340 "%u db=%llu\n", rc, lb, (unsigned long long)db);
341 break;
342 }
343 if (!prev_db || db != prev_db + 1) {
344 jext = kzalloc(sizeof(struct gfs2_journal_extent),
345 GFP_KERNEL);
346 if (!jext) {
347 printk(KERN_INFO "GFS2 error: out of memory "
348 "mapping journal extents.\n");
349 rc = -ENOMEM;
350 break;
351 }
352 jext->dblock = db;
353 jext->lblock = lb;
354 jext->blocks = 1;
355 list_add_tail(&jext->extent_list, &jd->extent_list);
356 } else {
357 jext->blocks++;
358 }
359 prev_db = db;
360 }
361 return rc;
362}
363
Steven Whitehouseda755fd2008-01-30 15:34:04 +0000364static void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp)
365{
Steven Whitehouse048bca22008-05-23 14:46:04 +0100366 if (!sdp->sd_lockstruct.ls_ops->lm_others_may_mount)
367 return;
Steven Whitehouseda755fd2008-01-30 15:34:04 +0000368 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
369 sdp->sd_lockstruct.ls_ops->lm_others_may_mount(
370 sdp->sd_lockstruct.ls_lockspace);
371}
372
David Teiglandb3b94fa2006-01-16 16:50:04 +0000373static int init_journal(struct gfs2_sbd *sdp, int undo)
374{
375 struct gfs2_holder ji_gh;
376 struct task_struct *p;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500377 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000378 int jindex = 1;
379 int error = 0;
380
381 if (undo) {
382 jindex = 0;
383 goto fail_recoverd;
384 }
385
Steven Whitehousec7526662006-03-20 12:30:04 -0500386 sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex");
387 if (IS_ERR(sdp->sd_jindex)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000388 fs_err(sdp, "can't lookup journal index: %d\n", error);
Steven Whitehousec7526662006-03-20 12:30:04 -0500389 return PTR_ERR(sdp->sd_jindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000390 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400391 ip = GFS2_I(sdp->sd_jindex);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500392 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000393
394 /* Load in the journal index special file */
395
396 error = gfs2_jindex_hold(sdp, &ji_gh);
397 if (error) {
398 fs_err(sdp, "can't read journal index: %d\n", error);
399 goto fail;
400 }
401
402 error = -EINVAL;
403 if (!gfs2_jindex_size(sdp)) {
404 fs_err(sdp, "no journals!\n");
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400405 goto fail_jindex;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000406 }
407
408 if (sdp->sd_args.ar_spectator) {
409 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
Steven Whitehousefd041f02007-11-08 14:55:03 +0000410 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000411 } else {
412 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
413 fs_err(sdp, "can't mount journal #%u\n",
414 sdp->sd_lockstruct.ls_jid);
415 fs_err(sdp, "there are only %u journals (0 - %u)\n",
416 gfs2_jindex_size(sdp),
417 gfs2_jindex_size(sdp) - 1);
418 goto fail_jindex;
419 }
420 sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
421
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400422 error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000423 &gfs2_journal_glops,
424 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
425 &sdp->sd_journal_gh);
426 if (error) {
427 fs_err(sdp, "can't acquire journal glock: %d\n", error);
428 goto fail_jindex;
429 }
430
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400431 ip = GFS2_I(sdp->sd_jdesc->jd_inode);
432 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
Bob Peterson75be73a2007-08-08 17:08:14 -0500433 LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000434 &sdp->sd_jinode_gh);
435 if (error) {
436 fs_err(sdp, "can't acquire journal inode glock: %d\n",
437 error);
438 goto fail_journal_gh;
439 }
440
441 error = gfs2_jdesc_check(sdp->sd_jdesc);
442 if (error) {
443 fs_err(sdp, "my journal (%u) is bad: %d\n",
444 sdp->sd_jdesc->jd_jid, error);
445 goto fail_jinode_gh;
446 }
Steven Whitehousefd041f02007-11-08 14:55:03 +0000447 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
Bob Petersonda6dd402007-12-11 18:49:21 -0600448
449 /* Map the extents for this journal's blocks */
450 map_journal_extents(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000451 }
452
453 if (sdp->sd_lockstruct.ls_first) {
454 unsigned int x;
455 for (x = 0; x < sdp->sd_journals; x++) {
David Teiglandc63e31c2006-04-20 17:03:48 -0400456 error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000457 if (error) {
458 fs_err(sdp, "error recovering journal %u: %d\n",
459 x, error);
460 goto fail_jinode_gh;
461 }
462 }
463
464 gfs2_lm_others_may_mount(sdp);
465 } else if (!sdp->sd_args.ar_spectator) {
David Teiglandc63e31c2006-04-20 17:03:48 -0400466 error = gfs2_recover_journal(sdp->sd_jdesc);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000467 if (error) {
468 fs_err(sdp, "error recovering my journal: %d\n", error);
469 goto fail_jinode_gh;
470 }
471 }
472
473 set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags);
474 gfs2_glock_dq_uninit(&ji_gh);
475 jindex = 0;
476
David Teiglandb3b94fa2006-01-16 16:50:04 +0000477 p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
478 error = IS_ERR(p);
479 if (error) {
480 fs_err(sdp, "can't start recoverd thread: %d\n", error);
481 goto fail_jinode_gh;
482 }
483 sdp->sd_recoverd_process = p;
484
485 return 0;
486
Steven Whitehousea91ea692006-09-04 12:04:26 -0400487fail_recoverd:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000488 kthread_stop(sdp->sd_recoverd_process);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400489fail_jinode_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000490 if (!sdp->sd_args.ar_spectator)
491 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400492fail_journal_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000493 if (!sdp->sd_args.ar_spectator)
494 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400495fail_jindex:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000496 gfs2_jindex_free(sdp);
497 if (jindex)
498 gfs2_glock_dq_uninit(&ji_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400499fail:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000500 iput(sdp->sd_jindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000501 return error;
502}
503
David Teiglandb3b94fa2006-01-16 16:50:04 +0000504
505static int init_inodes(struct gfs2_sbd *sdp, int undo)
506{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000507 int error = 0;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500508 struct gfs2_inode *ip;
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500509 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000510
511 if (undo)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000512 goto fail_qinode;
513
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100514 inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr);
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500515 if (IS_ERR(inode)) {
516 error = PTR_ERR(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000517 fs_err(sdp, "can't read in master directory: %d\n", error);
518 goto fail;
519 }
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500520 sdp->sd_master_dir = inode;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000521
522 error = init_journal(sdp, undo);
523 if (error)
524 goto fail_master;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000525
526 /* Read in the master inode number inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500527 sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum");
528 if (IS_ERR(sdp->sd_inum_inode)) {
529 error = PTR_ERR(sdp->sd_inum_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000530 fs_err(sdp, "can't read in inum inode: %d\n", error);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000531 goto fail_journal;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000532 }
533
Steven Whitehousef42faf42006-01-30 18:34:10 +0000534
David Teiglandb3b94fa2006-01-16 16:50:04 +0000535 /* Read in the master statfs inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500536 sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs");
537 if (IS_ERR(sdp->sd_statfs_inode)) {
538 error = PTR_ERR(sdp->sd_statfs_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000539 fs_err(sdp, "can't read in statfs inode: %d\n", error);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000540 goto fail_inum;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000541 }
542
543 /* Read in the resource index inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500544 sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex");
545 if (IS_ERR(sdp->sd_rindex)) {
546 error = PTR_ERR(sdp->sd_rindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000547 fs_err(sdp, "can't get resource index inode: %d\n", error);
548 goto fail_statfs;
549 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400550 ip = GFS2_I(sdp->sd_rindex);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500551 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
Bob Petersoncf45b752008-01-31 10:31:39 -0600552 sdp->sd_rindex_uptodate = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000553
554 /* Read in the quota inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500555 sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota");
556 if (IS_ERR(sdp->sd_quota_inode)) {
557 error = PTR_ERR(sdp->sd_quota_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000558 fs_err(sdp, "can't get quota file inode: %d\n", error);
559 goto fail_rindex;
560 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000561 return 0;
562
Steven Whitehousef42faf42006-01-30 18:34:10 +0000563fail_qinode:
564 iput(sdp->sd_quota_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000565fail_rindex:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000566 gfs2_clear_rgrpd(sdp);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000567 iput(sdp->sd_rindex);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000568fail_statfs:
569 iput(sdp->sd_statfs_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000570fail_inum:
571 iput(sdp->sd_inum_inode);
572fail_journal:
573 init_journal(sdp, UNDO);
574fail_master:
575 iput(sdp->sd_master_dir);
576fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000577 return error;
578}
579
580static int init_per_node(struct gfs2_sbd *sdp, int undo)
581{
Steven Whitehousef42faf42006-01-30 18:34:10 +0000582 struct inode *pn = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000583 char buf[30];
584 int error = 0;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500585 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000586
587 if (sdp->sd_args.ar_spectator)
588 return 0;
589
590 if (undo)
591 goto fail_qc_gh;
592
Steven Whitehousec7526662006-03-20 12:30:04 -0500593 pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node");
594 if (IS_ERR(pn)) {
595 error = PTR_ERR(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000596 fs_err(sdp, "can't find per_node directory: %d\n", error);
597 return error;
598 }
599
600 sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500601 sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
602 if (IS_ERR(sdp->sd_ir_inode)) {
603 error = PTR_ERR(sdp->sd_ir_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000604 fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
605 goto fail;
606 }
607
608 sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500609 sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
610 if (IS_ERR(sdp->sd_sc_inode)) {
611 error = PTR_ERR(sdp->sd_sc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000612 fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
613 goto fail_ir_i;
614 }
615
David Teiglandb3b94fa2006-01-16 16:50:04 +0000616 sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500617 sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
618 if (IS_ERR(sdp->sd_qc_inode)) {
619 error = PTR_ERR(sdp->sd_qc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000620 fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
621 goto fail_ut_i;
622 }
623
Steven Whitehousef42faf42006-01-30 18:34:10 +0000624 iput(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000625 pn = NULL;
626
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400627 ip = GFS2_I(sdp->sd_ir_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500628 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400629 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000630 &sdp->sd_ir_gh);
631 if (error) {
632 fs_err(sdp, "can't lock local \"ir\" file: %d\n", error);
633 goto fail_qc_i;
634 }
635
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400636 ip = GFS2_I(sdp->sd_sc_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500637 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400638 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000639 &sdp->sd_sc_gh);
640 if (error) {
641 fs_err(sdp, "can't lock local \"sc\" file: %d\n", error);
642 goto fail_ir_gh;
643 }
644
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400645 ip = GFS2_I(sdp->sd_qc_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500646 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400647 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000648 &sdp->sd_qc_gh);
649 if (error) {
650 fs_err(sdp, "can't lock local \"qc\" file: %d\n", error);
651 goto fail_ut_gh;
652 }
653
654 return 0;
655
Steven Whitehousea91ea692006-09-04 12:04:26 -0400656fail_qc_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000657 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400658fail_ut_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000659 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400660fail_ir_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000661 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400662fail_qc_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000663 iput(sdp->sd_qc_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400664fail_ut_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000665 iput(sdp->sd_sc_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400666fail_ir_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000667 iput(sdp->sd_ir_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400668fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000669 if (pn)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000670 iput(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000671 return error;
672}
673
674static int init_threads(struct gfs2_sbd *sdp, int undo)
675{
676 struct task_struct *p;
677 int error = 0;
678
679 if (undo)
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400680 goto fail_quotad;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000681
682 sdp->sd_log_flush_time = jiffies;
683 sdp->sd_jindex_refresh_time = jiffies;
684
685 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
686 error = IS_ERR(p);
687 if (error) {
688 fs_err(sdp, "can't start logd thread: %d\n", error);
689 return error;
690 }
691 sdp->sd_logd_process = p;
692
693 sdp->sd_statfs_sync_time = jiffies;
694 sdp->sd_quota_sync_time = jiffies;
695
696 p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
697 error = IS_ERR(p);
698 if (error) {
699 fs_err(sdp, "can't start quotad thread: %d\n", error);
700 goto fail;
701 }
702 sdp->sd_quotad_process = p;
703
David Teiglandb3b94fa2006-01-16 16:50:04 +0000704 return 0;
705
David Teiglandb3b94fa2006-01-16 16:50:04 +0000706
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400707fail_quotad:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000708 kthread_stop(sdp->sd_quotad_process);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400709fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000710 kthread_stop(sdp->sd_logd_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000711 return error;
712}
713
714/**
Steven Whitehouseda755fd2008-01-30 15:34:04 +0000715 * gfs2_lm_mount - mount a locking protocol
716 * @sdp: the filesystem
717 * @args: mount arguements
718 * @silent: if 1, don't complain if the FS isn't a GFS2 fs
719 *
720 * Returns: errno
721 */
722
723static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
724{
725 char *proto = sdp->sd_proto_name;
726 char *table = sdp->sd_table_name;
Benjamin Marzinski58e9fee2008-03-14 13:52:52 -0500727 int flags = LM_MFLAG_CONV_NODROP;
Steven Whitehouseda755fd2008-01-30 15:34:04 +0000728 int error;
729
730 if (sdp->sd_args.ar_spectator)
731 flags |= LM_MFLAG_SPECTATOR;
732
733 fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
734
735 error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata,
736 gfs2_glock_cb, sdp,
737 GFS2_MIN_LVB_SIZE, flags,
738 &sdp->sd_lockstruct, &sdp->sd_kobj);
739 if (error) {
740 fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n",
741 proto, table, sdp->sd_args.ar_hostdata);
742 goto out;
743 }
744
Steven Whitehouse048bca22008-05-23 14:46:04 +0100745 if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) ||
Steven Whitehouseda755fd2008-01-30 15:34:04 +0000746 gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >=
747 GFS2_MIN_LVB_SIZE)) {
748 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
749 goto out;
750 }
751
752 if (sdp->sd_args.ar_spectator)
753 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table);
754 else
755 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
756 sdp->sd_lockstruct.ls_jid);
757
758 fs_info(sdp, "Joined cluster. Now mounting FS...\n");
759
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;
764 }
765
766out:
767 return error;
768}
769
770void gfs2_lm_unmount(struct gfs2_sbd *sdp)
771{
772 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
773 gfs2_unmount_lockproto(&sdp->sd_lockstruct);
774}
775
776/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000777 * 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
781 *
782 * Returns: errno
783 */
784
785static int fill_super(struct super_block *sb, void *data, int silent)
786{
787 struct gfs2_sbd *sdp;
788 struct gfs2_holder mount_gh;
789 int error;
790
791 sdp = init_sbd(sb);
792 if (!sdp) {
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500793 printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000794 return -ENOMEM;
795 }
796
797 error = gfs2_mount_args(sdp, (char *)data, 0);
798 if (error) {
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500799 printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000800 goto fail;
801 }
802
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500803 init_vfs(sb, SDF_NOATIME);
804
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;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000812
813 error = init_names(sdp, silent);
814 if (error)
815 goto fail;
816
Robert Peterson7c52b162007-03-16 10:26:37 +0000817 gfs2_create_debugfs_file(sdp);
818
David Teiglandb3b94fa2006-01-16 16:50:04 +0000819 error = gfs2_sys_fs_add(sdp);
820 if (error)
821 goto fail;
822
823 error = gfs2_lm_mount(sdp, silent);
824 if (error)
825 goto fail_sys;
826
827 error = init_locking(sdp, &mount_gh, DO);
828 if (error)
829 goto fail_lm;
830
831 error = init_sb(sdp, silent, DO);
832 if (error)
833 goto fail_locking;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000834
835 error = init_inodes(sdp, DO);
836 if (error)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000837 goto fail_sb;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000838
839 error = init_per_node(sdp, DO);
840 if (error)
841 goto fail_inodes;
842
843 error = gfs2_statfs_init(sdp);
844 if (error) {
845 fs_err(sdp, "can't initialize statfs subsystem: %d\n", error);
846 goto fail_per_node;
847 }
848
849 error = init_threads(sdp, DO);
850 if (error)
851 goto fail_per_node;
852
853 if (!(sb->s_flags & MS_RDONLY)) {
854 error = gfs2_make_fs_rw(sdp);
855 if (error) {
856 fs_err(sdp, "can't make FS RW: %d\n", error);
857 goto fail_threads;
858 }
859 }
860
861 gfs2_glock_dq_uninit(&mount_gh);
862
863 return 0;
864
Steven Whitehousea91ea692006-09-04 12:04:26 -0400865fail_threads:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000866 init_threads(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400867fail_per_node:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000868 init_per_node(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400869fail_inodes:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000870 init_inodes(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400871fail_sb:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000872 init_sb(sdp, 0, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400873fail_locking:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000874 init_locking(sdp, &mount_gh, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400875fail_lm:
Steven Whitehouse1bdad602008-06-03 14:09:53 +0100876 gfs2_gl_hash_clear(sdp);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000877 gfs2_lm_unmount(sdp);
878 while (invalidate_inodes(sb))
879 yield();
Steven Whitehousea91ea692006-09-04 12:04:26 -0400880fail_sys:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000881 gfs2_sys_fs_del(sdp);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400882fail:
Robert Peterson5f882092007-04-18 11:41:11 -0500883 gfs2_delete_debugfs_file(sdp);
Steven Whitehousea2c45802006-09-08 10:13:03 -0400884 kfree(sdp);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500885 sb->s_fs_info = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000886 return error;
887}
888
Andrew Mortonccd6efd2006-06-30 02:16:34 -0700889static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
890 const char *dev_name, void *data, struct vfsmount *mnt)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000891{
Abhijith Das86384602006-08-25 11:13:37 -0500892 struct super_block *sb;
893 struct gfs2_sbd *sdp;
894 int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
895 if (error)
896 goto out;
897 sb = mnt->mnt_sb;
Steven Whitehouse26c1a572006-09-04 15:32:10 -0400898 sdp = sb->s_fs_info;
Abhijith Das86384602006-08-25 11:13:37 -0500899 sdp->sd_gfs2mnt = mnt;
900out:
901 return error;
902}
903
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400904static int fill_super_meta(struct super_block *sb, struct super_block *new,
Abhijith Das86384602006-08-25 11:13:37 -0500905 void *data, int silent)
906{
907 struct gfs2_sbd *sdp = sb->s_fs_info;
908 struct inode *inode;
909 int error = 0;
910
911 new->s_fs_info = sdp;
912 sdp->sd_vfs_meta = sb;
913
914 init_vfs(new, SDF_NOATIME);
915
916 /* Get the master inode */
917 inode = igrab(sdp->sd_master_dir);
918
919 new->s_root = d_alloc_root(inode);
920 if (!new->s_root) {
921 fs_err(sdp, "can't get root dentry\n");
922 error = -ENOMEM;
923 iput(inode);
Adrian Bunkbbbe4512006-10-19 15:27:00 +0200924 } else
925 new->s_root->d_op = &gfs2_dops;
Abhijith Das86384602006-08-25 11:13:37 -0500926
927 return error;
928}
Steven Whitehousea91ea692006-09-04 12:04:26 -0400929
Abhijith Das86384602006-08-25 11:13:37 -0500930static int set_bdev_super(struct super_block *s, void *data)
931{
932 s->s_bdev = data;
933 s->s_dev = s->s_bdev->bd_dev;
934 return 0;
935}
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400936
Abhijith Das86384602006-08-25 11:13:37 -0500937static int test_bdev_super(struct super_block *s, void *data)
938{
Steven Whitehouse26c1a572006-09-04 15:32:10 -0400939 return s->s_bdev == data;
Abhijith Das86384602006-08-25 11:13:37 -0500940}
941
942static struct super_block* get_gfs2_sb(const char *dev_name)
943{
944 struct kstat stat;
945 struct nameidata nd;
Abhijith Das86384602006-08-25 11:13:37 -0500946 struct super_block *sb = NULL, *s;
Abhijith Das86384602006-08-25 11:13:37 -0500947 int error;
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400948
Abhijith Das86384602006-08-25 11:13:37 -0500949 error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
950 if (error) {
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400951 printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n",
Abhijith Das86384602006-08-25 11:13:37 -0500952 dev_name);
953 goto out;
954 }
Jan Blunck4ac91372008-02-14 19:34:32 -0800955 error = vfs_getattr(nd.path.mnt, nd.path.dentry, &stat);
Abhijith Das86384602006-08-25 11:13:37 -0500956
Christoph Hellwig7dc2cf12008-02-25 18:58:36 +0100957 list_for_each_entry(s, &gfs2_fs_type.fs_supers, s_instances) {
Abhijith Das86384602006-08-25 11:13:37 -0500958 if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) ||
Jan Blunck4ac91372008-02-14 19:34:32 -0800959 (S_ISDIR(stat.mode) &&
960 s == nd.path.dentry->d_inode->i_sb)) {
Abhijith Das86384602006-08-25 11:13:37 -0500961 sb = s;
962 goto free_nd;
963 }
964 }
965
966 printk(KERN_WARNING "GFS2: Unrecognized block device or "
Richard Fearnd5a67512007-02-17 17:29:15 +0000967 "mount point %s\n", dev_name);
Abhijith Das86384602006-08-25 11:13:37 -0500968
969free_nd:
Jan Blunck1d957f92008-02-14 19:34:35 -0800970 path_put(&nd.path);
Abhijith Das86384602006-08-25 11:13:37 -0500971out:
972 return sb;
973}
974
975static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
976 const char *dev_name, void *data, struct vfsmount *mnt)
977{
978 int error = 0;
979 struct super_block *sb = NULL, *new;
980 struct gfs2_sbd *sdp;
Abhijith Das86384602006-08-25 11:13:37 -0500981
982 sb = get_gfs2_sb(dev_name);
983 if (!sb) {
984 printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n");
985 error = -ENOENT;
986 goto error;
987 }
Denis Cheng2d3ba1e2007-08-11 10:27:08 +0800988 sdp = sb->s_fs_info;
Abhijith Das86384602006-08-25 11:13:37 -0500989 if (sdp->sd_vfs_meta) {
990 printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n");
991 error = -EBUSY;
992 goto error;
993 }
David Chinnerf73ca1b2007-01-10 23:15:41 -0800994 down(&sb->s_bdev->bd_mount_sem);
Abhijith Das86384602006-08-25 11:13:37 -0500995 new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev);
David Chinnerf73ca1b2007-01-10 23:15:41 -0800996 up(&sb->s_bdev->bd_mount_sem);
Abhijith Das86384602006-08-25 11:13:37 -0500997 if (IS_ERR(new)) {
998 error = PTR_ERR(new);
999 goto error;
1000 }
Abhijith Das86384602006-08-25 11:13:37 -05001001 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);
1005 if (error) {
1006 up_write(&new->s_umount);
1007 deactivate_super(new);
1008 goto error;
1009 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -04001010
Abhijith Das86384602006-08-25 11:13:37 -05001011 new->s_flags |= MS_ACTIVE;
Steven Whitehouse907b9bc2006-09-25 09:26:04 -04001012
Abhijith Das86384602006-08-25 11:13:37 -05001013 /* Grab a reference to the gfs2 mount point */
1014 atomic_inc(&sdp->sd_gfs2mnt->mnt_count);
1015 return simple_set_mnt(mnt, new);
1016error:
Abhijith Das86384602006-08-25 11:13:37 -05001017 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001018}
1019
Steven Whitehouse419c93e2006-03-02 16:33:41 -05001020static void gfs2_kill_sb(struct super_block *sb)
1021{
Abhijith Dasd1e27772007-08-23 13:33:01 -05001022 if (sb->s_fs_info) {
1023 gfs2_delete_debugfs_file(sb->s_fs_info);
1024 gfs2_meta_syncfs(sb->s_fs_info);
1025 }
Steven Whitehouse419c93e2006-03-02 16:33:41 -05001026 kill_block_super(sb);
1027}
1028
Abhijith Das86384602006-08-25 11:13:37 -05001029static void gfs2_kill_sb_meta(struct super_block *sb)
1030{
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);
1035}
1036
David Teiglandb3b94fa2006-01-16 16:50:04 +00001037struct file_system_type gfs2_fs_type = {
1038 .name = "gfs2",
1039 .fs_flags = FS_REQUIRES_DEV,
1040 .get_sb = gfs2_get_sb,
Steven Whitehouse419c93e2006-03-02 16:33:41 -05001041 .kill_sb = gfs2_kill_sb,
1042 .owner = THIS_MODULE,
1043};
1044
1045struct file_system_type gfs2meta_fs_type = {
1046 .name = "gfs2meta",
1047 .fs_flags = FS_REQUIRES_DEV,
Abhijith Das86384602006-08-25 11:13:37 -05001048 .get_sb = gfs2_get_sb_meta,
1049 .kill_sb = gfs2_kill_sb_meta,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001050 .owner = THIS_MODULE,
1051};
1052