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 if (current->flags & PF_MEMALLOC)
52 gfs2_log_flush_glock(ip->i_gl);
58 * gfs2_put_super - Unmount the filesystem
59 * @sb: The VFS superblock
63 static void gfs2_put_super(struct super_block *sb)
65 struct gfs2_sbd *sdp = get_v2sdp(sb);
71 /* Unfreeze the filesystem, if we need to */
73 mutex_lock(&sdp->sd_freeze_lock);
74 if (sdp->sd_freeze_count)
75 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
76 mutex_unlock(&sdp->sd_freeze_lock);
78 kthread_stop(sdp->sd_inoded_process);
79 kthread_stop(sdp->sd_quotad_process);
80 kthread_stop(sdp->sd_logd_process);
81 kthread_stop(sdp->sd_recoverd_process);
82 while (sdp->sd_glockd_num--)
83 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
84 kthread_stop(sdp->sd_scand_process);
86 if (!(sb->s_flags & MS_RDONLY)) {
87 error = gfs2_make_fs_ro(sdp);
92 /* At this point, we're through modifying the disk */
96 iput(sdp->sd_master_dir);
98 iput(sdp->sd_inum_inode);
99 iput(sdp->sd_statfs_inode);
100 iput(sdp->sd_rindex);
101 iput(sdp->sd_quota_inode);
102 iput(sdp->sd_root_dir);
104 gfs2_glock_put(sdp->sd_rename_gl);
105 gfs2_glock_put(sdp->sd_trans_gl);
107 if (!sdp->sd_args.ar_spectator) {
108 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
109 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
110 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
111 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
112 gfs2_glock_dq_uninit(&sdp->sd_ut_gh);
113 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
114 iput(sdp->sd_ir_inode);
115 iput(sdp->sd_sc_inode);
116 iput(sdp->sd_ut_inode);
117 iput(sdp->sd_qc_inode);
120 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
122 gfs2_clear_rgrpd(sdp);
123 gfs2_jindex_free(sdp);
125 /* Take apart glock structures and buffer lists */
126 gfs2_gl_hash_clear(sdp, WAIT);
128 /* Unmount the locking protocol */
129 gfs2_lm_unmount(sdp);
131 /* At this point, we're through participating in the lockspace */
133 gfs2_sys_fs_del(sdp);
135 /* Get rid of any extra inodes */
136 while (invalidate_inodes(sb))
145 * gfs2_write_super - disk commit all incore transactions
146 * @sb: the filesystem
148 * This function is called every time sync(2) is called.
149 * After this exits, all dirty buffers and synced.
152 static void gfs2_write_super(struct super_block *sb)
154 struct gfs2_sbd *sdp = get_v2sdp(sb);
159 * gfs2_write_super_lockfs - prevent further writes to the filesystem
160 * @sb: the VFS structure for the filesystem
164 static void gfs2_write_super_lockfs(struct super_block *sb)
166 struct gfs2_sbd *sdp = get_v2sdp(sb);
170 error = gfs2_freeze_fs(sdp);
176 fs_err(sdp, "waiting for recovery before freeze\n");
180 fs_err(sdp, "error freezing FS: %d\n", error);
184 fs_err(sdp, "retrying...\n");
190 * gfs2_unlockfs - reallow writes to the filesystem
191 * @sb: the VFS structure for the filesystem
195 static void gfs2_unlockfs(struct super_block *sb)
197 struct gfs2_sbd *sdp = get_v2sdp(sb);
198 gfs2_unfreeze_fs(sdp);
202 * gfs2_statfs - Gather and return stats about the filesystem
203 * @sb: The superblock
204 * @statfsbuf: The buffer
206 * Returns: 0 on success or error code
209 static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf)
211 struct gfs2_sbd *sdp = get_v2sdp(sb);
212 struct gfs2_statfs_change sc;
215 if (gfs2_tune_get(sdp, gt_statfs_slow))
216 error = gfs2_statfs_slow(sdp, &sc);
218 error = gfs2_statfs_i(sdp, &sc);
223 memset(buf, 0, sizeof(struct kstatfs));
225 buf->f_type = GFS2_MAGIC;
226 buf->f_bsize = sdp->sd_sb.sb_bsize;
227 buf->f_blocks = sc.sc_total;
228 buf->f_bfree = sc.sc_free;
229 buf->f_bavail = sc.sc_free;
230 buf->f_files = sc.sc_dinodes + sc.sc_free;
231 buf->f_ffree = sc.sc_free;
232 buf->f_namelen = GFS2_FNAMESIZE;
238 * gfs2_remount_fs - called when the FS is remounted
239 * @sb: the filesystem
240 * @flags: the remount flags
241 * @data: extra data passed in (not used right now)
246 static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
248 struct gfs2_sbd *sdp = get_v2sdp(sb);
251 error = gfs2_mount_args(sdp, data, 1);
255 if (sdp->sd_args.ar_spectator)
258 if (*flags & MS_RDONLY) {
259 if (!(sb->s_flags & MS_RDONLY))
260 error = gfs2_make_fs_ro(sdp);
261 } else if (!(*flags & MS_RDONLY) &&
262 (sb->s_flags & MS_RDONLY)) {
263 error = gfs2_make_fs_rw(sdp);
267 if (*flags & (MS_NOATIME | MS_NODIRATIME))
268 set_bit(SDF_NOATIME, &sdp->sd_flags);
270 clear_bit(SDF_NOATIME, &sdp->sd_flags);
272 /* Don't let the VFS update atimes. GFS2 handles this itself. */
273 *flags |= MS_NOATIME | MS_NODIRATIME;
279 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
280 * @inode: The VFS inode
284 static void gfs2_clear_inode(struct inode *inode)
286 struct gfs2_inode *ip = get_v2ip(inode);
289 spin_lock(&ip->i_spin);
291 set_v2ip(inode, NULL);
292 spin_unlock(&ip->i_spin);
294 gfs2_glock_schedule_for_reclaim(ip->i_gl);
300 * gfs2_show_options - Show mount options for /proc/mounts
301 * @s: seq_file structure
304 * Returns: 0 on success or error code
307 static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
309 struct gfs2_sbd *sdp = get_v2sdp(mnt->mnt_sb);
310 struct gfs2_args *args = &sdp->sd_args;
312 if (args->ar_lockproto[0])
313 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
314 if (args->ar_locktable[0])
315 seq_printf(s, ",locktable=%s", args->ar_locktable);
316 if (args->ar_hostdata[0])
317 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
318 if (args->ar_spectator)
319 seq_printf(s, ",spectator");
320 if (args->ar_ignore_local_fs)
321 seq_printf(s, ",ignore_local_fs");
322 if (args->ar_localflocks)
323 seq_printf(s, ",localflocks");
324 if (args->ar_localcaching)
325 seq_printf(s, ",localcaching");
327 seq_printf(s, ",debug");
328 if (args->ar_upgrade)
329 seq_printf(s, ",upgrade");
330 if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT)
331 seq_printf(s, ",num_glockd=%u", args->ar_num_glockd);
332 if (args->ar_posix_acl)
333 seq_printf(s, ",acl");
334 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
336 switch (args->ar_quota) {
340 case GFS2_QUOTA_ACCOUNT:
350 seq_printf(s, ",quota=%s", state);
352 if (args->ar_suiddir)
353 seq_printf(s, ",suiddir");
354 if (args->ar_data != GFS2_DATA_DEFAULT) {
356 switch (args->ar_data) {
357 case GFS2_DATA_WRITEBACK:
360 case GFS2_DATA_ORDERED:
367 seq_printf(s, ",data=%s", state);
373 struct super_operations gfs2_super_ops = {
374 .write_inode = gfs2_write_inode,
375 .put_super = gfs2_put_super,
376 .write_super = gfs2_write_super,
377 .write_super_lockfs = gfs2_write_super_lockfs,
378 .unlockfs = gfs2_unlockfs,
379 .statfs = gfs2_statfs,
380 .remount_fs = gfs2_remount_fs,
381 .clear_inode = gfs2_clear_inode,
382 .show_options = gfs2_show_options,