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 <asm/semaphore.h>
34 * gfs2_tune_init - Fill a gfs2_tune structure with default values
39 void gfs2_tune_init(struct gfs2_tune *gt)
41 spin_lock_init(>->gt_spin);
44 gt->gt_ilimit_tries = 3;
45 gt->gt_ilimit_min = 1;
46 gt->gt_demote_secs = 300;
47 gt->gt_incore_log_blocks = 1024;
48 gt->gt_log_flush_secs = 60;
49 gt->gt_jindex_refresh_secs = 60;
50 gt->gt_scand_secs = 15;
51 gt->gt_recoverd_secs = 60;
53 gt->gt_quotad_secs = 5;
54 gt->gt_inoded_secs = 15;
55 gt->gt_quota_simul_sync = 64;
56 gt->gt_quota_warn_period = 10;
57 gt->gt_quota_scale_num = 1;
58 gt->gt_quota_scale_den = 1;
59 gt->gt_quota_cache_secs = 300;
60 gt->gt_quota_quantum = 60;
61 gt->gt_atime_quantum = 3600;
62 gt->gt_new_files_jdata = 0;
63 gt->gt_new_files_directio = 0;
64 gt->gt_max_atomic_write = 4 << 20;
65 gt->gt_max_readahead = 1 << 18;
66 gt->gt_lockdump_size = 131072;
67 gt->gt_stall_secs = 600;
68 gt->gt_complain_secs = 10;
69 gt->gt_reclaim_limit = 5000;
70 gt->gt_entries_per_readdir = 32;
71 gt->gt_prefetch_secs = 10;
72 gt->gt_greedy_default = HZ / 10;
73 gt->gt_greedy_quantum = HZ / 40;
74 gt->gt_greedy_max = HZ / 4;
75 gt->gt_statfs_quantum = 30;
76 gt->gt_statfs_slow = 0;
80 * gfs2_check_sb - Check superblock
81 * @sdp: the filesystem
83 * @silent: Don't print a message if the check fails
85 * Checks the version code of the FS is one that we understand how to
86 * read and that the sizes of the various on-disk structures have not
90 int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent)
94 if (sb->sb_header.mh_magic != GFS2_MAGIC ||
95 sb->sb_header.mh_type != GFS2_METATYPE_SB) {
97 printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n");
101 /* If format numbers match exactly, we're done. */
103 if (sb->sb_fs_format == GFS2_FORMAT_FS &&
104 sb->sb_multihost_format == GFS2_FORMAT_MULTI)
107 if (sb->sb_fs_format != GFS2_FORMAT_FS) {
108 for (x = 0; gfs2_old_fs_formats[x]; x++)
109 if (gfs2_old_fs_formats[x] == sb->sb_fs_format)
112 if (!gfs2_old_fs_formats[x]) {
114 "GFS2: code version (%u, %u) is incompatible "
115 "with ondisk format (%u, %u)\n",
116 GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
117 sb->sb_fs_format, sb->sb_multihost_format);
119 "GFS2: I don't know how to upgrade this FS\n");
124 if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) {
125 for (x = 0; gfs2_old_multihost_formats[x]; x++)
126 if (gfs2_old_multihost_formats[x] ==
127 sb->sb_multihost_format)
130 if (!gfs2_old_multihost_formats[x]) {
132 "GFS2: code version (%u, %u) is incompatible "
133 "with ondisk format (%u, %u)\n",
134 GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
135 sb->sb_fs_format, sb->sb_multihost_format);
137 "GFS2: I don't know how to upgrade this FS\n");
142 if (!sdp->sd_args.ar_upgrade) {
144 "GFS2: code version (%u, %u) is incompatible "
145 "with ondisk format (%u, %u)\n",
146 GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
147 sb->sb_fs_format, sb->sb_multihost_format);
149 "GFS2: Use the \"upgrade\" mount option to upgrade "
151 printk(KERN_INFO "GFS2: See the manual for more details\n");
159 * gfs2_read_sb - Read super block
160 * @sdp: The GFS2 superblock
161 * @gl: the glock for the superblock (assumed to be held)
162 * @silent: Don't print message if mount fails
166 int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent)
168 struct buffer_head *bh;
169 uint32_t hash_blocks, ind_blocks, leaf_blocks;
174 error = gfs2_meta_read(gl, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift,
175 DIO_FORCE | DIO_START | DIO_WAIT, &bh);
178 fs_err(sdp, "can't read superblock\n");
182 gfs2_assert(sdp, sizeof(struct gfs2_sb) <= bh->b_size);
183 gfs2_sb_in(&sdp->sd_sb, bh->b_data);
186 error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
190 sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
191 GFS2_BASIC_BLOCK_SHIFT;
192 sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
193 sdp->sd_diptrs = (sdp->sd_sb.sb_bsize -
194 sizeof(struct gfs2_dinode)) / sizeof(uint64_t);
195 sdp->sd_inptrs = (sdp->sd_sb.sb_bsize -
196 sizeof(struct gfs2_meta_header)) / sizeof(uint64_t);
197 sdp->sd_jbsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header);
198 sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2;
199 sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1;
200 sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(uint64_t);
201 sdp->sd_ut_per_block = (sdp->sd_sb.sb_bsize -
202 sizeof(struct gfs2_meta_header)) /
203 sizeof(struct gfs2_unlinked_tag);
204 sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize -
205 sizeof(struct gfs2_meta_header)) /
206 sizeof(struct gfs2_quota_change);
208 /* Compute maximum reservation required to add a entry to a directory */
210 hash_blocks = DIV_RU(sizeof(uint64_t) * (1 << GFS2_DIR_MAX_DEPTH),
214 for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) {
215 tmp_blocks = DIV_RU(tmp_blocks, sdp->sd_inptrs);
216 ind_blocks += tmp_blocks;
219 leaf_blocks = 2 + GFS2_DIR_MAX_DEPTH;
221 sdp->sd_max_dirres = hash_blocks + ind_blocks + leaf_blocks;
223 sdp->sd_heightsize[0] = sdp->sd_sb.sb_bsize -
224 sizeof(struct gfs2_dinode);
225 sdp->sd_heightsize[1] = sdp->sd_sb.sb_bsize * sdp->sd_diptrs;
230 space = sdp->sd_heightsize[x - 1] * sdp->sd_inptrs;
232 m = do_div(d, sdp->sd_inptrs);
234 if (d != sdp->sd_heightsize[x - 1] || m)
236 sdp->sd_heightsize[x] = space;
238 sdp->sd_max_height = x;
239 gfs2_assert(sdp, sdp->sd_max_height <= GFS2_MAX_META_HEIGHT);
241 sdp->sd_jheightsize[0] = sdp->sd_sb.sb_bsize -
242 sizeof(struct gfs2_dinode);
243 sdp->sd_jheightsize[1] = sdp->sd_jbsize * sdp->sd_diptrs;
248 space = sdp->sd_jheightsize[x - 1] * sdp->sd_inptrs;
250 m = do_div(d, sdp->sd_inptrs);
252 if (d != sdp->sd_jheightsize[x - 1] || m)
254 sdp->sd_jheightsize[x] = space;
256 sdp->sd_max_jheight = x;
257 gfs2_assert(sdp, sdp->sd_max_jheight <= GFS2_MAX_META_HEIGHT);
262 int gfs2_do_upgrade(struct gfs2_sbd *sdp, struct gfs2_glock *sb_gl)
268 * gfs2_jindex_hold - Grab a lock on the jindex
269 * @sdp: The GFS2 superblock
270 * @ji_gh: the holder for the jindex glock
272 * This is very similar to the gfs2_rindex_hold() function, except that
273 * in general we hold the jindex lock for longer periods of time and
274 * we grab it far less frequently (in general) then the rgrp lock.
279 int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
281 struct gfs2_inode *dip = get_v2ip(sdp->sd_jindex);
284 struct gfs2_jdesc *jd;
289 mutex_lock(&sdp->sd_jindex_mutex);
292 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED,
293 GL_LOCAL_EXCL, ji_gh);
297 name.len = sprintf(buf, "journal%u", sdp->sd_journals);
299 error = gfs2_dir_search(get_v2ip(sdp->sd_jindex),
301 if (error == -ENOENT) {
306 gfs2_glock_dq_uninit(ji_gh);
312 jd = kzalloc(sizeof(struct gfs2_jdesc), GFP_KERNEL);
316 error = gfs2_lookupi(sdp->sd_jindex, &name, 1, &jd->jd_inode);
322 spin_lock(&sdp->sd_jindex_spin);
323 jd->jd_jid = sdp->sd_journals++;
324 list_add_tail(&jd->jd_list, &sdp->sd_jindex_list);
325 spin_unlock(&sdp->sd_jindex_spin);
328 mutex_unlock(&sdp->sd_jindex_mutex);
334 * gfs2_jindex_free - Clear all the journal index information
335 * @sdp: The GFS2 superblock
339 void gfs2_jindex_free(struct gfs2_sbd *sdp)
341 struct list_head list;
342 struct gfs2_jdesc *jd;
344 spin_lock(&sdp->sd_jindex_spin);
345 list_add(&list, &sdp->sd_jindex_list);
346 list_del_init(&sdp->sd_jindex_list);
347 sdp->sd_journals = 0;
348 spin_unlock(&sdp->sd_jindex_spin);
350 while (!list_empty(&list)) {
351 jd = list_entry(list.next, struct gfs2_jdesc, jd_list);
352 list_del(&jd->jd_list);
358 static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid)
360 struct gfs2_jdesc *jd;
363 list_for_each_entry(jd, head, jd_list) {
364 if (jd->jd_jid == jid) {
376 struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid)
378 struct gfs2_jdesc *jd;
380 spin_lock(&sdp->sd_jindex_spin);
381 jd = jdesc_find_i(&sdp->sd_jindex_list, jid);
382 spin_unlock(&sdp->sd_jindex_spin);
387 void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
389 struct gfs2_jdesc *jd;
391 spin_lock(&sdp->sd_jindex_spin);
392 jd = jdesc_find_i(&sdp->sd_jindex_list, jid);
395 spin_unlock(&sdp->sd_jindex_spin);
398 struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp)
400 struct gfs2_jdesc *jd;
403 spin_lock(&sdp->sd_jindex_spin);
405 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
412 spin_unlock(&sdp->sd_jindex_spin);
420 int gfs2_jdesc_check(struct gfs2_jdesc *jd)
422 struct gfs2_inode *ip = get_v2ip(jd->jd_inode);
423 struct gfs2_sbd *sdp = ip->i_sbd;
427 if (ip->i_di.di_size < (8 << 20) ||
428 ip->i_di.di_size > (1 << 30) ||
429 (ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1))) {
430 gfs2_consist_inode(ip);
433 jd->jd_blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift;
435 error = gfs2_write_alloc_required(ip,
439 gfs2_consist_inode(ip);
446 int gfs2_lookup_master_dir(struct gfs2_sbd *sdp)
448 struct inode *inode = NULL;
449 struct gfs2_glock *gl;
452 error = gfs2_glock_get(sdp,
453 sdp->sd_sb.sb_master_dir.no_addr,
454 &gfs2_inode_glops, CREATE, &gl);
456 error = gfs2_lookup_simple(sdp->sd_root_dir, ".gfs2_admin",
458 sdp->sd_master_dir = inode;
466 * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
467 * @sdp: the filesystem
472 int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
474 struct gfs2_glock *j_gl = get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl;
475 struct gfs2_holder t_gh;
476 struct gfs2_log_header head;
479 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED,
480 GL_LOCAL_EXCL | GL_NEVER_RECURSE, &t_gh);
484 gfs2_meta_cache_flush(get_v2ip(sdp->sd_jdesc->jd_inode));
485 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA);
487 error = gfs2_find_jhead(sdp->sd_jdesc, &head);
491 if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
497 /* Initialize some head of the log stuff */
498 sdp->sd_log_sequence = head.lh_sequence + 1;
499 gfs2_log_pointers_init(sdp, head.lh_blkno);
501 error = gfs2_unlinked_init(sdp);
504 error = gfs2_quota_init(sdp);
508 set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
510 gfs2_glock_dq_uninit(&t_gh);
515 gfs2_unlinked_cleanup(sdp);
518 t_gh.gh_flags |= GL_NOCACHE;
519 gfs2_glock_dq_uninit(&t_gh);
525 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
526 * @sdp: the filesystem
531 int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
533 struct gfs2_holder t_gh;
536 gfs2_unlinked_dealloc(sdp);
537 gfs2_quota_sync(sdp);
538 gfs2_statfs_sync(sdp);
540 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED,
541 GL_LOCAL_EXCL | GL_NEVER_RECURSE | GL_NOCACHE,
543 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
546 gfs2_meta_syncfs(sdp);
547 gfs2_log_shutdown(sdp);
549 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
552 gfs2_glock_dq_uninit(&t_gh);
554 gfs2_unlinked_cleanup(sdp);
555 gfs2_quota_cleanup(sdp);
560 int gfs2_statfs_init(struct gfs2_sbd *sdp)
562 struct gfs2_inode *m_ip = get_v2ip(sdp->sd_statfs_inode);
563 struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master;
564 struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode);
565 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
566 struct buffer_head *m_bh, *l_bh;
567 struct gfs2_holder gh;
570 error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
575 error = gfs2_meta_inode_buffer(m_ip, &m_bh);
579 if (sdp->sd_args.ar_spectator) {
580 spin_lock(&sdp->sd_statfs_spin);
581 gfs2_statfs_change_in(m_sc, m_bh->b_data +
582 sizeof(struct gfs2_dinode));
583 spin_unlock(&sdp->sd_statfs_spin);
585 error = gfs2_meta_inode_buffer(l_ip, &l_bh);
589 spin_lock(&sdp->sd_statfs_spin);
590 gfs2_statfs_change_in(m_sc, m_bh->b_data +
591 sizeof(struct gfs2_dinode));
592 gfs2_statfs_change_in(l_sc, l_bh->b_data +
593 sizeof(struct gfs2_dinode));
594 spin_unlock(&sdp->sd_statfs_spin);
603 gfs2_glock_dq_uninit(&gh);
608 void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free,
611 struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode);
612 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
613 struct buffer_head *l_bh;
616 error = gfs2_meta_inode_buffer(l_ip, &l_bh);
620 mutex_lock(&sdp->sd_statfs_mutex);
621 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
622 mutex_unlock(&sdp->sd_statfs_mutex);
624 spin_lock(&sdp->sd_statfs_spin);
625 l_sc->sc_total += total;
626 l_sc->sc_free += free;
627 l_sc->sc_dinodes += dinodes;
628 gfs2_statfs_change_out(l_sc, l_bh->b_data +
629 sizeof(struct gfs2_dinode));
630 spin_unlock(&sdp->sd_statfs_spin);
635 int gfs2_statfs_sync(struct gfs2_sbd *sdp)
637 struct gfs2_inode *m_ip = get_v2ip(sdp->sd_statfs_inode);
638 struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode);
639 struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master;
640 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
641 struct gfs2_holder gh;
642 struct buffer_head *m_bh, *l_bh;
645 error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
650 error = gfs2_meta_inode_buffer(m_ip, &m_bh);
654 spin_lock(&sdp->sd_statfs_spin);
655 gfs2_statfs_change_in(m_sc, m_bh->b_data +
656 sizeof(struct gfs2_dinode));
657 if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) {
658 spin_unlock(&sdp->sd_statfs_spin);
661 spin_unlock(&sdp->sd_statfs_spin);
663 error = gfs2_meta_inode_buffer(l_ip, &l_bh);
667 error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0);
671 mutex_lock(&sdp->sd_statfs_mutex);
672 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
673 mutex_unlock(&sdp->sd_statfs_mutex);
675 spin_lock(&sdp->sd_statfs_spin);
676 m_sc->sc_total += l_sc->sc_total;
677 m_sc->sc_free += l_sc->sc_free;
678 m_sc->sc_dinodes += l_sc->sc_dinodes;
679 memset(l_sc, 0, sizeof(struct gfs2_statfs_change));
680 memset(l_bh->b_data + sizeof(struct gfs2_dinode),
681 0, sizeof(struct gfs2_statfs_change));
682 spin_unlock(&sdp->sd_statfs_spin);
684 gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1);
685 gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode));
696 gfs2_glock_dq_uninit(&gh);
702 * gfs2_statfs_i - Do a statfs
703 * @sdp: the filesystem
704 * @sg: the sg structure
709 int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc)
711 struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master;
712 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
714 spin_lock(&sdp->sd_statfs_spin);
717 sc->sc_total += l_sc->sc_total;
718 sc->sc_free += l_sc->sc_free;
719 sc->sc_dinodes += l_sc->sc_dinodes;
721 spin_unlock(&sdp->sd_statfs_spin);
725 if (sc->sc_free > sc->sc_total)
726 sc->sc_free = sc->sc_total;
727 if (sc->sc_dinodes < 0)
734 * statfs_fill - fill in the sg for a given RG
736 * @sc: the sc structure
738 * Returns: 0 on success, -ESTALE if the LVB is invalid
741 static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
742 struct gfs2_statfs_change *sc)
744 gfs2_rgrp_verify(rgd);
745 sc->sc_total += rgd->rd_ri.ri_data;
746 sc->sc_free += rgd->rd_rg.rg_free;
747 sc->sc_dinodes += rgd->rd_rg.rg_dinodes;
752 * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
753 * @sdp: the filesystem
754 * @sc: the sc info that will be returned
756 * Any error (other than a signal) will cause this routine to fall back
757 * to the synchronous version.
759 * FIXME: This really shouldn't busy wait like this.
764 int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc)
766 struct gfs2_holder ri_gh;
767 struct gfs2_rgrpd *rgd_next;
768 struct gfs2_holder *gha, *gh;
769 unsigned int slots = 64;
774 memset(sc, 0, sizeof(struct gfs2_statfs_change));
775 gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
779 error = gfs2_rindex_hold(sdp, &ri_gh);
783 rgd_next = gfs2_rgrpd_get_first(sdp);
788 for (x = 0; x < slots; x++) {
791 if (gh->gh_gl && gfs2_glock_poll(gh)) {
792 err = gfs2_glock_wait(gh);
794 gfs2_holder_uninit(gh);
798 error = statfs_slow_fill(get_gl2rgd(gh->gh_gl), sc);
799 gfs2_glock_dq_uninit(gh);
805 else if (rgd_next && !error) {
806 error = gfs2_glock_nq_init(rgd_next->rd_gl,
810 rgd_next = gfs2_rgrpd_get_next(rgd_next);
814 if (signal_pending(current))
815 error = -ERESTARTSYS;
824 gfs2_glock_dq_uninit(&ri_gh);
833 struct list_head list;
834 struct gfs2_holder gh;
838 * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all
840 * @sdp: the file system
841 * @state: the state to put the transaction lock into
842 * @t_gh: the hold on the transaction lock
847 int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh)
849 struct gfs2_holder ji_gh;
850 struct gfs2_jdesc *jd;
853 struct gfs2_log_header lh;
856 error = gfs2_jindex_hold(sdp, &ji_gh);
860 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
861 lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL);
866 error = gfs2_glock_nq_init(get_v2ip(jd->jd_inode)->i_gl,
873 list_add(&lfcc->list, &list);
876 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_DEFERRED,
877 LM_FLAG_PRIORITY | GL_NEVER_RECURSE | GL_NOCACHE,
880 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
881 error = gfs2_jdesc_check(jd);
884 error = gfs2_find_jhead(jd, &lh);
887 if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
894 gfs2_glock_dq_uninit(t_gh);
897 while (!list_empty(&list)) {
898 lfcc = list_entry(list.next, struct lfcc, list);
899 list_del(&lfcc->list);
900 gfs2_glock_dq_uninit(&lfcc->gh);
903 gfs2_glock_dq_uninit(&ji_gh);
909 * gfs2_freeze_fs - freezes the file system
910 * @sdp: the file system
912 * This function flushes data and meta data for all machines by
913 * aquiring the transaction log exclusively. All journals are
914 * ensured to be in a clean state as well.
919 int gfs2_freeze_fs(struct gfs2_sbd *sdp)
923 mutex_lock(&sdp->sd_freeze_lock);
925 if (!sdp->sd_freeze_count++) {
926 error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh);
928 sdp->sd_freeze_count--;
931 mutex_unlock(&sdp->sd_freeze_lock);
937 * gfs2_unfreeze_fs - unfreezes the file system
938 * @sdp: the file system
940 * This function allows the file system to proceed by unlocking
941 * the exclusively held transaction lock. Other GFS2 nodes are
942 * now free to acquire the lock shared and go on with their lives.
946 void gfs2_unfreeze_fs(struct gfs2_sbd *sdp)
948 mutex_lock(&sdp->sd_freeze_lock);
950 if (sdp->sd_freeze_count && !--sdp->sd_freeze_count)
951 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
953 mutex_unlock(&sdp->sd_freeze_lock);