aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2009-05-22 05:36:01 -0400
committerSteven Whitehouse <swhiteho@redhat.com>2009-05-22 05:36:01 -0400
commit9e6e0a128bca0a151d8d3fbd9459b22fc21cfebb (patch)
tree1634ddf642a127bbd8533b7e73d5a1ebc572343f /fs/gfs2
parentb1e71b0622974953e46a284aa986504a90869a9b (diff)
GFS2: Merge mount.c and ops_super.c into super.c
mount.c only contained a single function, so is not really worth retaining on its own. All of the super related code is now either in super.c or ops_fstype.c Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2')
-rw-r--r--fs/gfs2/Makefile4
-rw-r--r--fs/gfs2/mount.c195
-rw-r--r--fs/gfs2/ops_super.c757
-rw-r--r--fs/gfs2/super.c903
4 files changed, 903 insertions, 956 deletions
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile
index 4f7332c7682f..d53a9bea1c2f 100644
--- a/fs/gfs2/Makefile
+++ b/fs/gfs2/Makefile
@@ -1,8 +1,8 @@
1obj-$(CONFIG_GFS2_FS) += gfs2.o 1obj-$(CONFIG_GFS2_FS) += gfs2.o
2gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \ 2gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \
3 glops.o inode.o log.o lops.o main.o meta_io.o \ 3 glops.o inode.o log.o lops.o main.o meta_io.o \
4 mount.o aops.o dentry.o export.o file.o \ 4 aops.o dentry.o export.o file.o \
5 ops_fstype.o ops_inode.o ops_super.o quota.o \ 5 ops_fstype.o ops_inode.o quota.o \
6 recovery.o rgrp.o super.o sys.o trans.o util.o 6 recovery.o rgrp.o super.o sys.o trans.o util.o
7 7
8gfs2-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o 8gfs2-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o
diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c
deleted file mode 100644
index 947af151fa24..000000000000
--- a/fs/gfs2/mount.c
+++ /dev/null
@@ -1,195 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
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
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/slab.h>
11#include <linux/spinlock.h>
12#include <linux/completion.h>
13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h>
15#include <linux/parser.h>
16
17#include "gfs2.h"
18#include "incore.h"
19#include "super.h"
20#include "sys.h"
21#include "util.h"
22
23enum {
24 Opt_lockproto,
25 Opt_locktable,
26 Opt_hostdata,
27 Opt_spectator,
28 Opt_ignore_local_fs,
29 Opt_localflocks,
30 Opt_localcaching,
31 Opt_debug,
32 Opt_nodebug,
33 Opt_upgrade,
34 Opt_acl,
35 Opt_noacl,
36 Opt_quota_off,
37 Opt_quota_account,
38 Opt_quota_on,
39 Opt_quota,
40 Opt_noquota,
41 Opt_suiddir,
42 Opt_nosuiddir,
43 Opt_data_writeback,
44 Opt_data_ordered,
45 Opt_meta,
46 Opt_discard,
47 Opt_nodiscard,
48 Opt_commit,
49 Opt_err,
50};
51
52static const match_table_t tokens = {
53 {Opt_lockproto, "lockproto=%s"},
54 {Opt_locktable, "locktable=%s"},
55 {Opt_hostdata, "hostdata=%s"},
56 {Opt_spectator, "spectator"},
57 {Opt_ignore_local_fs, "ignore_local_fs"},
58 {Opt_localflocks, "localflocks"},
59 {Opt_localcaching, "localcaching"},
60 {Opt_debug, "debug"},
61 {Opt_nodebug, "nodebug"},
62 {Opt_upgrade, "upgrade"},
63 {Opt_acl, "acl"},
64 {Opt_noacl, "noacl"},
65 {Opt_quota_off, "quota=off"},
66 {Opt_quota_account, "quota=account"},
67 {Opt_quota_on, "quota=on"},
68 {Opt_quota, "quota"},
69 {Opt_noquota, "noquota"},
70 {Opt_suiddir, "suiddir"},
71 {Opt_nosuiddir, "nosuiddir"},
72 {Opt_data_writeback, "data=writeback"},
73 {Opt_data_ordered, "data=ordered"},
74 {Opt_meta, "meta"},
75 {Opt_discard, "discard"},
76 {Opt_nodiscard, "nodiscard"},
77 {Opt_commit, "commit=%d"},
78 {Opt_err, NULL}
79};
80
81/**
82 * gfs2_mount_args - Parse mount options
83 * @sdp:
84 * @data:
85 *
86 * Return: errno
87 */
88
89int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
90{
91 char *o;
92 int token;
93 substring_t tmp[MAX_OPT_ARGS];
94 int rv;
95
96 /* Split the options into tokens with the "," character and
97 process them */
98
99 while (1) {
100 o = strsep(&options, ",");
101 if (o == NULL)
102 break;
103 if (*o == '\0')
104 continue;
105
106 token = match_token(o, tokens, tmp);
107 switch (token) {
108 case Opt_lockproto:
109 match_strlcpy(args->ar_lockproto, &tmp[0],
110 GFS2_LOCKNAME_LEN);
111 break;
112 case Opt_locktable:
113 match_strlcpy(args->ar_locktable, &tmp[0],
114 GFS2_LOCKNAME_LEN);
115 break;
116 case Opt_hostdata:
117 match_strlcpy(args->ar_hostdata, &tmp[0],
118 GFS2_LOCKNAME_LEN);
119 break;
120 case Opt_spectator:
121 args->ar_spectator = 1;
122 break;
123 case Opt_ignore_local_fs:
124 args->ar_ignore_local_fs = 1;
125 break;
126 case Opt_localflocks:
127 args->ar_localflocks = 1;
128 break;
129 case Opt_localcaching:
130 args->ar_localcaching = 1;
131 break;
132 case Opt_debug:
133 args->ar_debug = 1;
134 break;
135 case Opt_nodebug:
136 args->ar_debug = 0;
137 break;
138 case Opt_upgrade:
139 args->ar_upgrade = 1;
140 break;
141 case Opt_acl:
142 args->ar_posix_acl = 1;
143 break;
144 case Opt_noacl:
145 args->ar_posix_acl = 0;
146 break;
147 case Opt_quota_off:
148 case Opt_noquota:
149 args->ar_quota = GFS2_QUOTA_OFF;
150 break;
151 case Opt_quota_account:
152 args->ar_quota = GFS2_QUOTA_ACCOUNT;
153 break;
154 case Opt_quota_on:
155 case Opt_quota:
156 args->ar_quota = GFS2_QUOTA_ON;
157 break;
158 case Opt_suiddir:
159 args->ar_suiddir = 1;
160 break;
161 case Opt_nosuiddir:
162 args->ar_suiddir = 0;
163 break;
164 case Opt_data_writeback:
165 args->ar_data = GFS2_DATA_WRITEBACK;
166 break;
167 case Opt_data_ordered:
168 args->ar_data = GFS2_DATA_ORDERED;
169 break;
170 case Opt_meta:
171 args->ar_meta = 1;
172 break;
173 case Opt_discard:
174 args->ar_discard = 1;
175 break;
176 case Opt_nodiscard:
177 args->ar_discard = 0;
178 break;
179 case Opt_commit:
180 rv = match_int(&tmp[0], &args->ar_commit);
181 if (rv || args->ar_commit <= 0) {
182 fs_info(sdp, "commit mount option requires a positive numeric argument\n");
183 return rv ? rv : -EINVAL;
184 }
185 break;
186 case Opt_err:
187 default:
188 fs_info(sdp, "invalid mount option: %s\n", o);
189 return -EINVAL;
190 }
191 }
192
193 return 0;
194}
195
diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c
deleted file mode 100644
index 2fd1dcbcc5b7..000000000000
--- a/fs/gfs2/ops_super.c
+++ /dev/null
@@ -1,757 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
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
7 * of the GNU General Public License version 2.
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>
15#include <linux/statfs.h>
16#include <linux/seq_file.h>
17#include <linux/mount.h>
18#include <linux/kthread.h>
19#include <linux/delay.h>
20#include <linux/gfs2_ondisk.h>
21#include <linux/crc32.h>
22#include <linux/time.h>
23
24#include "gfs2.h"
25#include "incore.h"
26#include "glock.h"
27#include "inode.h"
28#include "log.h"
29#include "quota.h"
30#include "recovery.h"
31#include "rgrp.h"
32#include "super.h"
33#include "sys.h"
34#include "util.h"
35#include "trans.h"
36#include "dir.h"
37#include "eattr.h"
38#include "bmap.h"
39#include "meta_io.h"
40
41#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
42
43/**
44 * gfs2_write_inode - Make sure the inode is stable on the disk
45 * @inode: The inode
46 * @sync: synchronous write flag
47 *
48 * Returns: errno
49 */
50
51static int gfs2_write_inode(struct inode *inode, int sync)
52{
53 struct gfs2_inode *ip = GFS2_I(inode);
54 struct gfs2_sbd *sdp = GFS2_SB(inode);
55 struct gfs2_holder gh;
56 struct buffer_head *bh;
57 struct timespec atime;
58 struct gfs2_dinode *di;
59 int ret = 0;
60
61 /* Check this is a "normal" inode, etc */
62 if (!test_bit(GIF_USER, &ip->i_flags) ||
63 (current->flags & PF_MEMALLOC))
64 return 0;
65 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
66 if (ret)
67 goto do_flush;
68 ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
69 if (ret)
70 goto do_unlock;
71 ret = gfs2_meta_inode_buffer(ip, &bh);
72 if (ret == 0) {
73 di = (struct gfs2_dinode *)bh->b_data;
74 atime.tv_sec = be64_to_cpu(di->di_atime);
75 atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
76 if (timespec_compare(&inode->i_atime, &atime) > 0) {
77 gfs2_trans_add_bh(ip->i_gl, bh, 1);
78 gfs2_dinode_out(ip, bh->b_data);
79 }
80 brelse(bh);
81 }
82 gfs2_trans_end(sdp);
83do_unlock:
84 gfs2_glock_dq_uninit(&gh);
85do_flush:
86 if (sync != 0)
87 gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
88 return ret;
89}
90
91/**
92 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
93 * @sdp: the filesystem
94 *
95 * Returns: errno
96 */
97
98static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
99{
100 struct gfs2_holder t_gh;
101 int error;
102
103 gfs2_quota_sync(sdp);
104 gfs2_statfs_sync(sdp);
105
106 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
107 &t_gh);
108 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
109 return error;
110
111 gfs2_meta_syncfs(sdp);
112 gfs2_log_shutdown(sdp);
113
114 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
115
116 if (t_gh.gh_gl)
117 gfs2_glock_dq_uninit(&t_gh);
118
119 gfs2_quota_cleanup(sdp);
120
121 return error;
122}
123
124static int gfs2_umount_recovery_wait(void *word)
125{
126 schedule();
127 return 0;
128}
129
130/**
131 * gfs2_put_super - Unmount the filesystem
132 * @sb: The VFS superblock
133 *
134 */
135
136static void gfs2_put_super(struct super_block *sb)
137{
138 struct gfs2_sbd *sdp = sb->s_fs_info;
139 int error;
140 struct gfs2_jdesc *jd;
141
142 /* Unfreeze the filesystem, if we need to */
143
144 mutex_lock(&sdp->sd_freeze_lock);
145 if (sdp->sd_freeze_count)
146 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
147 mutex_unlock(&sdp->sd_freeze_lock);
148
149 /* No more recovery requests */
150 set_bit(SDF_NORECOVERY, &sdp->sd_flags);
151 smp_mb();
152
153 /* Wait on outstanding recovery */
154restart:
155 spin_lock(&sdp->sd_jindex_spin);
156 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
157 if (!test_bit(JDF_RECOVERY, &jd->jd_flags))
158 continue;
159 spin_unlock(&sdp->sd_jindex_spin);
160 wait_on_bit(&jd->jd_flags, JDF_RECOVERY,
161 gfs2_umount_recovery_wait, TASK_UNINTERRUPTIBLE);
162 goto restart;
163 }
164 spin_unlock(&sdp->sd_jindex_spin);
165
166 kthread_stop(sdp->sd_quotad_process);
167 kthread_stop(sdp->sd_logd_process);
168
169 if (!(sb->s_flags & MS_RDONLY)) {
170 error = gfs2_make_fs_ro(sdp);
171 if (error)
172 gfs2_io_error(sdp);
173 }
174 /* At this point, we're through modifying the disk */
175
176 /* Release stuff */
177
178 iput(sdp->sd_jindex);
179 iput(sdp->sd_inum_inode);
180 iput(sdp->sd_statfs_inode);
181 iput(sdp->sd_rindex);
182 iput(sdp->sd_quota_inode);
183
184 gfs2_glock_put(sdp->sd_rename_gl);
185 gfs2_glock_put(sdp->sd_trans_gl);
186
187 if (!sdp->sd_args.ar_spectator) {
188 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
189 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
190 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
191 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
192 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
193 iput(sdp->sd_ir_inode);
194 iput(sdp->sd_sc_inode);
195 iput(sdp->sd_qc_inode);
196 }
197
198 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
199 gfs2_clear_rgrpd(sdp);
200 gfs2_jindex_free(sdp);
201 /* Take apart glock structures and buffer lists */
202 gfs2_gl_hash_clear(sdp);
203 /* Unmount the locking protocol */
204 gfs2_lm_unmount(sdp);
205
206 /* At this point, we're through participating in the lockspace */
207 gfs2_sys_fs_del(sdp);
208}
209
210/**
211 * gfs2_write_super
212 * @sb: the superblock
213 *
214 */
215
216static void gfs2_write_super(struct super_block *sb)
217{
218 sb->s_dirt = 0;
219}
220
221/**
222 * gfs2_sync_fs - sync the filesystem
223 * @sb: the superblock
224 *
225 * Flushes the log to disk.
226 */
227
228static int gfs2_sync_fs(struct super_block *sb, int wait)
229{
230 sb->s_dirt = 0;
231 if (wait && sb->s_fs_info)
232 gfs2_log_flush(sb->s_fs_info, NULL);
233 return 0;
234}
235
236/**
237 * gfs2_freeze - prevent further writes to the filesystem
238 * @sb: the VFS structure for the filesystem
239 *
240 */
241
242static int gfs2_freeze(struct super_block *sb)
243{
244 struct gfs2_sbd *sdp = sb->s_fs_info;
245 int error;
246
247 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
248 return -EINVAL;
249
250 for (;;) {
251 error = gfs2_freeze_fs(sdp);
252 if (!error)
253 break;
254
255 switch (error) {
256 case -EBUSY:
257 fs_err(sdp, "waiting for recovery before freeze\n");
258 break;
259
260 default:
261 fs_err(sdp, "error freezing FS: %d\n", error);
262 break;
263 }
264
265 fs_err(sdp, "retrying...\n");
266 msleep(1000);
267 }
268 return 0;
269}
270
271/**
272 * gfs2_unfreeze - reallow writes to the filesystem
273 * @sb: the VFS structure for the filesystem
274 *
275 */
276
277static int gfs2_unfreeze(struct super_block *sb)
278{
279 gfs2_unfreeze_fs(sb->s_fs_info);
280 return 0;
281}
282
283/**
284 * statfs_fill - fill in the sg for a given RG
285 * @rgd: the RG
286 * @sc: the sc structure
287 *
288 * Returns: 0 on success, -ESTALE if the LVB is invalid
289 */
290
291static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
292 struct gfs2_statfs_change_host *sc)
293{
294 gfs2_rgrp_verify(rgd);
295 sc->sc_total += rgd->rd_data;
296 sc->sc_free += rgd->rd_free;
297 sc->sc_dinodes += rgd->rd_dinodes;
298 return 0;
299}
300
301/**
302 * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
303 * @sdp: the filesystem
304 * @sc: the sc info that will be returned
305 *
306 * Any error (other than a signal) will cause this routine to fall back
307 * to the synchronous version.
308 *
309 * FIXME: This really shouldn't busy wait like this.
310 *
311 * Returns: errno
312 */
313
314static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
315{
316 struct gfs2_holder ri_gh;
317 struct gfs2_rgrpd *rgd_next;
318 struct gfs2_holder *gha, *gh;
319 unsigned int slots = 64;
320 unsigned int x;
321 int done;
322 int error = 0, err;
323
324 memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
325 gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
326 if (!gha)
327 return -ENOMEM;
328
329 error = gfs2_rindex_hold(sdp, &ri_gh);
330 if (error)
331 goto out;
332
333 rgd_next = gfs2_rgrpd_get_first(sdp);
334
335 for (;;) {
336 done = 1;
337
338 for (x = 0; x < slots; x++) {
339 gh = gha + x;
340
341 if (gh->gh_gl && gfs2_glock_poll(gh)) {
342 err = gfs2_glock_wait(gh);
343 if (err) {
344 gfs2_holder_uninit(gh);
345 error = err;
346 } else {
347 if (!error)
348 error = statfs_slow_fill(
349 gh->gh_gl->gl_object, sc);
350 gfs2_glock_dq_uninit(gh);
351 }
352 }
353
354 if (gh->gh_gl)
355 done = 0;
356 else if (rgd_next && !error) {
357 error = gfs2_glock_nq_init(rgd_next->rd_gl,
358 LM_ST_SHARED,
359 GL_ASYNC,
360 gh);
361 rgd_next = gfs2_rgrpd_get_next(rgd_next);
362 done = 0;
363 }
364
365 if (signal_pending(current))
366 error = -ERESTARTSYS;
367 }
368
369 if (done)
370 break;
371
372 yield();
373 }
374
375 gfs2_glock_dq_uninit(&ri_gh);
376
377out:
378 kfree(gha);
379 return error;
380}
381
382/**
383 * gfs2_statfs_i - Do a statfs
384 * @sdp: the filesystem
385 * @sg: the sg structure
386 *
387 * Returns: errno
388 */
389
390static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
391{
392 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
393 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
394
395 spin_lock(&sdp->sd_statfs_spin);
396
397 *sc = *m_sc;
398 sc->sc_total += l_sc->sc_total;
399 sc->sc_free += l_sc->sc_free;
400 sc->sc_dinodes += l_sc->sc_dinodes;
401
402 spin_unlock(&sdp->sd_statfs_spin);
403
404 if (sc->sc_free < 0)
405 sc->sc_free = 0;
406 if (sc->sc_free > sc->sc_total)
407 sc->sc_free = sc->sc_total;
408 if (sc->sc_dinodes < 0)
409 sc->sc_dinodes = 0;
410
411 return 0;
412}
413
414/**
415 * gfs2_statfs - Gather and return stats about the filesystem
416 * @sb: The superblock
417 * @statfsbuf: The buffer
418 *
419 * Returns: 0 on success or error code
420 */
421
422static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
423{
424 struct super_block *sb = dentry->d_inode->i_sb;
425 struct gfs2_sbd *sdp = sb->s_fs_info;
426 struct gfs2_statfs_change_host sc;
427 int error;
428
429 if (gfs2_tune_get(sdp, gt_statfs_slow))
430 error = gfs2_statfs_slow(sdp, &sc);
431 else
432 error = gfs2_statfs_i(sdp, &sc);
433
434 if (error)
435 return error;
436
437 buf->f_type = GFS2_MAGIC;
438 buf->f_bsize = sdp->sd_sb.sb_bsize;
439 buf->f_blocks = sc.sc_total;
440 buf->f_bfree = sc.sc_free;
441 buf->f_bavail = sc.sc_free;
442 buf->f_files = sc.sc_dinodes + sc.sc_free;
443 buf->f_ffree = sc.sc_free;
444 buf->f_namelen = GFS2_FNAMESIZE;
445
446 return 0;
447}
448
449/**
450 * gfs2_remount_fs - called when the FS is remounted
451 * @sb: the filesystem
452 * @flags: the remount flags
453 * @data: extra data passed in (not used right now)
454 *
455 * Returns: errno
456 */
457
458static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
459{
460 struct gfs2_sbd *sdp = sb->s_fs_info;
461 struct gfs2_args args = sdp->sd_args; /* Default to current settings */
462 struct gfs2_tune *gt = &sdp->sd_tune;
463 int error;
464
465 spin_lock(&gt->gt_spin);
466 args.ar_commit = gt->gt_log_flush_secs;
467 spin_unlock(&gt->gt_spin);
468 error = gfs2_mount_args(sdp, &args, data);
469 if (error)
470 return error;
471
472 /* Not allowed to change locking details */
473 if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
474 strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
475 strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
476 return -EINVAL;
477
478 /* Some flags must not be changed */
479 if (args_neq(&args, &sdp->sd_args, spectator) ||
480 args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
481 args_neq(&args, &sdp->sd_args, localflocks) ||
482 args_neq(&args, &sdp->sd_args, localcaching) ||
483 args_neq(&args, &sdp->sd_args, meta))
484 return -EINVAL;
485
486 if (sdp->sd_args.ar_spectator)
487 *flags |= MS_RDONLY;
488
489 if ((sb->s_flags ^ *flags) & MS_RDONLY) {
490 if (*flags & MS_RDONLY)
491 error = gfs2_make_fs_ro(sdp);
492 else
493 error = gfs2_make_fs_rw(sdp);
494 if (error)
495 return error;
496 }
497
498 sdp->sd_args = args;
499 if (sdp->sd_args.ar_posix_acl)
500 sb->s_flags |= MS_POSIXACL;
501 else
502 sb->s_flags &= ~MS_POSIXACL;
503 spin_lock(&gt->gt_spin);
504 gt->gt_log_flush_secs = args.ar_commit;
505 spin_unlock(&gt->gt_spin);
506
507 return 0;
508}
509
510/**
511 * gfs2_drop_inode - Drop an inode (test for remote unlink)
512 * @inode: The inode to drop
513 *
514 * If we've received a callback on an iopen lock then its because a
515 * remote node tried to deallocate the inode but failed due to this node
516 * still having the inode open. Here we mark the link count zero
517 * since we know that it must have reached zero if the GLF_DEMOTE flag
518 * is set on the iopen glock. If we didn't do a disk read since the
519 * remote node removed the final link then we might otherwise miss
520 * this event. This check ensures that this node will deallocate the
521 * inode's blocks, or alternatively pass the baton on to another
522 * node for later deallocation.
523 */
524
525static void gfs2_drop_inode(struct inode *inode)
526{
527 struct gfs2_inode *ip = GFS2_I(inode);
528
529 if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
530 struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
531 if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
532 clear_nlink(inode);
533 }
534 generic_drop_inode(inode);
535}
536
537/**
538 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
539 * @inode: The VFS inode
540 *
541 */
542
543static void gfs2_clear_inode(struct inode *inode)
544{
545 struct gfs2_inode *ip = GFS2_I(inode);
546
547 /* This tells us its a "real" inode and not one which only
548 * serves to contain an address space (see rgrp.c, meta_io.c)
549 * which therefore doesn't have its own glocks.
550 */
551 if (test_bit(GIF_USER, &ip->i_flags)) {
552 ip->i_gl->gl_object = NULL;
553 gfs2_glock_put(ip->i_gl);
554 ip->i_gl = NULL;
555 if (ip->i_iopen_gh.gh_gl) {
556 ip->i_iopen_gh.gh_gl->gl_object = NULL;
557 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
558 }
559 }
560}
561
562static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
563{
564 do {
565 if (d1 == d2)
566 return 1;
567 d1 = d1->d_parent;
568 } while (!IS_ROOT(d1));
569 return 0;
570}
571
572/**
573 * gfs2_show_options - Show mount options for /proc/mounts
574 * @s: seq_file structure
575 * @mnt: vfsmount
576 *
577 * Returns: 0 on success or error code
578 */
579
580static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
581{
582 struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
583 struct gfs2_args *args = &sdp->sd_args;
584 int lfsecs;
585
586 if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
587 seq_printf(s, ",meta");
588 if (args->ar_lockproto[0])
589 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
590 if (args->ar_locktable[0])
591 seq_printf(s, ",locktable=%s", args->ar_locktable);
592 if (args->ar_hostdata[0])
593 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
594 if (args->ar_spectator)
595 seq_printf(s, ",spectator");
596 if (args->ar_ignore_local_fs)
597 seq_printf(s, ",ignore_local_fs");
598 if (args->ar_localflocks)
599 seq_printf(s, ",localflocks");
600 if (args->ar_localcaching)
601 seq_printf(s, ",localcaching");
602 if (args->ar_debug)
603 seq_printf(s, ",debug");
604 if (args->ar_upgrade)
605 seq_printf(s, ",upgrade");
606 if (args->ar_posix_acl)
607 seq_printf(s, ",acl");
608 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
609 char *state;
610 switch (args->ar_quota) {
611 case GFS2_QUOTA_OFF:
612 state = "off";
613 break;
614 case GFS2_QUOTA_ACCOUNT:
615 state = "account";
616 break;
617 case GFS2_QUOTA_ON:
618 state = "on";
619 break;
620 default:
621 state = "unknown";
622 break;
623 }
624 seq_printf(s, ",quota=%s", state);
625 }
626 if (args->ar_suiddir)
627 seq_printf(s, ",suiddir");
628 if (args->ar_data != GFS2_DATA_DEFAULT) {
629 char *state;
630 switch (args->ar_data) {
631 case GFS2_DATA_WRITEBACK:
632 state = "writeback";
633 break;
634 case GFS2_DATA_ORDERED:
635 state = "ordered";
636 break;
637 default:
638 state = "unknown";
639 break;
640 }
641 seq_printf(s, ",data=%s", state);
642 }
643 if (args->ar_discard)
644 seq_printf(s, ",discard");
645 lfsecs = sdp->sd_tune.gt_log_flush_secs;
646 if (lfsecs != 60)
647 seq_printf(s, ",commit=%d", lfsecs);
648 return 0;
649}
650
651/*
652 * We have to (at the moment) hold the inodes main lock to cover
653 * the gap between unlocking the shared lock on the iopen lock and
654 * taking the exclusive lock. I'd rather do a shared -> exclusive
655 * conversion on the iopen lock, but we can change that later. This
656 * is safe, just less efficient.
657 */
658
659static void gfs2_delete_inode(struct inode *inode)
660{
661 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
662 struct gfs2_inode *ip = GFS2_I(inode);
663 struct gfs2_holder gh;
664 int error;
665
666 if (!test_bit(GIF_USER, &ip->i_flags))
667 goto out;
668
669 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
670 if (unlikely(error)) {
671 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
672 goto out;
673 }
674
675 gfs2_glock_dq_wait(&ip->i_iopen_gh);
676 gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
677 error = gfs2_glock_nq(&ip->i_iopen_gh);
678 if (error)
679 goto out_truncate;
680
681 if (S_ISDIR(inode->i_mode) &&
682 (ip->i_diskflags & GFS2_DIF_EXHASH)) {
683 error = gfs2_dir_exhash_dealloc(ip);
684 if (error)
685 goto out_unlock;
686 }
687
688 if (ip->i_eattr) {
689 error = gfs2_ea_dealloc(ip);
690 if (error)
691 goto out_unlock;
692 }
693
694 if (!gfs2_is_stuffed(ip)) {
695 error = gfs2_file_dealloc(ip);
696 if (error)
697 goto out_unlock;
698 }
699
700 error = gfs2_dinode_dealloc(ip);
701 if (error)
702 goto out_unlock;
703
704out_truncate:
705 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
706 if (error)
707 goto out_unlock;
708 /* Needs to be done before glock release & also in a transaction */
709 truncate_inode_pages(&inode->i_data, 0);
710 gfs2_trans_end(sdp);
711
712out_unlock:
713 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
714 gfs2_glock_dq(&ip->i_iopen_gh);
715 gfs2_holder_uninit(&ip->i_iopen_gh);
716 gfs2_glock_dq_uninit(&gh);
717 if (error && error != GLR_TRYFAILED && error != -EROFS)
718 fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
719out:
720 truncate_inode_pages(&inode->i_data, 0);
721 clear_inode(inode);
722}
723
724static struct inode *gfs2_alloc_inode(struct super_block *sb)
725{
726 struct gfs2_inode *ip;
727
728 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
729 if (ip) {
730 ip->i_flags = 0;
731 ip->i_gl = NULL;
732 }
733 return &ip->i_inode;
734}
735
736static void gfs2_destroy_inode(struct inode *inode)
737{
738 kmem_cache_free(gfs2_inode_cachep, inode);
739}
740
741const struct super_operations gfs2_super_ops = {
742 .alloc_inode = gfs2_alloc_inode,
743 .destroy_inode = gfs2_destroy_inode,
744 .write_inode = gfs2_write_inode,
745 .delete_inode = gfs2_delete_inode,
746 .put_super = gfs2_put_super,
747 .write_super = gfs2_write_super,
748 .sync_fs = gfs2_sync_fs,
749 .freeze_fs = gfs2_freeze,
750 .unfreeze_fs = gfs2_unfreeze,
751 .statfs = gfs2_statfs,
752 .remount_fs = gfs2_remount_fs,
753 .clear_inode = gfs2_clear_inode,
754 .drop_inode = gfs2_drop_inode,
755 .show_options = gfs2_show_options,
756};
757
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 601913e0a482..40bcc37e5a70 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -7,14 +7,20 @@
7 * of the GNU General Public License version 2. 7 * of the GNU General Public License version 2.
8 */ 8 */
9 9
10#include <linux/bio.h>
10#include <linux/sched.h> 11#include <linux/sched.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
12#include <linux/spinlock.h> 13#include <linux/spinlock.h>
13#include <linux/completion.h> 14#include <linux/completion.h>
14#include <linux/buffer_head.h> 15#include <linux/buffer_head.h>
15#include <linux/crc32.h> 16#include <linux/statfs.h>
17#include <linux/seq_file.h>
18#include <linux/mount.h>
19#include <linux/kthread.h>
20#include <linux/delay.h>
16#include <linux/gfs2_ondisk.h> 21#include <linux/gfs2_ondisk.h>
17#include <linux/bio.h> 22#include <linux/crc32.h>
23#include <linux/time.h>
18 24
19#include "gfs2.h" 25#include "gfs2.h"
20#include "incore.h" 26#include "incore.h"
@@ -31,6 +37,183 @@
31#include "super.h" 37#include "super.h"
32#include "trans.h" 38#include "trans.h"
33#include "util.h" 39#include "util.h"
40#include "sys.h"
41#include "eattr.h"
42
43#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
44
45enum {
46 Opt_lockproto,
47 Opt_locktable,
48 Opt_hostdata,
49 Opt_spectator,
50 Opt_ignore_local_fs,
51 Opt_localflocks,
52 Opt_localcaching,
53 Opt_debug,
54 Opt_nodebug,
55 Opt_upgrade,
56 Opt_acl,
57 Opt_noacl,
58 Opt_quota_off,
59 Opt_quota_account,
60 Opt_quota_on,
61 Opt_quota,
62 Opt_noquota,
63 Opt_suiddir,
64 Opt_nosuiddir,
65 Opt_data_writeback,
66 Opt_data_ordered,
67 Opt_meta,
68 Opt_discard,
69 Opt_nodiscard,
70 Opt_commit,
71 Opt_error,
72};
73
74static const match_table_t tokens = {
75 {Opt_lockproto, "lockproto=%s"},
76 {Opt_locktable, "locktable=%s"},
77 {Opt_hostdata, "hostdata=%s"},
78 {Opt_spectator, "spectator"},
79 {Opt_ignore_local_fs, "ignore_local_fs"},
80 {Opt_localflocks, "localflocks"},
81 {Opt_localcaching, "localcaching"},
82 {Opt_debug, "debug"},
83 {Opt_nodebug, "nodebug"},
84 {Opt_upgrade, "upgrade"},
85 {Opt_acl, "acl"},
86 {Opt_noacl, "noacl"},
87 {Opt_quota_off, "quota=off"},
88 {Opt_quota_account, "quota=account"},
89 {Opt_quota_on, "quota=on"},
90 {Opt_quota, "quota"},
91 {Opt_noquota, "noquota"},
92 {Opt_suiddir, "suiddir"},
93 {Opt_nosuiddir, "nosuiddir"},
94 {Opt_data_writeback, "data=writeback"},
95 {Opt_data_ordered, "data=ordered"},
96 {Opt_meta, "meta"},
97 {Opt_discard, "discard"},
98 {Opt_nodiscard, "nodiscard"},
99 {Opt_commit, "commit=%d"},
100 {Opt_error, NULL}
101};
102
103/**
104 * gfs2_mount_args - Parse mount options
105 * @sdp:
106 * @data:
107 *
108 * Return: errno
109 */
110
111int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
112{
113 char *o;
114 int token;
115 substring_t tmp[MAX_OPT_ARGS];
116 int rv;
117
118 /* Split the options into tokens with the "," character and
119 process them */
120
121 while (1) {
122 o = strsep(&options, ",");
123 if (o == NULL)
124 break;
125 if (*o == '\0')
126 continue;
127
128 token = match_token(o, tokens, tmp);
129 switch (token) {
130 case Opt_lockproto:
131 match_strlcpy(args->ar_lockproto, &tmp[0],
132 GFS2_LOCKNAME_LEN);
133 break;
134 case Opt_locktable:
135 match_strlcpy(args->ar_locktable, &tmp[0],
136 GFS2_LOCKNAME_LEN);
137 break;
138 case Opt_hostdata:
139 match_strlcpy(args->ar_hostdata, &tmp[0],
140 GFS2_LOCKNAME_LEN);
141 break;
142 case Opt_spectator:
143 args->ar_spectator = 1;
144 break;
145 case Opt_ignore_local_fs:
146 args->ar_ignore_local_fs = 1;
147 break;
148 case Opt_localflocks:
149 args->ar_localflocks = 1;
150 break;
151 case Opt_localcaching:
152 args->ar_localcaching = 1;
153 break;
154 case Opt_debug:
155 args->ar_debug = 1;
156 break;
157 case Opt_nodebug:
158 args->ar_debug = 0;
159 break;
160 case Opt_upgrade:
161 args->ar_upgrade = 1;
162 break;
163 case Opt_acl:
164 args->ar_posix_acl = 1;
165 break;
166 case Opt_noacl:
167 args->ar_posix_acl = 0;
168 break;
169 case Opt_quota_off:
170 case Opt_noquota:
171 args->ar_quota = GFS2_QUOTA_OFF;
172 break;
173 case Opt_quota_account:
174 args->ar_quota = GFS2_QUOTA_ACCOUNT;
175 break;
176 case Opt_quota_on:
177 case Opt_quota:
178 args->ar_quota = GFS2_QUOTA_ON;
179 break;
180 case Opt_suiddir:
181 args->ar_suiddir = 1;
182 break;
183 case Opt_nosuiddir:
184 args->ar_suiddir = 0;
185 break;
186 case Opt_data_writeback:
187 args->ar_data = GFS2_DATA_WRITEBACK;
188 break;
189 case Opt_data_ordered:
190 args->ar_data = GFS2_DATA_ORDERED;
191 break;
192 case Opt_meta:
193 args->ar_meta = 1;
194 break;
195 case Opt_discard:
196 args->ar_discard = 1;
197 break;
198 case Opt_nodiscard:
199 args->ar_discard = 0;
200 break;
201 case Opt_commit:
202 rv = match_int(&tmp[0], &args->ar_commit);
203 if (rv || args->ar_commit <= 0) {
204 fs_info(sdp, "commit mount option requires a positive numeric argument\n");
205 return rv ? rv : -EINVAL;
206 }
207 break;
208 case Opt_error:
209 default:
210 fs_info(sdp, "invalid mount option: %s\n", o);
211 return -EINVAL;
212 }
213 }
214
215 return 0;
216}
34 217
35/** 218/**
36 * gfs2_jindex_free - Clear all the journal index information 219 * gfs2_jindex_free - Clear all the journal index information
@@ -436,3 +619,719 @@ void gfs2_unfreeze_fs(struct gfs2_sbd *sdp)
436 mutex_unlock(&sdp->sd_freeze_lock); 619 mutex_unlock(&sdp->sd_freeze_lock);
437} 620}
438 621
622
623/**
624 * gfs2_write_inode - Make sure the inode is stable on the disk
625 * @inode: The inode
626 * @sync: synchronous write flag
627 *
628 * Returns: errno
629 */
630
631static int gfs2_write_inode(struct inode *inode, int sync)
632{
633 struct gfs2_inode *ip = GFS2_I(inode);
634 struct gfs2_sbd *sdp = GFS2_SB(inode);
635 struct gfs2_holder gh;
636 struct buffer_head *bh;
637 struct timespec atime;
638 struct gfs2_dinode *di;
639 int ret = 0;
640
641 /* Check this is a "normal" inode, etc */
642 if (!test_bit(GIF_USER, &ip->i_flags) ||
643 (current->flags & PF_MEMALLOC))
644 return 0;
645 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
646 if (ret)
647 goto do_flush;
648 ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
649 if (ret)
650 goto do_unlock;
651 ret = gfs2_meta_inode_buffer(ip, &bh);
652 if (ret == 0) {
653 di = (struct gfs2_dinode *)bh->b_data;
654 atime.tv_sec = be64_to_cpu(di->di_atime);
655 atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
656 if (timespec_compare(&inode->i_atime, &atime) > 0) {
657 gfs2_trans_add_bh(ip->i_gl, bh, 1);
658 gfs2_dinode_out(ip, bh->b_data);
659 }
660 brelse(bh);
661 }
662 gfs2_trans_end(sdp);
663do_unlock:
664 gfs2_glock_dq_uninit(&gh);
665do_flush:
666 if (sync != 0)
667 gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
668 return ret;
669}
670
671/**
672 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
673 * @sdp: the filesystem
674 *
675 * Returns: errno
676 */
677
678static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
679{
680 struct gfs2_holder t_gh;
681 int error;
682
683 gfs2_quota_sync(sdp);
684 gfs2_statfs_sync(sdp);
685
686 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
687 &t_gh);
688 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
689 return error;
690
691 gfs2_meta_syncfs(sdp);
692 gfs2_log_shutdown(sdp);
693
694 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
695
696 if (t_gh.gh_gl)
697 gfs2_glock_dq_uninit(&t_gh);
698
699 gfs2_quota_cleanup(sdp);
700
701 return error;
702}
703
704static int gfs2_umount_recovery_wait(void *word)
705{
706 schedule();
707 return 0;
708}
709
710/**
711 * gfs2_put_super - Unmount the filesystem
712 * @sb: The VFS superblock
713 *
714 */
715
716static void gfs2_put_super(struct super_block *sb)
717{
718 struct gfs2_sbd *sdp = sb->s_fs_info;
719 int error;
720 struct gfs2_jdesc *jd;
721
722 /* Unfreeze the filesystem, if we need to */
723
724 mutex_lock(&sdp->sd_freeze_lock);
725 if (sdp->sd_freeze_count)
726 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
727 mutex_unlock(&sdp->sd_freeze_lock);
728
729 /* No more recovery requests */
730 set_bit(SDF_NORECOVERY, &sdp->sd_flags);
731 smp_mb();
732
733 /* Wait on outstanding recovery */
734restart:
735 spin_lock(&sdp->sd_jindex_spin);
736 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
737 if (!test_bit(JDF_RECOVERY, &jd->jd_flags))
738 continue;
739 spin_unlock(&sdp->sd_jindex_spin);
740 wait_on_bit(&jd->jd_flags, JDF_RECOVERY,
741 gfs2_umount_recovery_wait, TASK_UNINTERRUPTIBLE);
742 goto restart;
743 }
744 spin_unlock(&sdp->sd_jindex_spin);
745
746 kthread_stop(sdp->sd_quotad_process);
747 kthread_stop(sdp->sd_logd_process);
748
749 if (!(sb->s_flags & MS_RDONLY)) {
750 error = gfs2_make_fs_ro(sdp);
751 if (error)
752 gfs2_io_error(sdp);
753 }
754 /* At this point, we're through modifying the disk */
755
756 /* Release stuff */
757
758 iput(sdp->sd_jindex);
759 iput(sdp->sd_inum_inode);
760 iput(sdp->sd_statfs_inode);
761 iput(sdp->sd_rindex);
762 iput(sdp->sd_quota_inode);
763
764 gfs2_glock_put(sdp->sd_rename_gl);
765 gfs2_glock_put(sdp->sd_trans_gl);
766
767 if (!sdp->sd_args.ar_spectator) {
768 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
769 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
770 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
771 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
772 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
773 iput(sdp->sd_ir_inode);
774 iput(sdp->sd_sc_inode);
775 iput(sdp->sd_qc_inode);
776 }
777
778 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
779 gfs2_clear_rgrpd(sdp);
780 gfs2_jindex_free(sdp);
781 /* Take apart glock structures and buffer lists */
782 gfs2_gl_hash_clear(sdp);
783 /* Unmount the locking protocol */
784 gfs2_lm_unmount(sdp);
785
786 /* At this point, we're through participating in the lockspace */
787 gfs2_sys_fs_del(sdp);
788}
789
790/**
791 * gfs2_write_super
792 * @sb: the superblock
793 *
794 */
795
796static void gfs2_write_super(struct super_block *sb)
797{
798 sb->s_dirt = 0;
799}
800
801/**
802 * gfs2_sync_fs - sync the filesystem
803 * @sb: the superblock
804 *
805 * Flushes the log to disk.
806 */
807
808static int gfs2_sync_fs(struct super_block *sb, int wait)
809{
810 sb->s_dirt = 0;
811 if (wait && sb->s_fs_info)
812 gfs2_log_flush(sb->s_fs_info, NULL);
813 return 0;
814}
815
816/**
817 * gfs2_freeze - prevent further writes to the filesystem
818 * @sb: the VFS structure for the filesystem
819 *
820 */
821
822static int gfs2_freeze(struct super_block *sb)
823{
824 struct gfs2_sbd *sdp = sb->s_fs_info;
825 int error;
826
827 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
828 return -EINVAL;
829
830 for (;;) {
831 error = gfs2_freeze_fs(sdp);
832 if (!error)
833 break;
834
835 switch (error) {
836 case -EBUSY:
837 fs_err(sdp, "waiting for recovery before freeze\n");
838 break;
839
840 default:
841 fs_err(sdp, "error freezing FS: %d\n", error);
842 break;
843 }
844
845 fs_err(sdp, "retrying...\n");
846 msleep(1000);
847 }
848 return 0;
849}
850
851/**
852 * gfs2_unfreeze - reallow writes to the filesystem
853 * @sb: the VFS structure for the filesystem
854 *
855 */
856
857static int gfs2_unfreeze(struct super_block *sb)
858{
859 gfs2_unfreeze_fs(sb->s_fs_info);
860 return 0;
861}
862
863/**
864 * statfs_fill - fill in the sg for a given RG
865 * @rgd: the RG
866 * @sc: the sc structure
867 *
868 * Returns: 0 on success, -ESTALE if the LVB is invalid
869 */
870
871static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
872 struct gfs2_statfs_change_host *sc)
873{
874 gfs2_rgrp_verify(rgd);
875 sc->sc_total += rgd->rd_data;
876 sc->sc_free += rgd->rd_free;
877 sc->sc_dinodes += rgd->rd_dinodes;
878 return 0;
879}
880
881/**
882 * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
883 * @sdp: the filesystem
884 * @sc: the sc info that will be returned
885 *
886 * Any error (other than a signal) will cause this routine to fall back
887 * to the synchronous version.
888 *
889 * FIXME: This really shouldn't busy wait like this.
890 *
891 * Returns: errno
892 */
893
894static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
895{
896 struct gfs2_holder ri_gh;
897 struct gfs2_rgrpd *rgd_next;
898 struct gfs2_holder *gha, *gh;
899 unsigned int slots = 64;
900 unsigned int x;
901 int done;
902 int error = 0, err;
903
904 memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
905 gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
906 if (!gha)
907 return -ENOMEM;
908
909 error = gfs2_rindex_hold(sdp, &ri_gh);
910 if (error)
911 goto out;
912
913 rgd_next = gfs2_rgrpd_get_first(sdp);
914
915 for (;;) {
916 done = 1;
917
918 for (x = 0; x < slots; x++) {
919 gh = gha + x;
920
921 if (gh->gh_gl && gfs2_glock_poll(gh)) {
922 err = gfs2_glock_wait(gh);
923 if (err) {
924 gfs2_holder_uninit(gh);
925 error = err;
926 } else {
927 if (!error)
928 error = statfs_slow_fill(
929 gh->gh_gl->gl_object, sc);
930 gfs2_glock_dq_uninit(gh);
931 }
932 }
933
934 if (gh->gh_gl)
935 done = 0;
936 else if (rgd_next && !error) {
937 error = gfs2_glock_nq_init(rgd_next->rd_gl,
938 LM_ST_SHARED,
939 GL_ASYNC,
940 gh);
941 rgd_next = gfs2_rgrpd_get_next(rgd_next);
942 done = 0;
943 }
944
945 if (signal_pending(current))
946 error = -ERESTARTSYS;
947 }
948
949 if (done)
950 break;
951
952 yield();
953 }
954
955 gfs2_glock_dq_uninit(&ri_gh);
956
957out:
958 kfree(gha);
959 return error;
960}
961
962/**
963 * gfs2_statfs_i - Do a statfs
964 * @sdp: the filesystem
965 * @sg: the sg structure
966 *
967 * Returns: errno
968 */
969
970static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
971{
972 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
973 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
974
975 spin_lock(&sdp->sd_statfs_spin);
976
977 *sc = *m_sc;
978 sc->sc_total += l_sc->sc_total;
979 sc->sc_free += l_sc->sc_free;
980 sc->sc_dinodes += l_sc->sc_dinodes;
981
982 spin_unlock(&sdp->sd_statfs_spin);
983
984 if (sc->sc_free < 0)
985 sc->sc_free = 0;
986 if (sc->sc_free > sc->sc_total)
987 sc->sc_free = sc->sc_total;
988 if (sc->sc_dinodes < 0)
989 sc->sc_dinodes = 0;
990
991 return 0;
992}
993
994/**
995 * gfs2_statfs - Gather and return stats about the filesystem
996 * @sb: The superblock
997 * @statfsbuf: The buffer
998 *
999 * Returns: 0 on success or error code
1000 */
1001
1002static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1003{
1004 struct super_block *sb = dentry->d_inode->i_sb;
1005 struct gfs2_sbd *sdp = sb->s_fs_info;
1006 struct gfs2_statfs_change_host sc;
1007 int error;
1008
1009 if (gfs2_tune_get(sdp, gt_statfs_slow))
1010 error = gfs2_statfs_slow(sdp, &sc);
1011 else
1012 error = gfs2_statfs_i(sdp, &sc);
1013
1014 if (error)
1015 return error;
1016
1017 buf->f_type = GFS2_MAGIC;
1018 buf->f_bsize = sdp->sd_sb.sb_bsize;
1019 buf->f_blocks = sc.sc_total;
1020 buf->f_bfree = sc.sc_free;
1021 buf->f_bavail = sc.sc_free;
1022 buf->f_files = sc.sc_dinodes + sc.sc_free;
1023 buf->f_ffree = sc.sc_free;
1024 buf->f_namelen = GFS2_FNAMESIZE;
1025
1026 return 0;
1027}
1028
1029/**
1030 * gfs2_remount_fs - called when the FS is remounted
1031 * @sb: the filesystem
1032 * @flags: the remount flags
1033 * @data: extra data passed in (not used right now)
1034 *
1035 * Returns: errno
1036 */
1037
1038static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
1039{
1040 struct gfs2_sbd *sdp = sb->s_fs_info;
1041 struct gfs2_args args = sdp->sd_args; /* Default to current settings */
1042 struct gfs2_tune *gt = &sdp->sd_tune;
1043 int error;
1044
1045 spin_lock(&gt->gt_spin);
1046 args.ar_commit = gt->gt_log_flush_secs;
1047 spin_unlock(&gt->gt_spin);
1048 error = gfs2_mount_args(sdp, &args, data);
1049 if (error)
1050 return error;
1051
1052 /* Not allowed to change locking details */
1053 if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
1054 strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
1055 strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
1056 return -EINVAL;
1057
1058 /* Some flags must not be changed */
1059 if (args_neq(&args, &sdp->sd_args, spectator) ||
1060 args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
1061 args_neq(&args, &sdp->sd_args, localflocks) ||
1062 args_neq(&args, &sdp->sd_args, localcaching) ||
1063 args_neq(&args, &sdp->sd_args, meta))
1064 return -EINVAL;
1065
1066 if (sdp->sd_args.ar_spectator)
1067 *flags |= MS_RDONLY;
1068
1069 if ((sb->s_flags ^ *flags) & MS_RDONLY) {
1070 if (*flags & MS_RDONLY)
1071 error = gfs2_make_fs_ro(sdp);
1072 else
1073 error = gfs2_make_fs_rw(sdp);
1074 if (error)
1075 return error;
1076 }
1077
1078 sdp->sd_args = args;
1079 if (sdp->sd_args.ar_posix_acl)
1080 sb->s_flags |= MS_POSIXACL;
1081 else
1082 sb->s_flags &= ~MS_POSIXACL;
1083 spin_lock(&gt->gt_spin);
1084 gt->gt_log_flush_secs = args.ar_commit;
1085 spin_unlock(&gt->gt_spin);
1086
1087 return 0;
1088}
1089
1090/**
1091 * gfs2_drop_inode - Drop an inode (test for remote unlink)
1092 * @inode: The inode to drop
1093 *
1094 * If we've received a callback on an iopen lock then its because a
1095 * remote node tried to deallocate the inode but failed due to this node
1096 * still having the inode open. Here we mark the link count zero
1097 * since we know that it must have reached zero if the GLF_DEMOTE flag
1098 * is set on the iopen glock. If we didn't do a disk read since the
1099 * remote node removed the final link then we might otherwise miss
1100 * this event. This check ensures that this node will deallocate the
1101 * inode's blocks, or alternatively pass the baton on to another
1102 * node for later deallocation.
1103 */
1104
1105static void gfs2_drop_inode(struct inode *inode)
1106{
1107 struct gfs2_inode *ip = GFS2_I(inode);
1108
1109 if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
1110 struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
1111 if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
1112 clear_nlink(inode);
1113 }
1114 generic_drop_inode(inode);
1115}
1116
1117/**
1118 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
1119 * @inode: The VFS inode
1120 *
1121 */
1122
1123static void gfs2_clear_inode(struct inode *inode)
1124{
1125 struct gfs2_inode *ip = GFS2_I(inode);
1126
1127 /* This tells us its a "real" inode and not one which only
1128 * serves to contain an address space (see rgrp.c, meta_io.c)
1129 * which therefore doesn't have its own glocks.
1130 */
1131 if (test_bit(GIF_USER, &ip->i_flags)) {
1132 ip->i_gl->gl_object = NULL;
1133 gfs2_glock_put(ip->i_gl);
1134 ip->i_gl = NULL;
1135 if (ip->i_iopen_gh.gh_gl) {
1136 ip->i_iopen_gh.gh_gl->gl_object = NULL;
1137 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
1138 }
1139 }
1140}
1141
1142static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
1143{
1144 do {
1145 if (d1 == d2)
1146 return 1;
1147 d1 = d1->d_parent;
1148 } while (!IS_ROOT(d1));
1149 return 0;
1150}
1151
1152/**
1153 * gfs2_show_options - Show mount options for /proc/mounts
1154 * @s: seq_file structure
1155 * @mnt: vfsmount
1156 *
1157 * Returns: 0 on success or error code
1158 */
1159
1160static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1161{
1162 struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
1163 struct gfs2_args *args = &sdp->sd_args;
1164 int lfsecs;
1165
1166 if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
1167 seq_printf(s, ",meta");
1168 if (args->ar_lockproto[0])
1169 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
1170 if (args->ar_locktable[0])
1171 seq_printf(s, ",locktable=%s", args->ar_locktable);
1172 if (args->ar_hostdata[0])
1173 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
1174 if (args->ar_spectator)
1175 seq_printf(s, ",spectator");
1176 if (args->ar_ignore_local_fs)
1177 seq_printf(s, ",ignore_local_fs");
1178 if (args->ar_localflocks)
1179 seq_printf(s, ",localflocks");
1180 if (args->ar_localcaching)
1181 seq_printf(s, ",localcaching");
1182 if (args->ar_debug)
1183 seq_printf(s, ",debug");
1184 if (args->ar_upgrade)
1185 seq_printf(s, ",upgrade");
1186 if (args->ar_posix_acl)
1187 seq_printf(s, ",acl");
1188 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
1189 char *state;
1190 switch (args->ar_quota) {
1191 case GFS2_QUOTA_OFF:
1192 state = "off";
1193 break;
1194 case GFS2_QUOTA_ACCOUNT:
1195 state = "account";
1196 break;
1197 case GFS2_QUOTA_ON:
1198 state = "on";
1199 break;
1200 default:
1201 state = "unknown";
1202 break;
1203 }
1204 seq_printf(s, ",quota=%s", state);
1205 }
1206 if (args->ar_suiddir)
1207 seq_printf(s, ",suiddir");
1208 if (args->ar_data != GFS2_DATA_DEFAULT) {
1209 char *state;
1210 switch (args->ar_data) {
1211 case GFS2_DATA_WRITEBACK:
1212 state = "writeback";
1213 break;
1214 case GFS2_DATA_ORDERED:
1215 state = "ordered";
1216 break;
1217 default:
1218 state = "unknown";
1219 break;
1220 }
1221 seq_printf(s, ",data=%s", state);
1222 }
1223 if (args->ar_discard)
1224 seq_printf(s, ",discard");
1225 lfsecs = sdp->sd_tune.gt_log_flush_secs;
1226 if (lfsecs != 60)
1227 seq_printf(s, ",commit=%d", lfsecs);
1228 return 0;
1229}
1230
1231/*
1232 * We have to (at the moment) hold the inodes main lock to cover
1233 * the gap between unlocking the shared lock on the iopen lock and
1234 * taking the exclusive lock. I'd rather do a shared -> exclusive
1235 * conversion on the iopen lock, but we can change that later. This
1236 * is safe, just less efficient.
1237 */
1238
1239static void gfs2_delete_inode(struct inode *inode)
1240{
1241 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
1242 struct gfs2_inode *ip = GFS2_I(inode);
1243 struct gfs2_holder gh;
1244 int error;
1245
1246 if (!test_bit(GIF_USER, &ip->i_flags))
1247 goto out;
1248
1249 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1250 if (unlikely(error)) {
1251 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
1252 goto out;
1253 }
1254
1255 gfs2_glock_dq_wait(&ip->i_iopen_gh);
1256 gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
1257 error = gfs2_glock_nq(&ip->i_iopen_gh);
1258 if (error)
1259 goto out_truncate;
1260
1261 if (S_ISDIR(inode->i_mode) &&
1262 (ip->i_diskflags & GFS2_DIF_EXHASH)) {
1263 error = gfs2_dir_exhash_dealloc(ip);
1264 if (error)
1265 goto out_unlock;
1266 }
1267
1268 if (ip->i_eattr) {
1269 error = gfs2_ea_dealloc(ip);
1270 if (error)
1271 goto out_unlock;
1272 }
1273
1274 if (!gfs2_is_stuffed(ip)) {
1275 error = gfs2_file_dealloc(ip);
1276 if (error)
1277 goto out_unlock;
1278 }
1279
1280 error = gfs2_dinode_dealloc(ip);
1281 if (error)
1282 goto out_unlock;
1283
1284out_truncate:
1285 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
1286 if (error)
1287 goto out_unlock;
1288 /* Needs to be done before glock release & also in a transaction */
1289 truncate_inode_pages(&inode->i_data, 0);
1290 gfs2_trans_end(sdp);
1291
1292out_unlock:
1293 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
1294 gfs2_glock_dq(&ip->i_iopen_gh);
1295 gfs2_holder_uninit(&ip->i_iopen_gh);
1296 gfs2_glock_dq_uninit(&gh);
1297 if (error && error != GLR_TRYFAILED && error != -EROFS)
1298 fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
1299out:
1300 truncate_inode_pages(&inode->i_data, 0);
1301 clear_inode(inode);
1302}
1303
1304static struct inode *gfs2_alloc_inode(struct super_block *sb)
1305{
1306 struct gfs2_inode *ip;
1307
1308 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
1309 if (ip) {
1310 ip->i_flags = 0;
1311 ip->i_gl = NULL;
1312 }
1313 return &ip->i_inode;
1314}
1315
1316static void gfs2_destroy_inode(struct inode *inode)
1317{
1318 kmem_cache_free(gfs2_inode_cachep, inode);
1319}
1320
1321const struct super_operations gfs2_super_ops = {
1322 .alloc_inode = gfs2_alloc_inode,
1323 .destroy_inode = gfs2_destroy_inode,
1324 .write_inode = gfs2_write_inode,
1325 .delete_inode = gfs2_delete_inode,
1326 .put_super = gfs2_put_super,
1327 .write_super = gfs2_write_super,
1328 .sync_fs = gfs2_sync_fs,
1329 .freeze_fs = gfs2_freeze,
1330 .unfreeze_fs = gfs2_unfreeze,
1331 .statfs = gfs2_statfs,
1332 .remount_fs = gfs2_remount_fs,
1333 .clear_inode = gfs2_clear_inode,
1334 .drop_inode = gfs2_drop_inode,
1335 .show_options = gfs2_show_options,
1336};
1337