blob: dae1d7142fe5e8f48d9e7120031a6401453bc790 [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;
Steven Whitehouse4bd91ba2007-06-05 09:39:18 +0100107 sb->s_time_gran = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000108 sb->s_maxbytes = MAX_LFS_FILESIZE;
109
110 if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME))
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500111 set_bit(noatime, &sdp->sd_flags);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000112
113 /* Don't let the VFS update atimes. GFS2 handles this itself. */
114 sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000115}
116
117static int init_names(struct gfs2_sbd *sdp, int silent)
118{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000119 char *proto, *table;
120 int error = 0;
121
122 proto = sdp->sd_args.ar_lockproto;
123 table = sdp->sd_args.ar_locktable;
124
125 /* Try to autodetect */
126
127 if (!proto[0] || !table[0]) {
Steven Whitehousebb8d8a62007-06-01 14:11:58 +0100128 error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
129 if (error)
130 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000131
Steven Whitehouse3cf1e7b2006-10-02 11:49:41 -0400132 error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000133 if (error)
134 goto out;
135
136 if (!proto[0])
Steven Whitehouse3cf1e7b2006-10-02 11:49:41 -0400137 proto = sdp->sd_sb.sb_lockproto;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000138 if (!table[0])
Steven Whitehouse3cf1e7b2006-10-02 11:49:41 -0400139 table = sdp->sd_sb.sb_locktable;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000140 }
141
142 if (!table[0])
143 table = sdp->sd_vfs->s_id;
144
145 snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto);
146 snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table);
147
Robert Petersonb35997d2007-06-07 09:10:01 -0500148 while ((table = strchr(sdp->sd_table_name, '/')))
149 *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
164 p = kthread_run(gfs2_scand, sdp, "gfs2_scand");
165 error = IS_ERR(p);
166 if (error) {
167 fs_err(sdp, "can't start scand thread: %d\n", error);
168 return error;
169 }
170 sdp->sd_scand_process = p;
171
172 for (sdp->sd_glockd_num = 0;
173 sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd;
174 sdp->sd_glockd_num++) {
175 p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd");
176 error = IS_ERR(p);
177 if (error) {
178 fs_err(sdp, "can't start glockd thread: %d\n", error);
179 goto fail;
180 }
181 sdp->sd_glockd_process[sdp->sd_glockd_num] = p;
182 }
183
184 error = gfs2_glock_nq_num(sdp,
185 GFS2_MOUNT_LOCK, &gfs2_nondisk_glops,
186 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE,
187 mount_gh);
188 if (error) {
189 fs_err(sdp, "can't acquire mount glock: %d\n", error);
190 goto fail;
191 }
192
193 error = gfs2_glock_nq_num(sdp,
194 GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
195 LM_ST_SHARED,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400196 LM_FLAG_NOEXP | GL_EXACT,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000197 &sdp->sd_live_gh);
198 if (error) {
199 fs_err(sdp, "can't acquire live glock: %d\n", error);
200 goto fail_mount;
201 }
202
203 error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops,
204 CREATE, &sdp->sd_rename_gl);
205 if (error) {
206 fs_err(sdp, "can't create rename glock: %d\n", error);
207 goto fail_live;
208 }
209
210 error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops,
211 CREATE, &sdp->sd_trans_gl);
212 if (error) {
213 fs_err(sdp, "can't create transaction glock: %d\n", error);
214 goto fail_rename;
215 }
216 set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags);
217
218 return 0;
219
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400220fail_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000221 gfs2_glock_put(sdp->sd_trans_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400222fail_rename:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000223 gfs2_glock_put(sdp->sd_rename_gl);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400224fail_live:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000225 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400226fail_mount:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000227 gfs2_glock_dq_uninit(mount_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400228fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000229 while (sdp->sd_glockd_num--)
230 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
231
232 kthread_stop(sdp->sd_scand_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000233 return error;
234}
235
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100236static inline struct inode *gfs2_lookup_root(struct super_block *sb,
237 u64 no_addr)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000238{
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100239 return gfs2_inode_lookup(sb, no_addr, DT_DIR);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000240}
241
David Teiglandb3b94fa2006-01-16 16:50:04 +0000242static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
243{
244 struct super_block *sb = sdp->sd_vfs;
245 struct gfs2_holder sb_gh;
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100246 u64 no_addr;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000247 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000248 int error = 0;
249
250 if (undo) {
Russell Cattelan88721872006-08-10 11:08:40 -0500251 if (sb->s_root) {
252 dput(sb->s_root);
253 sb->s_root = NULL;
254 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000255 return 0;
256 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400257
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400258 error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000259 LM_ST_SHARED, 0, &sb_gh);
260 if (error) {
261 fs_err(sdp, "can't acquire superblock glock: %d\n", error);
262 return error;
263 }
264
265 error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent);
266 if (error) {
267 fs_err(sdp, "can't read superblock: %d\n", error);
268 goto out;
269 }
270
271 /* Set up the buffer cache and SB for real */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000272 if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500273 error = -EINVAL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000274 fs_err(sdp, "FS block size (%u) is too small for device "
275 "block size (%u)\n",
276 sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
277 goto out;
278 }
279 if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500280 error = -EINVAL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000281 fs_err(sdp, "FS block size (%u) is too big for machine "
282 "page size (%u)\n",
283 sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
284 goto out;
285 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000286 sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
287
Steven Whitehousef42faf42006-01-30 18:34:10 +0000288 /* Get the root inode */
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100289 no_addr = sdp->sd_sb.sb_root_dir.no_addr;
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500290 if (sb->s_type == &gfs2meta_fs_type)
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100291 no_addr = sdp->sd_sb.sb_master_dir.no_addr;
292 inode = gfs2_lookup_root(sb, no_addr);
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500293 if (IS_ERR(inode)) {
294 error = PTR_ERR(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000295 fs_err(sdp, "can't read in root inode: %d\n", error);
296 goto out;
297 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000298
Steven Whitehousef42faf42006-01-30 18:34:10 +0000299 sb->s_root = d_alloc_root(inode);
300 if (!sb->s_root) {
301 fs_err(sdp, "can't get root dentry\n");
302 error = -ENOMEM;
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500303 iput(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000304 }
Robert S Peterson5bb76af2006-05-05 16:29:50 -0400305 sb->s_root->d_op = &gfs2_dops;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000306out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000307 gfs2_glock_dq_uninit(&sb_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000308 return error;
309}
310
311static int init_journal(struct gfs2_sbd *sdp, int undo)
312{
313 struct gfs2_holder ji_gh;
314 struct task_struct *p;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500315 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000316 int jindex = 1;
317 int error = 0;
318
319 if (undo) {
320 jindex = 0;
321 goto fail_recoverd;
322 }
323
Steven Whitehousec7526662006-03-20 12:30:04 -0500324 sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex");
325 if (IS_ERR(sdp->sd_jindex)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000326 fs_err(sdp, "can't lookup journal index: %d\n", error);
Steven Whitehousec7526662006-03-20 12:30:04 -0500327 return PTR_ERR(sdp->sd_jindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000328 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400329 ip = GFS2_I(sdp->sd_jindex);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500330 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000331
332 /* Load in the journal index special file */
333
334 error = gfs2_jindex_hold(sdp, &ji_gh);
335 if (error) {
336 fs_err(sdp, "can't read journal index: %d\n", error);
337 goto fail;
338 }
339
340 error = -EINVAL;
341 if (!gfs2_jindex_size(sdp)) {
342 fs_err(sdp, "no journals!\n");
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400343 goto fail_jindex;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000344 }
345
346 if (sdp->sd_args.ar_spectator) {
347 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
348 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks;
349 } else {
350 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
351 fs_err(sdp, "can't mount journal #%u\n",
352 sdp->sd_lockstruct.ls_jid);
353 fs_err(sdp, "there are only %u journals (0 - %u)\n",
354 gfs2_jindex_size(sdp),
355 gfs2_jindex_size(sdp) - 1);
356 goto fail_jindex;
357 }
358 sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
359
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400360 error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000361 &gfs2_journal_glops,
362 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
363 &sdp->sd_journal_gh);
364 if (error) {
365 fs_err(sdp, "can't acquire journal glock: %d\n", error);
366 goto fail_jindex;
367 }
368
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400369 ip = GFS2_I(sdp->sd_jdesc->jd_inode);
370 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000371 LM_FLAG_NOEXP | GL_EXACT,
372 &sdp->sd_jinode_gh);
373 if (error) {
374 fs_err(sdp, "can't acquire journal inode glock: %d\n",
375 error);
376 goto fail_journal_gh;
377 }
378
379 error = gfs2_jdesc_check(sdp->sd_jdesc);
380 if (error) {
381 fs_err(sdp, "my journal (%u) is bad: %d\n",
382 sdp->sd_jdesc->jd_jid, error);
383 goto fail_jinode_gh;
384 }
385 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks;
386 }
387
388 if (sdp->sd_lockstruct.ls_first) {
389 unsigned int x;
390 for (x = 0; x < sdp->sd_journals; x++) {
David Teiglandc63e31c2006-04-20 17:03:48 -0400391 error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000392 if (error) {
393 fs_err(sdp, "error recovering journal %u: %d\n",
394 x, error);
395 goto fail_jinode_gh;
396 }
397 }
398
399 gfs2_lm_others_may_mount(sdp);
400 } else if (!sdp->sd_args.ar_spectator) {
David Teiglandc63e31c2006-04-20 17:03:48 -0400401 error = gfs2_recover_journal(sdp->sd_jdesc);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000402 if (error) {
403 fs_err(sdp, "error recovering my journal: %d\n", error);
404 goto fail_jinode_gh;
405 }
406 }
407
408 set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags);
409 gfs2_glock_dq_uninit(&ji_gh);
410 jindex = 0;
411
David Teiglandb3b94fa2006-01-16 16:50:04 +0000412 p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
413 error = IS_ERR(p);
414 if (error) {
415 fs_err(sdp, "can't start recoverd thread: %d\n", error);
416 goto fail_jinode_gh;
417 }
418 sdp->sd_recoverd_process = p;
419
420 return 0;
421
Steven Whitehousea91ea692006-09-04 12:04:26 -0400422fail_recoverd:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000423 kthread_stop(sdp->sd_recoverd_process);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400424fail_jinode_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000425 if (!sdp->sd_args.ar_spectator)
426 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400427fail_journal_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000428 if (!sdp->sd_args.ar_spectator)
429 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400430fail_jindex:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000431 gfs2_jindex_free(sdp);
432 if (jindex)
433 gfs2_glock_dq_uninit(&ji_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400434fail:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000435 iput(sdp->sd_jindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000436 return error;
437}
438
David Teiglandb3b94fa2006-01-16 16:50:04 +0000439
440static int init_inodes(struct gfs2_sbd *sdp, int undo)
441{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000442 int error = 0;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500443 struct gfs2_inode *ip;
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500444 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000445
446 if (undo)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000447 goto fail_qinode;
448
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100449 inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr);
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500450 if (IS_ERR(inode)) {
451 error = PTR_ERR(inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000452 fs_err(sdp, "can't read in master directory: %d\n", error);
453 goto fail;
454 }
Steven Whitehousec9fd4302006-03-01 15:31:02 -0500455 sdp->sd_master_dir = inode;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000456
457 error = init_journal(sdp, undo);
458 if (error)
459 goto fail_master;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000460
461 /* Read in the master inode number inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500462 sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum");
463 if (IS_ERR(sdp->sd_inum_inode)) {
464 error = PTR_ERR(sdp->sd_inum_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000465 fs_err(sdp, "can't read in inum inode: %d\n", error);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000466 goto fail_journal;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000467 }
468
Steven Whitehousef42faf42006-01-30 18:34:10 +0000469
David Teiglandb3b94fa2006-01-16 16:50:04 +0000470 /* Read in the master statfs inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500471 sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs");
472 if (IS_ERR(sdp->sd_statfs_inode)) {
473 error = PTR_ERR(sdp->sd_statfs_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000474 fs_err(sdp, "can't read in statfs inode: %d\n", error);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000475 goto fail_inum;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000476 }
477
478 /* Read in the resource index inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500479 sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex");
480 if (IS_ERR(sdp->sd_rindex)) {
481 error = PTR_ERR(sdp->sd_rindex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000482 fs_err(sdp, "can't get resource index inode: %d\n", error);
483 goto fail_statfs;
484 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400485 ip = GFS2_I(sdp->sd_rindex);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500486 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
487 sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000488
489 /* Read in the quota inode */
Steven Whitehousec7526662006-03-20 12:30:04 -0500490 sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota");
491 if (IS_ERR(sdp->sd_quota_inode)) {
492 error = PTR_ERR(sdp->sd_quota_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000493 fs_err(sdp, "can't get quota file inode: %d\n", error);
494 goto fail_rindex;
495 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000496 return 0;
497
Steven Whitehousef42faf42006-01-30 18:34:10 +0000498fail_qinode:
499 iput(sdp->sd_quota_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000500fail_rindex:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000501 gfs2_clear_rgrpd(sdp);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000502 iput(sdp->sd_rindex);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000503fail_statfs:
504 iput(sdp->sd_statfs_inode);
Steven Whitehousef42faf42006-01-30 18:34:10 +0000505fail_inum:
506 iput(sdp->sd_inum_inode);
507fail_journal:
508 init_journal(sdp, UNDO);
509fail_master:
510 iput(sdp->sd_master_dir);
511fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000512 return error;
513}
514
515static int init_per_node(struct gfs2_sbd *sdp, int undo)
516{
Steven Whitehousef42faf42006-01-30 18:34:10 +0000517 struct inode *pn = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000518 char buf[30];
519 int error = 0;
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500520 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000521
522 if (sdp->sd_args.ar_spectator)
523 return 0;
524
525 if (undo)
526 goto fail_qc_gh;
527
Steven Whitehousec7526662006-03-20 12:30:04 -0500528 pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node");
529 if (IS_ERR(pn)) {
530 error = PTR_ERR(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000531 fs_err(sdp, "can't find per_node directory: %d\n", error);
532 return error;
533 }
534
535 sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500536 sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
537 if (IS_ERR(sdp->sd_ir_inode)) {
538 error = PTR_ERR(sdp->sd_ir_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000539 fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
540 goto fail;
541 }
542
543 sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500544 sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
545 if (IS_ERR(sdp->sd_sc_inode)) {
546 error = PTR_ERR(sdp->sd_sc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000547 fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
548 goto fail_ir_i;
549 }
550
David Teiglandb3b94fa2006-01-16 16:50:04 +0000551 sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
Steven Whitehousec7526662006-03-20 12:30:04 -0500552 sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
553 if (IS_ERR(sdp->sd_qc_inode)) {
554 error = PTR_ERR(sdp->sd_qc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000555 fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
556 goto fail_ut_i;
557 }
558
Steven Whitehousef42faf42006-01-30 18:34:10 +0000559 iput(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000560 pn = NULL;
561
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400562 ip = GFS2_I(sdp->sd_ir_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500563 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400564 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000565 &sdp->sd_ir_gh);
566 if (error) {
567 fs_err(sdp, "can't lock local \"ir\" file: %d\n", error);
568 goto fail_qc_i;
569 }
570
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400571 ip = GFS2_I(sdp->sd_sc_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500572 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400573 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000574 &sdp->sd_sc_gh);
575 if (error) {
576 fs_err(sdp, "can't lock local \"sc\" file: %d\n", error);
577 goto fail_ir_gh;
578 }
579
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400580 ip = GFS2_I(sdp->sd_qc_inode);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500581 error = gfs2_glock_nq_init(ip->i_gl,
Steven Whitehouse579b78a2006-04-26 14:58:26 -0400582 LM_ST_EXCLUSIVE, 0,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000583 &sdp->sd_qc_gh);
584 if (error) {
585 fs_err(sdp, "can't lock local \"qc\" file: %d\n", error);
586 goto fail_ut_gh;
587 }
588
589 return 0;
590
Steven Whitehousea91ea692006-09-04 12:04:26 -0400591fail_qc_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000592 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400593fail_ut_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000594 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400595fail_ir_gh:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000596 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400597fail_qc_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000598 iput(sdp->sd_qc_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400599fail_ut_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000600 iput(sdp->sd_sc_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400601fail_ir_i:
Steven Whitehousef42faf42006-01-30 18:34:10 +0000602 iput(sdp->sd_ir_inode);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400603fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000604 if (pn)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000605 iput(pn);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000606 return error;
607}
608
609static int init_threads(struct gfs2_sbd *sdp, int undo)
610{
611 struct task_struct *p;
612 int error = 0;
613
614 if (undo)
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400615 goto fail_quotad;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000616
617 sdp->sd_log_flush_time = jiffies;
618 sdp->sd_jindex_refresh_time = jiffies;
619
620 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
621 error = IS_ERR(p);
622 if (error) {
623 fs_err(sdp, "can't start logd thread: %d\n", error);
624 return error;
625 }
626 sdp->sd_logd_process = p;
627
628 sdp->sd_statfs_sync_time = jiffies;
629 sdp->sd_quota_sync_time = jiffies;
630
631 p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
632 error = IS_ERR(p);
633 if (error) {
634 fs_err(sdp, "can't start quotad thread: %d\n", error);
635 goto fail;
636 }
637 sdp->sd_quotad_process = p;
638
David Teiglandb3b94fa2006-01-16 16:50:04 +0000639 return 0;
640
David Teiglandb3b94fa2006-01-16 16:50:04 +0000641
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400642fail_quotad:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000643 kthread_stop(sdp->sd_quotad_process);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400644fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000645 kthread_stop(sdp->sd_logd_process);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000646 return error;
647}
648
649/**
650 * fill_super - Read in superblock
651 * @sb: The VFS superblock
652 * @data: Mount options
653 * @silent: Don't complain if it's not a GFS2 filesystem
654 *
655 * Returns: errno
656 */
657
658static int fill_super(struct super_block *sb, void *data, int silent)
659{
660 struct gfs2_sbd *sdp;
661 struct gfs2_holder mount_gh;
662 int error;
663
664 sdp = init_sbd(sb);
665 if (!sdp) {
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500666 printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000667 return -ENOMEM;
668 }
669
670 error = gfs2_mount_args(sdp, (char *)data, 0);
671 if (error) {
Steven Whitehoused92a8d42006-02-27 10:57:14 -0500672 printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
David Teiglandb3b94fa2006-01-16 16:50:04 +0000673 goto fail;
674 }
675
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500676 init_vfs(sb, SDF_NOATIME);
677
678 /* Set up the buffer cache and fill in some fake block size values
679 to allow us to read-in the on-disk superblock. */
680 sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
681 sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
682 sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
683 GFS2_BASIC_BLOCK_SHIFT;
684 sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000685
686 error = init_names(sdp, silent);
687 if (error)
688 goto fail;
689
Robert Peterson7c52b162007-03-16 10:26:37 +0000690 gfs2_create_debugfs_file(sdp);
691
David Teiglandb3b94fa2006-01-16 16:50:04 +0000692 error = gfs2_sys_fs_add(sdp);
693 if (error)
694 goto fail;
695
696 error = gfs2_lm_mount(sdp, silent);
697 if (error)
698 goto fail_sys;
699
700 error = init_locking(sdp, &mount_gh, DO);
701 if (error)
702 goto fail_lm;
703
704 error = init_sb(sdp, silent, DO);
705 if (error)
706 goto fail_locking;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000707
708 error = init_inodes(sdp, DO);
709 if (error)
Steven Whitehousef42faf42006-01-30 18:34:10 +0000710 goto fail_sb;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000711
712 error = init_per_node(sdp, DO);
713 if (error)
714 goto fail_inodes;
715
716 error = gfs2_statfs_init(sdp);
717 if (error) {
718 fs_err(sdp, "can't initialize statfs subsystem: %d\n", error);
719 goto fail_per_node;
720 }
721
722 error = init_threads(sdp, DO);
723 if (error)
724 goto fail_per_node;
725
726 if (!(sb->s_flags & MS_RDONLY)) {
727 error = gfs2_make_fs_rw(sdp);
728 if (error) {
729 fs_err(sdp, "can't make FS RW: %d\n", error);
730 goto fail_threads;
731 }
732 }
733
734 gfs2_glock_dq_uninit(&mount_gh);
735
736 return 0;
737
Steven Whitehousea91ea692006-09-04 12:04:26 -0400738fail_threads:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000739 init_threads(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400740fail_per_node:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000741 init_per_node(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400742fail_inodes:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000743 init_inodes(sdp, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400744fail_sb:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000745 init_sb(sdp, 0, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400746fail_locking:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000747 init_locking(sdp, &mount_gh, UNDO);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400748fail_lm:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000749 gfs2_gl_hash_clear(sdp, WAIT);
750 gfs2_lm_unmount(sdp);
751 while (invalidate_inodes(sb))
752 yield();
Steven Whitehousea91ea692006-09-04 12:04:26 -0400753fail_sys:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000754 gfs2_sys_fs_del(sdp);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400755fail:
Robert Peterson5f882092007-04-18 11:41:11 -0500756 gfs2_delete_debugfs_file(sdp);
Steven Whitehousea2c45802006-09-08 10:13:03 -0400757 kfree(sdp);
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500758 sb->s_fs_info = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000759 return error;
760}
761
Andrew Mortonccd6efd2006-06-30 02:16:34 -0700762static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
763 const char *dev_name, void *data, struct vfsmount *mnt)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000764{
Abhijith Das86384602006-08-25 11:13:37 -0500765 struct super_block *sb;
766 struct gfs2_sbd *sdp;
767 int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
768 if (error)
769 goto out;
770 sb = mnt->mnt_sb;
Steven Whitehouse26c1a572006-09-04 15:32:10 -0400771 sdp = sb->s_fs_info;
Abhijith Das86384602006-08-25 11:13:37 -0500772 sdp->sd_gfs2mnt = mnt;
773out:
774 return error;
775}
776
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400777static int fill_super_meta(struct super_block *sb, struct super_block *new,
Abhijith Das86384602006-08-25 11:13:37 -0500778 void *data, int silent)
779{
780 struct gfs2_sbd *sdp = sb->s_fs_info;
781 struct inode *inode;
782 int error = 0;
783
784 new->s_fs_info = sdp;
785 sdp->sd_vfs_meta = sb;
786
787 init_vfs(new, SDF_NOATIME);
788
789 /* Get the master inode */
790 inode = igrab(sdp->sd_master_dir);
791
792 new->s_root = d_alloc_root(inode);
793 if (!new->s_root) {
794 fs_err(sdp, "can't get root dentry\n");
795 error = -ENOMEM;
796 iput(inode);
Adrian Bunkbbbe4512006-10-19 15:27:00 +0200797 } else
798 new->s_root->d_op = &gfs2_dops;
Abhijith Das86384602006-08-25 11:13:37 -0500799
800 return error;
801}
Steven Whitehousea91ea692006-09-04 12:04:26 -0400802
Abhijith Das86384602006-08-25 11:13:37 -0500803static int set_bdev_super(struct super_block *s, void *data)
804{
805 s->s_bdev = data;
806 s->s_dev = s->s_bdev->bd_dev;
807 return 0;
808}
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400809
Abhijith Das86384602006-08-25 11:13:37 -0500810static int test_bdev_super(struct super_block *s, void *data)
811{
Steven Whitehouse26c1a572006-09-04 15:32:10 -0400812 return s->s_bdev == data;
Abhijith Das86384602006-08-25 11:13:37 -0500813}
814
815static struct super_block* get_gfs2_sb(const char *dev_name)
816{
817 struct kstat stat;
818 struct nameidata nd;
819 struct file_system_type *fstype;
820 struct super_block *sb = NULL, *s;
821 struct list_head *l;
822 int error;
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400823
Abhijith Das86384602006-08-25 11:13:37 -0500824 error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
825 if (error) {
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400826 printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n",
Abhijith Das86384602006-08-25 11:13:37 -0500827 dev_name);
828 goto out;
829 }
830 error = vfs_getattr(nd.mnt, nd.dentry, &stat);
831
832 fstype = get_fs_type("gfs2");
833 list_for_each(l, &fstype->fs_supers) {
834 s = list_entry(l, struct super_block, s_instances);
835 if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) ||
836 (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) {
837 sb = s;
838 goto free_nd;
839 }
840 }
841
842 printk(KERN_WARNING "GFS2: Unrecognized block device or "
Richard Fearnd5a67512007-02-17 17:29:15 +0000843 "mount point %s\n", dev_name);
Abhijith Das86384602006-08-25 11:13:37 -0500844
845free_nd:
846 path_release(&nd);
847out:
848 return sb;
849}
850
851static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
852 const char *dev_name, void *data, struct vfsmount *mnt)
853{
854 int error = 0;
855 struct super_block *sb = NULL, *new;
856 struct gfs2_sbd *sdp;
Abhijith Das86384602006-08-25 11:13:37 -0500857
858 sb = get_gfs2_sb(dev_name);
859 if (!sb) {
860 printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n");
861 error = -ENOENT;
862 goto error;
863 }
864 sdp = (struct gfs2_sbd*) sb->s_fs_info;
865 if (sdp->sd_vfs_meta) {
866 printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n");
867 error = -EBUSY;
868 goto error;
869 }
David Chinnerf73ca1b2007-01-10 23:15:41 -0800870 down(&sb->s_bdev->bd_mount_sem);
Abhijith Das86384602006-08-25 11:13:37 -0500871 new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev);
David Chinnerf73ca1b2007-01-10 23:15:41 -0800872 up(&sb->s_bdev->bd_mount_sem);
Abhijith Das86384602006-08-25 11:13:37 -0500873 if (IS_ERR(new)) {
874 error = PTR_ERR(new);
875 goto error;
876 }
877 module_put(fs_type->owner);
878 new->s_flags = flags;
879 strlcpy(new->s_id, sb->s_id, sizeof(new->s_id));
880 sb_set_blocksize(new, sb->s_blocksize);
881 error = fill_super_meta(sb, new, data, flags & MS_SILENT ? 1 : 0);
882 if (error) {
883 up_write(&new->s_umount);
884 deactivate_super(new);
885 goto error;
886 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400887
Abhijith Das86384602006-08-25 11:13:37 -0500888 new->s_flags |= MS_ACTIVE;
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400889
Abhijith Das86384602006-08-25 11:13:37 -0500890 /* Grab a reference to the gfs2 mount point */
891 atomic_inc(&sdp->sd_gfs2mnt->mnt_count);
892 return simple_set_mnt(mnt, new);
893error:
Abhijith Das86384602006-08-25 11:13:37 -0500894 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000895}
896
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500897static void gfs2_kill_sb(struct super_block *sb)
898{
Robert Peterson7c52b162007-03-16 10:26:37 +0000899 gfs2_delete_debugfs_file(sb->s_fs_info);
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500900 kill_block_super(sb);
901}
902
Abhijith Das86384602006-08-25 11:13:37 -0500903static void gfs2_kill_sb_meta(struct super_block *sb)
904{
905 struct gfs2_sbd *sdp = sb->s_fs_info;
906 generic_shutdown_super(sb);
907 sdp->sd_vfs_meta = NULL;
908 atomic_dec(&sdp->sd_gfs2mnt->mnt_count);
909}
910
David Teiglandb3b94fa2006-01-16 16:50:04 +0000911struct file_system_type gfs2_fs_type = {
912 .name = "gfs2",
913 .fs_flags = FS_REQUIRES_DEV,
914 .get_sb = gfs2_get_sb,
Steven Whitehouse419c93e2006-03-02 16:33:41 -0500915 .kill_sb = gfs2_kill_sb,
916 .owner = THIS_MODULE,
917};
918
919struct file_system_type gfs2meta_fs_type = {
920 .name = "gfs2meta",
921 .fs_flags = FS_REQUIRES_DEV,
Abhijith Das86384602006-08-25 11:13:37 -0500922 .get_sb = gfs2_get_sb_meta,
923 .kill_sb = gfs2_kill_sb_meta,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000924 .owner = THIS_MODULE,
925};
926