2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2007 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/bio.h>
11 #include <linux/sched.h>
12 #include <linux/slab.h>
13 #include <linux/spinlock.h>
14 #include <linux/completion.h>
15 #include <linux/buffer_head.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 <linux/gfs2_ondisk.h>
22 #include <linux/crc32.h>
23 #include <linux/time.h>
43 #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
74 static 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"},
83 {Opt_nodebug, "nodebug"},
84 {Opt_upgrade, "upgrade"},
87 {Opt_quota_off, "quota=off"},
88 {Opt_quota_account, "quota=account"},
89 {Opt_quota_on, "quota=on"},
91 {Opt_noquota, "noquota"},
92 {Opt_suiddir, "suiddir"},
93 {Opt_nosuiddir, "nosuiddir"},
94 {Opt_data_writeback, "data=writeback"},
95 {Opt_data_ordered, "data=ordered"},
97 {Opt_discard, "discard"},
98 {Opt_nodiscard, "nodiscard"},
99 {Opt_commit, "commit=%d"},
104 * gfs2_mount_args - Parse mount options
111 int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
115 substring_t tmp[MAX_OPT_ARGS];
118 /* Split the options into tokens with the "," character and
122 o = strsep(&options, ",");
128 token = match_token(o, tokens, tmp);
131 match_strlcpy(args->ar_lockproto, &tmp[0],
135 match_strlcpy(args->ar_locktable, &tmp[0],
139 match_strlcpy(args->ar_hostdata, &tmp[0],
143 args->ar_spectator = 1;
145 case Opt_ignore_local_fs:
146 args->ar_ignore_local_fs = 1;
148 case Opt_localflocks:
149 args->ar_localflocks = 1;
151 case Opt_localcaching:
152 args->ar_localcaching = 1;
161 args->ar_upgrade = 1;
164 args->ar_posix_acl = 1;
167 args->ar_posix_acl = 0;
171 args->ar_quota = GFS2_QUOTA_OFF;
173 case Opt_quota_account:
174 args->ar_quota = GFS2_QUOTA_ACCOUNT;
178 args->ar_quota = GFS2_QUOTA_ON;
181 args->ar_suiddir = 1;
184 args->ar_suiddir = 0;
186 case Opt_data_writeback:
187 args->ar_data = GFS2_DATA_WRITEBACK;
189 case Opt_data_ordered:
190 args->ar_data = GFS2_DATA_ORDERED;
196 args->ar_discard = 1;
199 args->ar_discard = 0;
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;
210 fs_info(sdp, "invalid mount option: %s\n", o);
219 * gfs2_jindex_free - Clear all the journal index information
220 * @sdp: The GFS2 superblock
224 void gfs2_jindex_free(struct gfs2_sbd *sdp)
226 struct list_head list, *head;
227 struct gfs2_jdesc *jd;
228 struct gfs2_journal_extent *jext;
230 spin_lock(&sdp->sd_jindex_spin);
231 list_add(&list, &sdp->sd_jindex_list);
232 list_del_init(&sdp->sd_jindex_list);
233 sdp->sd_journals = 0;
234 spin_unlock(&sdp->sd_jindex_spin);
236 while (!list_empty(&list)) {
237 jd = list_entry(list.next, struct gfs2_jdesc, jd_list);
238 head = &jd->extent_list;
239 while (!list_empty(head)) {
240 jext = list_entry(head->next,
241 struct gfs2_journal_extent,
243 list_del(&jext->extent_list);
246 list_del(&jd->jd_list);
252 static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid)
254 struct gfs2_jdesc *jd;
257 list_for_each_entry(jd, head, jd_list) {
258 if (jd->jd_jid == jid) {
270 struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid)
272 struct gfs2_jdesc *jd;
274 spin_lock(&sdp->sd_jindex_spin);
275 jd = jdesc_find_i(&sdp->sd_jindex_list, jid);
276 spin_unlock(&sdp->sd_jindex_spin);
281 int gfs2_jdesc_check(struct gfs2_jdesc *jd)
283 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
284 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
288 if (ip->i_disksize < (8 << 20) || ip->i_disksize > (1 << 30) ||
289 (ip->i_disksize & (sdp->sd_sb.sb_bsize - 1))) {
290 gfs2_consist_inode(ip);
293 jd->jd_blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift;
295 error = gfs2_write_alloc_required(ip, 0, ip->i_disksize, &ar);
297 gfs2_consist_inode(ip);
305 * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
306 * @sdp: the filesystem
311 int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
313 struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
314 struct gfs2_glock *j_gl = ip->i_gl;
315 struct gfs2_holder t_gh;
316 struct gfs2_log_header_host head;
319 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &t_gh);
323 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
325 error = gfs2_find_jhead(sdp->sd_jdesc, &head);
329 if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
335 /* Initialize some head of the log stuff */
336 sdp->sd_log_sequence = head.lh_sequence + 1;
337 gfs2_log_pointers_init(sdp, head.lh_blkno);
339 error = gfs2_quota_init(sdp);
343 set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
345 gfs2_glock_dq_uninit(&t_gh);
350 t_gh.gh_flags |= GL_NOCACHE;
351 gfs2_glock_dq_uninit(&t_gh);
356 static void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf)
358 const struct gfs2_statfs_change *str = buf;
360 sc->sc_total = be64_to_cpu(str->sc_total);
361 sc->sc_free = be64_to_cpu(str->sc_free);
362 sc->sc_dinodes = be64_to_cpu(str->sc_dinodes);
365 static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf)
367 struct gfs2_statfs_change *str = buf;
369 str->sc_total = cpu_to_be64(sc->sc_total);
370 str->sc_free = cpu_to_be64(sc->sc_free);
371 str->sc_dinodes = cpu_to_be64(sc->sc_dinodes);
374 int gfs2_statfs_init(struct gfs2_sbd *sdp)
376 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
377 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
378 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
379 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
380 struct buffer_head *m_bh, *l_bh;
381 struct gfs2_holder gh;
384 error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
389 error = gfs2_meta_inode_buffer(m_ip, &m_bh);
393 if (sdp->sd_args.ar_spectator) {
394 spin_lock(&sdp->sd_statfs_spin);
395 gfs2_statfs_change_in(m_sc, m_bh->b_data +
396 sizeof(struct gfs2_dinode));
397 spin_unlock(&sdp->sd_statfs_spin);
399 error = gfs2_meta_inode_buffer(l_ip, &l_bh);
403 spin_lock(&sdp->sd_statfs_spin);
404 gfs2_statfs_change_in(m_sc, m_bh->b_data +
405 sizeof(struct gfs2_dinode));
406 gfs2_statfs_change_in(l_sc, l_bh->b_data +
407 sizeof(struct gfs2_dinode));
408 spin_unlock(&sdp->sd_statfs_spin);
416 gfs2_glock_dq_uninit(&gh);
420 void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
423 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
424 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
425 struct buffer_head *l_bh;
428 error = gfs2_meta_inode_buffer(l_ip, &l_bh);
432 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
434 spin_lock(&sdp->sd_statfs_spin);
435 l_sc->sc_total += total;
436 l_sc->sc_free += free;
437 l_sc->sc_dinodes += dinodes;
438 gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode));
439 spin_unlock(&sdp->sd_statfs_spin);
444 int gfs2_statfs_sync(struct gfs2_sbd *sdp)
446 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
447 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
448 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
449 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
450 struct gfs2_holder gh;
451 struct buffer_head *m_bh, *l_bh;
454 error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
459 error = gfs2_meta_inode_buffer(m_ip, &m_bh);
463 spin_lock(&sdp->sd_statfs_spin);
464 gfs2_statfs_change_in(m_sc, m_bh->b_data +
465 sizeof(struct gfs2_dinode));
466 if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) {
467 spin_unlock(&sdp->sd_statfs_spin);
470 spin_unlock(&sdp->sd_statfs_spin);
472 error = gfs2_meta_inode_buffer(l_ip, &l_bh);
476 error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0);
480 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
482 spin_lock(&sdp->sd_statfs_spin);
483 m_sc->sc_total += l_sc->sc_total;
484 m_sc->sc_free += l_sc->sc_free;
485 m_sc->sc_dinodes += l_sc->sc_dinodes;
486 memset(l_sc, 0, sizeof(struct gfs2_statfs_change));
487 memset(l_bh->b_data + sizeof(struct gfs2_dinode),
488 0, sizeof(struct gfs2_statfs_change));
489 spin_unlock(&sdp->sd_statfs_spin);
491 gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1);
492 gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode));
501 gfs2_glock_dq_uninit(&gh);
506 struct list_head list;
507 struct gfs2_holder gh;
511 * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all
513 * @sdp: the file system
514 * @state: the state to put the transaction lock into
515 * @t_gh: the hold on the transaction lock
520 static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
521 struct gfs2_holder *t_gh)
523 struct gfs2_inode *ip;
524 struct gfs2_jdesc *jd;
527 struct gfs2_log_header_host lh;
530 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
531 lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL);
536 ip = GFS2_I(jd->jd_inode);
537 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh);
542 list_add(&lfcc->list, &list);
545 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_DEFERRED,
548 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
549 error = gfs2_jdesc_check(jd);
552 error = gfs2_find_jhead(jd, &lh);
555 if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
562 gfs2_glock_dq_uninit(t_gh);
565 while (!list_empty(&list)) {
566 lfcc = list_entry(list.next, struct lfcc, list);
567 list_del(&lfcc->list);
568 gfs2_glock_dq_uninit(&lfcc->gh);
575 * gfs2_freeze_fs - freezes the file system
576 * @sdp: the file system
578 * This function flushes data and meta data for all machines by
579 * aquiring the transaction log exclusively. All journals are
580 * ensured to be in a clean state as well.
585 int gfs2_freeze_fs(struct gfs2_sbd *sdp)
589 mutex_lock(&sdp->sd_freeze_lock);
591 if (!sdp->sd_freeze_count++) {
592 error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh);
594 sdp->sd_freeze_count--;
597 mutex_unlock(&sdp->sd_freeze_lock);
603 * gfs2_unfreeze_fs - unfreezes the file system
604 * @sdp: the file system
606 * This function allows the file system to proceed by unlocking
607 * the exclusively held transaction lock. Other GFS2 nodes are
608 * now free to acquire the lock shared and go on with their lives.
612 void gfs2_unfreeze_fs(struct gfs2_sbd *sdp)
614 mutex_lock(&sdp->sd_freeze_lock);
616 if (sdp->sd_freeze_count && !--sdp->sd_freeze_count)
617 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
619 mutex_unlock(&sdp->sd_freeze_lock);
624 * gfs2_write_inode - Make sure the inode is stable on the disk
626 * @sync: synchronous write flag
631 static int gfs2_write_inode(struct inode *inode, int sync)
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;
641 /* Check this is a "normal" inode, etc */
642 if (!test_bit(GIF_USER, &ip->i_flags) ||
643 (current->flags & PF_MEMALLOC))
645 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
648 ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
651 ret = gfs2_meta_inode_buffer(ip, &bh);
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);
664 gfs2_glock_dq_uninit(&gh);
667 gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
672 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
673 * @sdp: the filesystem
678 static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
680 struct gfs2_holder t_gh;
683 gfs2_quota_sync(sdp);
684 gfs2_statfs_sync(sdp);
686 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
688 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
691 gfs2_meta_syncfs(sdp);
692 gfs2_log_shutdown(sdp);
694 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
697 gfs2_glock_dq_uninit(&t_gh);
699 gfs2_quota_cleanup(sdp);
704 static int gfs2_umount_recovery_wait(void *word)
711 * gfs2_put_super - Unmount the filesystem
712 * @sb: The VFS superblock
716 static void gfs2_put_super(struct super_block *sb)
718 struct gfs2_sbd *sdp = sb->s_fs_info;
720 struct gfs2_jdesc *jd;
724 /* Unfreeze the filesystem, if we need to */
726 mutex_lock(&sdp->sd_freeze_lock);
727 if (sdp->sd_freeze_count)
728 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
729 mutex_unlock(&sdp->sd_freeze_lock);
731 /* No more recovery requests */
732 set_bit(SDF_NORECOVERY, &sdp->sd_flags);
735 /* Wait on outstanding recovery */
737 spin_lock(&sdp->sd_jindex_spin);
738 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
739 if (!test_bit(JDF_RECOVERY, &jd->jd_flags))
741 spin_unlock(&sdp->sd_jindex_spin);
742 wait_on_bit(&jd->jd_flags, JDF_RECOVERY,
743 gfs2_umount_recovery_wait, TASK_UNINTERRUPTIBLE);
746 spin_unlock(&sdp->sd_jindex_spin);
748 kthread_stop(sdp->sd_quotad_process);
749 kthread_stop(sdp->sd_logd_process);
751 if (!(sb->s_flags & MS_RDONLY)) {
752 error = gfs2_make_fs_ro(sdp);
756 /* At this point, we're through modifying the disk */
760 iput(sdp->sd_jindex);
761 iput(sdp->sd_inum_inode);
762 iput(sdp->sd_statfs_inode);
763 iput(sdp->sd_rindex);
764 iput(sdp->sd_quota_inode);
766 gfs2_glock_put(sdp->sd_rename_gl);
767 gfs2_glock_put(sdp->sd_trans_gl);
769 if (!sdp->sd_args.ar_spectator) {
770 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
771 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
772 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
773 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
774 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
775 iput(sdp->sd_ir_inode);
776 iput(sdp->sd_sc_inode);
777 iput(sdp->sd_qc_inode);
780 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
781 gfs2_clear_rgrpd(sdp);
782 gfs2_jindex_free(sdp);
783 /* Take apart glock structures and buffer lists */
784 gfs2_gl_hash_clear(sdp);
785 /* Unmount the locking protocol */
786 gfs2_lm_unmount(sdp);
788 /* At this point, we're through participating in the lockspace */
789 gfs2_sys_fs_del(sdp);
795 * gfs2_sync_fs - sync the filesystem
796 * @sb: the superblock
798 * Flushes the log to disk.
801 static int gfs2_sync_fs(struct super_block *sb, int wait)
803 if (wait && sb->s_fs_info)
804 gfs2_log_flush(sb->s_fs_info, NULL);
809 * gfs2_freeze - prevent further writes to the filesystem
810 * @sb: the VFS structure for the filesystem
814 static int gfs2_freeze(struct super_block *sb)
816 struct gfs2_sbd *sdp = sb->s_fs_info;
819 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
823 error = gfs2_freeze_fs(sdp);
829 fs_err(sdp, "waiting for recovery before freeze\n");
833 fs_err(sdp, "error freezing FS: %d\n", error);
837 fs_err(sdp, "retrying...\n");
844 * gfs2_unfreeze - reallow writes to the filesystem
845 * @sb: the VFS structure for the filesystem
849 static int gfs2_unfreeze(struct super_block *sb)
851 gfs2_unfreeze_fs(sb->s_fs_info);
856 * statfs_fill - fill in the sg for a given RG
858 * @sc: the sc structure
860 * Returns: 0 on success, -ESTALE if the LVB is invalid
863 static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
864 struct gfs2_statfs_change_host *sc)
866 gfs2_rgrp_verify(rgd);
867 sc->sc_total += rgd->rd_data;
868 sc->sc_free += rgd->rd_free;
869 sc->sc_dinodes += rgd->rd_dinodes;
874 * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
875 * @sdp: the filesystem
876 * @sc: the sc info that will be returned
878 * Any error (other than a signal) will cause this routine to fall back
879 * to the synchronous version.
881 * FIXME: This really shouldn't busy wait like this.
886 static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
888 struct gfs2_holder ri_gh;
889 struct gfs2_rgrpd *rgd_next;
890 struct gfs2_holder *gha, *gh;
891 unsigned int slots = 64;
896 memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
897 gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
901 error = gfs2_rindex_hold(sdp, &ri_gh);
905 rgd_next = gfs2_rgrpd_get_first(sdp);
910 for (x = 0; x < slots; x++) {
913 if (gh->gh_gl && gfs2_glock_poll(gh)) {
914 err = gfs2_glock_wait(gh);
916 gfs2_holder_uninit(gh);
920 error = statfs_slow_fill(
921 gh->gh_gl->gl_object, sc);
922 gfs2_glock_dq_uninit(gh);
928 else if (rgd_next && !error) {
929 error = gfs2_glock_nq_init(rgd_next->rd_gl,
933 rgd_next = gfs2_rgrpd_get_next(rgd_next);
937 if (signal_pending(current))
938 error = -ERESTARTSYS;
947 gfs2_glock_dq_uninit(&ri_gh);
955 * gfs2_statfs_i - Do a statfs
956 * @sdp: the filesystem
957 * @sg: the sg structure
962 static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
964 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
965 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
967 spin_lock(&sdp->sd_statfs_spin);
970 sc->sc_total += l_sc->sc_total;
971 sc->sc_free += l_sc->sc_free;
972 sc->sc_dinodes += l_sc->sc_dinodes;
974 spin_unlock(&sdp->sd_statfs_spin);
978 if (sc->sc_free > sc->sc_total)
979 sc->sc_free = sc->sc_total;
980 if (sc->sc_dinodes < 0)
987 * gfs2_statfs - Gather and return stats about the filesystem
988 * @sb: The superblock
989 * @statfsbuf: The buffer
991 * Returns: 0 on success or error code
994 static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
996 struct super_block *sb = dentry->d_inode->i_sb;
997 struct gfs2_sbd *sdp = sb->s_fs_info;
998 struct gfs2_statfs_change_host sc;
1001 if (gfs2_tune_get(sdp, gt_statfs_slow))
1002 error = gfs2_statfs_slow(sdp, &sc);
1004 error = gfs2_statfs_i(sdp, &sc);
1009 buf->f_type = GFS2_MAGIC;
1010 buf->f_bsize = sdp->sd_sb.sb_bsize;
1011 buf->f_blocks = sc.sc_total;
1012 buf->f_bfree = sc.sc_free;
1013 buf->f_bavail = sc.sc_free;
1014 buf->f_files = sc.sc_dinodes + sc.sc_free;
1015 buf->f_ffree = sc.sc_free;
1016 buf->f_namelen = GFS2_FNAMESIZE;
1022 * gfs2_remount_fs - called when the FS is remounted
1023 * @sb: the filesystem
1024 * @flags: the remount flags
1025 * @data: extra data passed in (not used right now)
1030 static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
1032 struct gfs2_sbd *sdp = sb->s_fs_info;
1033 struct gfs2_args args = sdp->sd_args; /* Default to current settings */
1034 struct gfs2_tune *gt = &sdp->sd_tune;
1037 spin_lock(>->gt_spin);
1038 args.ar_commit = gt->gt_log_flush_secs;
1039 spin_unlock(>->gt_spin);
1040 error = gfs2_mount_args(sdp, &args, data);
1044 /* Not allowed to change locking details */
1045 if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
1046 strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
1047 strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
1050 /* Some flags must not be changed */
1051 if (args_neq(&args, &sdp->sd_args, spectator) ||
1052 args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
1053 args_neq(&args, &sdp->sd_args, localflocks) ||
1054 args_neq(&args, &sdp->sd_args, localcaching) ||
1055 args_neq(&args, &sdp->sd_args, meta))
1058 if (sdp->sd_args.ar_spectator)
1059 *flags |= MS_RDONLY;
1061 if ((sb->s_flags ^ *flags) & MS_RDONLY) {
1062 if (*flags & MS_RDONLY)
1063 error = gfs2_make_fs_ro(sdp);
1065 error = gfs2_make_fs_rw(sdp);
1070 sdp->sd_args = args;
1071 if (sdp->sd_args.ar_posix_acl)
1072 sb->s_flags |= MS_POSIXACL;
1074 sb->s_flags &= ~MS_POSIXACL;
1075 spin_lock(>->gt_spin);
1076 gt->gt_log_flush_secs = args.ar_commit;
1077 spin_unlock(>->gt_spin);
1083 * gfs2_drop_inode - Drop an inode (test for remote unlink)
1084 * @inode: The inode to drop
1086 * If we've received a callback on an iopen lock then its because a
1087 * remote node tried to deallocate the inode but failed due to this node
1088 * still having the inode open. Here we mark the link count zero
1089 * since we know that it must have reached zero if the GLF_DEMOTE flag
1090 * is set on the iopen glock. If we didn't do a disk read since the
1091 * remote node removed the final link then we might otherwise miss
1092 * this event. This check ensures that this node will deallocate the
1093 * inode's blocks, or alternatively pass the baton on to another
1094 * node for later deallocation.
1097 static void gfs2_drop_inode(struct inode *inode)
1099 struct gfs2_inode *ip = GFS2_I(inode);
1101 if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
1102 struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
1103 if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
1106 generic_drop_inode(inode);
1110 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
1111 * @inode: The VFS inode
1115 static void gfs2_clear_inode(struct inode *inode)
1117 struct gfs2_inode *ip = GFS2_I(inode);
1119 /* This tells us its a "real" inode and not one which only
1120 * serves to contain an address space (see rgrp.c, meta_io.c)
1121 * which therefore doesn't have its own glocks.
1123 if (test_bit(GIF_USER, &ip->i_flags)) {
1124 ip->i_gl->gl_object = NULL;
1125 gfs2_glock_put(ip->i_gl);
1127 if (ip->i_iopen_gh.gh_gl) {
1128 ip->i_iopen_gh.gh_gl->gl_object = NULL;
1129 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
1134 static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
1140 } while (!IS_ROOT(d1));
1145 * gfs2_show_options - Show mount options for /proc/mounts
1146 * @s: seq_file structure
1149 * Returns: 0 on success or error code
1152 static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1154 struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
1155 struct gfs2_args *args = &sdp->sd_args;
1158 if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
1159 seq_printf(s, ",meta");
1160 if (args->ar_lockproto[0])
1161 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
1162 if (args->ar_locktable[0])
1163 seq_printf(s, ",locktable=%s", args->ar_locktable);
1164 if (args->ar_hostdata[0])
1165 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
1166 if (args->ar_spectator)
1167 seq_printf(s, ",spectator");
1168 if (args->ar_ignore_local_fs)
1169 seq_printf(s, ",ignore_local_fs");
1170 if (args->ar_localflocks)
1171 seq_printf(s, ",localflocks");
1172 if (args->ar_localcaching)
1173 seq_printf(s, ",localcaching");
1175 seq_printf(s, ",debug");
1176 if (args->ar_upgrade)
1177 seq_printf(s, ",upgrade");
1178 if (args->ar_posix_acl)
1179 seq_printf(s, ",acl");
1180 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
1182 switch (args->ar_quota) {
1183 case GFS2_QUOTA_OFF:
1186 case GFS2_QUOTA_ACCOUNT:
1196 seq_printf(s, ",quota=%s", state);
1198 if (args->ar_suiddir)
1199 seq_printf(s, ",suiddir");
1200 if (args->ar_data != GFS2_DATA_DEFAULT) {
1202 switch (args->ar_data) {
1203 case GFS2_DATA_WRITEBACK:
1204 state = "writeback";
1206 case GFS2_DATA_ORDERED:
1213 seq_printf(s, ",data=%s", state);
1215 if (args->ar_discard)
1216 seq_printf(s, ",discard");
1217 lfsecs = sdp->sd_tune.gt_log_flush_secs;
1219 seq_printf(s, ",commit=%d", lfsecs);
1224 * We have to (at the moment) hold the inodes main lock to cover
1225 * the gap between unlocking the shared lock on the iopen lock and
1226 * taking the exclusive lock. I'd rather do a shared -> exclusive
1227 * conversion on the iopen lock, but we can change that later. This
1228 * is safe, just less efficient.
1231 static void gfs2_delete_inode(struct inode *inode)
1233 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
1234 struct gfs2_inode *ip = GFS2_I(inode);
1235 struct gfs2_holder gh;
1238 if (!test_bit(GIF_USER, &ip->i_flags))
1241 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1242 if (unlikely(error)) {
1243 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
1247 gfs2_glock_dq_wait(&ip->i_iopen_gh);
1248 gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
1249 error = gfs2_glock_nq(&ip->i_iopen_gh);
1253 if (S_ISDIR(inode->i_mode) &&
1254 (ip->i_diskflags & GFS2_DIF_EXHASH)) {
1255 error = gfs2_dir_exhash_dealloc(ip);
1261 error = gfs2_ea_dealloc(ip);
1266 if (!gfs2_is_stuffed(ip)) {
1267 error = gfs2_file_dealloc(ip);
1272 error = gfs2_dinode_dealloc(ip);
1277 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
1280 /* Needs to be done before glock release & also in a transaction */
1281 truncate_inode_pages(&inode->i_data, 0);
1282 gfs2_trans_end(sdp);
1285 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
1286 gfs2_glock_dq(&ip->i_iopen_gh);
1287 gfs2_holder_uninit(&ip->i_iopen_gh);
1288 gfs2_glock_dq_uninit(&gh);
1289 if (error && error != GLR_TRYFAILED && error != -EROFS)
1290 fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
1292 truncate_inode_pages(&inode->i_data, 0);
1296 static struct inode *gfs2_alloc_inode(struct super_block *sb)
1298 struct gfs2_inode *ip;
1300 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
1305 return &ip->i_inode;
1308 static void gfs2_destroy_inode(struct inode *inode)
1310 kmem_cache_free(gfs2_inode_cachep, inode);
1313 const struct super_operations gfs2_super_ops = {
1314 .alloc_inode = gfs2_alloc_inode,
1315 .destroy_inode = gfs2_destroy_inode,
1316 .write_inode = gfs2_write_inode,
1317 .delete_inode = gfs2_delete_inode,
1318 .put_super = gfs2_put_super,
1319 .sync_fs = gfs2_sync_fs,
1320 .freeze_fs = gfs2_freeze,
1321 .unfreeze_fs = gfs2_unfreeze,
1322 .statfs = gfs2_statfs,
1323 .remount_fs = gfs2_remount_fs,
1324 .clear_inode = gfs2_clear_inode,
1325 .drop_inode = gfs2_drop_inode,
1326 .show_options = gfs2_show_options,