Blame view

fs/gfs2/ops_fstype.c 23.1 KB
b3b94faa5   David Teigland   [GFS2] The core o...
1
2
  /*
   * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
da6dd40d5   Bob Peterson   [GFS2] Journal ex...
3
   * Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
b3b94faa5   David Teigland   [GFS2] The core o...
4
5
6
   *
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
e9fc2aa09   Steven Whitehouse   [GFS2] Update cop...
7
   * of the GNU General Public License version 2.
b3b94faa5   David Teigland   [GFS2] The core o...
8
9
10
11
12
13
14
   */
  
  #include <linux/sched.h>
  #include <linux/slab.h>
  #include <linux/spinlock.h>
  #include <linux/completion.h>
  #include <linux/buffer_head.h>
b3b94faa5   David Teigland   [GFS2] The core o...
15
16
  #include <linux/blkdev.h>
  #include <linux/kthread.h>
863846054   Abhijith Das   [GFS2] Allow moun...
17
18
  #include <linux/namei.h>
  #include <linux/mount.h>
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
19
  #include <linux/gfs2_ondisk.h>
7d308590a   Fabio Massimo Di Nitto   [GFS2] Export lm_...
20
  #include <linux/lm_interface.h>
b3b94faa5   David Teigland   [GFS2] The core o...
21
22
  
  #include "gfs2.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
23
  #include "incore.h"
da6dd40d5   Bob Peterson   [GFS2] Journal ex...
24
  #include "bmap.h"
b3b94faa5   David Teigland   [GFS2] The core o...
25
26
27
28
29
30
  #include "daemon.h"
  #include "glock.h"
  #include "glops.h"
  #include "inode.h"
  #include "lm.h"
  #include "mount.h"
b3b94faa5   David Teigland   [GFS2] The core o...
31
  #include "ops_fstype.h"
ca5a939b3   Denis Cheng   [GFS2] use the de...
32
  #include "ops_dentry.h"
b3b94faa5   David Teigland   [GFS2] The core o...
33
34
35
36
  #include "ops_super.h"
  #include "recovery.h"
  #include "rgrp.h"
  #include "super.h"
b3b94faa5   David Teigland   [GFS2] The core o...
37
  #include "sys.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
38
  #include "util.h"
bb3b0e3df   Steven Whitehouse   [GFS2] Clean up i...
39
  #include "log.h"
b3b94faa5   David Teigland   [GFS2] The core o...
40
41
42
43
44
45
46
  
  #define DO 0
  #define UNDO 1
  
  static struct gfs2_sbd *init_sbd(struct super_block *sb)
  {
  	struct gfs2_sbd *sdp;
b3b94faa5   David Teigland   [GFS2] The core o...
47

85d1da67f   Steven Whitehouse   [GFS2] Move glock...
48
  	sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
b3b94faa5   David Teigland   [GFS2] The core o...
49
50
  	if (!sdp)
  		return NULL;
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
51
  	sb->s_fs_info = sdp;
b3b94faa5   David Teigland   [GFS2] The core o...
52
53
54
  	sdp->sd_vfs = sb;
  
  	gfs2_tune_init(&sdp->sd_tune);
b3b94faa5   David Teigland   [GFS2] The core o...
55
56
57
  	INIT_LIST_HEAD(&sdp->sd_reclaim_list);
  	spin_lock_init(&sdp->sd_reclaim_lock);
  	init_waitqueue_head(&sdp->sd_reclaim_wq);
b3b94faa5   David Teigland   [GFS2] The core o...
58

f55ab26a8   Steven Whitehouse   [GFS2] Use mutice...
59
  	mutex_init(&sdp->sd_inum_mutex);
b3b94faa5   David Teigland   [GFS2] The core o...
60
  	spin_lock_init(&sdp->sd_statfs_spin);
b3b94faa5   David Teigland   [GFS2] The core o...
61
62
  
  	spin_lock_init(&sdp->sd_rindex_spin);
f55ab26a8   Steven Whitehouse   [GFS2] Use mutice...
63
  	mutex_init(&sdp->sd_rindex_mutex);
b3b94faa5   David Teigland   [GFS2] The core o...
64
65
66
67
68
69
  	INIT_LIST_HEAD(&sdp->sd_rindex_list);
  	INIT_LIST_HEAD(&sdp->sd_rindex_mru_list);
  	INIT_LIST_HEAD(&sdp->sd_rindex_recent_list);
  
  	INIT_LIST_HEAD(&sdp->sd_jindex_list);
  	spin_lock_init(&sdp->sd_jindex_spin);
f55ab26a8   Steven Whitehouse   [GFS2] Use mutice...
70
  	mutex_init(&sdp->sd_jindex_mutex);
b3b94faa5   David Teigland   [GFS2] The core o...
71

b3b94faa5   David Teigland   [GFS2] The core o...
72
73
  	INIT_LIST_HEAD(&sdp->sd_quota_list);
  	spin_lock_init(&sdp->sd_quota_spin);
f55ab26a8   Steven Whitehouse   [GFS2] Use mutice...
74
  	mutex_init(&sdp->sd_quota_mutex);
b3b94faa5   David Teigland   [GFS2] The core o...
75
76
  
  	spin_lock_init(&sdp->sd_log_lock);
b3b94faa5   David Teigland   [GFS2] The core o...
77

b3b94faa5   David Teigland   [GFS2] The core o...
78
79
80
81
  	INIT_LIST_HEAD(&sdp->sd_log_le_buf);
  	INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
  	INIT_LIST_HEAD(&sdp->sd_log_le_rg);
  	INIT_LIST_HEAD(&sdp->sd_log_le_databuf);
d7b616e25   Steven Whitehouse   [GFS2] Clean up o...
82
  	INIT_LIST_HEAD(&sdp->sd_log_le_ordered);
b3b94faa5   David Teigland   [GFS2] The core o...
83

71b86f562   Steven Whitehouse   [GFS2] Further up...
84
  	mutex_init(&sdp->sd_log_reserve_mutex);
b3b94faa5   David Teigland   [GFS2] The core o...
85
86
  	INIT_LIST_HEAD(&sdp->sd_ail1_list);
  	INIT_LIST_HEAD(&sdp->sd_ail2_list);
484adff8a   Steven Whitehouse   [GFS2] Update loc...
87
  	init_rwsem(&sdp->sd_log_flush_lock);
16615be18   Steven Whitehouse   [GFS2] Clean up j...
88
89
  	atomic_set(&sdp->sd_log_in_flight, 0);
  	init_waitqueue_head(&sdp->sd_log_flush_wait);
b3b94faa5   David Teigland   [GFS2] The core o...
90
91
  
  	INIT_LIST_HEAD(&sdp->sd_revoke_list);
f55ab26a8   Steven Whitehouse   [GFS2] Use mutice...
92
  	mutex_init(&sdp->sd_freeze_lock);
b3b94faa5   David Teigland   [GFS2] The core o...
93
94
95
  
  	return sdp;
  }
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
96
  static void init_vfs(struct super_block *sb, unsigned noatime)
