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/statfs.h>
16 #include <linux/vmalloc.h>
17 #include <linux/seq_file.h>
18 #include <linux/mount.h>
19 #include <linux/kthread.h>
20 #include <linux/delay.h>
21 #include <linux/gfs2_ondisk.h>
24 #include "lm_interface.h"
31 #include "ops_super.h"
41 * gfs2_write_inode - Make sure the inode is stable on the disk
43 * @sync: synchronous write flag
48 static int gfs2_write_inode(struct inode *inode, int sync)
50 struct gfs2_inode *ip = inode->u.generic_ip;
52 if (current->flags & PF_MEMALLOC)
55 gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl);
61 * gfs2_put_super - Unmount the filesystem
62 * @sb: The VFS superblock
66 static void gfs2_put_super(struct super_block *sb)
68 struct gfs2_sbd *sdp = sb->s_fs_info;
74 /* Unfreeze the filesystem, if we need to */
76 mutex_lock(&sdp->sd_freeze_lock);
77 if (sdp->sd_freeze_count)
78 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
79 mutex_unlock(&sdp->sd_freeze_lock);
81 kthread_stop(sdp->sd_inoded_process);
82 kthread_stop(sdp->sd_quotad_process);
83 kthread_stop(sdp->sd_logd_process);
84 kthread_stop(sdp->sd_recoverd_process);
85 while (sdp->sd_glockd_num--)
86 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
87 kthread_stop(sdp->sd_scand_process);
89 if (!(sb->s_flags & MS_RDONLY)) {
90 error = gfs2_make_fs_ro(sdp);
94 /* At this point, we're through modifying the disk */
98 iput(sdp->sd_master_dir);
100 iput(sdp->sd_inum_inode);
101 iput(sdp->sd_statfs_inode);
102 iput(sdp->sd_rindex);
103 iput(sdp->sd_quota_inode);
105 gfs2_glock_put(sdp->sd_rename_gl);
106 gfs2_glock_put(sdp->sd_trans_gl);
108 if (!sdp->sd_args.ar_spectator) {
109 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
110 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
111 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
112 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
113 gfs2_glock_dq_uninit(&sdp->sd_ut_gh);
114 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
115 iput(sdp->sd_ir_inode);
116 iput(sdp->sd_sc_inode);
117 iput(sdp->sd_ut_inode);
118 iput(sdp->sd_qc_inode);
121 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
122 gfs2_clear_rgrpd(sdp);
123 gfs2_jindex_free(sdp);
124 /* Take apart glock structures and buffer lists */
125 gfs2_gl_hash_clear(sdp, WAIT);
126 /* Unmount the locking protocol */
127 gfs2_lm_unmount(sdp);
129 /* At this point, we're through participating in the lockspace */
130 gfs2_sys_fs_del(sdp);
132 sb->s_fs_info = NULL;
136 * gfs2_write_super - disk commit all incore transactions
137 * @sb: the filesystem
139 * This function is called every time sync(2) is called.
140 * After this exits, all dirty buffers are synced.
143 static void gfs2_write_super(struct super_block *sb)
145 struct gfs2_sbd *sdp = sb->s_fs_info;
146 gfs2_log_flush(sdp, NULL);
150 * gfs2_write_super_lockfs - prevent further writes to the filesystem
151 * @sb: the VFS structure for the filesystem
155 static void gfs2_write_super_lockfs(struct super_block *sb)
157 struct gfs2_sbd *sdp = sb->s_fs_info;
161 error = gfs2_freeze_fs(sdp);
167 fs_err(sdp, "waiting for recovery before freeze\n");
171 fs_err(sdp, "error freezing FS: %d\n", error);
175 fs_err(sdp, "retrying...\n");
181 * gfs2_unlockfs - reallow writes to the filesystem
182 * @sb: the VFS structure for the filesystem
186 static void gfs2_unlockfs(struct super_block *sb)
188 struct gfs2_sbd *sdp = sb->s_fs_info;
189 gfs2_unfreeze_fs(sdp);
193 * gfs2_statfs - Gather and return stats about the filesystem
194 * @sb: The superblock
195 * @statfsbuf: The buffer
197 * Returns: 0 on success or error code
200 static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf)
202 struct gfs2_sbd *sdp = sb->s_fs_info;
203 struct gfs2_statfs_change sc;
206 if (gfs2_tune_get(sdp, gt_statfs_slow))
207 error = gfs2_statfs_slow(sdp, &sc);
209 error = gfs2_statfs_i(sdp, &sc);
214 memset(buf, 0, sizeof(struct kstatfs));
216 buf->f_type = GFS2_MAGIC;
217 buf->f_bsize = sdp->sd_sb.sb_bsize;
218 buf->f_blocks = sc.sc_total;
219 buf->f_bfree = sc.sc_free;
220 buf->f_bavail = sc.sc_free;
221 buf->f_files = sc.sc_dinodes + sc.sc_free;
222 buf->f_ffree = sc.sc_free;
223 buf->f_namelen = GFS2_FNAMESIZE;
229 * gfs2_remount_fs - called when the FS is remounted
230 * @sb: the filesystem
231 * @flags: the remount flags
232 * @data: extra data passed in (not used right now)
237 static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
239 struct gfs2_sbd *sdp = sb->s_fs_info;
242 error = gfs2_mount_args(sdp, data, 1);
246 if (sdp->sd_args.ar_spectator)
249 if (*flags & MS_RDONLY) {
250 if (!(sb->s_flags & MS_RDONLY))
251 error = gfs2_make_fs_ro(sdp);
252 } else if (!(*flags & MS_RDONLY) &&
253 (sb->s_flags & MS_RDONLY)) {
254 error = gfs2_make_fs_rw(sdp);
258 if (*flags & (MS_NOATIME | MS_NODIRATIME))
259 set_bit(SDF_NOATIME, &sdp->sd_flags);
261 clear_bit(SDF_NOATIME, &sdp->sd_flags);
263 /* Don't let the VFS update atimes. GFS2 handles this itself. */
264 *flags |= MS_NOATIME | MS_NODIRATIME;
270 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
271 * @inode: The VFS inode
275 static void gfs2_clear_inode(struct inode *inode)
277 struct gfs2_inode *ip = inode->u.generic_ip;
280 spin_lock(&ip->i_spin);
282 inode->u.generic_ip = NULL;
283 spin_unlock(&ip->i_spin);
285 gfs2_glock_schedule_for_reclaim(ip->i_gl);
291 * gfs2_show_options - Show mount options for /proc/mounts
292 * @s: seq_file structure
295 * Returns: 0 on success or error code
298 static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
300 struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
301 struct gfs2_args *args = &sdp->sd_args;
303 if (args->ar_lockproto[0])
304 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
305 if (args->ar_locktable[0])
306 seq_printf(s, ",locktable=%s", args->ar_locktable);
307 if (args->ar_hostdata[0])
308 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
309 if (args->ar_spectator)
310 seq_printf(s, ",spectator");
311 if (args->ar_ignore_local_fs)
312 seq_printf(s, ",ignore_local_fs");
313 if (args->ar_localflocks)
314 seq_printf(s, ",localflocks");
315 if (args->ar_localcaching)
316 seq_printf(s, ",localcaching");
318 seq_printf(s, ",debug");
319 if (args->ar_upgrade)
320 seq_printf(s, ",upgrade");
321 if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT)
322 seq_printf(s, ",num_glockd=%u", args->ar_num_glockd);
323 if (args->ar_posix_acl)
324 seq_printf(s, ",acl");
325 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
327 switch (args->ar_quota) {
331 case GFS2_QUOTA_ACCOUNT:
341 seq_printf(s, ",quota=%s", state);
343 if (args->ar_suiddir)
344 seq_printf(s, ",suiddir");
345 if (args->ar_data != GFS2_DATA_DEFAULT) {
347 switch (args->ar_data) {
348 case GFS2_DATA_WRITEBACK:
351 case GFS2_DATA_ORDERED:
358 seq_printf(s, ",data=%s", state);
364 struct super_operations gfs2_super_ops = {
365 .write_inode = gfs2_write_inode,
366 .put_super = gfs2_put_super,
367 .write_super = gfs2_write_super,
368 .write_super_lockfs = gfs2_write_super_lockfs,
369 .unlockfs = gfs2_unlockfs,
370 .statfs = gfs2_statfs,
371 .remount_fs = gfs2_remount_fs,
372 .clear_inode = gfs2_clear_inode,
373 .show_options = gfs2_show_options,