2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
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 v.2.
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/vmalloc.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>
21 #include <asm/semaphore.h>
29 #include "ops_super.h"
38 * gfs2_write_inode - Make sure the inode is stable on the disk
40 * @sync: synchronous write flag
45 static int gfs2_write_inode(struct inode *inode, int sync)
47 struct gfs2_inode *ip = get_v2ip(inode);
49 atomic_inc(&ip->i_sbd->sd_ops_super);
51 if (current->flags & PF_MEMALLOC)
54 gfs2_log_flush_glock(ip->i_gl);
60 * gfs2_put_super - Unmount the filesystem
61 * @sb: The VFS superblock
65 static void gfs2_put_super(struct super_block *sb)
67 struct gfs2_sbd *sdp = get_v2sdp(sb);
73 atomic_inc(&sdp->sd_ops_super);
75 /* Unfreeze the filesystem, if we need to */
77 mutex_lock(&sdp->sd_freeze_lock);
78 if (sdp->sd_freeze_count)
79 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
80 mutex_unlock(&sdp->sd_freeze_lock);
82 kthread_stop(sdp->sd_inoded_process);
83 kthread_stop(sdp->sd_quotad_process);
84 kthread_stop(sdp->sd_logd_process);
85 kthread_stop(sdp->sd_recoverd_process);
86 while (sdp->sd_glockd_num--)
87 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
88 kthread_stop(sdp->sd_scand_process);
90 if (!(sb->s_flags & MS_RDONLY)) {
91 error = gfs2_make_fs_ro(sdp);
96 /* At this point, we're through modifying the disk */
100 iput(sdp->sd_master_dir);
101 iput(sdp->sd_jindex);
102 iput(sdp->sd_inum_inode);
103 iput(sdp->sd_statfs_inode);
104 iput(sdp->sd_rindex);
105 iput(sdp->sd_quota_inode);
106 iput(sdp->sd_root_dir);
108 gfs2_glock_put(sdp->sd_rename_gl);
109 gfs2_glock_put(sdp->sd_trans_gl);
111 if (!sdp->sd_args.ar_spectator) {
112 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
113 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
114 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
115 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
116 gfs2_glock_dq_uninit(&sdp->sd_ut_gh);
117 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
118 iput(sdp->sd_ir_inode);
119 iput(sdp->sd_sc_inode);
120 iput(sdp->sd_ut_inode);
121 iput(sdp->sd_qc_inode);
124 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
126 gfs2_clear_rgrpd(sdp);
127 gfs2_jindex_free(sdp);
129 /* Take apart glock structures and buffer lists */
130 gfs2_gl_hash_clear(sdp, WAIT);
132 /* Unmount the locking protocol */
133 gfs2_lm_unmount(sdp);
135 /* At this point, we're through participating in the lockspace */
137 gfs2_sys_fs_del(sdp);
139 /* Get rid of any extra inodes */
140 while (invalidate_inodes(sb))
149 * gfs2_write_super - disk commit all incore transactions
150 * @sb: the filesystem
152 * This function is called every time sync(2) is called.
153 * After this exits, all dirty buffers and synced.
156 static void gfs2_write_super(struct super_block *sb)
158 struct gfs2_sbd *sdp = get_v2sdp(sb);
159 atomic_inc(&sdp->sd_ops_super);
164 * gfs2_write_super_lockfs - prevent further writes to the filesystem
165 * @sb: the VFS structure for the filesystem
169 static void gfs2_write_super_lockfs(struct super_block *sb)
171 struct gfs2_sbd *sdp = get_v2sdp(sb);
174 atomic_inc(&sdp->sd_ops_super);
177 error = gfs2_freeze_fs(sdp);
183 fs_err(sdp, "waiting for recovery before freeze\n");
187 fs_err(sdp, "error freezing FS: %d\n", error);
191 fs_err(sdp, "retrying...\n");
197 * gfs2_unlockfs - reallow writes to the filesystem
198 * @sb: the VFS structure for the filesystem
202 static void gfs2_unlockfs(struct super_block *sb)
204 struct gfs2_sbd *sdp = get_v2sdp(sb);
206 atomic_inc(&sdp->sd_ops_super);
207 gfs2_unfreeze_fs(sdp);
211 * gfs2_statfs - Gather and return stats about the filesystem
212 * @sb: The superblock
213 * @statfsbuf: The buffer
215 * Returns: 0 on success or error code
218 static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf)
220 struct gfs2_sbd *sdp = get_v2sdp(sb);
221 struct gfs2_statfs_change sc;
224 atomic_inc(&sdp->sd_ops_super);
226 if (gfs2_tune_get(sdp, gt_statfs_slow))
227 error = gfs2_statfs_slow(sdp, &sc);
229 error = gfs2_statfs_i(sdp, &sc);
234 memset(buf, 0, sizeof(struct kstatfs));
236 buf->f_type = GFS2_MAGIC;
237 buf->f_bsize = sdp->sd_sb.sb_bsize;
238 buf->f_blocks = sc.sc_total;
239 buf->f_bfree = sc.sc_free;
240 buf->f_bavail = sc.sc_free;
241 buf->f_files = sc.sc_dinodes + sc.sc_free;
242 buf->f_ffree = sc.sc_free;
243 buf->f_namelen = GFS2_FNAMESIZE;
249 * gfs2_remount_fs - called when the FS is remounted
250 * @sb: the filesystem
251 * @flags: the remount flags
252 * @data: extra data passed in (not used right now)
257 static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
259 struct gfs2_sbd *sdp = get_v2sdp(sb);
262 atomic_inc(&sdp->sd_ops_super);
264 error = gfs2_mount_args(sdp, data, 1);
268 if (sdp->sd_args.ar_spectator)
271 if (*flags & MS_RDONLY) {
272 if (!(sb->s_flags & MS_RDONLY))
273 error = gfs2_make_fs_ro(sdp);
274 } else if (!(*flags & MS_RDONLY) &&
275 (sb->s_flags & MS_RDONLY)) {
276 error = gfs2_make_fs_rw(sdp);
280 if (*flags & (MS_NOATIME | MS_NODIRATIME))
281 set_bit(SDF_NOATIME, &sdp->sd_flags);
283 clear_bit(SDF_NOATIME, &sdp->sd_flags);
285 /* Don't let the VFS update atimes. GFS2 handles this itself. */
286 *flags |= MS_NOATIME | MS_NODIRATIME;
292 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
293 * @inode: The VFS inode
297 static void gfs2_clear_inode(struct inode *inode)
299 struct gfs2_inode *ip = get_v2ip(inode);
301 atomic_inc(&get_v2sdp(inode->i_sb)->sd_ops_super);
304 spin_lock(&ip->i_spin);
306 set_v2ip(inode, NULL);
307 spin_unlock(&ip->i_spin);
309 gfs2_glock_schedule_for_reclaim(ip->i_gl);
315 * gfs2_show_options - Show mount options for /proc/mounts
316 * @s: seq_file structure
319 * Returns: 0 on success or error code
322 static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
324 struct gfs2_sbd *sdp = get_v2sdp(mnt->mnt_sb);
325 struct gfs2_args *args = &sdp->sd_args;
327 atomic_inc(&sdp->sd_ops_super);
329 if (args->ar_lockproto[0])
330 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
331 if (args->ar_locktable[0])
332 seq_printf(s, ",locktable=%s", args->ar_locktable);
333 if (args->ar_hostdata[0])
334 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
335 if (args->ar_spectator)
336 seq_printf(s, ",spectator");
337 if (args->ar_ignore_local_fs)
338 seq_printf(s, ",ignore_local_fs");
339 if (args->ar_localflocks)
340 seq_printf(s, ",localflocks");
341 if (args->ar_localcaching)
342 seq_printf(s, ",localcaching");
344 seq_printf(s, ",debug");
345 if (args->ar_upgrade)
346 seq_printf(s, ",upgrade");
347 if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT)
348 seq_printf(s, ",num_glockd=%u", args->ar_num_glockd);
349 if (args->ar_posix_acl)
350 seq_printf(s, ",acl");
351 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
353 switch (args->ar_quota) {
357 case GFS2_QUOTA_ACCOUNT:
367 seq_printf(s, ",quota=%s", state);
369 if (args->ar_suiddir)
370 seq_printf(s, ",suiddir");
371 if (args->ar_data != GFS2_DATA_DEFAULT) {
373 switch (args->ar_data) {
374 case GFS2_DATA_WRITEBACK:
377 case GFS2_DATA_ORDERED:
384 seq_printf(s, ",data=%s", state);
390 struct super_operations gfs2_super_ops = {
391 .write_inode = gfs2_write_inode,
392 .put_super = gfs2_put_super,
393 .write_super = gfs2_write_super,
394 .write_super_lockfs = gfs2_write_super_lockfs,
395 .unlockfs = gfs2_unlockfs,
396 .statfs = gfs2_statfs,
397 .remount_fs = gfs2_remount_fs,
398 .clear_inode = gfs2_clear_inode,
399 .show_options = gfs2_show_options,