2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 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 version 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/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/lm_interface.h>
31 #include "ops_super.h"
44 * gfs2_write_inode - Make sure the inode is stable on the disk
46 * @sync: synchronous write flag
51 static int gfs2_write_inode(struct inode
*inode
, int sync
)
53 struct gfs2_inode
*ip
= GFS2_I(inode
);
55 /* Check this is a "normal" inode */
56 if (inode
->i_private
) {
57 if (current
->flags
& PF_MEMALLOC
)
60 gfs2_log_flush(GFS2_SB(inode
), ip
->i_gl
);
67 * gfs2_put_super - Unmount the filesystem
68 * @sb: The VFS superblock
72 static void gfs2_put_super(struct super_block
*sb
)
74 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
80 if (!strncmp(sb
->s_type
->name
, "gfs2meta", 8))
81 return; /* Nothing to do */
83 /* Unfreeze the filesystem, if we need to */
85 mutex_lock(&sdp
->sd_freeze_lock
);
86 if (sdp
->sd_freeze_count
)
87 gfs2_glock_dq_uninit(&sdp
->sd_freeze_gh
);
88 mutex_unlock(&sdp
->sd_freeze_lock
);
90 kthread_stop(sdp
->sd_quotad_process
);
91 kthread_stop(sdp
->sd_logd_process
);
92 kthread_stop(sdp
->sd_recoverd_process
);
93 while (sdp
->sd_glockd_num
--)
94 kthread_stop(sdp
->sd_glockd_process
[sdp
->sd_glockd_num
]);
95 kthread_stop(sdp
->sd_scand_process
);
97 if (!(sb
->s_flags
& MS_RDONLY
)) {
98 error
= gfs2_make_fs_ro(sdp
);
102 /* At this point, we're through modifying the disk */
106 iput(sdp
->sd_master_dir
);
107 iput(sdp
->sd_jindex
);
108 iput(sdp
->sd_inum_inode
);
109 iput(sdp
->sd_statfs_inode
);
110 iput(sdp
->sd_rindex
);
111 iput(sdp
->sd_quota_inode
);
113 gfs2_glock_put(sdp
->sd_rename_gl
);
114 gfs2_glock_put(sdp
->sd_trans_gl
);
116 if (!sdp
->sd_args
.ar_spectator
) {
117 gfs2_glock_dq_uninit(&sdp
->sd_journal_gh
);
118 gfs2_glock_dq_uninit(&sdp
->sd_jinode_gh
);
119 gfs2_glock_dq_uninit(&sdp
->sd_ir_gh
);
120 gfs2_glock_dq_uninit(&sdp
->sd_sc_gh
);
121 gfs2_glock_dq_uninit(&sdp
->sd_qc_gh
);
122 iput(sdp
->sd_ir_inode
);
123 iput(sdp
->sd_sc_inode
);
124 iput(sdp
->sd_qc_inode
);
127 gfs2_glock_dq_uninit(&sdp
->sd_live_gh
);
128 gfs2_clear_rgrpd(sdp
);
129 gfs2_jindex_free(sdp
);
130 /* Take apart glock structures and buffer lists */
131 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 */
136 gfs2_sys_fs_del(sdp
);
142 * @sb: the superblock
146 static void gfs2_write_super(struct super_block
*sb
)
152 * gfs2_sync_fs - sync the filesystem
153 * @sb: the superblock
155 * Flushes the log to disk.
157 static int gfs2_sync_fs(struct super_block
*sb
, int wait
)
161 gfs2_log_flush(sb
->s_fs_info
, NULL
);
166 * gfs2_write_super_lockfs - prevent further writes to the filesystem
167 * @sb: the VFS structure for the filesystem
171 static void gfs2_write_super_lockfs(struct super_block
*sb
)
173 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
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 gfs2_unfreeze_fs(sb
->s_fs_info
);
208 * gfs2_statfs - Gather and return stats about the filesystem
209 * @sb: The superblock
210 * @statfsbuf: The buffer
212 * Returns: 0 on success or error code
215 static int gfs2_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
217 struct super_block
*sb
= dentry
->d_inode
->i_sb
;
218 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
219 struct gfs2_statfs_change_host sc
;
222 if (gfs2_tune_get(sdp
, gt_statfs_slow
))
223 error
= gfs2_statfs_slow(sdp
, &sc
);
225 error
= gfs2_statfs_i(sdp
, &sc
);
230 buf
->f_type
= GFS2_MAGIC
;
231 buf
->f_bsize
= sdp
->sd_sb
.sb_bsize
;
232 buf
->f_blocks
= sc
.sc_total
;
233 buf
->f_bfree
= sc
.sc_free
;
234 buf
->f_bavail
= sc
.sc_free
;
235 buf
->f_files
= sc
.sc_dinodes
+ sc
.sc_free
;
236 buf
->f_ffree
= sc
.sc_free
;
237 buf
->f_namelen
= GFS2_FNAMESIZE
;
243 * gfs2_remount_fs - called when the FS is remounted
244 * @sb: the filesystem
245 * @flags: the remount flags
246 * @data: extra data passed in (not used right now)
251 static int gfs2_remount_fs(struct super_block
*sb
, int *flags
, char *data
)
253 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
256 error
= gfs2_mount_args(sdp
, data
, 1);
260 if (sdp
->sd_args
.ar_spectator
)
263 if (*flags
& MS_RDONLY
) {
264 if (!(sb
->s_flags
& MS_RDONLY
))
265 error
= gfs2_make_fs_ro(sdp
);
266 } else if (!(*flags
& MS_RDONLY
) &&
267 (sb
->s_flags
& MS_RDONLY
)) {
268 error
= gfs2_make_fs_rw(sdp
);
272 if (*flags
& (MS_NOATIME
| MS_NODIRATIME
))
273 set_bit(SDF_NOATIME
, &sdp
->sd_flags
);
275 clear_bit(SDF_NOATIME
, &sdp
->sd_flags
);
277 /* Don't let the VFS update atimes. GFS2 handles this itself. */
278 *flags
|= MS_NOATIME
| MS_NODIRATIME
;
284 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
285 * @inode: The VFS inode
289 static void gfs2_clear_inode(struct inode
*inode
)
291 /* This tells us its a "real" inode and not one which only
292 * serves to contain an address space (see rgrp.c, meta_io.c)
293 * which therefore doesn't have its own glocks.
295 if (inode
->i_private
) {
296 struct gfs2_inode
*ip
= GFS2_I(inode
);
297 ip
->i_gl
->gl_object
= NULL
;
298 gfs2_glock_schedule_for_reclaim(ip
->i_gl
);
299 gfs2_glock_put(ip
->i_gl
);
301 if (ip
->i_iopen_gh
.gh_gl
)
302 gfs2_glock_dq_uninit(&ip
->i_iopen_gh
);
307 * gfs2_show_options - Show mount options for /proc/mounts
308 * @s: seq_file structure
311 * Returns: 0 on success or error code
314 static int gfs2_show_options(struct seq_file
*s
, struct vfsmount
*mnt
)
316 struct gfs2_sbd
*sdp
= mnt
->mnt_sb
->s_fs_info
;
317 struct gfs2_args
*args
= &sdp
->sd_args
;
319 if (args
->ar_lockproto
[0])
320 seq_printf(s
, ",lockproto=%s", args
->ar_lockproto
);
321 if (args
->ar_locktable
[0])
322 seq_printf(s
, ",locktable=%s", args
->ar_locktable
);
323 if (args
->ar_hostdata
[0])
324 seq_printf(s
, ",hostdata=%s", args
->ar_hostdata
);
325 if (args
->ar_spectator
)
326 seq_printf(s
, ",spectator");
327 if (args
->ar_ignore_local_fs
)
328 seq_printf(s
, ",ignore_local_fs");
329 if (args
->ar_localflocks
)
330 seq_printf(s
, ",localflocks");
331 if (args
->ar_localcaching
)
332 seq_printf(s
, ",localcaching");
334 seq_printf(s
, ",debug");
335 if (args
->ar_upgrade
)
336 seq_printf(s
, ",upgrade");
337 if (args
->ar_num_glockd
!= GFS2_GLOCKD_DEFAULT
)
338 seq_printf(s
, ",num_glockd=%u", args
->ar_num_glockd
);
339 if (args
->ar_posix_acl
)
340 seq_printf(s
, ",acl");
341 if (args
->ar_quota
!= GFS2_QUOTA_DEFAULT
) {
343 switch (args
->ar_quota
) {
347 case GFS2_QUOTA_ACCOUNT
:
357 seq_printf(s
, ",quota=%s", state
);
359 if (args
->ar_suiddir
)
360 seq_printf(s
, ",suiddir");
361 if (args
->ar_data
!= GFS2_DATA_DEFAULT
) {
363 switch (args
->ar_data
) {
364 case GFS2_DATA_WRITEBACK
:
367 case GFS2_DATA_ORDERED
:
374 seq_printf(s
, ",data=%s", state
);
381 * We have to (at the moment) hold the inodes main lock to cover
382 * the gap between unlocking the shared lock on the iopen lock and
383 * taking the exclusive lock. I'd rather do a shared -> exclusive
384 * conversion on the iopen lock, but we can change that later. This
385 * is safe, just less efficient.
387 static void gfs2_delete_inode(struct inode
*inode
)
389 struct gfs2_sbd
*sdp
= inode
->i_sb
->s_fs_info
;
390 struct gfs2_inode
*ip
= GFS2_I(inode
);
391 struct gfs2_holder gh
;
394 if (!inode
->i_private
)
397 error
= gfs2_glock_nq_init(ip
->i_gl
, LM_ST_EXCLUSIVE
, LM_FLAG_TRY_1CB
, &gh
);
398 if (unlikely(error
)) {
399 gfs2_glock_dq_uninit(&ip
->i_iopen_gh
);
403 gfs2_glock_dq(&ip
->i_iopen_gh
);
404 gfs2_holder_reinit(LM_ST_EXCLUSIVE
, LM_FLAG_TRY_1CB
| GL_NOCACHE
, &ip
->i_iopen_gh
);
405 error
= gfs2_glock_nq(&ip
->i_iopen_gh
);
409 if (S_ISDIR(inode
->i_mode
) &&
410 (ip
->i_di
.di_flags
& GFS2_DIF_EXHASH
)) {
411 error
= gfs2_dir_exhash_dealloc(ip
);
416 if (ip
->i_di
.di_eattr
) {
417 error
= gfs2_ea_dealloc(ip
);
422 if (!gfs2_is_stuffed(ip
)) {
423 error
= gfs2_file_dealloc(ip
);
428 error
= gfs2_dinode_dealloc(ip
);
431 gfs2_glock_dq(&ip
->i_iopen_gh
);
433 gfs2_holder_uninit(&ip
->i_iopen_gh
);
434 gfs2_glock_dq_uninit(&gh
);
436 fs_warn(sdp
, "gfs2_delete_inode: %d\n", error
);
438 truncate_inode_pages(&inode
->i_data
, 0);
444 static struct inode
*gfs2_alloc_inode(struct super_block
*sb
)
446 struct gfs2_sbd
*sdp
= sb
->s_fs_info
;
447 struct gfs2_inode
*ip
;
449 ip
= kmem_cache_alloc(gfs2_inode_cachep
, GFP_KERNEL
);
453 ip
->i_greedy
= gfs2_tune_get(sdp
, gt_greedy_default
);
454 ip
->i_last_pfault
= jiffies
;
459 static void gfs2_destroy_inode(struct inode
*inode
)
461 kmem_cache_free(gfs2_inode_cachep
, inode
);
464 struct super_operations gfs2_super_ops
= {
465 .alloc_inode
= gfs2_alloc_inode
,
466 .destroy_inode
= gfs2_destroy_inode
,
467 .write_inode
= gfs2_write_inode
,
468 .delete_inode
= gfs2_delete_inode
,
469 .put_super
= gfs2_put_super
,
470 .write_super
= gfs2_write_super
,
471 .sync_fs
= gfs2_sync_fs
,
472 .write_super_lockfs
= gfs2_write_super_lockfs
,
473 .unlockfs
= gfs2_unlockfs
,
474 .statfs
= gfs2_statfs
,
475 .remount_fs
= gfs2_remount_fs
,
476 .clear_inode
= gfs2_clear_inode
,
477 .show_options
= gfs2_show_options
,