b3b94faa5   David Teigland   [GFS2] The core o...
97
  {
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
98
  	struct gfs2_sbd *sdp = sb->s_fs_info;
b3b94faa5   David Teigland   [GFS2] The core o...
99
100
101
102
  
  	sb->s_magic = GFS2_MAGIC;
  	sb->s_op = &gfs2_super_ops;
  	sb->s_export_op = &gfs2_export_ops;
4bd91ba18   Steven Whitehouse   [GFS2] Add nanose...
103
  	sb->s_time_gran = 1;
b3b94faa5   David Teigland   [GFS2] The core o...
104
105
106
  	sb->s_maxbytes = MAX_LFS_FILESIZE;
  
  	if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME))
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
107
  		set_bit(noatime, &sdp->sd_flags);
b3b94faa5   David Teigland   [GFS2] The core o...
108
109
110
  
  	/* Don't let the VFS update atimes.  GFS2 handles this itself. */
  	sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
b3b94faa5   David Teigland   [GFS2] The core o...
111
112
113
114
  }
  
  static int init_names(struct gfs2_sbd *sdp, int silent)
  {
b3b94faa5   David Teigland   [GFS2] The core o...
115
116
117
118
119
120
121
122
123
  	char *proto, *table;
  	int error = 0;
  
  	proto = sdp->sd_args.ar_lockproto;
  	table = sdp->sd_args.ar_locktable;
  
  	/*  Try to autodetect  */
  
  	if (!proto[0] || !table[0]) {
bb8d8a6f5   Steven Whitehouse   [GFS2] Fix sign p...
124
125
126
  		error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
  		if (error)
  			return error;
3cf1e7bed   Steven Whitehouse   [GFS2] Remove dup...
127
128
  
  		error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
b3b94faa5   David Teigland   [GFS2] The core o...
129
130
131
132
  		if (error)
  			goto out;
  
  		if (!proto[0])
3cf1e7bed   Steven Whitehouse   [GFS2] Remove dup...
133
  			proto = sdp->sd_sb.sb_lockproto;
b3b94faa5   David Teigland   [GFS2] The core o...
134
  		if (!table[0])
3cf1e7bed   Steven Whitehouse   [GFS2] Remove dup...
135
  			table = sdp->sd_sb.sb_locktable;
b3b94faa5   David Teigland   [GFS2] The core o...
136
137
138
139
140
141
142
  	}
  
  	if (!table[0])
  		table = sdp->sd_vfs->s_id;
  
  	snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto);
  	snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table);
5d35e31f4   Denis Cheng   [GFS2] better cod...
143
144
  	table = sdp->sd_table_name;
  	while ((table = strchr(table, '/')))
b35997d44   Robert Peterson   [GFS2] Can't moun...
145
  		*table = '_';
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
146
  out:
