]>
Commit | Line | Data |
---|---|---|
b3b94faa DT |
1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | |
3a8a9a10 | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
b3b94faa DT |
4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | |
6 | * modify, copy, or redistribute it subject to the terms and conditions | |
e9fc2aa0 | 7 | * of the GNU General Public License version 2. |
b3b94faa DT |
8 | */ |
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> | |
b3b94faa DT |
15 | #include <linux/blkdev.h> |
16 | #include <linux/kthread.h> | |
86384605 AD |
17 | #include <linux/namei.h> |
18 | #include <linux/mount.h> | |
5c676f6d | 19 | #include <linux/gfs2_ondisk.h> |
7d308590 | 20 | #include <linux/lm_interface.h> |
b3b94faa DT |
21 | |
22 | #include "gfs2.h" | |
5c676f6d | 23 | #include "incore.h" |
b3b94faa DT |
24 | #include "daemon.h" |
25 | #include "glock.h" | |
26 | #include "glops.h" | |
27 | #include "inode.h" | |
28 | #include "lm.h" | |
29 | #include "mount.h" | |
b3b94faa | 30 | #include "ops_fstype.h" |
ca5a939b | 31 | #include "ops_dentry.h" |
b3b94faa DT |
32 | #include "ops_super.h" |
33 | #include "recovery.h" | |
34 | #include "rgrp.h" | |
35 | #include "super.h" | |
b3b94faa | 36 | #include "sys.h" |
5c676f6d | 37 | #include "util.h" |
b3b94faa DT |
38 | |
39 | #define DO 0 | |
40 | #define UNDO 1 | |
41 | ||
42 | static struct gfs2_sbd *init_sbd(struct super_block *sb) | |
43 | { | |
44 | struct gfs2_sbd *sdp; | |
b3b94faa | 45 | |
85d1da67 | 46 | sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); |
b3b94faa DT |
47 | if (!sdp) |
48 | return NULL; | |
49 | ||
5c676f6d | 50 | sb->s_fs_info = sdp; |
b3b94faa DT |
51 | sdp->sd_vfs = sb; |
52 | ||
53 | gfs2_tune_init(&sdp->sd_tune); | |
54 | ||
b3b94faa DT |
55 | INIT_LIST_HEAD(&sdp->sd_reclaim_list); |
56 | spin_lock_init(&sdp->sd_reclaim_lock); | |
57 | init_waitqueue_head(&sdp->sd_reclaim_wq); | |
b3b94faa | 58 | |
f55ab26a | 59 | mutex_init(&sdp->sd_inum_mutex); |
b3b94faa | 60 | spin_lock_init(&sdp->sd_statfs_spin); |
f55ab26a | 61 | mutex_init(&sdp->sd_statfs_mutex); |
b3b94faa DT |
62 | |
63 | spin_lock_init(&sdp->sd_rindex_spin); | |
f55ab26a | 64 | mutex_init(&sdp->sd_rindex_mutex); |
b3b94faa DT |
65 | 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); | |
f55ab26a | 71 | mutex_init(&sdp->sd_jindex_mutex); |
b3b94faa | 72 | |
b3b94faa DT |
73 | INIT_LIST_HEAD(&sdp->sd_quota_list); |
74 | spin_lock_init(&sdp->sd_quota_spin); | |
f55ab26a | 75 | mutex_init(&sdp->sd_quota_mutex); |
b3b94faa DT |
76 | |
77 | spin_lock_init(&sdp->sd_log_lock); | |
b3b94faa DT |
78 | |
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 | ||
71b86f56 | 85 | mutex_init(&sdp->sd_log_reserve_mutex); |
b3b94faa DT |
86 | INIT_LIST_HEAD(&sdp->sd_ail1_list); |
87 | INIT_LIST_HEAD(&sdp->sd_ail2_list); | |
88 | ||
484adff8 | 89 | init_rwsem(&sdp->sd_log_flush_lock); |
b3b94faa DT |
90 | INIT_LIST_HEAD(&sdp->sd_log_flush_list); |
91 | ||
92 | INIT_LIST_HEAD(&sdp->sd_revoke_list); | |
93 | ||
f55ab26a | 94 | mutex_init(&sdp->sd_freeze_lock); |
b3b94faa DT |
95 | |
96 | return sdp; | |
97 | } | |
98 | ||
419c93e0 | 99 | static void init_vfs(struct super_block *sb, unsigned noatime) |
b3b94faa | 100 | { |
419c93e0 | 101 | struct gfs2_sbd *sdp = sb->s_fs_info; |
b3b94faa DT |
102 | |
103 | sb->s_magic = GFS2_MAGIC; | |
104 | sb->s_op = &gfs2_super_ops; | |
105 | sb->s_export_op = &gfs2_export_ops; | |
4bd91ba1 | 106 | sb->s_time_gran = 1; |
b3b94faa DT |
107 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
108 | ||
109 | if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME)) | |
419c93e0 | 110 | set_bit(noatime, &sdp->sd_flags); |
b3b94faa DT |
111 | |
112 | /* Don't let the VFS update atimes. GFS2 handles this itself. */ | |
113 | sb->s_flags |= MS_NOATIME | MS_NODIRATIME; | |
b3b94faa DT |
114 | } |
115 | ||
116 | static int init_names(struct gfs2_sbd *sdp, int silent) | |
117 | { | |
b3b94faa DT |
118 | 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]) { | |
bb8d8a6f SW |
127 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); |
128 | if (error) | |
129 | return error; | |
3cf1e7be SW |
130 | |
131 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); | |
b3b94faa DT |
132 | if (error) |
133 | goto out; | |
134 | ||
135 | if (!proto[0]) | |
3cf1e7be | 136 | proto = sdp->sd_sb.sb_lockproto; |
b3b94faa | 137 | if (!table[0]) |
3cf1e7be | 138 | table = sdp->sd_sb.sb_locktable; |
b3b94faa DT |
139 | } |
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 | ||
5d35e31f DC |
147 | table = sdp->sd_table_name; |
148 | while ((table = strchr(table, '/'))) | |
b35997d4 RP |
149 | *table = '_'; |
150 | ||
a91ea69f | 151 | out: |
b3b94faa DT |
152 | return error; |
153 | } | |
154 | ||
155 | static 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 | ||
b3b94faa DT |
164 | for (sdp->sd_glockd_num = 0; |
165 | sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd; | |
166 | sdp->sd_glockd_num++) { | |
167 | p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd"); | |
168 | error = IS_ERR(p); | |
169 | if (error) { | |
170 | fs_err(sdp, "can't start glockd thread: %d\n", error); | |
171 | goto fail; | |
172 | } | |
173 | sdp->sd_glockd_process[sdp->sd_glockd_num] = p; | |
174 | } | |
175 | ||
176 | error = gfs2_glock_nq_num(sdp, | |
177 | GFS2_MOUNT_LOCK, &gfs2_nondisk_glops, | |
178 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE, | |
179 | mount_gh); | |
180 | if (error) { | |
181 | fs_err(sdp, "can't acquire mount glock: %d\n", error); | |
182 | goto fail; | |
183 | } | |
184 | ||
185 | error = gfs2_glock_nq_num(sdp, | |
186 | GFS2_LIVE_LOCK, &gfs2_nondisk_glops, | |
187 | LM_ST_SHARED, | |
579b78a4 | 188 | LM_FLAG_NOEXP | GL_EXACT, |
b3b94faa DT |
189 | &sdp->sd_live_gh); |
190 | if (error) { | |
191 | fs_err(sdp, "can't acquire live glock: %d\n", error); | |
192 | goto fail_mount; | |
193 | } | |
194 | ||
195 | error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops, | |
196 | CREATE, &sdp->sd_rename_gl); | |
197 | if (error) { | |
198 | fs_err(sdp, "can't create rename glock: %d\n", error); | |
199 | goto fail_live; | |
200 | } | |
201 | ||
202 | error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops, | |
203 | CREATE, &sdp->sd_trans_gl); | |
204 | if (error) { | |
205 | fs_err(sdp, "can't create transaction glock: %d\n", error); | |
206 | goto fail_rename; | |
207 | } | |
208 | set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags); | |
209 | ||
210 | return 0; | |
211 | ||
feaa7bba | 212 | fail_trans: |
b3b94faa | 213 | gfs2_glock_put(sdp->sd_trans_gl); |
feaa7bba | 214 | fail_rename: |
b3b94faa | 215 | gfs2_glock_put(sdp->sd_rename_gl); |
feaa7bba | 216 | fail_live: |
b3b94faa | 217 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
feaa7bba | 218 | fail_mount: |
b3b94faa | 219 | gfs2_glock_dq_uninit(mount_gh); |
feaa7bba | 220 | fail: |
b3b94faa DT |
221 | while (sdp->sd_glockd_num--) |
222 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); | |
223 | ||
b3b94faa DT |
224 | return error; |
225 | } | |
226 | ||
dbb7cae2 SW |
227 | static inline struct inode *gfs2_lookup_root(struct super_block *sb, |
228 | u64 no_addr) | |
f42faf4f | 229 | { |
bb9bcf06 | 230 | return gfs2_inode_lookup(sb, DT_DIR, no_addr, 0); |
f42faf4f SW |
231 | } |
232 | ||
b3b94faa DT |
233 | static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) |
234 | { | |
235 | struct super_block *sb = sdp->sd_vfs; | |
236 | struct gfs2_holder sb_gh; | |
dbb7cae2 | 237 | u64 no_addr; |
f42faf4f | 238 | struct inode *inode; |
b3b94faa DT |
239 | int error = 0; |
240 | ||
241 | if (undo) { | |
88721877 RC |
242 | if (sb->s_root) { |
243 | dput(sb->s_root); | |
244 | sb->s_root = NULL; | |
245 | } | |
b3b94faa DT |
246 | return 0; |
247 | } | |
907b9bce | 248 | |
feaa7bba | 249 | error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops, |
b3b94faa DT |
250 | LM_ST_SHARED, 0, &sb_gh); |
251 | if (error) { | |
252 | fs_err(sdp, "can't acquire superblock glock: %d\n", error); | |
253 | return error; | |
254 | } | |
255 | ||
256 | error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); | |
257 | if (error) { | |
258 | fs_err(sdp, "can't read superblock: %d\n", error); | |
259 | goto out; | |
260 | } | |
261 | ||
262 | /* Set up the buffer cache and SB for real */ | |
b3b94faa | 263 | if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { |
419c93e0 | 264 | error = -EINVAL; |
b3b94faa DT |
265 | fs_err(sdp, "FS block size (%u) is too small for device " |
266 | "block size (%u)\n", | |
267 | sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); | |
268 | goto out; | |
269 | } | |
270 | if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { | |
419c93e0 | 271 | error = -EINVAL; |
b3b94faa DT |
272 | fs_err(sdp, "FS block size (%u) is too big for machine " |
273 | "page size (%u)\n", | |
274 | sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); | |
275 | goto out; | |
276 | } | |
b3b94faa DT |
277 | sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); |
278 | ||
f42faf4f | 279 | /* Get the root inode */ |
dbb7cae2 | 280 | no_addr = sdp->sd_sb.sb_root_dir.no_addr; |
419c93e0 | 281 | if (sb->s_type == &gfs2meta_fs_type) |
dbb7cae2 SW |
282 | no_addr = sdp->sd_sb.sb_master_dir.no_addr; |
283 | inode = gfs2_lookup_root(sb, no_addr); | |
c9fd4307 SW |
284 | if (IS_ERR(inode)) { |
285 | error = PTR_ERR(inode); | |
f42faf4f SW |
286 | fs_err(sdp, "can't read in root inode: %d\n", error); |
287 | goto out; | |
288 | } | |
b3b94faa | 289 | |
f42faf4f SW |
290 | sb->s_root = d_alloc_root(inode); |
291 | if (!sb->s_root) { | |
292 | fs_err(sdp, "can't get root dentry\n"); | |
293 | error = -ENOMEM; | |
c9fd4307 | 294 | iput(inode); |
34eaae39 DC |
295 | } else |
296 | sb->s_root->d_op = &gfs2_dops; | |
297 | ||
f42faf4f | 298 | out: |
b3b94faa | 299 | gfs2_glock_dq_uninit(&sb_gh); |
b3b94faa DT |
300 | return error; |
301 | } | |
302 | ||
303 | static int init_journal(struct gfs2_sbd *sdp, int undo) | |
304 | { | |
305 | struct gfs2_holder ji_gh; | |
306 | struct task_struct *p; | |
5c676f6d | 307 | struct gfs2_inode *ip; |
b3b94faa DT |
308 | int jindex = 1; |
309 | int error = 0; | |
310 | ||
311 | if (undo) { | |
312 | jindex = 0; | |
313 | goto fail_recoverd; | |
314 | } | |
315 | ||
c752666c SW |
316 | sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex"); |
317 | if (IS_ERR(sdp->sd_jindex)) { | |
b3b94faa | 318 | fs_err(sdp, "can't lookup journal index: %d\n", error); |
c752666c | 319 | return PTR_ERR(sdp->sd_jindex); |
b3b94faa | 320 | } |
feaa7bba | 321 | ip = GFS2_I(sdp->sd_jindex); |
5c676f6d | 322 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
b3b94faa DT |
323 | |
324 | /* Load in the journal index special file */ | |
325 | ||
326 | error = gfs2_jindex_hold(sdp, &ji_gh); | |
327 | if (error) { | |
328 | fs_err(sdp, "can't read journal index: %d\n", error); | |
329 | goto fail; | |
330 | } | |
331 | ||
332 | error = -EINVAL; | |
333 | if (!gfs2_jindex_size(sdp)) { | |
334 | fs_err(sdp, "no journals!\n"); | |
907b9bce | 335 | goto fail_jindex; |
b3b94faa DT |
336 | } |
337 | ||
338 | if (sdp->sd_args.ar_spectator) { | |
339 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); | |
340 | sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; | |
341 | } else { | |
342 | if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { | |
343 | fs_err(sdp, "can't mount journal #%u\n", | |
344 | sdp->sd_lockstruct.ls_jid); | |
345 | fs_err(sdp, "there are only %u journals (0 - %u)\n", | |
346 | gfs2_jindex_size(sdp), | |
347 | gfs2_jindex_size(sdp) - 1); | |
348 | goto fail_jindex; | |
349 | } | |
350 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); | |
351 | ||
feaa7bba | 352 | error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid, |
b3b94faa DT |
353 | &gfs2_journal_glops, |
354 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, | |
355 | &sdp->sd_journal_gh); | |
356 | if (error) { | |
357 | fs_err(sdp, "can't acquire journal glock: %d\n", error); | |
358 | goto fail_jindex; | |
359 | } | |
360 | ||
feaa7bba SW |
361 | ip = GFS2_I(sdp->sd_jdesc->jd_inode); |
362 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, | |
75be73a8 | 363 | LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE, |
b3b94faa DT |
364 | &sdp->sd_jinode_gh); |
365 | if (error) { | |
366 | fs_err(sdp, "can't acquire journal inode glock: %d\n", | |
367 | error); | |
368 | goto fail_journal_gh; | |
369 | } | |
370 | ||
371 | error = gfs2_jdesc_check(sdp->sd_jdesc); | |
372 | if (error) { | |
373 | fs_err(sdp, "my journal (%u) is bad: %d\n", | |
374 | sdp->sd_jdesc->jd_jid, error); | |
375 | goto fail_jinode_gh; | |
376 | } | |
377 | sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; | |
378 | } | |
379 | ||
380 | if (sdp->sd_lockstruct.ls_first) { | |
381 | unsigned int x; | |
382 | for (x = 0; x < sdp->sd_journals; x++) { | |
c63e31c2 | 383 | error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x)); |
b3b94faa DT |
384 | if (error) { |
385 | fs_err(sdp, "error recovering journal %u: %d\n", | |
386 | x, error); | |
387 | goto fail_jinode_gh; | |
388 | } | |
389 | } | |
390 | ||
391 | gfs2_lm_others_may_mount(sdp); | |
392 | } else if (!sdp->sd_args.ar_spectator) { | |
c63e31c2 | 393 | error = gfs2_recover_journal(sdp->sd_jdesc); |
b3b94faa DT |
394 | if (error) { |
395 | fs_err(sdp, "error recovering my journal: %d\n", error); | |
396 | goto fail_jinode_gh; | |
397 | } | |
398 | } | |
399 | ||
400 | set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags); | |
401 | gfs2_glock_dq_uninit(&ji_gh); | |
402 | jindex = 0; | |
403 | ||
b3b94faa DT |
404 | p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd"); |
405 | error = IS_ERR(p); | |
406 | if (error) { | |
407 | fs_err(sdp, "can't start recoverd thread: %d\n", error); | |
408 | goto fail_jinode_gh; | |
409 | } | |
410 | sdp->sd_recoverd_process = p; | |
411 | ||
412 | return 0; | |
413 | ||
a91ea69f | 414 | fail_recoverd: |
b3b94faa | 415 | kthread_stop(sdp->sd_recoverd_process); |
a91ea69f | 416 | fail_jinode_gh: |
b3b94faa DT |
417 | if (!sdp->sd_args.ar_spectator) |
418 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); | |
a91ea69f | 419 | fail_journal_gh: |
b3b94faa DT |
420 | if (!sdp->sd_args.ar_spectator) |
421 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); | |
a91ea69f | 422 | fail_jindex: |
b3b94faa DT |
423 | gfs2_jindex_free(sdp); |
424 | if (jindex) | |
425 | gfs2_glock_dq_uninit(&ji_gh); | |
a91ea69f | 426 | fail: |
f42faf4f | 427 | iput(sdp->sd_jindex); |
b3b94faa DT |
428 | return error; |
429 | } | |
430 | ||
b3b94faa DT |
431 | |
432 | static int init_inodes(struct gfs2_sbd *sdp, int undo) | |
433 | { | |
b3b94faa | 434 | int error = 0; |
5c676f6d | 435 | struct gfs2_inode *ip; |
c9fd4307 | 436 | struct inode *inode; |
b3b94faa DT |
437 | |
438 | if (undo) | |
f42faf4f SW |
439 | goto fail_qinode; |
440 | ||
dbb7cae2 | 441 | inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr); |
c9fd4307 SW |
442 | if (IS_ERR(inode)) { |
443 | error = PTR_ERR(inode); | |
f42faf4f SW |
444 | fs_err(sdp, "can't read in master directory: %d\n", error); |
445 | goto fail; | |
446 | } | |
c9fd4307 | 447 | sdp->sd_master_dir = inode; |
f42faf4f SW |
448 | |
449 | error = init_journal(sdp, undo); | |
450 | if (error) | |
451 | goto fail_master; | |
b3b94faa DT |
452 | |
453 | /* Read in the master inode number inode */ | |
c752666c SW |
454 | sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum"); |
455 | if (IS_ERR(sdp->sd_inum_inode)) { | |
456 | error = PTR_ERR(sdp->sd_inum_inode); | |
b3b94faa | 457 | fs_err(sdp, "can't read in inum inode: %d\n", error); |
f42faf4f | 458 | goto fail_journal; |
b3b94faa DT |
459 | } |
460 | ||
f42faf4f | 461 | |
b3b94faa | 462 | /* Read in the master statfs inode */ |
c752666c SW |
463 | sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs"); |
464 | if (IS_ERR(sdp->sd_statfs_inode)) { | |
465 | error = PTR_ERR(sdp->sd_statfs_inode); | |
b3b94faa | 466 | fs_err(sdp, "can't read in statfs inode: %d\n", error); |
f42faf4f | 467 | goto fail_inum; |
b3b94faa DT |
468 | } |
469 | ||
470 | /* Read in the resource index inode */ | |
c752666c SW |
471 | sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex"); |
472 | if (IS_ERR(sdp->sd_rindex)) { | |
473 | error = PTR_ERR(sdp->sd_rindex); | |
b3b94faa DT |
474 | fs_err(sdp, "can't get resource index inode: %d\n", error); |
475 | goto fail_statfs; | |
476 | } | |
feaa7bba | 477 | ip = GFS2_I(sdp->sd_rindex); |
5c676f6d SW |
478 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
479 | sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1; | |
b3b94faa DT |
480 | |
481 | /* Read in the quota inode */ | |
c752666c SW |
482 | sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota"); |
483 | if (IS_ERR(sdp->sd_quota_inode)) { | |
484 | error = PTR_ERR(sdp->sd_quota_inode); | |
b3b94faa DT |
485 | fs_err(sdp, "can't get quota file inode: %d\n", error); |
486 | goto fail_rindex; | |
487 | } | |
b3b94faa DT |
488 | return 0; |
489 | ||
f42faf4f SW |
490 | fail_qinode: |
491 | iput(sdp->sd_quota_inode); | |
f42faf4f | 492 | fail_rindex: |
b3b94faa | 493 | gfs2_clear_rgrpd(sdp); |
f42faf4f | 494 | iput(sdp->sd_rindex); |
f42faf4f SW |
495 | fail_statfs: |
496 | iput(sdp->sd_statfs_inode); | |
f42faf4f SW |
497 | fail_inum: |
498 | iput(sdp->sd_inum_inode); | |
499 | fail_journal: | |
500 | init_journal(sdp, UNDO); | |
501 | fail_master: | |
502 | iput(sdp->sd_master_dir); | |
503 | fail: | |
b3b94faa DT |
504 | return error; |
505 | } | |
506 | ||
507 | static int init_per_node(struct gfs2_sbd *sdp, int undo) | |
508 | { | |
f42faf4f | 509 | struct inode *pn = NULL; |
b3b94faa DT |
510 | char buf[30]; |
511 | int error = 0; | |
5c676f6d | 512 | struct gfs2_inode *ip; |
b3b94faa DT |
513 | |
514 | if (sdp->sd_args.ar_spectator) | |
515 | return 0; | |
516 | ||
517 | if (undo) | |
518 | goto fail_qc_gh; | |
519 | ||
c752666c SW |
520 | pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node"); |
521 | if (IS_ERR(pn)) { | |
522 | error = PTR_ERR(pn); | |
b3b94faa DT |
523 | fs_err(sdp, "can't find per_node directory: %d\n", error); |
524 | return error; | |
525 | } | |
526 | ||
527 | sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid); | |
c752666c SW |
528 | sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf); |
529 | if (IS_ERR(sdp->sd_ir_inode)) { | |
530 | error = PTR_ERR(sdp->sd_ir_inode); | |
b3b94faa DT |
531 | fs_err(sdp, "can't find local \"ir\" file: %d\n", error); |
532 | goto fail; | |
533 | } | |
534 | ||
535 | sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid); | |
c752666c SW |
536 | sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf); |
537 | if (IS_ERR(sdp->sd_sc_inode)) { | |
538 | error = PTR_ERR(sdp->sd_sc_inode); | |
b3b94faa DT |
539 | fs_err(sdp, "can't find local \"sc\" file: %d\n", error); |
540 | goto fail_ir_i; | |
541 | } | |
542 | ||
b3b94faa | 543 | sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); |
c752666c SW |
544 | sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); |
545 | if (IS_ERR(sdp->sd_qc_inode)) { | |
546 | error = PTR_ERR(sdp->sd_qc_inode); | |
b3b94faa DT |
547 | fs_err(sdp, "can't find local \"qc\" file: %d\n", error); |
548 | goto fail_ut_i; | |
549 | } | |
550 | ||
f42faf4f | 551 | iput(pn); |
b3b94faa DT |
552 | pn = NULL; |
553 | ||
feaa7bba | 554 | ip = GFS2_I(sdp->sd_ir_inode); |
5c676f6d | 555 | error = gfs2_glock_nq_init(ip->i_gl, |
579b78a4 | 556 | LM_ST_EXCLUSIVE, 0, |
b3b94faa DT |
557 | &sdp->sd_ir_gh); |
558 | if (error) { | |
559 | fs_err(sdp, "can't lock local \"ir\" file: %d\n", error); | |
560 | goto fail_qc_i; | |
561 | } | |
562 | ||
feaa7bba | 563 | ip = GFS2_I(sdp->sd_sc_inode); |
5c676f6d | 564 | error = gfs2_glock_nq_init(ip->i_gl, |
579b78a4 | 565 | LM_ST_EXCLUSIVE, 0, |
b3b94faa DT |
566 | &sdp->sd_sc_gh); |
567 | if (error) { | |
568 | fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); | |
569 | goto fail_ir_gh; | |
570 | } | |
571 | ||
feaa7bba | 572 | ip = GFS2_I(sdp->sd_qc_inode); |
5c676f6d | 573 | error = gfs2_glock_nq_init(ip->i_gl, |
579b78a4 | 574 | LM_ST_EXCLUSIVE, 0, |
b3b94faa DT |
575 | &sdp->sd_qc_gh); |
576 | if (error) { | |
577 | fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); | |
578 | goto fail_ut_gh; | |
579 | } | |
580 | ||
581 | return 0; | |
582 | ||
a91ea69f | 583 | fail_qc_gh: |
b3b94faa | 584 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
a91ea69f | 585 | fail_ut_gh: |
b3b94faa | 586 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
a91ea69f | 587 | fail_ir_gh: |
b3b94faa | 588 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
a91ea69f | 589 | fail_qc_i: |
f42faf4f | 590 | iput(sdp->sd_qc_inode); |
a91ea69f | 591 | fail_ut_i: |
f42faf4f | 592 | iput(sdp->sd_sc_inode); |
a91ea69f | 593 | fail_ir_i: |
f42faf4f | 594 | iput(sdp->sd_ir_inode); |
a91ea69f | 595 | fail: |
b3b94faa | 596 | if (pn) |
f42faf4f | 597 | iput(pn); |
b3b94faa DT |
598 | return error; |
599 | } | |
600 | ||
601 | static int init_threads(struct gfs2_sbd *sdp, int undo) | |
602 | { | |
603 | struct task_struct *p; | |
604 | int error = 0; | |
605 | ||
606 | if (undo) | |
feaa7bba | 607 | goto fail_quotad; |
b3b94faa DT |
608 | |
609 | sdp->sd_log_flush_time = jiffies; | |
610 | sdp->sd_jindex_refresh_time = jiffies; | |
611 | ||
612 | p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); | |
613 | error = IS_ERR(p); | |
614 | if (error) { | |
615 | fs_err(sdp, "can't start logd thread: %d\n", error); | |
616 | return error; | |
617 | } | |
618 | sdp->sd_logd_process = p; | |
619 | ||
620 | sdp->sd_statfs_sync_time = jiffies; | |
621 | sdp->sd_quota_sync_time = jiffies; | |
622 | ||
623 | p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); | |
624 | error = IS_ERR(p); | |
625 | if (error) { | |
626 | fs_err(sdp, "can't start quotad thread: %d\n", error); | |
627 | goto fail; | |
628 | } | |
629 | sdp->sd_quotad_process = p; | |
630 | ||
b3b94faa DT |
631 | return 0; |
632 | ||
b3b94faa | 633 | |
feaa7bba | 634 | fail_quotad: |
b3b94faa | 635 | kthread_stop(sdp->sd_quotad_process); |
feaa7bba | 636 | fail: |
b3b94faa | 637 | kthread_stop(sdp->sd_logd_process); |
b3b94faa DT |
638 | return error; |
639 | } | |
640 | ||
641 | /** | |
642 | * fill_super - Read in superblock | |
643 | * @sb: The VFS superblock | |
644 | * @data: Mount options | |
645 | * @silent: Don't complain if it's not a GFS2 filesystem | |
646 | * | |
647 | * Returns: errno | |
648 | */ | |
649 | ||
650 | static int fill_super(struct super_block *sb, void *data, int silent) | |
651 | { | |
652 | struct gfs2_sbd *sdp; | |
653 | struct gfs2_holder mount_gh; | |
654 | int error; | |
655 | ||
656 | sdp = init_sbd(sb); | |
657 | if (!sdp) { | |
d92a8d48 | 658 | printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n"); |
b3b94faa DT |
659 | return -ENOMEM; |
660 | } | |
661 | ||
662 | error = gfs2_mount_args(sdp, (char *)data, 0); | |
663 | if (error) { | |
d92a8d48 | 664 | printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); |
b3b94faa DT |
665 | goto fail; |
666 | } | |
667 | ||
419c93e0 SW |
668 | init_vfs(sb, SDF_NOATIME); |
669 | ||
670 | /* Set up the buffer cache and fill in some fake block size values | |
671 | to allow us to read-in the on-disk superblock. */ | |
672 | sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); | |
673 | sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; | |
674 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - | |
675 | GFS2_BASIC_BLOCK_SHIFT; | |
676 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; | |
b3b94faa DT |
677 | |
678 | error = init_names(sdp, silent); | |
679 | if (error) | |
680 | goto fail; | |
681 | ||
7c52b166 RP |
682 | gfs2_create_debugfs_file(sdp); |
683 | ||
b3b94faa DT |
684 | error = gfs2_sys_fs_add(sdp); |
685 | if (error) | |
686 | goto fail; | |
687 | ||
688 | error = gfs2_lm_mount(sdp, silent); | |
689 | if (error) | |
690 | goto fail_sys; | |
691 | ||
692 | error = init_locking(sdp, &mount_gh, DO); | |
693 | if (error) | |
694 | goto fail_lm; | |
695 | ||
696 | error = init_sb(sdp, silent, DO); | |
697 | if (error) | |
698 | goto fail_locking; | |
b3b94faa DT |
699 | |
700 | error = init_inodes(sdp, DO); | |
701 | if (error) | |
f42faf4f | 702 | goto fail_sb; |
b3b94faa DT |
703 | |
704 | error = init_per_node(sdp, DO); | |
705 | if (error) | |
706 | goto fail_inodes; | |
707 | ||
708 | error = gfs2_statfs_init(sdp); | |
709 | if (error) { | |
710 | fs_err(sdp, "can't initialize statfs subsystem: %d\n", error); | |
711 | goto fail_per_node; | |
712 | } | |
713 | ||
714 | error = init_threads(sdp, DO); | |
715 | if (error) | |
716 | goto fail_per_node; | |
717 | ||
718 | if (!(sb->s_flags & MS_RDONLY)) { | |
719 | error = gfs2_make_fs_rw(sdp); | |
720 | if (error) { | |
721 | fs_err(sdp, "can't make FS RW: %d\n", error); | |
722 | goto fail_threads; | |
723 | } | |
724 | } | |
725 | ||
726 | gfs2_glock_dq_uninit(&mount_gh); | |
727 | ||
728 | return 0; | |
729 | ||
a91ea69f | 730 | fail_threads: |
b3b94faa | 731 | init_threads(sdp, UNDO); |
a91ea69f | 732 | fail_per_node: |
b3b94faa | 733 | init_per_node(sdp, UNDO); |
a91ea69f | 734 | fail_inodes: |
b3b94faa | 735 | init_inodes(sdp, UNDO); |
a91ea69f | 736 | fail_sb: |
b3b94faa | 737 | init_sb(sdp, 0, UNDO); |
a91ea69f | 738 | fail_locking: |
b3b94faa | 739 | init_locking(sdp, &mount_gh, UNDO); |
a91ea69f | 740 | fail_lm: |
b3b94faa DT |
741 | gfs2_gl_hash_clear(sdp, WAIT); |
742 | gfs2_lm_unmount(sdp); | |
743 | while (invalidate_inodes(sb)) | |
744 | yield(); | |
a91ea69f | 745 | fail_sys: |
b3b94faa | 746 | gfs2_sys_fs_del(sdp); |
a91ea69f | 747 | fail: |
5f882096 | 748 | gfs2_delete_debugfs_file(sdp); |
a2c45807 | 749 | kfree(sdp); |
5c676f6d | 750 | sb->s_fs_info = NULL; |
b3b94faa DT |
751 | return error; |
752 | } | |
753 | ||
ccd6efd0 AM |
754 | static int gfs2_get_sb(struct file_system_type *fs_type, int flags, |
755 | const char *dev_name, void *data, struct vfsmount *mnt) | |
b3b94faa | 756 | { |
86384605 AD |
757 | struct super_block *sb; |
758 | struct gfs2_sbd *sdp; | |
759 | int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); | |
760 | if (error) | |
761 | goto out; | |
762 | sb = mnt->mnt_sb; | |
26c1a574 | 763 | sdp = sb->s_fs_info; |
86384605 AD |
764 | sdp->sd_gfs2mnt = mnt; |
765 | out: | |
766 | return error; | |
767 | } | |
768 | ||
907b9bce | 769 | static int fill_super_meta(struct super_block *sb, struct super_block *new, |
86384605 AD |
770 | void *data, int silent) |
771 | { | |
772 | struct gfs2_sbd *sdp = sb->s_fs_info; | |
773 | struct inode *inode; | |
774 | int error = 0; | |
775 | ||
776 | new->s_fs_info = sdp; | |
777 | sdp->sd_vfs_meta = sb; | |
778 | ||
779 | init_vfs(new, SDF_NOATIME); | |
780 | ||
781 | /* Get the master inode */ | |
782 | inode = igrab(sdp->sd_master_dir); | |
783 | ||
784 | new->s_root = d_alloc_root(inode); | |
785 | if (!new->s_root) { | |
786 | fs_err(sdp, "can't get root dentry\n"); | |
787 | error = -ENOMEM; | |
788 | iput(inode); | |
bbbe4512 AB |
789 | } else |
790 | new->s_root->d_op = &gfs2_dops; | |
86384605 AD |
791 | |
792 | return error; | |
793 | } | |
a91ea69f | 794 | |
86384605 AD |
795 | static int set_bdev_super(struct super_block *s, void *data) |
796 | { | |
797 | s->s_bdev = data; | |
798 | s->s_dev = s->s_bdev->bd_dev; | |
799 | return 0; | |
800 | } | |
907b9bce | 801 | |
86384605 AD |
802 | static int test_bdev_super(struct super_block *s, void *data) |
803 | { | |
26c1a574 | 804 | return s->s_bdev == data; |
86384605 AD |
805 | } |
806 | ||
807 | static struct super_block* get_gfs2_sb(const char *dev_name) | |
808 | { | |
809 | struct kstat stat; | |
810 | struct nameidata nd; | |
811 | struct file_system_type *fstype; | |
812 | struct super_block *sb = NULL, *s; | |
86384605 | 813 | int error; |
907b9bce | 814 | |
86384605 AD |
815 | error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); |
816 | if (error) { | |
907b9bce | 817 | printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n", |
86384605 AD |
818 | dev_name); |
819 | goto out; | |
820 | } | |
821 | error = vfs_getattr(nd.mnt, nd.dentry, &stat); | |
822 | ||
823 | fstype = get_fs_type("gfs2"); | |
adb4ec13 | 824 | list_for_each_entry(s, &fstype->fs_supers, s_instances) { |
86384605 AD |
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 " | |
d5a6751b | 833 | "mount point %s\n", dev_name); |
86384605 AD |
834 | |
835 | free_nd: | |
836 | path_release(&nd); | |
837 | out: | |
838 | return sb; | |
839 | } | |
840 | ||
841 | static 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; | |
86384605 AD |
847 | |
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 | } | |
2d3ba1ea | 854 | sdp = sb->s_fs_info; |
86384605 AD |
855 | if (sdp->sd_vfs_meta) { |
856 | printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n"); | |
857 | error = -EBUSY; | |
858 | goto error; | |
859 | } | |
f73ca1b7 | 860 | down(&sb->s_bdev->bd_mount_sem); |
86384605 | 861 | new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev); |
f73ca1b7 | 862 | up(&sb->s_bdev->bd_mount_sem); |
86384605 AD |
863 | 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 | } | |
907b9bce | 877 | |
86384605 | 878 | new->s_flags |= MS_ACTIVE; |
907b9bce | 879 | |
86384605 AD |
880 | /* Grab a reference to the gfs2 mount point */ |
881 | atomic_inc(&sdp->sd_gfs2mnt->mnt_count); | |
882 | return simple_set_mnt(mnt, new); | |
883 | error: | |
86384605 | 884 | return error; |
b3b94faa DT |
885 | } |
886 | ||
419c93e0 SW |
887 | static void gfs2_kill_sb(struct super_block *sb) |
888 | { | |
7c52b166 | 889 | gfs2_delete_debugfs_file(sb->s_fs_info); |
419c93e0 SW |
890 | kill_block_super(sb); |
891 | } | |
892 | ||
86384605 AD |
893 | static 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 | ||
b3b94faa DT |
901 | struct file_system_type gfs2_fs_type = { |
902 | .name = "gfs2", | |
903 | .fs_flags = FS_REQUIRES_DEV, | |
904 | .get_sb = gfs2_get_sb, | |
419c93e0 SW |
905 | .kill_sb = gfs2_kill_sb, |
906 | .owner = THIS_MODULE, | |
907 | }; | |
908 | ||
909 | struct file_system_type gfs2meta_fs_type = { | |
910 | .name = "gfs2meta", | |
911 | .fs_flags = FS_REQUIRES_DEV, | |
86384605 AD |
912 | .get_sb = gfs2_get_sb_meta, |
913 | .kill_sb = gfs2_kill_sb_meta, | |
b3b94faa DT |
914 | .owner = THIS_MODULE, |
915 | }; | |
916 |