blob: 0443e255173dd2fa1de9d170eb1b6608cc4e5d1e [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 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"
David Teiglandb3b94fa2006-01-16 16:50:04 +000024#include "daemon.h"
25#include "glock.h"
26#include "glops.h"
27#include "inode.h"
28#include "lm.h"
29#include "mount.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000030#include "ops_fstype.h"
31#include "ops_super.h"
32#include "recovery.h"
33#include "rgrp.h"
34#include "super.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000035#include "sys.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050036#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000037
38#define DO 0
39#define UNDO 1
40
Robert S Peterson5bb76af2006-05-05 16:29:50 -040041extern struct dentry_operations gfs2_dops;
42
David Teiglandb3b94fa2006-01-16 16:50:04 +000043static 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);
Steven Whitehousef55ab262006-02-21 12:51:39 +000062 mutex_init(&sdp->sd_statfs_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000063
64 spin_lock_init(&sdp->sd_rindex_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000065 mutex_init(&sdp->sd_rindex_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000066 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);
69
70 INIT_LIST_HEAD(&sdp->sd_jindex_list);
71 spin_lock_init(&sdp->sd_jindex_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000072 mutex_init(&sdp->sd_jindex_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000073
David Teiglandb3b94fa2006-01-16 16:50:04 +000074 INIT_LIST_HEAD(&sdp->sd_quota_list);
75 spin_lock_init(&sdp->sd_quota_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000076 mutex_init(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000077
78 spin_lock_init(&sdp->sd_log_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000079
80 INIT_LIST_HEAD(&sdp->sd_log_le_gl);
81 INIT_LIST_HEAD(&sdp->sd_log_le_buf);
82 INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
83 INIT_LIST_HEAD(&sdp->sd_log_le_rg);
84 INIT_LIST_HEAD(&sdp->sd_log_le_databuf);
85
Steven Whitehouse71b86f52006-03-28 14:14:04 -050086 mutex_init(&sdp->sd_log_reserve_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000087 INIT_LIST_HEAD(&sdp->sd_ail1_list);
88 INIT_LIST_HEAD(&sdp->sd_ail2_list);
89
Steven Whitehouse484adff2006-03-29 09:12:12 -050090 init_rwsem(&sdp->sd_log_flush_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000091 INIT_LIST_HEAD(&sdp->sd_log_flush_list);
92
93 INIT_LIST_HEAD(&sdp->sd_revoke_list);
94
Steven Whitehousef55ab262006-02-21 12:51:39 +000095 mutex_init(&sdp->sd_freeze_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000096
97 return sdp;
98}
99
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500100static void init_vfs(struct super_block *sb, unsigned noatime)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000101{
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500102 struct gfs2_sbd *sdp = sb->s_fs_info;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000103
104 sb->s_magic = GFS2_MAGIC;
105 sb->s_op = &gfs2_super_ops;
106 sb->s_export_op = &gfs2_export_ops;
107 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
144 snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto);
145 snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table);
146
Steven Whitehousea91ea692006-09-04 12:04:26 -0400147out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000148 return error;
149}
150
151static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
152 int undo)
153{
154 struct task_struct *p;
155 int error = 0;
156
157 if (undo)
158 goto fail_trans;
159
160 p = kthread_run(gfs2_scand, sdp, "gfs2_scand");
161 error = IS_ERR(p);
162 if (error) {
163 fs_err(sdp, "can't start scand thread: %d\n", error);
164 return error;
165 }
166 sdp->sd_scand_process = p;
167
168 for (sdp->sd_glockd_num = 0;
169 sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd;
170 sdp->sd_glockd_num++) {
171 p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd");
172 error = IS_ERR(p);
173 if (error) {
174 fs_err(sdp, "can't start glockd thread: %d\n", error);
175 goto fail;
176 }
177 sdp->sd_glockd_process[sdp->sd_glockd_num] = p;
178 }
179
180 error = gfs2_glock_nq_num(sdp,
181 GFS2_MOUNT_LOCK, &gfs2_nondisk_glops,
182 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE,
183 mount_gh);
184 if (error) {
185 fs_err(sdp, "can't acquire mount glock: %d\n", error);
186 goto fail;
187 }
188
189 error = gfs2_glock_nq_num(sdp,
190 GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
191 LM_ST_SHARED,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400192 LM_FLAG_NOEXP | GL_EXACT,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000193 &sdp->sd_live_gh);
194 if (error) {
195 fs_err(sdp, "can't acquire live glock: %d\n", error);
196 goto fail_mount;
197 }
198
199 error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops,
200 CREATE, &sdp->sd_rename_gl);
201 if (error) {
202 fs_err(sdp, "can't create rename glock: %d\n", error);
203 goto fail_live;
204 }
205
206 error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops,
207 CREATE, &sdp->sd_trans_gl);
208 if (error) {
209 fs_err(sdp, "can't create transaction glock: %d\n", error);
210 goto fail_rename;
211 }
212 set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags);
213
214 return 0;
215
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400216fail_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000217 gfs2_glock_put(sdp->sd_trans_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400218fail_rename:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000219 gfs2_glock_put(sdp->sd_rename_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400220fail_live:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000221 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400222fail_mount:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000223 gfs2_glock_dq_uninit(mount_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400224fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000225 while (sdp->sd_glockd_num--)
226 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
227
228 kthread_stop(sdp->sd_scand_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000229 return error;
230}
231
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100232static inline struct inode *gfs2_lookup_root(struct super_block *sb,
233 u64 no_addr)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000234{
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100235 return gfs2_inode_lookup(sb, no_addr, DT_DIR);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000236}
237
David Teiglandb3b94fa2006-01-16 16:50:04 +0000238static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
239{
240 struct super_block *sb = sdp->sd_vfs;
241 struct gfs2_holder sb_gh;
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100242 u64 no_addr;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000243 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000244 int error = 0;
245
246 if (undo) {
Russell Cattelan88721872006-08-10 11:08:40 -0500247 if (sb->s_root) {
248 dput(sb->s_root);
249 sb->s_root = NULL;
250 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000251 return 0;
252 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400253
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400254 error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000255 LM_ST_SHARED, 0, &sb_gh);
256 if (error) {
257 fs_err(sdp, "can't acquire superblock glock: %d\n", error);
258 return error;
259 }
260
261 error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent);
262 if (error) {
263 fs_err(sdp, "can't read superblock: %d\n", error);
264 goto out;
265 }
266
267 /* Set up the buffer cache and SB for real */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000268 if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500269 error = -EINVAL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000270 fs_err(sdp, "FS block size (%u) is too small for device "
271 "block size (%u)\n",
272 sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
273 goto out;
274 }
275 if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500276 error = -EINVAL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000277 fs_err(sdp, "FS block size (%u) is too big for machine "
278 "page size (%u)\n",
279 sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
280 goto out;
281 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000282 sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
283
Steven Whitehousef42faf42006-01-30 18:34:10 +0000284 /* Get the root inode */
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100285 no_addr = sdp->sd_sb.sb_root_dir.no_addr;
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500286 if (sb->s_type == &gfs2meta_fs_type)
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100287 no_addr = sdp->sd_sb.sb_master_dir.no_addr;
288 inode = gfs2_lookup_root(sb, no_addr);
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500289 if (IS_ERR(inode)) {
290 error = PTR_ERR(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000291 fs_err(sdp, "can't read in root inode: %d\n", error);
292 goto out;
293 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000294
Steven Whitehousef42faf42006-01-30 18:34:10 +0000295 sb->s_root = d_alloc_root(inode);
296 if (!sb->s_root) {
297 fs_err(sdp, "can't get root dentry\n");
298 error = -ENOMEM;
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500299 iput(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000300 }
Robert S Peterson5bb76af2006-05-05 16:29:50 -0400301 sb->s_root->d_op = &gfs2_dops;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000302out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000303 gfs2_glock_dq_uninit(&sb_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000304 return error;
305}
306
307static int init_journal(struct gfs2_sbd *sdp, int undo)
308{
309 struct gfs2_holder ji_gh;
310 struct task_struct *p;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500311 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000312 int jindex = 1;
313 int error = 0;
314
315 if (undo) {
316 jindex = 0;
317 goto fail_recoverd;
318 }
319
Steven Whitehousec7526662006-03-20 12:30:04 -0500320 sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex");
321 if (IS_ERR(sdp->sd_jindex)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000322 fs_err(sdp, "can't lookup journal index: %d\n", error);
Steven Whitehousec7526662006-03-20 12:30:04 -0500323 return PTR_ERR(sdp->sd_jindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000324 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400325 ip = GFS2_I(sdp->sd_jindex);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500326 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000327
328 /* Load in the journal index special file */
329
330 error = gfs2_jindex_hold(sdp, &ji_gh);
331 if (error) {
332 fs_err(sdp, "can't read journal index: %d\n", error);
333 goto fail;
334 }
335
336 error = -EINVAL;
337 if (!gfs2_jindex_size(sdp)) {
338 fs_err(sdp, "no journals!\n");
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400339 goto fail_jindex;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000340 }
341
342 if (sdp->sd_args.ar_spectator) {
343 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
344 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks;
345 } else {
346 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
347 fs_err(sdp, "can't mount journal #%u\n",
348 sdp->sd_lockstruct.ls_jid);
349 fs_err(sdp, "there are only %u journals (0 - %u)\n",
350 gfs2_jindex_size(sdp),
351 gfs2_jindex_size(sdp) - 1);
352 goto fail_jindex;
353 }
354 sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
355
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400356 error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000357 &gfs2_journal_glops,
358 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
359 &sdp->sd_journal_gh);
360 if (error) {
361 fs_err(sdp, "can't acquire journal glock: %d\n", error);
362 goto fail_jindex;
363 }
364
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400365 ip = GFS2_I(sdp->sd_jdesc->jd_inode);
366 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000367 LM_FLAG_NOEXP | GL_EXACT,
368 &sdp->sd_jinode_gh);
369 if (error) {
370 fs_err(sdp, "can't acquire journal inode glock: %d\n",
371 error);
372 goto fail_journal_gh;
373 }
374
375 error = gfs2_jdesc_check(sdp->sd_jdesc);
376 if (error) {
377 fs_err(sdp, "my journal (%u) is bad: %d\n",
378 sdp->sd_jdesc->jd_jid, error);
379 goto fail_jinode_gh;
380 }
381 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks;
382 }
383
384 if (sdp->sd_lockstruct.ls_first) {
385 unsigned int x;
386 for (x = 0; x < sdp->sd_journals; x++) {
David Teiglandc63e31c2006-04-20 17:03:48 -0400387 error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000388 if (error) {
389 fs_err(sdp, "error recovering journal %u: %d\n",
390 x, error);
391 goto fail_jinode_gh;
392 }
393 }
394
395 gfs2_lm_others_may_mount(sdp);
396 } else if (!sdp->sd_args.ar_spectator) {
David Teiglandc63e31c2006-04-20 17:03:48 -0400397 error = gfs2_recover_journal(sdp->sd_jdesc);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000398 if (error) {
399 fs_err(sdp, "error recovering my journal: %d\n", error);
400 goto fail_jinode_gh;
401 }
402 }
403
404 set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags);
405 gfs2_glock_dq_uninit(&ji_gh);
406 jindex = 0;
407
David Teiglandb3b94fa2006-01-16 16:50:04 +0000408 p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
409 error = IS_ERR(p);
410 if (error) {
411 fs_err(sdp, "can't start recoverd thread: %d\n", error);
412 goto fail_jinode_gh;
413 }
414 sdp->sd_recoverd_process = p;
415
416 return 0;
417
Steven Whitehousea91ea692006-09-04 12:04:26 -0400418fail_recoverd:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000419 kthread_stop(sdp->sd_recoverd_process);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400420fail_jinode_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000421 if (!sdp->sd_args.ar_spectator)
422 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400423fail_journal_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000424 if (!sdp->sd_args.ar_spectator)
425 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400426fail_jindex:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000427 gfs2_jindex_free(sdp);
428 if (jindex)
429 gfs2_glock_dq_uninit(&ji_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400430fail:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000431 iput(sdp->sd_jindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000432 return error;
433}
434
David Teiglandb3b94fa2006-01-16 16:50:04 +0000435
436static int init_inodes(struct gfs2_sbd *sdp, int undo)
437{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000438 int error = 0;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500439 struct gfs2_inode *ip;
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500440 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000441
442 if (undo)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000443 goto fail_qinode;
444
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100445 inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr);
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500446 if (IS_ERR(inode)) {
447 error = PTR_ERR(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000448 fs_err(sdp, "can't read in master directory: %d\n", error);
449 goto fail;
450 }
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500451 sdp->sd_master_dir = inode;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000452
453 error = init_journal(sdp, undo);
454 if (error)
455 goto fail_master;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000456
457 /* Read in the master inode number inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500458 sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum");
459 if (IS_ERR(sdp->sd_inum_inode)) {
460 error = PTR_ERR(sdp->sd_inum_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000461 fs_err(sdp, "can't read in inum inode: %d\n", error);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000462 goto fail_journal;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000463 }
464
Steven Whitehousef42faf42006-01-30 18:34:10 +0000465
David Teiglandb3b94fa2006-01-16 16:50:04 +0000466 /* Read in the master statfs inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500467 sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs");
468 if (IS_ERR(sdp->sd_statfs_inode)) {
469 error = PTR_ERR(sdp->sd_statfs_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000470 fs_err(sdp, "can't read in statfs inode: %d\n", error);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000471 goto fail_inum;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000472 }
473
474 /* Read in the resource index inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500475 sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex");
476 if (IS_ERR(sdp->sd_rindex)) {
477 error = PTR_ERR(sdp->sd_rindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000478 fs_err(sdp, "can't get resource index inode: %d\n", error);
479 goto fail_statfs;
480 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400481 ip = GFS2_I(sdp->sd_rindex);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500482 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
483 sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000484
485 /* Read in the quota inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500486 sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota");
487 if (IS_ERR(sdp->sd_quota_inode)) {
488 error = PTR_ERR(sdp->sd_quota_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000489 fs_err(sdp, "can't get quota file inode: %d\n", error);
490 goto fail_rindex;
491 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000492 return 0;
493
Steven Whitehousef42faf42006-01-30 18:34:10 +0000494fail_qinode:
495 iput(sdp->sd_quota_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000496fail_rindex:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000497 gfs2_clear_rgrpd(sdp);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000498 iput(sdp->sd_rindex);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000499fail_statfs:
500 iput(sdp->sd_statfs_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000501fail_inum:
502 iput(sdp->sd_inum_inode);
503fail_journal:
504 init_journal(sdp, UNDO);
505fail_master:
506 iput(sdp->sd_master_dir);
507fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000508 return error;
509}
510
511static int init_per_node(struct gfs2_sbd *sdp, int undo)
512{
Steven Whitehousef42faf42006-01-30 18:34:10 +0000513 struct inode *pn = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000514 char buf[30];
515 int error = 0;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500516 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000517
518 if (sdp->sd_args.ar_spectator)
519 return 0;
520
521 if (undo)
522 goto fail_qc_gh;
523
Steven Whitehousec7526662006-03-20 12:30:04 -0500524 pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node");
525 if (IS_ERR(pn)) {
526 error = PTR_ERR(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000527 fs_err(sdp, "can't find per_node directory: %d\n", error);
528 return error;
529 }
530
531 sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500532 sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
533 if (IS_ERR(sdp->sd_ir_inode)) {
534 error = PTR_ERR(sdp->sd_ir_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000535 fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
536 goto fail;
537 }
538
539 sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500540 sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
541 if (IS_ERR(sdp->sd_sc_inode)) {
542 error = PTR_ERR(sdp->sd_sc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000543 fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
544 goto fail_ir_i;
545 }
546
David Teiglandb3b94fa2006-01-16 16:50:04 +0000547 sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500548 sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
549 if (IS_ERR(sdp->sd_qc_inode)) {
550 error = PTR_ERR(sdp->sd_qc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000551 fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
552 goto fail_ut_i;
553 }
554
Steven Whitehousef42faf42006-01-30 18:34:10 +0000555 iput(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000556 pn = NULL;
557
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400558 ip = GFS2_I(sdp->sd_ir_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500559 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400560 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000561 &sdp->sd_ir_gh);
562 if (error) {
563 fs_err(sdp, "can't lock local \"ir\" file: %d\n", error);
564 goto fail_qc_i;
565 }
566
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400567 ip = GFS2_I(sdp->sd_sc_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500568 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400569 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000570 &sdp->sd_sc_gh);
571 if (error) {
572 fs_err(sdp, "can't lock local \"sc\" file: %d\n", error);
573 goto fail_ir_gh;
574 }
575
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400576 ip = GFS2_I(sdp->sd_qc_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500577 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400578 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000579 &sdp->sd_qc_gh);
580 if (error) {
581 fs_err(sdp, "can't lock local \"qc\" file: %d\n", error);
582 goto fail_ut_gh;
583 }
584
585 return 0;
586
Steven Whitehousea91ea692006-09-04 12:04:26 -0400587fail_qc_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000588 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400589fail_ut_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000590 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400591fail_ir_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000592 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400593fail_qc_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000594 iput(sdp->sd_qc_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400595fail_ut_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000596 iput(sdp->sd_sc_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400597fail_ir_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000598 iput(sdp->sd_ir_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400599fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000600 if (pn)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000601 iput(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000602 return error;
603}
604
605static int init_threads(struct gfs2_sbd *sdp, int undo)
606{
607 struct task_struct *p;
608 int error = 0;
609
610 if (undo)
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400611 goto fail_quotad;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000612
613 sdp->sd_log_flush_time = jiffies;
614 sdp->sd_jindex_refresh_time = jiffies;
615
616 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
617 error = IS_ERR(p);
618 if (error) {
619 fs_err(sdp, "can't start logd thread: %d\n", error);
620 return error;
621 }
622 sdp->sd_logd_process = p;
623
624 sdp->sd_statfs_sync_time = jiffies;
625 sdp->sd_quota_sync_time = jiffies;
626
627 p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
628 error = IS_ERR(p);
629 if (error) {
630 fs_err(sdp, "can't start quotad thread: %d\n", error);
631 goto fail;
632 }
633 sdp->sd_quotad_process = p;
634
David Teiglandb3b94fa2006-01-16 16:50:04 +0000635 return 0;
636
David Teiglandb3b94fa2006-01-16 16:50:04 +0000637
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400638fail_quotad:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000639 kthread_stop(sdp->sd_quotad_process);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400640fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000641 kthread_stop(sdp->sd_logd_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000642 return error;
643}
644
645/**
646 * fill_super - Read in superblock
647 * @sb: The VFS superblock
648 * @data: Mount options
649 * @silent: Don't complain if it's not a GFS2 filesystem
650 *
651 * Returns: errno
652 */
653
654static int fill_super(struct super_block *sb, void *data, int silent)
655{
656 struct gfs2_sbd *sdp;
657 struct gfs2_holder mount_gh;
658 int error;
659
660 sdp = init_sbd(sb);
661 if (!sdp) {
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500662 printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000663 return -ENOMEM;
664 }
665
666 error = gfs2_mount_args(sdp, (char *)data, 0);
667 if (error) {
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500668 printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000669 goto fail;
670 }
671
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500672 init_vfs(sb, SDF_NOATIME);
673
674 /* Set up the buffer cache and fill in some fake block size values
675 to allow us to read-in the on-disk superblock. */
676 sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
677 sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
678 sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
679 GFS2_BASIC_BLOCK_SHIFT;
680 sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000681
682 error = init_names(sdp, silent);
683 if (error)
684 goto fail;
685
Robert Peterson7c52b162007-03-16 10:26:37 +0000686 gfs2_create_debugfs_file(sdp);
687
David Teiglandb3b94fa2006-01-16 16:50:04 +0000688 error = gfs2_sys_fs_add(sdp);
689 if (error)
690 goto fail;
691
692 error = gfs2_lm_mount(sdp, silent);
693 if (error)
694 goto fail_sys;
695
696 error = init_locking(sdp, &mount_gh, DO);
697 if (error)
698 goto fail_lm;
699
700 error = init_sb(sdp, silent, DO);
701 if (error)
702 goto fail_locking;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000703
704 error = init_inodes(sdp, DO);
705 if (error)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000706 goto fail_sb;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000707
708 error = init_per_node(sdp, DO);
709 if (error)
710 goto fail_inodes;
711
712 error = gfs2_statfs_init(sdp);
713 if (error) {
714 fs_err(sdp, "can't initialize statfs subsystem: %d\n", error);
715 goto fail_per_node;
716 }
717
718 error = init_threads(sdp, DO);
719 if (error)
720 goto fail_per_node;
721
722 if (!(sb->s_flags & MS_RDONLY)) {
723 error = gfs2_make_fs_rw(sdp);
724 if (error) {
725 fs_err(sdp, "can't make FS RW: %d\n", error);
726 goto fail_threads;
727 }
728 }
729
730 gfs2_glock_dq_uninit(&mount_gh);
731
732 return 0;
733
Steven Whitehousea91ea692006-09-04 12:04:26 -0400734fail_threads:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000735 init_threads(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400736fail_per_node:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000737 init_per_node(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400738fail_inodes:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000739 init_inodes(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400740fail_sb:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000741 init_sb(sdp, 0, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400742fail_locking:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000743 init_locking(sdp, &mount_gh, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400744fail_lm:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000745 gfs2_gl_hash_clear(sdp, WAIT);
746 gfs2_lm_unmount(sdp);
747 while (invalidate_inodes(sb))
748 yield();
Steven Whitehousea91ea692006-09-04 12:04:26 -0400749fail_sys:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000750 gfs2_sys_fs_del(sdp);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400751fail:
Robert Peterson5f882092007-04-18 11:41:11 -0500752 gfs2_delete_debugfs_file(sdp);
Steven Whitehousea2c45802006-09-08 10:13:03 -0400753 kfree(sdp);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500754 sb->s_fs_info = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000755 return error;
756}
757
Andrew Mortonccd6efd2006-06-30 02:16:34 -0700758static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
759 const char *dev_name, void *data, struct vfsmount *mnt)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000760{
Abhijith Das86384602006-08-25 11:13:37 -0500761 struct super_block *sb;
762 struct gfs2_sbd *sdp;
763 int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
764 if (error)
765 goto out;
766 sb = mnt->mnt_sb;
Steven Whitehouse26c1a572006-09-04 15:32:10 -0400767 sdp = sb->s_fs_info;
Abhijith Das86384602006-08-25 11:13:37 -0500768 sdp->sd_gfs2mnt = mnt;
769out:
770 return error;
771}
772
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400773static int fill_super_meta(struct super_block *sb, struct super_block *new,
Abhijith Das86384602006-08-25 11:13:37 -0500774 void *data, int silent)
775{
776 struct gfs2_sbd *sdp = sb->s_fs_info;
777 struct inode *inode;
778 int error = 0;
779
780 new->s_fs_info = sdp;
781 sdp->sd_vfs_meta = sb;
782
783 init_vfs(new, SDF_NOATIME);
784
785 /* Get the master inode */
786 inode = igrab(sdp->sd_master_dir);
787
788 new->s_root = d_alloc_root(inode);
789 if (!new->s_root) {
790 fs_err(sdp, "can't get root dentry\n");
791 error = -ENOMEM;
792 iput(inode);
Adrian Bunkbbbe4512006-10-19 15:27:00 +0200793 } else
794 new->s_root->d_op = &gfs2_dops;
Abhijith Das86384602006-08-25 11:13:37 -0500795
796 return error;
797}
Steven Whitehousea91ea692006-09-04 12:04:26 -0400798
Abhijith Das86384602006-08-25 11:13:37 -0500799static int set_bdev_super(struct super_block *s, void *data)
800{
801 s->s_bdev = data;
802 s->s_dev = s->s_bdev->bd_dev;
803 return 0;
804}
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400805
Abhijith Das86384602006-08-25 11:13:37 -0500806static int test_bdev_super(struct super_block *s, void *data)
807{
Steven Whitehouse26c1a572006-09-04 15:32:10 -0400808 return s->s_bdev == data;
Abhijith Das86384602006-08-25 11:13:37 -0500809}
810
811static struct super_block* get_gfs2_sb(const char *dev_name)
812{
813 struct kstat stat;
814 struct nameidata nd;
815 struct file_system_type *fstype;
816 struct super_block *sb = NULL, *s;
817 struct list_head *l;
818 int error;
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400819
Abhijith Das86384602006-08-25 11:13:37 -0500820 error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
821 if (error) {
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400822 printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n",
Abhijith Das86384602006-08-25 11:13:37 -0500823 dev_name);
824 goto out;
825 }
826 error = vfs_getattr(nd.mnt, nd.dentry, &stat);
827
828 fstype = get_fs_type("gfs2");
829 list_for_each(l, &fstype->fs_supers) {
830 s = list_entry(l, struct super_block, s_instances);
831 if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) ||
832 (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) {
833 sb = s;
834 goto free_nd;
835 }
836 }
837
838 printk(KERN_WARNING "GFS2: Unrecognized block device or "
Richard Fearnd5a67512007-02-17 17:29:15 +0000839 "mount point %s\n", dev_name);
Abhijith Das86384602006-08-25 11:13:37 -0500840
841free_nd:
842 path_release(&nd);
843out:
844 return sb;
845}
846
847static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
848 const char *dev_name, void *data, struct vfsmount *mnt)
849{
850 int error = 0;
851 struct super_block *sb = NULL, *new;
852 struct gfs2_sbd *sdp;
Abhijith Das86384602006-08-25 11:13:37 -0500853
854 sb = get_gfs2_sb(dev_name);
855 if (!sb) {
856 printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n");
857 error = -ENOENT;
858 goto error;
859 }
860 sdp = (struct gfs2_sbd*) sb->s_fs_info;
861 if (sdp->sd_vfs_meta) {
862 printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n");
863 error = -EBUSY;
864 goto error;
865 }
David Chinnerf73ca1b2007-01-10 23:15:41 -0800866 down(&sb->s_bdev->bd_mount_sem);
Abhijith Das86384602006-08-25 11:13:37 -0500867 new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev);
David Chinnerf73ca1b2007-01-10 23:15:41 -0800868 up(&sb->s_bdev->bd_mount_sem);
Abhijith Das86384602006-08-25 11:13:37 -0500869 if (IS_ERR(new)) {
870 error = PTR_ERR(new);
871 goto error;
872 }
873 module_put(fs_type->owner);
874 new->s_flags = flags;
875 strlcpy(new->s_id, sb->s_id, sizeof(new->s_id));
876 sb_set_blocksize(new, sb->s_blocksize);
877 error = fill_super_meta(sb, new, data, flags & MS_SILENT ? 1 : 0);
878 if (error) {
879 up_write(&new->s_umount);
880 deactivate_super(new);
881 goto error;
882 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400883
Abhijith Das86384602006-08-25 11:13:37 -0500884 new->s_flags |= MS_ACTIVE;
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400885
Abhijith Das86384602006-08-25 11:13:37 -0500886 /* Grab a reference to the gfs2 mount point */
887 atomic_inc(&sdp->sd_gfs2mnt->mnt_count);
888 return simple_set_mnt(mnt, new);
889error:
Abhijith Das86384602006-08-25 11:13:37 -0500890 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000891}
892
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500893static void gfs2_kill_sb(struct super_block *sb)
894{
Robert Peterson7c52b162007-03-16 10:26:37 +0000895 gfs2_delete_debugfs_file(sb->s_fs_info);
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500896 kill_block_super(sb);
897}
898
Abhijith Das86384602006-08-25 11:13:37 -0500899static void gfs2_kill_sb_meta(struct super_block *sb)
900{
901 struct gfs2_sbd *sdp = sb->s_fs_info;
902 generic_shutdown_super(sb);
903 sdp->sd_vfs_meta = NULL;
904 atomic_dec(&sdp->sd_gfs2mnt->mnt_count);
905}
906
David Teiglandb3b94fa2006-01-16 16:50:04 +0000907struct file_system_type gfs2_fs_type = {
908 .name = "gfs2",
909 .fs_flags = FS_REQUIRES_DEV,
910 .get_sb = gfs2_get_sb,
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500911 .kill_sb = gfs2_kill_sb,
912 .owner = THIS_MODULE,
913};
914
915struct file_system_type gfs2meta_fs_type = {
916 .name = "gfs2meta",
917 .fs_flags = FS_REQUIRES_DEV,
Abhijith Das86384602006-08-25 11:13:37 -0500918 .get_sb = gfs2_get_sb_meta,
919 .kill_sb = gfs2_kill_sb_meta,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000920 .owner = THIS_MODULE,
921};
922