blob: f0bcaa25737c4198004076ac5b3bb9ad0f9a9636 [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"
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"
David Teiglandb3b94fa2006-01-16 16:50:04 +000038
39#define DO 0
40#define UNDO 1
41
42static struct gfs2_sbd *init_sbd(struct super_block *sb)
43{
44 struct gfs2_sbd *sdp;
David Teiglandb3b94fa2006-01-16 16:50:04 +000045
Steven Whitehouse85d1da62006-09-07 14:40:21 -040046 sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
David Teiglandb3b94fa2006-01-16 16:50:04 +000047 if (!sdp)
48 return NULL;
49
Steven Whitehouse5c676f62006-02-27 17:23:27 -050050 sb->s_fs_info = sdp;
David Teiglandb3b94fa2006-01-16 16:50:04 +000051 sdp->sd_vfs = sb;
52
53 gfs2_tune_init(&sdp->sd_tune);
54
David Teiglandb3b94fa2006-01-16 16:50:04 +000055 INIT_LIST_HEAD(&sdp->sd_reclaim_list);
56 spin_lock_init(&sdp->sd_reclaim_lock);
57 init_waitqueue_head(&sdp->sd_reclaim_wq);
David Teiglandb3b94fa2006-01-16 16:50:04 +000058
Steven Whitehousef55ab262006-02-21 12:51:39 +000059 mutex_init(&sdp->sd_inum_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000060 spin_lock_init(&sdp->sd_statfs_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000061 mutex_init(&sdp->sd_statfs_mutex);
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);
67 INIT_LIST_HEAD(&sdp->sd_rindex_recent_list);
68
69 INIT_LIST_HEAD(&sdp->sd_jindex_list);
70 spin_lock_init(&sdp->sd_jindex_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000071 mutex_init(&sdp->sd_jindex_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000072
David Teiglandb3b94fa2006-01-16 16:50:04 +000073 INIT_LIST_HEAD(&sdp->sd_quota_list);
74 spin_lock_init(&sdp->sd_quota_spin);
Steven Whitehousef55ab262006-02-21 12:51:39 +000075 mutex_init(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000076
77 spin_lock_init(&sdp->sd_log_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000078
79 INIT_LIST_HEAD(&sdp->sd_log_le_gl);
80 INIT_LIST_HEAD(&sdp->sd_log_le_buf);
81 INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
82 INIT_LIST_HEAD(&sdp->sd_log_le_rg);
83 INIT_LIST_HEAD(&sdp->sd_log_le_databuf);
84
Steven Whitehouse71b86f52006-03-28 14:14:04 -050085 mutex_init(&sdp->sd_log_reserve_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +000086 INIT_LIST_HEAD(&sdp->sd_ail1_list);
87 INIT_LIST_HEAD(&sdp->sd_ail2_list);
88
Steven Whitehouse484adff2006-03-29 09:12:12 -050089 init_rwsem(&sdp->sd_log_flush_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +000090 INIT_LIST_HEAD(&sdp->sd_log_flush_list);
91
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
144 snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto);
145 snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table);
146
Robert Petersonb35997d2007-06-07 09:10:01 -0500147 while ((table = strchr(sdp->sd_table_name, '/')))
148 *table = '_';
149
Steven Whitehousea91ea692006-09-04 12:04:26 -0400150out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000151 return error;
152}
153
154static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
155 int undo)
156{
157 struct task_struct *p;
158 int error = 0;
159
160 if (undo)
161 goto fail_trans;
162
David Teiglandb3b94fa2006-01-16 16:50:04 +0000163 for (sdp->sd_glockd_num = 0;
164 sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd;
165 sdp->sd_glockd_num++) {
166 p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd");
167 error = IS_ERR(p);
168 if (error) {
169 fs_err(sdp, "can't start glockd thread: %d\n", error);
170 goto fail;
171 }
172 sdp->sd_glockd_process[sdp->sd_glockd_num] = p;
173 }
174
175 error = gfs2_glock_nq_num(sdp,
176 GFS2_MOUNT_LOCK, &gfs2_nondisk_glops,
177 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE,
178 mount_gh);
179 if (error) {
180 fs_err(sdp, "can't acquire mount glock: %d\n", error);
181 goto fail;
182 }
183
184 error = gfs2_glock_nq_num(sdp,
185 GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
186 LM_ST_SHARED,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400187 LM_FLAG_NOEXP | GL_EXACT,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000188 &sdp->sd_live_gh);
189 if (error) {
190 fs_err(sdp, "can't acquire live glock: %d\n", error);
191 goto fail_mount;
192 }
193
194 error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops,
195 CREATE, &sdp->sd_rename_gl);
196 if (error) {
197 fs_err(sdp, "can't create rename glock: %d\n", error);
198 goto fail_live;
199 }
200
201 error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops,
202 CREATE, &sdp->sd_trans_gl);
203 if (error) {
204 fs_err(sdp, "can't create transaction glock: %d\n", error);
205 goto fail_rename;
206 }
207 set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags);
208
209 return 0;
210
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400211fail_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000212 gfs2_glock_put(sdp->sd_trans_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400213fail_rename:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000214 gfs2_glock_put(sdp->sd_rename_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400215fail_live:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000216 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400217fail_mount:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000218 gfs2_glock_dq_uninit(mount_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400219fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000220 while (sdp->sd_glockd_num--)
221 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
222
David Teiglandb3b94fa2006-01-16 16:50:04 +0000223 return error;
224}
225
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100226static inline struct inode *gfs2_lookup_root(struct super_block *sb,
227 u64 no_addr)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000228{
Wendy Chengbb9bcf02007-06-27 17:07:08 -0400229 return gfs2_inode_lookup(sb, DT_DIR, no_addr, 0);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000230}
231
David Teiglandb3b94fa2006-01-16 16:50:04 +0000232static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
233{
234 struct super_block *sb = sdp->sd_vfs;
235 struct gfs2_holder sb_gh;
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100236 u64 no_addr;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000237 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000238 int error = 0;
239
240 if (undo) {
Russell Cattelan88721872006-08-10 11:08:40 -0500241 if (sb->s_root) {
242 dput(sb->s_root);
243 sb->s_root = NULL;
244 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000245 return 0;
246 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400247
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400248 error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000249 LM_ST_SHARED, 0, &sb_gh);
250 if (error) {
251 fs_err(sdp, "can't acquire superblock glock: %d\n", error);
252 return error;
253 }
254
255 error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent);
256 if (error) {
257 fs_err(sdp, "can't read superblock: %d\n", error);
258 goto out;
259 }
260
261 /* Set up the buffer cache and SB for real */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000262 if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500263 error = -EINVAL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000264 fs_err(sdp, "FS block size (%u) is too small for device "
265 "block size (%u)\n",
266 sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
267 goto out;
268 }
269 if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500270 error = -EINVAL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000271 fs_err(sdp, "FS block size (%u) is too big for machine "
272 "page size (%u)\n",
273 sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
274 goto out;
275 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000276 sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
277
Steven Whitehousef42faf42006-01-30 18:34:10 +0000278 /* Get the root inode */
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100279 no_addr = sdp->sd_sb.sb_root_dir.no_addr;
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500280 if (sb->s_type == &gfs2meta_fs_type)
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100281 no_addr = sdp->sd_sb.sb_master_dir.no_addr;
282 inode = gfs2_lookup_root(sb, no_addr);
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500283 if (IS_ERR(inode)) {
284 error = PTR_ERR(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000285 fs_err(sdp, "can't read in root inode: %d\n", error);
286 goto out;
287 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000288
Steven Whitehousef42faf42006-01-30 18:34:10 +0000289 sb->s_root = d_alloc_root(inode);
290 if (!sb->s_root) {
291 fs_err(sdp, "can't get root dentry\n");
292 error = -ENOMEM;
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500293 iput(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000294 }
Robert S Peterson5bb76af2006-05-05 16:29:50 -0400295 sb->s_root->d_op = &gfs2_dops;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000296out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000297 gfs2_glock_dq_uninit(&sb_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000298 return error;
299}
300
301static int init_journal(struct gfs2_sbd *sdp, int undo)
302{
303 struct gfs2_holder ji_gh;
304 struct task_struct *p;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500305 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000306 int jindex = 1;
307 int error = 0;
308
309 if (undo) {
310 jindex = 0;
311 goto fail_recoverd;
312 }
313
Steven Whitehousec7526662006-03-20 12:30:04 -0500314 sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex");
315 if (IS_ERR(sdp->sd_jindex)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000316 fs_err(sdp, "can't lookup journal index: %d\n", error);
Steven Whitehousec7526662006-03-20 12:30:04 -0500317 return PTR_ERR(sdp->sd_jindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000318 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400319 ip = GFS2_I(sdp->sd_jindex);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500320 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000321
322 /* Load in the journal index special file */
323
324 error = gfs2_jindex_hold(sdp, &ji_gh);
325 if (error) {
326 fs_err(sdp, "can't read journal index: %d\n", error);
327 goto fail;
328 }
329
330 error = -EINVAL;
331 if (!gfs2_jindex_size(sdp)) {
332 fs_err(sdp, "no journals!\n");
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400333 goto fail_jindex;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000334 }
335
336 if (sdp->sd_args.ar_spectator) {
337 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
338 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks;
339 } else {
340 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
341 fs_err(sdp, "can't mount journal #%u\n",
342 sdp->sd_lockstruct.ls_jid);
343 fs_err(sdp, "there are only %u journals (0 - %u)\n",
344 gfs2_jindex_size(sdp),
345 gfs2_jindex_size(sdp) - 1);
346 goto fail_jindex;
347 }
348 sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
349
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400350 error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000351 &gfs2_journal_glops,
352 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
353 &sdp->sd_journal_gh);
354 if (error) {
355 fs_err(sdp, "can't acquire journal glock: %d\n", error);
356 goto fail_jindex;
357 }
358
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400359 ip = GFS2_I(sdp->sd_jdesc->jd_inode);
360 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
Bob Peterson75be73a2007-08-08 17:08:14 -0500361 LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000362 &sdp->sd_jinode_gh);
363 if (error) {
364 fs_err(sdp, "can't acquire journal inode glock: %d\n",
365 error);
366 goto fail_journal_gh;
367 }
368
369 error = gfs2_jdesc_check(sdp->sd_jdesc);
370 if (error) {
371 fs_err(sdp, "my journal (%u) is bad: %d\n",
372 sdp->sd_jdesc->jd_jid, error);
373 goto fail_jinode_gh;
374 }
375 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks;
376 }
377
378 if (sdp->sd_lockstruct.ls_first) {
379 unsigned int x;
380 for (x = 0; x < sdp->sd_journals; x++) {
David Teiglandc63e31c2006-04-20 17:03:48 -0400381 error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000382 if (error) {
383 fs_err(sdp, "error recovering journal %u: %d\n",
384 x, error);
385 goto fail_jinode_gh;
386 }
387 }
388
389 gfs2_lm_others_may_mount(sdp);
390 } else if (!sdp->sd_args.ar_spectator) {
David Teiglandc63e31c2006-04-20 17:03:48 -0400391 error = gfs2_recover_journal(sdp->sd_jdesc);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000392 if (error) {
393 fs_err(sdp, "error recovering my journal: %d\n", error);
394 goto fail_jinode_gh;
395 }
396 }
397
398 set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags);
399 gfs2_glock_dq_uninit(&ji_gh);
400 jindex = 0;
401
David Teiglandb3b94fa2006-01-16 16:50:04 +0000402 p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
403 error = IS_ERR(p);
404 if (error) {
405 fs_err(sdp, "can't start recoverd thread: %d\n", error);
406 goto fail_jinode_gh;
407 }
408 sdp->sd_recoverd_process = p;
409
410 return 0;
411
Steven Whitehousea91ea692006-09-04 12:04:26 -0400412fail_recoverd:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000413 kthread_stop(sdp->sd_recoverd_process);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400414fail_jinode_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000415 if (!sdp->sd_args.ar_spectator)
416 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400417fail_journal_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000418 if (!sdp->sd_args.ar_spectator)
419 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400420fail_jindex:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000421 gfs2_jindex_free(sdp);
422 if (jindex)
423 gfs2_glock_dq_uninit(&ji_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400424fail:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000425 iput(sdp->sd_jindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000426 return error;
427}
428
David Teiglandb3b94fa2006-01-16 16:50:04 +0000429
430static int init_inodes(struct gfs2_sbd *sdp, int undo)
431{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000432 int error = 0;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500433 struct gfs2_inode *ip;
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500434 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000435
436 if (undo)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000437 goto fail_qinode;
438
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100439 inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr);
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500440 if (IS_ERR(inode)) {
441 error = PTR_ERR(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000442 fs_err(sdp, "can't read in master directory: %d\n", error);
443 goto fail;
444 }
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500445 sdp->sd_master_dir = inode;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000446
447 error = init_journal(sdp, undo);
448 if (error)
449 goto fail_master;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000450
451 /* Read in the master inode number inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500452 sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum");
453 if (IS_ERR(sdp->sd_inum_inode)) {
454 error = PTR_ERR(sdp->sd_inum_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000455 fs_err(sdp, "can't read in inum inode: %d\n", error);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000456 goto fail_journal;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000457 }
458
Steven Whitehousef42faf42006-01-30 18:34:10 +0000459
David Teiglandb3b94fa2006-01-16 16:50:04 +0000460 /* Read in the master statfs inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500461 sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs");
462 if (IS_ERR(sdp->sd_statfs_inode)) {
463 error = PTR_ERR(sdp->sd_statfs_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000464 fs_err(sdp, "can't read in statfs inode: %d\n", error);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000465 goto fail_inum;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000466 }
467
468 /* Read in the resource index inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500469 sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex");
470 if (IS_ERR(sdp->sd_rindex)) {
471 error = PTR_ERR(sdp->sd_rindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000472 fs_err(sdp, "can't get resource index inode: %d\n", error);
473 goto fail_statfs;
474 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400475 ip = GFS2_I(sdp->sd_rindex);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500476 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
477 sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000478
479 /* Read in the quota inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500480 sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota");
481 if (IS_ERR(sdp->sd_quota_inode)) {
482 error = PTR_ERR(sdp->sd_quota_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000483 fs_err(sdp, "can't get quota file inode: %d\n", error);
484 goto fail_rindex;
485 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000486 return 0;
487
Steven Whitehousef42faf42006-01-30 18:34:10 +0000488fail_qinode:
489 iput(sdp->sd_quota_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000490fail_rindex:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000491 gfs2_clear_rgrpd(sdp);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000492 iput(sdp->sd_rindex);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000493fail_statfs:
494 iput(sdp->sd_statfs_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000495fail_inum:
496 iput(sdp->sd_inum_inode);
497fail_journal:
498 init_journal(sdp, UNDO);
499fail_master:
500 iput(sdp->sd_master_dir);
501fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000502 return error;
503}
504
505static int init_per_node(struct gfs2_sbd *sdp, int undo)
506{
Steven Whitehousef42faf42006-01-30 18:34:10 +0000507 struct inode *pn = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000508 char buf[30];
509 int error = 0;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500510 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000511
512 if (sdp->sd_args.ar_spectator)
513 return 0;
514
515 if (undo)
516 goto fail_qc_gh;
517
Steven Whitehousec7526662006-03-20 12:30:04 -0500518 pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node");
519 if (IS_ERR(pn)) {
520 error = PTR_ERR(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000521 fs_err(sdp, "can't find per_node directory: %d\n", error);
522 return error;
523 }
524
525 sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500526 sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
527 if (IS_ERR(sdp->sd_ir_inode)) {
528 error = PTR_ERR(sdp->sd_ir_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000529 fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
530 goto fail;
531 }
532
533 sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500534 sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
535 if (IS_ERR(sdp->sd_sc_inode)) {
536 error = PTR_ERR(sdp->sd_sc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000537 fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
538 goto fail_ir_i;
539 }
540
David Teiglandb3b94fa2006-01-16 16:50:04 +0000541 sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500542 sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
543 if (IS_ERR(sdp->sd_qc_inode)) {
544 error = PTR_ERR(sdp->sd_qc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000545 fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
546 goto fail_ut_i;
547 }
548
Steven Whitehousef42faf42006-01-30 18:34:10 +0000549 iput(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000550 pn = NULL;
551
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400552 ip = GFS2_I(sdp->sd_ir_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500553 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400554 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000555 &sdp->sd_ir_gh);
556 if (error) {
557 fs_err(sdp, "can't lock local \"ir\" file: %d\n", error);
558 goto fail_qc_i;
559 }
560
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400561 ip = GFS2_I(sdp->sd_sc_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500562 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400563 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000564 &sdp->sd_sc_gh);
565 if (error) {
566 fs_err(sdp, "can't lock local \"sc\" file: %d\n", error);
567 goto fail_ir_gh;
568 }
569
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400570 ip = GFS2_I(sdp->sd_qc_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500571 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400572 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000573 &sdp->sd_qc_gh);
574 if (error) {
575 fs_err(sdp, "can't lock local \"qc\" file: %d\n", error);
576 goto fail_ut_gh;
577 }
578
579 return 0;
580
Steven Whitehousea91ea692006-09-04 12:04:26 -0400581fail_qc_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000582 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400583fail_ut_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000584 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400585fail_ir_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000586 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400587fail_qc_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000588 iput(sdp->sd_qc_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400589fail_ut_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000590 iput(sdp->sd_sc_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400591fail_ir_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000592 iput(sdp->sd_ir_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400593fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000594 if (pn)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000595 iput(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000596 return error;
597}
598
599static int init_threads(struct gfs2_sbd *sdp, int undo)
600{
601 struct task_struct *p;
602 int error = 0;
603
604 if (undo)
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400605 goto fail_quotad;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000606
607 sdp->sd_log_flush_time = jiffies;
608 sdp->sd_jindex_refresh_time = jiffies;
609
610 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
611 error = IS_ERR(p);
612 if (error) {
613 fs_err(sdp, "can't start logd thread: %d\n", error);
614 return error;
615 }
616 sdp->sd_logd_process = p;
617
618 sdp->sd_statfs_sync_time = jiffies;
619 sdp->sd_quota_sync_time = jiffies;
620
621 p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
622 error = IS_ERR(p);
623 if (error) {
624 fs_err(sdp, "can't start quotad thread: %d\n", error);
625 goto fail;
626 }
627 sdp->sd_quotad_process = p;
628
David Teiglandb3b94fa2006-01-16 16:50:04 +0000629 return 0;
630
David Teiglandb3b94fa2006-01-16 16:50:04 +0000631
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400632fail_quotad:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000633 kthread_stop(sdp->sd_quotad_process);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400634fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000635 kthread_stop(sdp->sd_logd_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000636 return error;
637}
638
639/**
640 * fill_super - Read in superblock
641 * @sb: The VFS superblock
642 * @data: Mount options
643 * @silent: Don't complain if it's not a GFS2 filesystem
644 *
645 * Returns: errno
646 */
647
648static int fill_super(struct super_block *sb, void *data, int silent)
649{
650 struct gfs2_sbd *sdp;
651 struct gfs2_holder mount_gh;
652 int error;
653
654 sdp = init_sbd(sb);
655 if (!sdp) {
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500656 printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000657 return -ENOMEM;
658 }
659
660 error = gfs2_mount_args(sdp, (char *)data, 0);
661 if (error) {
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500662 printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000663 goto fail;
664 }
665
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500666 init_vfs(sb, SDF_NOATIME);
667
668 /* Set up the buffer cache and fill in some fake block size values
669 to allow us to read-in the on-disk superblock. */
670 sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
671 sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
672 sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
673 GFS2_BASIC_BLOCK_SHIFT;
674 sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000675
676 error = init_names(sdp, silent);
677 if (error)
678 goto fail;
679
Robert Peterson7c52b162007-03-16 10:26:37 +0000680 gfs2_create_debugfs_file(sdp);
681
David Teiglandb3b94fa2006-01-16 16:50:04 +0000682 error = gfs2_sys_fs_add(sdp);
683 if (error)
684 goto fail;
685
686 error = gfs2_lm_mount(sdp, silent);
687 if (error)
688 goto fail_sys;
689
690 error = init_locking(sdp, &mount_gh, DO);
691 if (error)
692 goto fail_lm;
693
694 error = init_sb(sdp, silent, DO);
695 if (error)
696 goto fail_locking;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000697
698 error = init_inodes(sdp, DO);
699 if (error)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000700 goto fail_sb;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000701
702 error = init_per_node(sdp, DO);
703 if (error)
704 goto fail_inodes;
705
706 error = gfs2_statfs_init(sdp);
707 if (error) {
708 fs_err(sdp, "can't initialize statfs subsystem: %d\n", error);
709 goto fail_per_node;
710 }
711
712 error = init_threads(sdp, DO);
713 if (error)
714 goto fail_per_node;
715
716 if (!(sb->s_flags & MS_RDONLY)) {
717 error = gfs2_make_fs_rw(sdp);
718 if (error) {
719 fs_err(sdp, "can't make FS RW: %d\n", error);
720 goto fail_threads;
721 }
722 }
723
724 gfs2_glock_dq_uninit(&mount_gh);
725
726 return 0;
727
Steven Whitehousea91ea692006-09-04 12:04:26 -0400728fail_threads:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000729 init_threads(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400730fail_per_node:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000731 init_per_node(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400732fail_inodes:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000733 init_inodes(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400734fail_sb:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000735 init_sb(sdp, 0, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400736fail_locking:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000737 init_locking(sdp, &mount_gh, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400738fail_lm:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000739 gfs2_gl_hash_clear(sdp, WAIT);
740 gfs2_lm_unmount(sdp);
741 while (invalidate_inodes(sb))
742 yield();
Steven Whitehousea91ea692006-09-04 12:04:26 -0400743fail_sys:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000744 gfs2_sys_fs_del(sdp);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400745fail:
Robert Peterson5f882092007-04-18 11:41:11 -0500746 gfs2_delete_debugfs_file(sdp);
Steven Whitehousea2c45802006-09-08 10:13:03 -0400747 kfree(sdp);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500748 sb->s_fs_info = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000749 return error;
750}
751
Andrew Mortonccd6efd2006-06-30 02:16:34 -0700752static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
753 const char *dev_name, void *data, struct vfsmount *mnt)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000754{
Abhijith Das86384602006-08-25 11:13:37 -0500755 struct super_block *sb;
756 struct gfs2_sbd *sdp;
757 int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
758 if (error)
759 goto out;
760 sb = mnt->mnt_sb;
Steven Whitehouse26c1a572006-09-04 15:32:10 -0400761 sdp = sb->s_fs_info;
Abhijith Das86384602006-08-25 11:13:37 -0500762 sdp->sd_gfs2mnt = mnt;
763out:
764 return error;
765}
766
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400767static int fill_super_meta(struct super_block *sb, struct super_block *new,
Abhijith Das86384602006-08-25 11:13:37 -0500768 void *data, int silent)
769{
770 struct gfs2_sbd *sdp = sb->s_fs_info;
771 struct inode *inode;
772 int error = 0;
773
774 new->s_fs_info = sdp;
775 sdp->sd_vfs_meta = sb;
776
777 init_vfs(new, SDF_NOATIME);
778
779 /* Get the master inode */
780 inode = igrab(sdp->sd_master_dir);
781
782 new->s_root = d_alloc_root(inode);
783 if (!new->s_root) {
784 fs_err(sdp, "can't get root dentry\n");
785 error = -ENOMEM;
786 iput(inode);
Adrian Bunkbbbe4512006-10-19 15:27:00 +0200787 } else
788 new->s_root->d_op = &gfs2_dops;
Abhijith Das86384602006-08-25 11:13:37 -0500789
790 return error;
791}
Steven Whitehousea91ea692006-09-04 12:04:26 -0400792
Abhijith Das86384602006-08-25 11:13:37 -0500793static int set_bdev_super(struct super_block *s, void *data)
794{
795 s->s_bdev = data;
796 s->s_dev = s->s_bdev->bd_dev;
797 return 0;
798}
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400799
Abhijith Das86384602006-08-25 11:13:37 -0500800static int test_bdev_super(struct super_block *s, void *data)
801{
Steven Whitehouse26c1a572006-09-04 15:32:10 -0400802 return s->s_bdev == data;
Abhijith Das86384602006-08-25 11:13:37 -0500803}
804
805static struct super_block* get_gfs2_sb(const char *dev_name)
806{
807 struct kstat stat;
808 struct nameidata nd;
809 struct file_system_type *fstype;
810 struct super_block *sb = NULL, *s;
811 struct list_head *l;
812 int error;
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400813
Abhijith Das86384602006-08-25 11:13:37 -0500814 error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
815 if (error) {
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400816 printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n",
Abhijith Das86384602006-08-25 11:13:37 -0500817 dev_name);
818 goto out;
819 }
820 error = vfs_getattr(nd.mnt, nd.dentry, &stat);
821
822 fstype = get_fs_type("gfs2");
823 list_for_each(l, &fstype->fs_supers) {
824 s = list_entry(l, struct super_block, s_instances);
825 if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) ||
826 (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) {
827 sb = s;
828 goto free_nd;
829 }
830 }
831
832 printk(KERN_WARNING "GFS2: Unrecognized block device or "
Richard Fearnd5a67512007-02-17 17:29:15 +0000833 "mount point %s\n", dev_name);
Abhijith Das86384602006-08-25 11:13:37 -0500834
835free_nd:
836 path_release(&nd);
837out:
838 return sb;
839}
840
841static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
842 const char *dev_name, void *data, struct vfsmount *mnt)
843{
844 int error = 0;
845 struct super_block *sb = NULL, *new;
846 struct gfs2_sbd *sdp;
Abhijith Das86384602006-08-25 11:13:37 -0500847
848 sb = get_gfs2_sb(dev_name);
849 if (!sb) {
850 printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n");
851 error = -ENOENT;
852 goto error;
853 }
854 sdp = (struct gfs2_sbd*) sb->s_fs_info;
855 if (sdp->sd_vfs_meta) {
856 printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n");
857 error = -EBUSY;
858 goto error;
859 }
David Chinnerf73ca1b2007-01-10 23:15:41 -0800860 down(&sb->s_bdev->bd_mount_sem);
Abhijith Das86384602006-08-25 11:13:37 -0500861 new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev);
David Chinnerf73ca1b2007-01-10 23:15:41 -0800862 up(&sb->s_bdev->bd_mount_sem);
Abhijith Das86384602006-08-25 11:13:37 -0500863 if (IS_ERR(new)) {
864 error = PTR_ERR(new);
865 goto error;
866 }
867 module_put(fs_type->owner);
868 new->s_flags = flags;
869 strlcpy(new->s_id, sb->s_id, sizeof(new->s_id));
870 sb_set_blocksize(new, sb->s_blocksize);
871 error = fill_super_meta(sb, new, data, flags & MS_SILENT ? 1 : 0);
872 if (error) {
873 up_write(&new->s_umount);
874 deactivate_super(new);
875 goto error;
876 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400877
Abhijith Das86384602006-08-25 11:13:37 -0500878 new->s_flags |= MS_ACTIVE;
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400879
Abhijith Das86384602006-08-25 11:13:37 -0500880 /* Grab a reference to the gfs2 mount point */
881 atomic_inc(&sdp->sd_gfs2mnt->mnt_count);
882 return simple_set_mnt(mnt, new);
883error:
Abhijith Das86384602006-08-25 11:13:37 -0500884 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000885}
886
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500887static void gfs2_kill_sb(struct super_block *sb)
888{
Robert Peterson7c52b162007-03-16 10:26:37 +0000889 gfs2_delete_debugfs_file(sb->s_fs_info);
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500890 kill_block_super(sb);
891}
892
Abhijith Das86384602006-08-25 11:13:37 -0500893static void gfs2_kill_sb_meta(struct super_block *sb)
894{
895 struct gfs2_sbd *sdp = sb->s_fs_info;
896 generic_shutdown_super(sb);
897 sdp->sd_vfs_meta = NULL;
898 atomic_dec(&sdp->sd_gfs2mnt->mnt_count);
899}
900
David Teiglandb3b94fa2006-01-16 16:50:04 +0000901struct file_system_type gfs2_fs_type = {
902 .name = "gfs2",
903 .fs_flags = FS_REQUIRES_DEV,
904 .get_sb = gfs2_get_sb,
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500905 .kill_sb = gfs2_kill_sb,
906 .owner = THIS_MODULE,
907};
908
909struct file_system_type gfs2meta_fs_type = {
910 .name = "gfs2meta",
911 .fs_flags = FS_REQUIRES_DEV,
Abhijith Das86384602006-08-25 11:13:37 -0500912 .get_sb = gfs2_get_sb_meta,
913 .kill_sb = gfs2_kill_sb_meta,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000914 .owner = THIS_MODULE,
915};
916