b3b94faa5   David Teigland   [GFS2] The core o...
147
148
149
150
151
152
153
154
155
156
157
  	return error;
  }
  
  static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
  			int undo)
  {
  	struct task_struct *p;
  	int error = 0;
  
  	if (undo)
  		goto fail_trans;
b3b94faa5   David Teigland   [GFS2] The core o...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  	for (sdp->sd_glockd_num = 0;
  	     sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd;
  	     sdp->sd_glockd_num++) {
  		p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd");
  		error = IS_ERR(p);
  		if (error) {
  			fs_err(sdp, "can't start glockd thread: %d
  ", error);
  			goto fail;
  		}
  		sdp->sd_glockd_process[sdp->sd_glockd_num] = p;
  	}
  
  	error = gfs2_glock_nq_num(sdp,
  				  GFS2_MOUNT_LOCK, &gfs2_nondisk_glops,
  				  LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE,
  				  mount_gh);
  	if (error) {
  		fs_err(sdp, "can't acquire mount glock: %d
  ", error);
  		goto fail;
  	}
  
  	error = gfs2_glock_nq_num(sdp,
  				  GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
  				  LM_ST_SHARED,
579b78a43   Steven Whitehouse   [GFS2] Remove GL_...
184
  				  LM_FLAG_NOEXP | GL_EXACT,
b3b94faa5   David Teigland   [GFS2] The core o...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  				  &sdp->sd_live_gh);
  	if (error) {
  		fs_err(sdp, "can't acquire live glock: %d
  ", error);
  		goto fail_mount;
  	}
  
  	error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops,
  			       CREATE, &sdp->sd_rename_gl);
  	if (error) {
  		fs_err(sdp, "can't create rename glock: %d
  ", error);
  		goto fail_live;
  	}
  
  	error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops,
  			       CREATE, &sdp->sd_trans_gl);
  	if (error) {
  		fs_err(sdp, "can't create transaction glock: %d
  ", error);
  		goto fail_rename;
  	}
  	set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags);
  
  	return 0;
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
210
  fail_trans:
b3b94faa5   David Teigland   [GFS2] The core o...
211
  	gfs2_glock_put(sdp->sd_trans_gl);
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
212
  fail_rename:
b3b94faa5   David Teigland   [GFS2] The core o...
213
  	gfs2_glock_put(sdp->sd_rename_gl);
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
214
  fail_live:
b3b94faa5   David Teigland   [GFS2] The core o...
215
  	gfs2_glock_dq_uninit(&sdp->sd_live_gh);
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
216
  fail_mount:
b3b94faa5   David Teigland   [GFS2] The core o...
217
  	gfs2_glock_dq_uninit(mount_gh);
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
218
  fail:
b3b94faa5   David Teigland   [GFS2] The core o...
219
220
  	while (sdp->sd_glockd_num--)
  		kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
b3b94faa5   David Teigland   [GFS2] The core o...
221
222
  	return error;
  }
dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
223
224
  static inline struct inode *gfs2_lookup_root(struct super_block *sb,
  					     u64 no_addr)
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
225
  {
7a9f53b3c   Benjamin Marzinski   [GFS2] Alternate ...
226
  	return gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
227
  }
b3b94faa5   David Teigland   [GFS2] The core o...
228
229
230
231
  static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
  {
  	struct super_block *sb = sdp->sd_vfs;
  	struct gfs2_holder sb_gh;
dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
232
  	u64 no_addr;
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
233
  	struct inode *inode;
b3b94faa5   David Teigland   [GFS2] The core o...
234
235
236
  	int error = 0;
  
  	if (undo) {
887218778   Russell Cattelan   [GFS2] Fix a coup...
237
238
239
240
  		if (sb->s_root) {
  			dput(sb->s_root);
  			sb->s_root = NULL;
  		}
b3b94faa5   David Teigland   [GFS2] The core o...
241
242
  		return 0;
  	}
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
243

feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
244
  	error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
b3b94faa5   David Teigland   [GFS2] The core o...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
  				 LM_ST_SHARED, 0, &sb_gh);
  	if (error) {
  		fs_err(sdp, "can't acquire superblock glock: %d
  ", error);
  		return error;
  	}
  
  	error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent);
  	if (error) {
  		fs_err(sdp, "can't read superblock: %d
  ", error);
  		goto out;
  	}
  
  	/* Set up the buffer cache and SB for real */
b3b94faa5   David Teigland   [GFS2] The core o...
260
  	if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
261
  		error = -EINVAL;
b3b94faa5   David Teigland   [GFS2] The core o...
262
263
264
265
266
267
268
  		fs_err(sdp, "FS block size (%u) is too small for device "
  		       "block size (%u)
  ",
  		       sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
  		goto out;
  	}
  	if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
269
  		error = -EINVAL;
b3b94faa5   David Teigland   [GFS2] The core o...
270
271
272
273
274
275
  		fs_err(sdp, "FS block size (%u) is too big for machine "
  		       "page size (%u)
  ",
  		       sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
  		goto out;
  	}
b3b94faa5   David Teigland   [GFS2] The core o...
276
  	sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
277
  	/* Get the root inode */
dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
278
  	no_addr = sdp->sd_sb.sb_root_dir.no_addr;
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
279
  	if (sb->s_type == &gfs2meta_fs_type)
dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
280
281
  		no_addr = sdp->sd_sb.sb_master_dir.no_addr;
  	inode = gfs2_lookup_root(sb, no_addr);
c9fd43078   Steven Whitehouse   [GFS2] Tidy up mo...
282
283
  	if (IS_ERR(inode)) {
  		error = PTR_ERR(inode);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
284
285
286
287
  		fs_err(sdp, "can't read in root inode: %d
  ", error);
  		goto out;
  	}
b3b94faa5   David Teigland   [GFS2] The core o...
288

f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
289
290
291
292
293
  	sb->s_root = d_alloc_root(inode);
  	if (!sb->s_root) {
  		fs_err(sdp, "can't get root dentry
  ");
  		error = -ENOMEM;
c9fd43078   Steven Whitehouse   [GFS2] Tidy up mo...
294
  		iput(inode);
34eaae398   Denis Cheng   [GFS2] fixed a NU...
295
296
297
  	} else
  		sb->s_root->d_op = &gfs2_dops;
  	
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
298
  out:
b3b94faa5   David Teigland   [GFS2] The core o...
299
  	gfs2_glock_dq_uninit(&sb_gh);
b3b94faa5   David Teigland   [GFS2] The core o...
300
301
  	return error;
  }
da6dd40d5   Bob Peterson   [GFS2] Journal ex...
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  /**
   * map_journal_extents - create a reusable "extent" mapping from all logical
   * blocks to all physical blocks for the given journal.  This will save
   * us time when writing journal blocks.  Most journals will have only one
   * extent that maps all their logical blocks.  That's because gfs2.mkfs
   * arranges the journal blocks sequentially to maximize performance.
   * So the extent would map the first block for the entire file length.
   * However, gfs2_jadd can happen while file activity is happening, so
   * those journals may not be sequential.  Less likely is the case where
   * the users created their own journals by mounting the metafs and
   * laying it out.  But it's still possible.  These journals might have
   * several extents.
   *
   * TODO: This should be done in bigger chunks rather than one block at a time,
   *       but since it's only done at mount time, I'm not worried about the
   *       time it takes.
   */
  static int map_journal_extents(struct gfs2_sbd *sdp)
  {
  	struct gfs2_jdesc *jd = sdp->sd_jdesc;
  	unsigned int lb;
  	u64 db, prev_db; /* logical block, disk block, prev disk block */
  	struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
  	struct gfs2_journal_extent *jext = NULL;
  	struct buffer_head bh;
  	int rc = 0;
da6dd40d5   Bob Peterson   [GFS2] Journal ex...
328
  	prev_db = 0;
fa3742fa8   Bob Peterson   [GFS2] Minor corr...
329
  	for (lb = 0; lb < ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; lb++) {
da6dd40d5   Bob Peterson   [GFS2] Journal ex...
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
  		bh.b_state = 0;
  		bh.b_blocknr = 0;
  		bh.b_size = 1 << ip->i_inode.i_blkbits;
  		rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0);
  		db = bh.b_blocknr;
  		if (rc || !db) {
  			printk(KERN_INFO "GFS2 journal mapping error %d: lb="
  			       "%u db=%llu
  ", rc, lb, (unsigned long long)db);
  			break;
  		}
  		if (!prev_db || db != prev_db + 1) {
  			jext = kzalloc(sizeof(struct gfs2_journal_extent),
  				       GFP_KERNEL);
  			if (!jext) {
  				printk(KERN_INFO "GFS2 error: out of memory "
  				       "mapping journal extents.
  ");
  				rc = -ENOMEM;
  				break;
  			}
  			jext->dblock = db;
  			jext->lblock = lb;
  			jext->blocks = 1;
  			list_add_tail(&jext->extent_list, &jd->extent_list);
  		} else {
  			jext->blocks++;
  		}
  		prev_db = db;
  	}
  	return rc;
  }
b3b94faa5   David Teigland   [GFS2] The core o...
362
363
364
365
  static int init_journal(struct gfs2_sbd *sdp, int undo)
  {
  	struct gfs2_holder ji_gh;
  	struct task_struct *p;
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
366
  	struct gfs2_inode *ip;
b3b94faa5   David Teigland   [GFS2] The core o...
367
368
369
370
371
372
373
  	int jindex = 1;
  	int error = 0;
  
  	if (undo) {
  		jindex = 0;
  		goto fail_recoverd;
  	}
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
374
375
  	sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex");
  	if (IS_ERR(sdp->sd_jindex)) {
b3b94faa5   David Teigland   [GFS2] The core o...
376
377
  		fs_err(sdp, "can't lookup journal index: %d
  ", error);
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
378
  		return PTR_ERR(sdp->sd_jindex);
b3b94faa5   David Teigland   [GFS2] The core o...
379
  	}
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
380
  	ip = GFS2_I(sdp->sd_jindex);
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
381
  	set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
b3b94faa5   David Teigland   [GFS2] The core o...
382
383
384
385
386
387
388
389
390
391
392
393
394
395
  
  	/* Load in the journal index special file */
  
  	error = gfs2_jindex_hold(sdp, &ji_gh);
  	if (error) {
  		fs_err(sdp, "can't read journal index: %d
  ", error);
  		goto fail;
  	}
  
  	error = -EINVAL;
  	if (!gfs2_jindex_size(sdp)) {
  		fs_err(sdp, "no journals!
  ");
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
396
  		goto fail_jindex;
b3b94faa5   David Teigland   [GFS2] The core o...
397
398
399
400
  	}
  
  	if (sdp->sd_args.ar_spectator) {
  		sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
fd041f0b4   Steven Whitehouse   [GFS2] Use atomic...
401
  		atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
b3b94faa5   David Teigland   [GFS2] The core o...
402
403
404
405
406
407
408
409
410
411
412
413
  	} else {
  		if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
  			fs_err(sdp, "can't mount journal #%u
  ",
  			       sdp->sd_lockstruct.ls_jid);
  			fs_err(sdp, "there are only %u journals (0 - %u)
  ",
  			       gfs2_jindex_size(sdp),
  			       gfs2_jindex_size(sdp) - 1);
  			goto fail_jindex;
  		}
  		sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
414
  		error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
b3b94faa5   David Teigland   [GFS2] The core o...
415
416
417
418
419
420
421
422
  					  &gfs2_journal_glops,
  					  LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
  					  &sdp->sd_journal_gh);
  		if (error) {
  			fs_err(sdp, "can't acquire journal glock: %d
  ", error);
  			goto fail_jindex;
  		}
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
423
424
  		ip = GFS2_I(sdp->sd_jdesc->jd_inode);
  		error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
75be73a82   Bob Peterson   [GFS2] Ensure jou...
425
  					   LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE,
b3b94faa5   David Teigland   [GFS2] The core o...
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
  					   &sdp->sd_jinode_gh);
  		if (error) {
  			fs_err(sdp, "can't acquire journal inode glock: %d
  ",
  			       error);
  			goto fail_journal_gh;
  		}
  
  		error = gfs2_jdesc_check(sdp->sd_jdesc);
  		if (error) {
  			fs_err(sdp, "my journal (%u) is bad: %d
  ",
  			       sdp->sd_jdesc->jd_jid, error);
  			goto fail_jinode_gh;
  		}
fd041f0b4   Steven Whitehouse   [GFS2] Use atomic...
441
  		atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
da6dd40d5   Bob Peterson   [GFS2] Journal ex...
442
443
444
  
  		/* Map the extents for this journal's blocks */
  		map_journal_extents(sdp);
b3b94faa5   David Teigland   [GFS2] The core o...
445
446
447
448
449
  	}
  
  	if (sdp->sd_lockstruct.ls_first) {
  		unsigned int x;
  		for (x = 0; x < sdp->sd_journals; x++) {
c63e31c2c   David Teigland   [GFS2] journal re...
450
  			error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
b3b94faa5   David Teigland   [GFS2] The core o...
451
452
453
454
455
456
457
458
459
460
  			if (error) {
  				fs_err(sdp, "error recovering journal %u: %d
  ",
  				       x, error);
  				goto fail_jinode_gh;
  			}
  		}
  
  		gfs2_lm_others_may_mount(sdp);
  	} else if (!sdp->sd_args.ar_spectator) {
c63e31c2c   David Teigland   [GFS2] journal re...
461
  		error = gfs2_recover_journal(sdp->sd_jdesc);
b3b94faa5   David Teigland   [GFS2] The core o...
462
463
464
465
466
467
468
469
470
471
  		if (error) {
  			fs_err(sdp, "error recovering my journal: %d
  ", error);
  			goto fail_jinode_gh;
  		}
  	}
  
  	set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags);
  	gfs2_glock_dq_uninit(&ji_gh);
  	jindex = 0;
b3b94faa5   David Teigland   [GFS2] The core o...
472
473
474
475
476
477
478
479
480
481
  	p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
  	error = IS_ERR(p);
  	if (error) {
  		fs_err(sdp, "can't start recoverd thread: %d
  ", error);
  		goto fail_jinode_gh;
  	}
  	sdp->sd_recoverd_process = p;
  
  	return 0;
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
482
  fail_recoverd:
b3b94faa5   David Teigland   [GFS2] The core o...
483
  	kthread_stop(sdp->sd_recoverd_process);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
484
  fail_jinode_gh:
b3b94faa5   David Teigland   [GFS2] The core o...
485
486
  	if (!sdp->sd_args.ar_spectator)
  		gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
487
  fail_journal_gh:
b3b94faa5   David Teigland   [GFS2] The core o...
488
489
  	if (!sdp->sd_args.ar_spectator)
  		gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
490
  fail_jindex:
b3b94faa5   David Teigland   [GFS2] The core o...
491
492
493
  	gfs2_jindex_free(sdp);
  	if (jindex)
  		gfs2_glock_dq_uninit(&ji_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
494
  fail:
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
495
  	iput(sdp->sd_jindex);
b3b94faa5   David Teigland   [GFS2] The core o...
496
497
  	return error;
  }
b3b94faa5   David Teigland   [GFS2] The core o...
498
499
500
  
  static int init_inodes(struct gfs2_sbd *sdp, int undo)
  {
b3b94faa5   David Teigland   [GFS2] The core o...
501
  	int error = 0;
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
502
  	struct gfs2_inode *ip;
c9fd43078   Steven Whitehouse   [GFS2] Tidy up mo...
503
  	struct inode *inode;
b3b94faa5   David Teigland   [GFS2] The core o...
504
505
  
  	if (undo)
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
506
  		goto fail_qinode;
dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
507
  	inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr);
c9fd43078   Steven Whitehouse   [GFS2] Tidy up mo...
508
509
  	if (IS_ERR(inode)) {
  		error = PTR_ERR(inode);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
510
511
512
513
  		fs_err(sdp, "can't read in master directory: %d
  ", error);
  		goto fail;
  	}
c9fd43078   Steven Whitehouse   [GFS2] Tidy up mo...
514
  	sdp->sd_master_dir = inode;
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
515
516
517
518
  
  	error = init_journal(sdp, undo);
  	if (error)
  		goto fail_master;
b3b94faa5   David Teigland   [GFS2] The core o...
519
520
  
  	/* Read in the master inode number inode */
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
521
522
523
  	sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum");
  	if (IS_ERR(sdp->sd_inum_inode)) {
  		error = PTR_ERR(sdp->sd_inum_inode);
b3b94faa5   David Teigland   [GFS2] The core o...
524
525
  		fs_err(sdp, "can't read in inum inode: %d
  ", error);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
526
  		goto fail_journal;
b3b94faa5   David Teigland   [GFS2] The core o...
527
  	}
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
528

b3b94faa5   David Teigland   [GFS2] The core o...
529
  	/* Read in the master statfs inode */
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
530
531
532
  	sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs");
  	if (IS_ERR(sdp->sd_statfs_inode)) {
  		error = PTR_ERR(sdp->sd_statfs_inode);
b3b94faa5   David Teigland   [GFS2] The core o...
533
534
  		fs_err(sdp, "can't read in statfs inode: %d
  ", error);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
535
  		goto fail_inum;
b3b94faa5   David Teigland   [GFS2] The core o...
536
537
538
  	}
  
  	/* Read in the resource index inode */
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
539
540
541
  	sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex");
  	if (IS_ERR(sdp->sd_rindex)) {
  		error = PTR_ERR(sdp->sd_rindex);
b3b94faa5   David Teigland   [GFS2] The core o...
542
543
544
545
  		fs_err(sdp, "can't get resource index inode: %d
  ", error);
  		goto fail_statfs;
  	}
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
546
  	ip = GFS2_I(sdp->sd_rindex);
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
547
548
  	set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
  	sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1;
b3b94faa5   David Teigland   [GFS2] The core o...
549
550
  
  	/* Read in the quota inode */
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
551
552
553
  	sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota");
  	if (IS_ERR(sdp->sd_quota_inode)) {
  		error = PTR_ERR(sdp->sd_quota_inode);
b3b94faa5   David Teigland   [GFS2] The core o...
554
555
556
557
  		fs_err(sdp, "can't get quota file inode: %d
  ", error);
  		goto fail_rindex;
  	}
b3b94faa5   David Teigland   [GFS2] The core o...
558
  	return 0;
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
559
560
  fail_qinode:
  	iput(sdp->sd_quota_inode);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
561
  fail_rindex:
b3b94faa5   David Teigland   [GFS2] The core o...
562
  	gfs2_clear_rgrpd(sdp);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
563
  	iput(sdp->sd_rindex);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
564
565
  fail_statfs:
  	iput(sdp->sd_statfs_inode);
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
566
567
568
569
570
571
572
  fail_inum:
  	iput(sdp->sd_inum_inode);
  fail_journal:
  	init_journal(sdp, UNDO);
  fail_master:
  	iput(sdp->sd_master_dir);
  fail:
b3b94faa5   David Teigland   [GFS2] The core o...
573
574
575
576
577
  	return error;
  }
  
  static int init_per_node(struct gfs2_sbd *sdp, int undo)
  {
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
578
  	struct inode *pn = NULL;
b3b94faa5   David Teigland   [GFS2] The core o...
579
580
  	char buf[30];
  	int error = 0;
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
581
  	struct gfs2_inode *ip;
b3b94faa5   David Teigland   [GFS2] The core o...
582
583
584
585
586
587
  
  	if (sdp->sd_args.ar_spectator)
  		return 0;
  
  	if (undo)
  		goto fail_qc_gh;
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
588
589
590
  	pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node");
  	if (IS_ERR(pn)) {
  		error = PTR_ERR(pn);
b3b94faa5   David Teigland   [GFS2] The core o...
591
592
593
594
595
596
  		fs_err(sdp, "can't find per_node directory: %d
  ", error);
  		return error;
  	}
  
  	sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
597
598
599
  	sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
  	if (IS_ERR(sdp->sd_ir_inode)) {
  		error = PTR_ERR(sdp->sd_ir_inode);
b3b94faa5   David Teigland   [GFS2] The core o...
600
601
602
603
604
605
  		fs_err(sdp, "can't find local \"ir\" file: %d
  ", error);
  		goto fail;
  	}
  
  	sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
606
607
608
  	sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
  	if (IS_ERR(sdp->sd_sc_inode)) {
  		error = PTR_ERR(sdp->sd_sc_inode);
b3b94faa5   David Teigland   [GFS2] The core o...
609
610
611
612
  		fs_err(sdp, "can't find local \"sc\" file: %d
  ", error);
  		goto fail_ir_i;
  	}
b3b94faa5   David Teigland   [GFS2] The core o...
613
  	sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
614
615
616
  	sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
  	if (IS_ERR(sdp->sd_qc_inode)) {
  		error = PTR_ERR(sdp->sd_qc_inode);
b3b94faa5   David Teigland   [GFS2] The core o...
617
618
619
620
  		fs_err(sdp, "can't find local \"qc\" file: %d
  ", error);
  		goto fail_ut_i;
  	}
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
621
  	iput(pn);
b3b94faa5   David Teigland   [GFS2] The core o...
622
  	pn = NULL;
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
623
  	ip = GFS2_I(sdp->sd_ir_inode);
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
624
  	error = gfs2_glock_nq_init(ip->i_gl,
579b78a43   Steven Whitehouse   [GFS2] Remove GL_...
625
  				   LM_ST_EXCLUSIVE, 0,
b3b94faa5   David Teigland   [GFS2] The core o...
626
627
628
629
630
631
  				   &sdp->sd_ir_gh);
  	if (error) {
  		fs_err(sdp, "can't lock local \"ir\" file: %d
  ", error);
  		goto fail_qc_i;
  	}
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
632
  	ip = GFS2_I(sdp->sd_sc_inode);
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
633
  	error = gfs2_glock_nq_init(ip->i_gl,
579b78a43   Steven Whitehouse   [GFS2] Remove GL_...
634
  				   LM_ST_EXCLUSIVE, 0,
b3b94faa5   David Teigland   [GFS2] The core o...
635
636
637
638
639
640
  				   &sdp->sd_sc_gh);
  	if (error) {
  		fs_err(sdp, "can't lock local \"sc\" file: %d
  ", error);
  		goto fail_ir_gh;
  	}
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
641
  	ip = GFS2_I(sdp->sd_qc_inode);
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
642
  	error = gfs2_glock_nq_init(ip->i_gl,
579b78a43   Steven Whitehouse   [GFS2] Remove GL_...
643
  				   LM_ST_EXCLUSIVE, 0,
b3b94faa5   David Teigland   [GFS2] The core o...
644
645
646
647
648
649
650
651
  				   &sdp->sd_qc_gh);
  	if (error) {
  		fs_err(sdp, "can't lock local \"qc\" file: %d
  ", error);
  		goto fail_ut_gh;
  	}
  
  	return 0;
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
652
  fail_qc_gh:
b3b94faa5   David Teigland   [GFS2] The core o...
653
  	gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
654
  fail_ut_gh:
b3b94faa5   David Teigland   [GFS2] The core o...
655
  	gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
656
  fail_ir_gh:
b3b94faa5   David Teigland   [GFS2] The core o...
657
  	gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
658
  fail_qc_i:
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
659
  	iput(sdp->sd_qc_inode);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
660
  fail_ut_i:
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
661
  	iput(sdp->sd_sc_inode);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
662
  fail_ir_i:
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
663
  	iput(sdp->sd_ir_inode);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
664
  fail:
b3b94faa5   David Teigland   [GFS2] The core o...
665
  	if (pn)
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
666
  		iput(pn);
b3b94faa5   David Teigland   [GFS2] The core o...
667
668
669
670
671
672
673
674
675
  	return error;
  }
  
  static int init_threads(struct gfs2_sbd *sdp, int undo)
  {
  	struct task_struct *p;
  	int error = 0;
  
  	if (undo)
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
676
  		goto fail_quotad;
b3b94faa5   David Teigland   [GFS2] The core o...
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
  
  	sdp->sd_log_flush_time = jiffies;
  	sdp->sd_jindex_refresh_time = jiffies;
  
  	p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
  	error = IS_ERR(p);
  	if (error) {
  		fs_err(sdp, "can't start logd thread: %d
  ", error);
  		return error;
  	}
  	sdp->sd_logd_process = p;
  
  	sdp->sd_statfs_sync_time = jiffies;
  	sdp->sd_quota_sync_time = jiffies;
  
  	p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
  	error = IS_ERR(p);
  	if (error) {
  		fs_err(sdp, "can't start quotad thread: %d
  ", error);
  		goto fail;
  	}
  	sdp->sd_quotad_process = p;
b3b94faa5   David Teigland   [GFS2] The core o...
701
  	return 0;
b3b94faa5   David Teigland   [GFS2] The core o...
702

feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
703
  fail_quotad:
b3b94faa5   David Teigland   [GFS2] The core o...
704
  	kthread_stop(sdp->sd_quotad_process);
feaa7bba0   Steven Whitehouse   [GFS2] Fix unlink...
705
  fail:
b3b94faa5   David Teigland   [GFS2] The core o...
706
  	kthread_stop(sdp->sd_logd_process);
b3b94faa5   David Teigland   [GFS2] The core o...
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
  	return error;
  }
  
  /**
   * fill_super - Read in superblock
   * @sb: The VFS superblock
   * @data: Mount options
   * @silent: Don't complain if it's not a GFS2 filesystem
   *
   * Returns: errno
   */
  
  static int fill_super(struct super_block *sb, void *data, int silent)
  {
  	struct gfs2_sbd *sdp;
  	struct gfs2_holder mount_gh;
  	int error;
  
  	sdp = init_sbd(sb);
  	if (!sdp) {
d92a8d480   Steven Whitehouse   [GFS2] Audit prin...
727
728
  		printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd
  ");
b3b94faa5   David Teigland   [GFS2] The core o...
729
730
731
732
733
  		return -ENOMEM;
  	}
  
  	error = gfs2_mount_args(sdp, (char *)data, 0);
  	if (error) {
d92a8d480   Steven Whitehouse   [GFS2] Audit prin...
734
735
  		printk(KERN_WARNING "GFS2: can't parse mount arguments
  ");
b3b94faa5   David Teigland   [GFS2] The core o...
736
737
  		goto fail;
  	}
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
738
739
740
741
742
743
744
745
746
  	init_vfs(sb, SDF_NOATIME);
  
  	/* Set up the buffer cache and fill in some fake block size values
  	   to allow us to read-in the on-disk superblock. */
  	sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
  	sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
  	sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
                                 GFS2_BASIC_BLOCK_SHIFT;
  	sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
b3b94faa5   David Teigland   [GFS2] The core o...
747
748
749
750
  
  	error = init_names(sdp, silent);
  	if (error)
  		goto fail;
7c52b166c   Robert Peterson   [GFS2] Add gfs2_t...
751
  	gfs2_create_debugfs_file(sdp);
b3b94faa5   David Teigland   [GFS2] The core o...
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
  	error = gfs2_sys_fs_add(sdp);
  	if (error)
  		goto fail;
  
  	error = gfs2_lm_mount(sdp, silent);
  	if (error)
  		goto fail_sys;
  
  	error = init_locking(sdp, &mount_gh, DO);
  	if (error)
  		goto fail_lm;
  
  	error = init_sb(sdp, silent, DO);
  	if (error)
  		goto fail_locking;
b3b94faa5   David Teigland   [GFS2] The core o...
767
768
769
  
  	error = init_inodes(sdp, DO);
  	if (error)
f42faf4fa   Steven Whitehouse   [GFS2] Add gfs2_i...
770
  		goto fail_sb;
b3b94faa5   David Teigland   [GFS2] The core o...
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
  
  	error = init_per_node(sdp, DO);
  	if (error)
  		goto fail_inodes;
  
  	error = gfs2_statfs_init(sdp);
  	if (error) {
  		fs_err(sdp, "can't initialize statfs subsystem: %d
  ", error);
  		goto fail_per_node;
  	}
  
  	error = init_threads(sdp, DO);
  	if (error)
  		goto fail_per_node;
  
  	if (!(sb->s_flags & MS_RDONLY)) {
  		error = gfs2_make_fs_rw(sdp);
  		if (error) {
  			fs_err(sdp, "can't make FS RW: %d
  ", error);
  			goto fail_threads;
  		}
  	}
  
  	gfs2_glock_dq_uninit(&mount_gh);
  
  	return 0;
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
799
  fail_threads:
b3b94faa5   David Teigland   [GFS2] The core o...
800
  	init_threads(sdp, UNDO);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
801
  fail_per_node:
b3b94faa5   David Teigland   [GFS2] The core o...
802
  	init_per_node(sdp, UNDO);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
803
  fail_inodes:
b3b94faa5   David Teigland   [GFS2] The core o...
804
  	init_inodes(sdp, UNDO);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
805
  fail_sb:
b3b94faa5   David Teigland   [GFS2] The core o...
806
  	init_sb(sdp, 0, UNDO);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
807
  fail_locking:
b3b94faa5   David Teigland   [GFS2] The core o...
808
  	init_locking(sdp, &mount_gh, UNDO);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
809
  fail_lm:
b3b94faa5   David Teigland   [GFS2] The core o...
810
811
812
813
  	gfs2_gl_hash_clear(sdp, WAIT);
  	gfs2_lm_unmount(sdp);
  	while (invalidate_inodes(sb))
  		yield();
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
814
  fail_sys:
b3b94faa5   David Teigland   [GFS2] The core o...
815
  	gfs2_sys_fs_del(sdp);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
816
  fail:
5f8820960   Robert Peterson   [GFS2] lockdump i...
817
  	gfs2_delete_debugfs_file(sdp);
a2c458079   Steven Whitehouse   [GFS2] vfree shou...
818
  	kfree(sdp);
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
819
  	sb->s_fs_info = NULL;
b3b94faa5   David Teigland   [GFS2] The core o...
820
821
  	return error;
  }
ccd6efd0c   Andrew Morton   [patch 1/1] gfs2:...
822
823
  static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
  		const char *dev_name, void *data, struct vfsmount *mnt)
b3b94faa5   David Teigland   [GFS2] The core o...
824
  {
863846054   Abhijith Das   [GFS2] Allow moun...
825
826
827
828
829
830
  	struct super_block *sb;
  	struct gfs2_sbd *sdp;
  	int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
  	if (error)
  		goto out;
  	sb = mnt->mnt_sb;
26c1a5741   Steven Whitehouse   [GFS2] More code ...
831
  	sdp = sb->s_fs_info;
863846054   Abhijith Das   [GFS2] Allow moun...
832
833
834
835
  	sdp->sd_gfs2mnt = mnt;
  out:
  	return error;
  }
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
836
  static int fill_super_meta(struct super_block *sb, struct super_block *new,
863846054   Abhijith Das   [GFS2] Allow moun...
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
  			   void *data, int silent)
  {
  	struct gfs2_sbd *sdp = sb->s_fs_info;
  	struct inode *inode;
  	int error = 0;
  
  	new->s_fs_info = sdp;
  	sdp->sd_vfs_meta = sb;
  
  	init_vfs(new, SDF_NOATIME);
  
          /* Get the master inode */
  	inode = igrab(sdp->sd_master_dir);
  
  	new->s_root = d_alloc_root(inode);
  	if (!new->s_root) {
  		fs_err(sdp, "can't get root dentry
  ");
  		error = -ENOMEM;
  		iput(inode);
bbbe45127   Adrian Bunk   [GFS2] fs/gfs2/op...
857
858
  	} else
  		new->s_root->d_op = &gfs2_dops;
863846054   Abhijith Das   [GFS2] Allow moun...
859
860
861
  
  	return error;
  }
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
862

863846054   Abhijith Das   [GFS2] Allow moun...
863
864
865
866
867
868
  static int set_bdev_super(struct super_block *s, void *data)
  {
  	s->s_bdev = data;
  	s->s_dev = s->s_bdev->bd_dev;
  	return 0;
  }
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
869

863846054   Abhijith Das   [GFS2] Allow moun...
870
871
  static int test_bdev_super(struct super_block *s, void *data)
  {
26c1a5741   Steven Whitehouse   [GFS2] More code ...
872
  	return s->s_bdev == data;
863846054   Abhijith Das   [GFS2] Allow moun...
873
874
875
876
877
878
879
880
  }
  
  static struct super_block* get_gfs2_sb(const char *dev_name)
  {
  	struct kstat stat;
  	struct nameidata nd;
  	struct file_system_type *fstype;
  	struct super_block *sb = NULL, *s;
863846054   Abhijith Das   [GFS2] Allow moun...
881
  	int error;
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
882

863846054   Abhijith Das   [GFS2] Allow moun...
883
884
  	error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
  	if (error) {
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
885
886
  		printk(KERN_WARNING "GFS2: path_lookup on %s returned error
  ",
863846054   Abhijith Das   [GFS2] Allow moun...
887
888
889
890
891
892
  		       dev_name);
  		goto out;
  	}
  	error = vfs_getattr(nd.mnt, nd.dentry, &stat);
  
  	fstype = get_fs_type("gfs2");
adb4ec13c   Denis Cheng   [GFS2] use list_f...
893
  	list_for_each_entry(s, &fstype->fs_supers, s_instances) {
863846054   Abhijith Das   [GFS2] Allow moun...
894
895
896
897
898
899
900
901
  		if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) ||
  		    (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) {
  			sb = s;
  			goto free_nd;
  		}
  	}
  
  	printk(KERN_WARNING "GFS2: Unrecognized block device or "
d5a6751b3   Richard Fearn   [GFS2] add newlin...
902
903
  	       "mount point %s
  ", dev_name);
863846054   Abhijith Das   [GFS2] Allow moun...
904
905
906
907
908
909
910
911
912
913
914
915
916
  
  free_nd:
  	path_release(&nd);
  out:
  	return sb;
  }
  
  static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
  			    const char *dev_name, void *data, struct vfsmount *mnt)
  {
  	int error = 0;
  	struct super_block *sb = NULL, *new;
  	struct gfs2_sbd *sdp;
863846054   Abhijith Das   [GFS2] Allow moun...
917
918
919
920
921
922
923
924
  
  	sb = get_gfs2_sb(dev_name);
  	if (!sb) {
  		printk(KERN_WARNING "GFS2: gfs2 mount does not exist
  ");
  		error = -ENOENT;
  		goto error;
  	}
2d3ba1ea9   Denis Cheng   [GFS2] unneeded t...
925
  	sdp = sb->s_fs_info;
863846054   Abhijith Das   [GFS2] Allow moun...
926
927
928
929
930
931
  	if (sdp->sd_vfs_meta) {
  		printk(KERN_WARNING "GFS2: gfs2meta mount already exists
  ");
  		error = -EBUSY;
  		goto error;
  	}
f73ca1b76   David Chinner   [PATCH] Revert bd...
932
  	down(&sb->s_bdev->bd_mount_sem);
863846054   Abhijith Das   [GFS2] Allow moun...
933
  	new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev);
f73ca1b76   David Chinner   [PATCH] Revert bd...
934
  	up(&sb->s_bdev->bd_mount_sem);
863846054   Abhijith Das   [GFS2] Allow moun...
935
936
937
938
939
940
941
942
943
944
945
946
947
948
  	if (IS_ERR(new)) {
  		error = PTR_ERR(new);
  		goto error;
  	}
  	module_put(fs_type->owner);
  	new->s_flags = flags;
  	strlcpy(new->s_id, sb->s_id, sizeof(new->s_id));
  	sb_set_blocksize(new, sb->s_blocksize);
  	error = fill_super_meta(sb, new, data, flags & MS_SILENT ? 1 : 0);
  	if (error) {
  		up_write(&new->s_umount);
  		deactivate_super(new);
  		goto error;
  	}
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
949

863846054   Abhijith Das   [GFS2] Allow moun...
950
  	new->s_flags |= MS_ACTIVE;
907b9bceb   Steven Whitehouse   [GFS2/DLM] Fix tr...
951

863846054   Abhijith Das   [GFS2] Allow moun...
952
953
954
955
  	/* Grab a reference to the gfs2 mount point */
  	atomic_inc(&sdp->sd_gfs2mnt->mnt_count);
  	return simple_set_mnt(mnt, new);
  error:
863846054   Abhijith Das   [GFS2] Allow moun...
956
  	return error;
b3b94faa5   David Teigland   [GFS2] The core o...
957
  }
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
958
959
  static void gfs2_kill_sb(struct super_block *sb)
  {
d1e2777d4   Abhijith Das   [GFS2] panic afte...
960
961
962
963
  	if (sb->s_fs_info) {
  		gfs2_delete_debugfs_file(sb->s_fs_info);
  		gfs2_meta_syncfs(sb->s_fs_info);
  	}
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
964
965
  	kill_block_super(sb);
  }
863846054   Abhijith Das   [GFS2] Allow moun...
966
967
968
969
970
971
972
  static void gfs2_kill_sb_meta(struct super_block *sb)
  {
  	struct gfs2_sbd *sdp = sb->s_fs_info;
  	generic_shutdown_super(sb);
  	sdp->sd_vfs_meta = NULL;
  	atomic_dec(&sdp->sd_gfs2mnt->mnt_count);
  }
b3b94faa5   David Teigland   [GFS2] The core o...
973
974
975
976
  struct file_system_type gfs2_fs_type = {
  	.name = "gfs2",
  	.fs_flags = FS_REQUIRES_DEV,
  	.get_sb = gfs2_get_sb,
419c93e0b   Steven Whitehouse   [GFS2] Add gfs2me...
977
978
979
980
981
982
983
  	.kill_sb = gfs2_kill_sb,
  	.owner = THIS_MODULE,
  };
  
  struct file_system_type gfs2meta_fs_type = {
  	.name = "gfs2meta",
  	.fs_flags = FS_REQUIRES_DEV,
863846054   Abhijith Das   [GFS2] Allow moun...
984
985
  	.get_sb = gfs2_get_sb_meta,
  	.kill_sb = gfs2_kill_sb_meta,
b3b94faa5   David Teigland   [GFS2] The core o...
986
987
  	.owner = THIS_MODULE,
  };