aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-05-08 16:16:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-05-08 16:16:07 -0400
commitef75bd71c5d31dc17ae41ff8bec92630a3037d69 (patch)
treeb05e8843488668244df16c03e0fa6ccbf1d61980 /fs/gfs2
parent78d9affbb0e79d48fd82b34ef9cd673a7c86d6f2 (diff)
parentf4686c26ecc34e8e458b8235f0af5198c9b13bfd (diff)
Merge tag 'gfs2-for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull GFS2 updates from Andreas Gruenbacher: "We've got the following patches ready for this merge window: - "gfs2: Fix loop in gfs2_rbm_find (v2)" A rework of a fix we ended up reverting in 5.0 because of an iozone performance regression. - "gfs2: read journal in large chunks" "gfs2: fix race between gfs2_freeze_func and unmount" An improved version of a commit we also ended up reverting in 5.0 because of a regression in xfstest generic/311. It turns out that the journal changes were mostly innocent and that unfreeze didn't wait for the freeze to complete, which caused the filesystem to be unmounted before it was actually idle. - "gfs2: Fix occasional glock use-after-free" "gfs2: Fix iomap write page reclaim deadlock" "gfs2: Fix lru_count going negative" Fixes for various problems reported and partially fixed by Citrix engineers. Thank you very much. - "gfs2: clean_journal improperly set sd_log_flush_head" Another fix from Bob. - .. and a few other minor cleanups" * tag 'gfs2-for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: gfs2: read journal in large chunks gfs2: Fix iomap write page reclaim deadlock gfs2: fix race between gfs2_freeze_func and unmount gfs2: Rename gfs2_trans_{add_unrevoke => remove_revoke} gfs2: Rename sd_log_le_{revoke,ordered} gfs2: Remove unnecessary extern declarations gfs2: Remove misleading comments in gfs2_evict_inode gfs2: Replace gl_revokes with a GLF flag gfs2: Fix occasional glock use-after-free gfs2: clean_journal improperly set sd_log_flush_head gfs2: Fix lru_count going negative gfs2: Fix loop in gfs2_rbm_find (v2)
Diffstat (limited to 'fs/gfs2')
-rw-r--r--fs/gfs2/aops.c14
-rw-r--r--fs/gfs2/bmap.c118
-rw-r--r--fs/gfs2/bmap.h1
-rw-r--r--fs/gfs2/dir.c2
-rw-r--r--fs/gfs2/glock.c25
-rw-r--r--fs/gfs2/glops.c3
-rw-r--r--fs/gfs2/incore.h9
-rw-r--r--fs/gfs2/log.c47
-rw-r--r--fs/gfs2/log.h5
-rw-r--r--fs/gfs2/lops.c260
-rw-r--r--fs/gfs2/lops.h11
-rw-r--r--fs/gfs2/main.c1
-rw-r--r--fs/gfs2/ops_fstype.c7
-rw-r--r--fs/gfs2/recovery.c135
-rw-r--r--fs/gfs2/recovery.h4
-rw-r--r--fs/gfs2/rgrp.c56
-rw-r--r--fs/gfs2/super.c20
-rw-r--r--fs/gfs2/trans.c4
-rw-r--r--fs/gfs2/trans.h2
-rw-r--r--fs/gfs2/xattr.c6
20 files changed, 437 insertions, 293 deletions
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 05dd78f4b2b3..6210d4429d84 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -649,7 +649,7 @@ out_uninit:
649 */ 649 */
650void adjust_fs_space(struct inode *inode) 650void adjust_fs_space(struct inode *inode)
651{ 651{
652 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; 652 struct gfs2_sbd *sdp = GFS2_SB(inode);
653 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); 653 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
654 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); 654 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
655 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; 655 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
@@ -657,10 +657,13 @@ void adjust_fs_space(struct inode *inode)
657 struct buffer_head *m_bh, *l_bh; 657 struct buffer_head *m_bh, *l_bh;
658 u64 fs_total, new_free; 658 u64 fs_total, new_free;
659 659
660 if (gfs2_trans_begin(sdp, 2 * RES_STATFS, 0) != 0)
661 return;
662
660 /* Total up the file system space, according to the latest rindex. */ 663 /* Total up the file system space, according to the latest rindex. */
661 fs_total = gfs2_ri_total(sdp); 664 fs_total = gfs2_ri_total(sdp);
662 if (gfs2_meta_inode_buffer(m_ip, &m_bh) != 0) 665 if (gfs2_meta_inode_buffer(m_ip, &m_bh) != 0)
663 return; 666 goto out;
664 667
665 spin_lock(&sdp->sd_statfs_spin); 668 spin_lock(&sdp->sd_statfs_spin);
666 gfs2_statfs_change_in(m_sc, m_bh->b_data + 669 gfs2_statfs_change_in(m_sc, m_bh->b_data +
@@ -675,11 +678,14 @@ void adjust_fs_space(struct inode *inode)
675 gfs2_statfs_change(sdp, new_free, new_free, 0); 678 gfs2_statfs_change(sdp, new_free, new_free, 0);
676 679
677 if (gfs2_meta_inode_buffer(l_ip, &l_bh) != 0) 680 if (gfs2_meta_inode_buffer(l_ip, &l_bh) != 0)
678 goto out; 681 goto out2;
679 update_statfs(sdp, m_bh, l_bh); 682 update_statfs(sdp, m_bh, l_bh);
680 brelse(l_bh); 683 brelse(l_bh);
681out: 684out2:
682 brelse(m_bh); 685 brelse(m_bh);
686out:
687 sdp->sd_rindex_uptodate = 0;
688 gfs2_trans_end(sdp);
683} 689}
684 690
685/** 691/**
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 2f9290f69610..f42718dd292f 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -142,7 +142,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
142 if (error) 142 if (error)
143 goto out_brelse; 143 goto out_brelse;
144 if (isdir) { 144 if (isdir) {
145 gfs2_trans_add_unrevoke(GFS2_SB(&ip->i_inode), block, 1); 145 gfs2_trans_remove_revoke(GFS2_SB(&ip->i_inode), block, 1);
146 error = gfs2_dir_get_new_buffer(ip, block, &bh); 146 error = gfs2_dir_get_new_buffer(ip, block, &bh);
147 if (error) 147 if (error)
148 goto out_brelse; 148 goto out_brelse;
@@ -676,7 +676,7 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap,
676 goto out; 676 goto out;
677 alloced += n; 677 alloced += n;
678 if (state != ALLOC_DATA || gfs2_is_jdata(ip)) 678 if (state != ALLOC_DATA || gfs2_is_jdata(ip))
679 gfs2_trans_add_unrevoke(sdp, bn, n); 679 gfs2_trans_remove_revoke(sdp, bn, n);
680 switch (state) { 680 switch (state) {
681 /* Growing height of tree */ 681 /* Growing height of tree */
682 case ALLOC_GROW_HEIGHT: 682 case ALLOC_GROW_HEIGHT:
@@ -925,6 +925,32 @@ do_alloc:
925 goto out; 925 goto out;
926} 926}
927 927
928/**
929 * gfs2_lblk_to_dblk - convert logical block to disk block
930 * @inode: the inode of the file we're mapping
931 * @lblock: the block relative to the start of the file
932 * @dblock: the returned dblock, if no error
933 *
934 * This function maps a single block from a file logical block (relative to
935 * the start of the file) to a file system absolute block using iomap.
936 *
937 * Returns: the absolute file system block, or an error
938 */
939int gfs2_lblk_to_dblk(struct inode *inode, u32 lblock, u64 *dblock)
940{
941 struct iomap iomap = { };
942 struct metapath mp = { .mp_aheight = 1, };
943 loff_t pos = (loff_t)lblock << inode->i_blkbits;
944 int ret;
945
946 ret = gfs2_iomap_get(inode, pos, i_blocksize(inode), 0, &iomap, &mp);
947 release_metapath(&mp);
948 if (ret == 0)
949 *dblock = iomap.addr >> inode->i_blkbits;
950
951 return ret;
952}
953
928static int gfs2_write_lock(struct inode *inode) 954static int gfs2_write_lock(struct inode *inode)
929{ 955{
930 struct gfs2_inode *ip = GFS2_I(inode); 956 struct gfs2_inode *ip = GFS2_I(inode);
@@ -965,17 +991,28 @@ static void gfs2_write_unlock(struct inode *inode)
965 gfs2_glock_dq_uninit(&ip->i_gh); 991 gfs2_glock_dq_uninit(&ip->i_gh);
966} 992}
967 993
994static int gfs2_iomap_page_prepare(struct inode *inode, loff_t pos,
995 unsigned len, struct iomap *iomap)
996{
997 struct gfs2_sbd *sdp = GFS2_SB(inode);
998
999 return gfs2_trans_begin(sdp, RES_DINODE + (len >> inode->i_blkbits), 0);
1000}
1001
968static void gfs2_iomap_page_done(struct inode *inode, loff_t pos, 1002static void gfs2_iomap_page_done(struct inode *inode, loff_t pos,
969 unsigned copied, struct page *page, 1003 unsigned copied, struct page *page,
970 struct iomap *iomap) 1004 struct iomap *iomap)
971{ 1005{
972 struct gfs2_inode *ip = GFS2_I(inode); 1006 struct gfs2_inode *ip = GFS2_I(inode);
1007 struct gfs2_sbd *sdp = GFS2_SB(inode);
973 1008
974 if (page) 1009 if (page && !gfs2_is_stuffed(ip))
975 gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied); 1010 gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied);
1011 gfs2_trans_end(sdp);
976} 1012}
977 1013
978static const struct iomap_page_ops gfs2_iomap_page_ops = { 1014static const struct iomap_page_ops gfs2_iomap_page_ops = {
1015 .page_prepare = gfs2_iomap_page_prepare,
979 .page_done = gfs2_iomap_page_done, 1016 .page_done = gfs2_iomap_page_done,
980}; 1017};
981 1018
@@ -1031,31 +1068,45 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
1031 if (alloc_required) 1068 if (alloc_required)
1032 rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); 1069 rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks);
1033 1070
1034 ret = gfs2_trans_begin(sdp, rblocks, iomap->length >> inode->i_blkbits); 1071 if (unstuff || iomap->type == IOMAP_HOLE) {
1035 if (ret) 1072 struct gfs2_trans *tr;
1036 goto out_trans_fail;
1037 1073
1038 if (unstuff) { 1074 ret = gfs2_trans_begin(sdp, rblocks,
1039 ret = gfs2_unstuff_dinode(ip, NULL); 1075 iomap->length >> inode->i_blkbits);
1040 if (ret)
1041 goto out_trans_end;
1042 release_metapath(mp);
1043 ret = gfs2_iomap_get(inode, iomap->offset, iomap->length,
1044 flags, iomap, mp);
1045 if (ret) 1076 if (ret)
1046 goto out_trans_end; 1077 goto out_trans_fail;
1047 }
1048 1078
1049 if (iomap->type == IOMAP_HOLE) { 1079 if (unstuff) {
1050 ret = gfs2_iomap_alloc(inode, iomap, flags, mp); 1080 ret = gfs2_unstuff_dinode(ip, NULL);
1051 if (ret) { 1081 if (ret)
1052 gfs2_trans_end(sdp); 1082 goto out_trans_end;
1053 gfs2_inplace_release(ip); 1083 release_metapath(mp);
1054 punch_hole(ip, iomap->offset, iomap->length); 1084 ret = gfs2_iomap_get(inode, iomap->offset,
1055 goto out_qunlock; 1085 iomap->length, flags, iomap, mp);
1086 if (ret)
1087 goto out_trans_end;
1088 }
1089
1090 if (iomap->type == IOMAP_HOLE) {
1091 ret = gfs2_iomap_alloc(inode, iomap, flags, mp);
1092 if (ret) {
1093 gfs2_trans_end(sdp);
1094 gfs2_inplace_release(ip);
1095 punch_hole(ip, iomap->offset, iomap->length);
1096 goto out_qunlock;
1097 }
1056 } 1098 }
1099
1100 tr = current->journal_info;
1101 if (tr->tr_num_buf_new)
1102 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1103 else
1104 gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[0]);
1105
1106 gfs2_trans_end(sdp);
1057 } 1107 }
1058 if (!gfs2_is_stuffed(ip) && gfs2_is_jdata(ip)) 1108
1109 if (gfs2_is_stuffed(ip) || gfs2_is_jdata(ip))
1059 iomap->page_ops = &gfs2_iomap_page_ops; 1110 iomap->page_ops = &gfs2_iomap_page_ops;
1060 return 0; 1111 return 0;
1061 1112
@@ -1095,10 +1146,6 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
1095 iomap->type != IOMAP_MAPPED) 1146 iomap->type != IOMAP_MAPPED)
1096 ret = -ENOTBLK; 1147 ret = -ENOTBLK;
1097 } 1148 }
1098 if (!ret) {
1099 get_bh(mp.mp_bh[0]);
1100 iomap->private = mp.mp_bh[0];
1101 }
1102 release_metapath(&mp); 1149 release_metapath(&mp);
1103 trace_gfs2_iomap_end(ip, iomap, ret); 1150 trace_gfs2_iomap_end(ip, iomap, ret);
1104 return ret; 1151 return ret;
@@ -1109,27 +1156,16 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
1109{ 1156{
1110 struct gfs2_inode *ip = GFS2_I(inode); 1157 struct gfs2_inode *ip = GFS2_I(inode);
1111 struct gfs2_sbd *sdp = GFS2_SB(inode); 1158 struct gfs2_sbd *sdp = GFS2_SB(inode);
1112 struct gfs2_trans *tr = current->journal_info;
1113 struct buffer_head *dibh = iomap->private;
1114 1159
1115 if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE) 1160 if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE)
1116 goto out; 1161 goto out;
1117 1162
1118 if (iomap->type != IOMAP_INLINE) { 1163 if (!gfs2_is_stuffed(ip))
1119 gfs2_ordered_add_inode(ip); 1164 gfs2_ordered_add_inode(ip);
1120 1165
1121 if (tr->tr_num_buf_new) 1166 if (inode == sdp->sd_rindex)
1122 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1123 else
1124 gfs2_trans_add_meta(ip->i_gl, dibh);
1125 }
1126
1127 if (inode == sdp->sd_rindex) {
1128 adjust_fs_space(inode); 1167 adjust_fs_space(inode);
1129 sdp->sd_rindex_uptodate = 0;
1130 }
1131 1168
1132 gfs2_trans_end(sdp);
1133 gfs2_inplace_release(ip); 1169 gfs2_inplace_release(ip);
1134 1170
1135 if (length != written && (iomap->flags & IOMAP_F_NEW)) { 1171 if (length != written && (iomap->flags & IOMAP_F_NEW)) {
@@ -1149,8 +1185,6 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
1149 gfs2_write_unlock(inode); 1185 gfs2_write_unlock(inode);
1150 1186
1151out: 1187out:
1152 if (dibh)
1153 brelse(dibh);
1154 return 0; 1188 return 0;
1155} 1189}
1156 1190
diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h
index 6b18fb323f0a..19a1fd772c61 100644
--- a/fs/gfs2/bmap.h
+++ b/fs/gfs2/bmap.h
@@ -64,5 +64,6 @@ extern int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
64extern int gfs2_map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd); 64extern int gfs2_map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd);
65extern void gfs2_free_journal_extents(struct gfs2_jdesc *jd); 65extern void gfs2_free_journal_extents(struct gfs2_jdesc *jd);
66extern int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length); 66extern int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length);
67extern int gfs2_lblk_to_dblk(struct inode *inode, u32 lblock, u64 *dblock);
67 68
68#endif /* __BMAP_DOT_H__ */ 69#endif /* __BMAP_DOT_H__ */
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index daa14ab4e31b..db9a05244a35 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -883,7 +883,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
883 if (!bh) 883 if (!bh)
884 return NULL; 884 return NULL;
885 885
886 gfs2_trans_add_unrevoke(GFS2_SB(inode), bn, 1); 886 gfs2_trans_remove_revoke(GFS2_SB(inode), bn, 1);
887 gfs2_trans_add_meta(ip->i_gl, bh); 887 gfs2_trans_add_meta(ip->i_gl, bh);
888 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); 888 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
889 leaf = (struct gfs2_leaf *)bh->b_data; 889 leaf = (struct gfs2_leaf *)bh->b_data;
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index d32964cd1117..15c605cfcfc8 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -140,6 +140,7 @@ void gfs2_glock_free(struct gfs2_glock *gl)
140{ 140{
141 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 141 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
142 142
143 BUG_ON(test_bit(GLF_REVOKES, &gl->gl_flags));
143 rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms); 144 rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms);
144 smp_mb(); 145 smp_mb();
145 wake_up_glock(gl); 146 wake_up_glock(gl);
@@ -183,15 +184,19 @@ static int demote_ok(const struct gfs2_glock *gl)
183 184
184void gfs2_glock_add_to_lru(struct gfs2_glock *gl) 185void gfs2_glock_add_to_lru(struct gfs2_glock *gl)
185{ 186{
187 if (!(gl->gl_ops->go_flags & GLOF_LRU))
188 return;
189
186 spin_lock(&lru_lock); 190 spin_lock(&lru_lock);
187 191
188 if (!list_empty(&gl->gl_lru)) 192 list_del(&gl->gl_lru);
189 list_del_init(&gl->gl_lru); 193 list_add_tail(&gl->gl_lru, &lru_list);
190 else 194
195 if (!test_bit(GLF_LRU, &gl->gl_flags)) {
196 set_bit(GLF_LRU, &gl->gl_flags);
191 atomic_inc(&lru_count); 197 atomic_inc(&lru_count);
198 }
192 199
193 list_add_tail(&gl->gl_lru, &lru_list);
194 set_bit(GLF_LRU, &gl->gl_flags);
195 spin_unlock(&lru_lock); 200 spin_unlock(&lru_lock);
196} 201}
197 202
@@ -201,7 +206,7 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
201 return; 206 return;
202 207
203 spin_lock(&lru_lock); 208 spin_lock(&lru_lock);
204 if (!list_empty(&gl->gl_lru)) { 209 if (test_bit(GLF_LRU, &gl->gl_flags)) {
205 list_del_init(&gl->gl_lru); 210 list_del_init(&gl->gl_lru);
206 atomic_dec(&lru_count); 211 atomic_dec(&lru_count);
207 clear_bit(GLF_LRU, &gl->gl_flags); 212 clear_bit(GLF_LRU, &gl->gl_flags);
@@ -1159,8 +1164,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
1159 !test_bit(GLF_DEMOTE, &gl->gl_flags)) 1164 !test_bit(GLF_DEMOTE, &gl->gl_flags))
1160 fast_path = 1; 1165 fast_path = 1;
1161 } 1166 }
1162 if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl) && 1167 if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl))
1163 (glops->go_flags & GLOF_LRU))
1164 gfs2_glock_add_to_lru(gl); 1168 gfs2_glock_add_to_lru(gl);
1165 1169
1166 trace_gfs2_glock_queue(gh, 0); 1170 trace_gfs2_glock_queue(gh, 0);
@@ -1456,6 +1460,7 @@ __acquires(&lru_lock)
1456 if (!spin_trylock(&gl->gl_lockref.lock)) { 1460 if (!spin_trylock(&gl->gl_lockref.lock)) {
1457add_back_to_lru: 1461add_back_to_lru:
1458 list_add(&gl->gl_lru, &lru_list); 1462 list_add(&gl->gl_lru, &lru_list);
1463 set_bit(GLF_LRU, &gl->gl_flags);
1459 atomic_inc(&lru_count); 1464 atomic_inc(&lru_count);
1460 continue; 1465 continue;
1461 } 1466 }
@@ -1463,7 +1468,6 @@ add_back_to_lru:
1463 spin_unlock(&gl->gl_lockref.lock); 1468 spin_unlock(&gl->gl_lockref.lock);
1464 goto add_back_to_lru; 1469 goto add_back_to_lru;
1465 } 1470 }
1466 clear_bit(GLF_LRU, &gl->gl_flags);
1467 gl->gl_lockref.count++; 1471 gl->gl_lockref.count++;
1468 if (demote_ok(gl)) 1472 if (demote_ok(gl))
1469 handle_callback(gl, LM_ST_UNLOCKED, 0, false); 1473 handle_callback(gl, LM_ST_UNLOCKED, 0, false);
@@ -1498,6 +1502,7 @@ static long gfs2_scan_glock_lru(int nr)
1498 if (!test_bit(GLF_LOCK, &gl->gl_flags)) { 1502 if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
1499 list_move(&gl->gl_lru, &dispose); 1503 list_move(&gl->gl_lru, &dispose);
1500 atomic_dec(&lru_count); 1504 atomic_dec(&lru_count);
1505 clear_bit(GLF_LRU, &gl->gl_flags);
1501 freed++; 1506 freed++;
1502 continue; 1507 continue;
1503 } 1508 }
@@ -1796,7 +1801,7 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl)
1796 state2str(gl->gl_target), 1801 state2str(gl->gl_target),
1797 state2str(gl->gl_demote_state), dtime, 1802 state2str(gl->gl_demote_state), dtime,
1798 atomic_read(&gl->gl_ail_count), 1803 atomic_read(&gl->gl_ail_count),
1799 atomic_read(&gl->gl_revokes), 1804 test_bit(GLF_REVOKES, &gl->gl_flags) ? 1 : 0,
1800 (int)gl->gl_lockref.count, gl->gl_hold_time); 1805 (int)gl->gl_lockref.count, gl->gl_hold_time);
1801 1806
1802 list_for_each_entry(gh, &gl->gl_holders, gh_list) 1807 list_for_each_entry(gh, &gl->gl_holders, gh_list)
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 78510ab91835..24ada3ccc525 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -28,6 +28,7 @@
28#include "util.h" 28#include "util.h"
29#include "trans.h" 29#include "trans.h"
30#include "dir.h" 30#include "dir.h"
31#include "lops.h"
31 32
32struct workqueue_struct *gfs2_freeze_wq; 33struct workqueue_struct *gfs2_freeze_wq;
33 34
@@ -531,7 +532,7 @@ static int freeze_go_xmote_bh(struct gfs2_glock *gl, struct gfs2_holder *gh)
531 if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { 532 if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
532 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 533 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
533 534
534 error = gfs2_find_jhead(sdp->sd_jdesc, &head); 535 error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
535 if (error) 536 if (error)
536 gfs2_consist(sdp); 537 gfs2_consist(sdp);
537 if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) 538 if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT))
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index cdf07b408f54..b15755068593 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -345,6 +345,7 @@ enum {
345 GLF_OBJECT = 14, /* Used only for tracing */ 345 GLF_OBJECT = 14, /* Used only for tracing */
346 GLF_BLOCKING = 15, 346 GLF_BLOCKING = 15,
347 GLF_INODE_CREATING = 16, /* Inode creation occurring */ 347 GLF_INODE_CREATING = 16, /* Inode creation occurring */
348 GLF_REVOKES = 17, /* Glock has revokes in queue */
348}; 349};
349 350
350struct gfs2_glock { 351struct gfs2_glock {
@@ -374,7 +375,6 @@ struct gfs2_glock {
374 struct list_head gl_lru; 375 struct list_head gl_lru;
375 struct list_head gl_ail_list; 376 struct list_head gl_ail_list;
376 atomic_t gl_ail_count; 377 atomic_t gl_ail_count;
377 atomic_t gl_revokes;
378 struct delayed_work gl_work; 378 struct delayed_work gl_work;
379 union { 379 union {
380 /* For inode and iopen glocks only */ 380 /* For inode and iopen glocks only */
@@ -535,7 +535,7 @@ struct gfs2_jdesc {
535 unsigned long jd_flags; 535 unsigned long jd_flags;
536#define JDF_RECOVERY 1 536#define JDF_RECOVERY 1
537 unsigned int jd_jid; 537 unsigned int jd_jid;
538 unsigned int jd_blocks; 538 u32 jd_blocks;
539 int jd_recover_error; 539 int jd_recover_error;
540 /* Replay stuff */ 540 /* Replay stuff */
541 541
@@ -621,6 +621,7 @@ enum {
621 SDF_SKIP_DLM_UNLOCK = 8, 621 SDF_SKIP_DLM_UNLOCK = 8,
622 SDF_FORCE_AIL_FLUSH = 9, 622 SDF_FORCE_AIL_FLUSH = 9,
623 SDF_AIL1_IO_ERROR = 10, 623 SDF_AIL1_IO_ERROR = 10,
624 SDF_FS_FROZEN = 11,
624}; 625};
625 626
626enum gfs2_freeze_state { 627enum gfs2_freeze_state {
@@ -809,8 +810,8 @@ struct gfs2_sbd {
809 atomic_t sd_log_pinned; 810 atomic_t sd_log_pinned;
810 unsigned int sd_log_num_revoke; 811 unsigned int sd_log_num_revoke;
811 812
812 struct list_head sd_log_le_revoke; 813 struct list_head sd_log_revokes;
813 struct list_head sd_log_le_ordered; 814 struct list_head sd_log_ordered;
814 spinlock_t sd_ordered_lock; 815 spinlock_t sd_ordered_lock;
815 816
816 atomic_t sd_log_thresh1; 817 atomic_t sd_log_thresh1;
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index b8830fda51e8..a2e1df488df0 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -551,9 +551,9 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp)
551 LIST_HEAD(written); 551 LIST_HEAD(written);
552 552
553 spin_lock(&sdp->sd_ordered_lock); 553 spin_lock(&sdp->sd_ordered_lock);
554 list_sort(NULL, &sdp->sd_log_le_ordered, &ip_cmp); 554 list_sort(NULL, &sdp->sd_log_ordered, &ip_cmp);
555 while (!list_empty(&sdp->sd_log_le_ordered)) { 555 while (!list_empty(&sdp->sd_log_ordered)) {
556 ip = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_inode, i_ordered); 556 ip = list_entry(sdp->sd_log_ordered.next, struct gfs2_inode, i_ordered);
557 if (ip->i_inode.i_mapping->nrpages == 0) { 557 if (ip->i_inode.i_mapping->nrpages == 0) {
558 test_and_clear_bit(GIF_ORDERED, &ip->i_flags); 558 test_and_clear_bit(GIF_ORDERED, &ip->i_flags);
559 list_del(&ip->i_ordered); 559 list_del(&ip->i_ordered);
@@ -564,7 +564,7 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp)
564 filemap_fdatawrite(ip->i_inode.i_mapping); 564 filemap_fdatawrite(ip->i_inode.i_mapping);
565 spin_lock(&sdp->sd_ordered_lock); 565 spin_lock(&sdp->sd_ordered_lock);
566 } 566 }
567 list_splice(&written, &sdp->sd_log_le_ordered); 567 list_splice(&written, &sdp->sd_log_ordered);
568 spin_unlock(&sdp->sd_ordered_lock); 568 spin_unlock(&sdp->sd_ordered_lock);
569} 569}
570 570
@@ -573,8 +573,8 @@ static void gfs2_ordered_wait(struct gfs2_sbd *sdp)
573 struct gfs2_inode *ip; 573 struct gfs2_inode *ip;
574 574
575 spin_lock(&sdp->sd_ordered_lock); 575 spin_lock(&sdp->sd_ordered_lock);
576 while (!list_empty(&sdp->sd_log_le_ordered)) { 576 while (!list_empty(&sdp->sd_log_ordered)) {
577 ip = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_inode, i_ordered); 577 ip = list_entry(sdp->sd_log_ordered.next, struct gfs2_inode, i_ordered);
578 list_del(&ip->i_ordered); 578 list_del(&ip->i_ordered);
579 WARN_ON(!test_and_clear_bit(GIF_ORDERED, &ip->i_flags)); 579 WARN_ON(!test_and_clear_bit(GIF_ORDERED, &ip->i_flags));
580 if (ip->i_inode.i_mapping->nrpages == 0) 580 if (ip->i_inode.i_mapping->nrpages == 0)
@@ -606,9 +606,12 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
606 gfs2_remove_from_ail(bd); /* drops ref on bh */ 606 gfs2_remove_from_ail(bd); /* drops ref on bh */
607 bd->bd_bh = NULL; 607 bd->bd_bh = NULL;
608 sdp->sd_log_num_revoke++; 608 sdp->sd_log_num_revoke++;
609 atomic_inc(&gl->gl_revokes); 609 if (!test_bit(GLF_REVOKES, &gl->gl_flags)) {
610 set_bit(GLF_REVOKES, &gl->gl_flags);
611 gfs2_glock_hold(gl);
612 }
610 set_bit(GLF_LFLUSH, &gl->gl_flags); 613 set_bit(GLF_LFLUSH, &gl->gl_flags);
611 list_add(&bd->bd_list, &sdp->sd_log_le_revoke); 614 list_add(&bd->bd_list, &sdp->sd_log_revokes);
612} 615}
613 616
614void gfs2_write_revokes(struct gfs2_sbd *sdp) 617void gfs2_write_revokes(struct gfs2_sbd *sdp)
@@ -666,11 +669,12 @@ out_of_blocks:
666} 669}
667 670
668/** 671/**
669 * write_log_header - Write a journal log header buffer at sd_log_flush_head 672 * gfs2_write_log_header - Write a journal log header buffer at lblock
670 * @sdp: The GFS2 superblock 673 * @sdp: The GFS2 superblock
671 * @jd: journal descriptor of the journal to which we are writing 674 * @jd: journal descriptor of the journal to which we are writing
672 * @seq: sequence number 675 * @seq: sequence number
673 * @tail: tail of the log 676 * @tail: tail of the log
677 * @lblock: value for lh_blkno (block number relative to start of journal)
674 * @flags: log header flags GFS2_LOG_HEAD_* 678 * @flags: log header flags GFS2_LOG_HEAD_*
675 * @op_flags: flags to pass to the bio 679 * @op_flags: flags to pass to the bio
676 * 680 *
@@ -678,7 +682,8 @@ out_of_blocks:
678 */ 682 */
679 683
680void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, 684void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
681 u64 seq, u32 tail, u32 flags, int op_flags) 685 u64 seq, u32 tail, u32 lblock, u32 flags,
686 int op_flags)
682{ 687{
683 struct gfs2_log_header *lh; 688 struct gfs2_log_header *lh;
684 u32 hash, crc; 689 u32 hash, crc;
@@ -686,7 +691,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
686 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; 691 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
687 struct timespec64 tv; 692 struct timespec64 tv;
688 struct super_block *sb = sdp->sd_vfs; 693 struct super_block *sb = sdp->sd_vfs;
689 u64 addr; 694 u64 dblock;
690 695
691 lh = page_address(page); 696 lh = page_address(page);
692 clear_page(lh); 697 clear_page(lh);
@@ -699,15 +704,21 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
699 lh->lh_sequence = cpu_to_be64(seq); 704 lh->lh_sequence = cpu_to_be64(seq);
700 lh->lh_flags = cpu_to_be32(flags); 705 lh->lh_flags = cpu_to_be32(flags);
701 lh->lh_tail = cpu_to_be32(tail); 706 lh->lh_tail = cpu_to_be32(tail);
702 lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head); 707 lh->lh_blkno = cpu_to_be32(lblock);
703 hash = ~crc32(~0, lh, LH_V1_SIZE); 708 hash = ~crc32(~0, lh, LH_V1_SIZE);
704 lh->lh_hash = cpu_to_be32(hash); 709 lh->lh_hash = cpu_to_be32(hash);
705 710
706 ktime_get_coarse_real_ts64(&tv); 711 ktime_get_coarse_real_ts64(&tv);
707 lh->lh_nsec = cpu_to_be32(tv.tv_nsec); 712 lh->lh_nsec = cpu_to_be32(tv.tv_nsec);
708 lh->lh_sec = cpu_to_be64(tv.tv_sec); 713 lh->lh_sec = cpu_to_be64(tv.tv_sec);
709 addr = gfs2_log_bmap(sdp); 714 if (!list_empty(&jd->extent_list))
710 lh->lh_addr = cpu_to_be64(addr); 715 dblock = gfs2_log_bmap(sdp);
716 else {
717 int ret = gfs2_lblk_to_dblk(jd->jd_inode, lblock, &dblock);
718 if (gfs2_assert_withdraw(sdp, ret == 0))
719 return;
720 }
721 lh->lh_addr = cpu_to_be64(dblock);
711 lh->lh_jinode = cpu_to_be64(GFS2_I(jd->jd_inode)->i_no_addr); 722 lh->lh_jinode = cpu_to_be64(GFS2_I(jd->jd_inode)->i_no_addr);
712 723
713 /* We may only write local statfs, quota, etc., when writing to our 724 /* We may only write local statfs, quota, etc., when writing to our
@@ -732,8 +743,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
732 sb->s_blocksize - LH_V1_SIZE - 4); 743 sb->s_blocksize - LH_V1_SIZE - 4);
733 lh->lh_crc = cpu_to_be32(crc); 744 lh->lh_crc = cpu_to_be32(crc);
734 745
735 gfs2_log_write(sdp, page, sb->s_blocksize, 0, addr); 746 gfs2_log_write(sdp, page, sb->s_blocksize, 0, dblock);
736 gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE, op_flags); 747 gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE | op_flags);
737 log_flush_wait(sdp); 748 log_flush_wait(sdp);
738} 749}
739 750
@@ -761,7 +772,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
761 } 772 }
762 sdp->sd_log_idle = (tail == sdp->sd_log_flush_head); 773 sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
763 gfs2_write_log_header(sdp, sdp->sd_jdesc, sdp->sd_log_sequence++, tail, 774 gfs2_write_log_header(sdp, sdp->sd_jdesc, sdp->sd_log_sequence++, tail,
764 flags, op_flags); 775 sdp->sd_log_flush_head, flags, op_flags);
765 776
766 if (sdp->sd_log_tail != tail) 777 if (sdp->sd_log_tail != tail)
767 log_pull_tail(sdp, tail); 778 log_pull_tail(sdp, tail);
@@ -810,7 +821,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
810 821
811 gfs2_ordered_write(sdp); 822 gfs2_ordered_write(sdp);
812 lops_before_commit(sdp, tr); 823 lops_before_commit(sdp, tr);
813 gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE, 0); 824 gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE);
814 825
815 if (sdp->sd_log_head != sdp->sd_log_flush_head) { 826 if (sdp->sd_log_head != sdp->sd_log_flush_head) {
816 log_flush_wait(sdp); 827 log_flush_wait(sdp);
diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h
index 1bc9bd444b28..7a34a3234266 100644
--- a/fs/gfs2/log.h
+++ b/fs/gfs2/log.h
@@ -59,7 +59,7 @@ static inline void gfs2_ordered_add_inode(struct gfs2_inode *ip)
59 if (!test_bit(GIF_ORDERED, &ip->i_flags)) { 59 if (!test_bit(GIF_ORDERED, &ip->i_flags)) {
60 spin_lock(&sdp->sd_ordered_lock); 60 spin_lock(&sdp->sd_ordered_lock);
61 if (!test_and_set_bit(GIF_ORDERED, &ip->i_flags)) 61 if (!test_and_set_bit(GIF_ORDERED, &ip->i_flags))
62 list_add(&ip->i_ordered, &sdp->sd_log_le_ordered); 62 list_add(&ip->i_ordered, &sdp->sd_log_ordered);
63 spin_unlock(&sdp->sd_ordered_lock); 63 spin_unlock(&sdp->sd_ordered_lock);
64 } 64 }
65} 65}
@@ -70,7 +70,8 @@ extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
70extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks); 70extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks);
71extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks); 71extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
72extern void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, 72extern void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
73 u64 seq, u32 tail, u32 flags, int op_flags); 73 u64 seq, u32 tail, u32 lblock, u32 flags,
74 int op_flags);
74extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, 75extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
75 u32 type); 76 u32 type);
76extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans); 77extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 6f09b5e3dd6e..33ab662c9aac 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -17,7 +17,9 @@
17#include <linux/bio.h> 17#include <linux/bio.h>
18#include <linux/fs.h> 18#include <linux/fs.h>
19#include <linux/list_sort.h> 19#include <linux/list_sort.h>
20#include <linux/blkdev.h>
20 21
22#include "bmap.h"
21#include "dir.h" 23#include "dir.h"
22#include "gfs2.h" 24#include "gfs2.h"
23#include "incore.h" 25#include "incore.h"
@@ -194,7 +196,6 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp,
194/** 196/**
195 * gfs2_end_log_write - end of i/o to the log 197 * gfs2_end_log_write - end of i/o to the log
196 * @bio: The bio 198 * @bio: The bio
197 * @error: Status of i/o request
198 * 199 *
199 * Each bio_vec contains either data from the pagecache or data 200 * Each bio_vec contains either data from the pagecache or data
200 * relating to the log itself. Here we iterate over the bio_vec 201 * relating to the log itself. Here we iterate over the bio_vec
@@ -231,20 +232,19 @@ static void gfs2_end_log_write(struct bio *bio)
231/** 232/**
232 * gfs2_log_submit_bio - Submit any pending log bio 233 * gfs2_log_submit_bio - Submit any pending log bio
233 * @biop: Address of the bio pointer 234 * @biop: Address of the bio pointer
234 * @op: REQ_OP 235 * @opf: REQ_OP | op_flags
235 * @op_flags: req_flag_bits
236 * 236 *
237 * Submit any pending part-built or full bio to the block device. If 237 * Submit any pending part-built or full bio to the block device. If
238 * there is no pending bio, then this is a no-op. 238 * there is no pending bio, then this is a no-op.
239 */ 239 */
240 240
241void gfs2_log_submit_bio(struct bio **biop, int op, int op_flags) 241void gfs2_log_submit_bio(struct bio **biop, int opf)
242{ 242{
243 struct bio *bio = *biop; 243 struct bio *bio = *biop;
244 if (bio) { 244 if (bio) {
245 struct gfs2_sbd *sdp = bio->bi_private; 245 struct gfs2_sbd *sdp = bio->bi_private;
246 atomic_inc(&sdp->sd_log_in_flight); 246 atomic_inc(&sdp->sd_log_in_flight);
247 bio_set_op_attrs(bio, op, op_flags); 247 bio->bi_opf = opf;
248 submit_bio(bio); 248 submit_bio(bio);
249 *biop = NULL; 249 *biop = NULL;
250 } 250 }
@@ -305,7 +305,7 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
305 nblk >>= sdp->sd_fsb2bb_shift; 305 nblk >>= sdp->sd_fsb2bb_shift;
306 if (blkno == nblk && !flush) 306 if (blkno == nblk && !flush)
307 return bio; 307 return bio;
308 gfs2_log_submit_bio(biop, op, 0); 308 gfs2_log_submit_bio(biop, op);
309 } 309 }
310 310
311 *biop = gfs2_log_alloc_bio(sdp, blkno, end_io); 311 *biop = gfs2_log_alloc_bio(sdp, blkno, end_io);
@@ -376,6 +376,205 @@ void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page)
376 gfs2_log_bmap(sdp)); 376 gfs2_log_bmap(sdp));
377} 377}
378 378
379/**
380 * gfs2_end_log_read - end I/O callback for reads from the log
381 * @bio: The bio
382 *
383 * Simply unlock the pages in the bio. The main thread will wait on them and
384 * process them in order as necessary.
385 */
386
387static void gfs2_end_log_read(struct bio *bio)
388{
389 struct page *page;
390 struct bio_vec *bvec;
391 struct bvec_iter_all iter_all;
392
393 bio_for_each_segment_all(bvec, bio, iter_all) {
394 page = bvec->bv_page;
395 if (bio->bi_status) {
396 int err = blk_status_to_errno(bio->bi_status);
397
398 SetPageError(page);
399 mapping_set_error(page->mapping, err);
400 }
401 unlock_page(page);
402 }
403
404 bio_put(bio);
405}
406
407/**
408 * gfs2_jhead_pg_srch - Look for the journal head in a given page.
409 * @jd: The journal descriptor
410 * @page: The page to look in
411 *
412 * Returns: 1 if found, 0 otherwise.
413 */
414
415static bool gfs2_jhead_pg_srch(struct gfs2_jdesc *jd,
416 struct gfs2_log_header_host *head,
417 struct page *page)
418{
419 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
420 struct gfs2_log_header_host uninitialized_var(lh);
421 void *kaddr = kmap_atomic(page);
422 unsigned int offset;
423 bool ret = false;
424
425 for (offset = 0; offset < PAGE_SIZE; offset += sdp->sd_sb.sb_bsize) {
426 if (!__get_log_header(sdp, kaddr + offset, 0, &lh)) {
427 if (lh.lh_sequence > head->lh_sequence)
428 *head = lh;
429 else {
430 ret = true;
431 break;
432 }
433 }
434 }
435 kunmap_atomic(kaddr);
436 return ret;
437}
438
439/**
440 * gfs2_jhead_process_page - Search/cleanup a page
441 * @jd: The journal descriptor
442 * @index: Index of the page to look into
443 * @done: If set, perform only cleanup, else search and set if found.
444 *
445 * Find the page with 'index' in the journal's mapping. Search the page for
446 * the journal head if requested (cleanup == false). Release refs on the
447 * page so the page cache can reclaim it (put_page() twice). We grabbed a
448 * reference on this page two times, first when we did a find_or_create_page()
449 * to obtain the page to add it to the bio and second when we do a
450 * find_get_page() here to get the page to wait on while I/O on it is being
451 * completed.
452 * This function is also used to free up a page we might've grabbed but not
453 * used. Maybe we added it to a bio, but not submitted it for I/O. Or we
454 * submitted the I/O, but we already found the jhead so we only need to drop
455 * our references to the page.
456 */
457
458static void gfs2_jhead_process_page(struct gfs2_jdesc *jd, unsigned long index,
459 struct gfs2_log_header_host *head,
460 bool *done)
461{
462 struct page *page;
463
464 page = find_get_page(jd->jd_inode->i_mapping, index);
465 wait_on_page_locked(page);
466
467 if (PageError(page))
468 *done = true;
469
470 if (!*done)
471 *done = gfs2_jhead_pg_srch(jd, head, page);
472
473 put_page(page); /* Once for find_get_page */
474 put_page(page); /* Once more for find_or_create_page */
475}
476
477/**
478 * gfs2_find_jhead - find the head of a log
479 * @jd: The journal descriptor
480 * @head: The log descriptor for the head of the log is returned here
481 *
482 * Do a search of a journal by reading it in large chunks using bios and find
483 * the valid log entry with the highest sequence number. (i.e. the log head)
484 *
485 * Returns: 0 on success, errno otherwise
486 */
487int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head,
488 bool keep_cache)
489{
490 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
491 struct address_space *mapping = jd->jd_inode->i_mapping;
492 unsigned int block = 0, blocks_submitted = 0, blocks_read = 0;
493 unsigned int bsize = sdp->sd_sb.sb_bsize;
494 unsigned int bsize_shift = sdp->sd_sb.sb_bsize_shift;
495 unsigned int shift = PAGE_SHIFT - bsize_shift;
496 unsigned int readhead_blocks = BIO_MAX_PAGES << shift;
497 struct gfs2_journal_extent *je;
498 int sz, ret = 0;
499 struct bio *bio = NULL;
500 struct page *page = NULL;
501 bool done = false;
502 errseq_t since;
503
504 memset(head, 0, sizeof(*head));
505 if (list_empty(&jd->extent_list))
506 gfs2_map_journal_extents(sdp, jd);
507
508 since = filemap_sample_wb_err(mapping);
509 list_for_each_entry(je, &jd->extent_list, list) {
510 for (; block < je->lblock + je->blocks; block++) {
511 u64 dblock;
512
513 if (!page) {
514 page = find_or_create_page(mapping,
515 block >> shift, GFP_NOFS);
516 if (!page) {
517 ret = -ENOMEM;
518 done = true;
519 goto out;
520 }
521 }
522
523 if (bio) {
524 unsigned int off;
525
526 off = (block << bsize_shift) & ~PAGE_MASK;
527 sz = bio_add_page(bio, page, bsize, off);
528 if (sz == bsize) { /* block added */
529 if (off + bsize == PAGE_SIZE) {
530 page = NULL;
531 goto page_added;
532 }
533 continue;
534 }
535 blocks_submitted = block + 1;
536 submit_bio(bio);
537 bio = NULL;
538 }
539
540 dblock = je->dblock + (block - je->lblock);
541 bio = gfs2_log_alloc_bio(sdp, dblock, gfs2_end_log_read);
542 bio->bi_opf = REQ_OP_READ;
543 sz = bio_add_page(bio, page, bsize, 0);
544 gfs2_assert_warn(sdp, sz == bsize);
545 if (bsize == PAGE_SIZE)
546 page = NULL;
547
548page_added:
549 if (blocks_submitted < blocks_read + readhead_blocks) {
550 /* Keep at least one bio in flight */
551 continue;
552 }
553
554 gfs2_jhead_process_page(jd, blocks_read >> shift, head, &done);
555 blocks_read += PAGE_SIZE >> bsize_shift;
556 if (done)
557 goto out; /* found */
558 }
559 }
560
561out:
562 if (bio)
563 submit_bio(bio);
564 while (blocks_read < block) {
565 gfs2_jhead_process_page(jd, blocks_read >> shift, head, &done);
566 blocks_read += PAGE_SIZE >> bsize_shift;
567 }
568
569 if (!ret)
570 ret = filemap_check_wb_err(mapping, since);
571
572 if (!keep_cache)
573 truncate_inode_pages(mapping, 0);
574
575 return ret;
576}
577
379static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type, 578static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
380 u32 ld_length, u32 ld_data1) 579 u32 ld_length, u32 ld_data1)
381{ 580{
@@ -529,7 +728,7 @@ static void buf_lo_before_scan(struct gfs2_jdesc *jd,
529 jd->jd_replayed_blocks = 0; 728 jd->jd_replayed_blocks = 0;
530} 729}
531 730
532static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, 731static int buf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
533 struct gfs2_log_descriptor *ld, __be64 *ptr, 732 struct gfs2_log_descriptor *ld, __be64 *ptr,
534 int pass) 733 int pass)
535{ 734{
@@ -622,7 +821,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
622{ 821{
623 struct gfs2_meta_header *mh; 822 struct gfs2_meta_header *mh;
624 unsigned int offset; 823 unsigned int offset;
625 struct list_head *head = &sdp->sd_log_le_revoke; 824 struct list_head *head = &sdp->sd_log_revokes;
626 struct gfs2_bufdata *bd; 825 struct gfs2_bufdata *bd;
627 struct page *page; 826 struct page *page;
628 unsigned int length; 827 unsigned int length;
@@ -660,18 +859,35 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
660 859
661static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 860static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
662{ 861{
663 struct list_head *head = &sdp->sd_log_le_revoke; 862 struct list_head *head = &sdp->sd_log_revokes;
664 struct gfs2_bufdata *bd; 863 struct gfs2_bufdata *bd, *tmp;
665 struct gfs2_glock *gl;
666 864
667 while (!list_empty(head)) { 865 /*
668 bd = list_entry(head->next, struct gfs2_bufdata, bd_list); 866 * Glocks can be referenced repeatedly on the revoke list, but the list
669 list_del_init(&bd->bd_list); 867 * only holds one reference. All glocks on the list will have the
670 gl = bd->bd_gl; 868 * GLF_REVOKES flag set initially.
671 atomic_dec(&gl->gl_revokes); 869 */
672 clear_bit(GLF_LFLUSH, &gl->gl_flags); 870
871 list_for_each_entry_safe(bd, tmp, head, bd_list) {
872 struct gfs2_glock *gl = bd->bd_gl;
873
874 if (test_bit(GLF_REVOKES, &gl->gl_flags)) {
875 /* Keep each glock on the list exactly once. */
876 clear_bit(GLF_REVOKES, &gl->gl_flags);
877 continue;
878 }
879 list_del(&bd->bd_list);
673 kmem_cache_free(gfs2_bufdata_cachep, bd); 880 kmem_cache_free(gfs2_bufdata_cachep, bd);
674 } 881 }
882 list_for_each_entry_safe(bd, tmp, head, bd_list) {
883 struct gfs2_glock *gl = bd->bd_gl;
884
885 list_del(&bd->bd_list);
886 kmem_cache_free(gfs2_bufdata_cachep, bd);
887 clear_bit(GLF_LFLUSH, &gl->gl_flags);
888 gfs2_glock_queue_put(gl);
889 }
890 /* the list is empty now */
675} 891}
676 892
677static void revoke_lo_before_scan(struct gfs2_jdesc *jd, 893static void revoke_lo_before_scan(struct gfs2_jdesc *jd,
@@ -684,7 +900,7 @@ static void revoke_lo_before_scan(struct gfs2_jdesc *jd,
684 jd->jd_replay_tail = head->lh_tail; 900 jd->jd_replay_tail = head->lh_tail;
685} 901}
686 902
687static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, 903static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
688 struct gfs2_log_descriptor *ld, __be64 *ptr, 904 struct gfs2_log_descriptor *ld, __be64 *ptr,
689 int pass) 905 int pass)
690{ 906{
@@ -766,7 +982,7 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr
766 gfs2_before_commit(sdp, limit, nbuf, &tr->tr_databuf, 1); 982 gfs2_before_commit(sdp, limit, nbuf, &tr->tr_databuf, 1);
767} 983}
768 984
769static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, 985static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
770 struct gfs2_log_descriptor *ld, 986 struct gfs2_log_descriptor *ld,
771 __be64 *ptr, int pass) 987 __be64 *ptr, int pass)
772{ 988{
@@ -852,7 +1068,7 @@ static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
852} 1068}
853 1069
854 1070
855const struct gfs2_log_operations gfs2_buf_lops = { 1071static const struct gfs2_log_operations gfs2_buf_lops = {
856 .lo_before_commit = buf_lo_before_commit, 1072 .lo_before_commit = buf_lo_before_commit,
857 .lo_after_commit = buf_lo_after_commit, 1073 .lo_after_commit = buf_lo_after_commit,
858 .lo_before_scan = buf_lo_before_scan, 1074 .lo_before_scan = buf_lo_before_scan,
@@ -861,7 +1077,7 @@ const struct gfs2_log_operations gfs2_buf_lops = {
861 .lo_name = "buf", 1077 .lo_name = "buf",
862}; 1078};
863 1079
864const struct gfs2_log_operations gfs2_revoke_lops = { 1080static const struct gfs2_log_operations gfs2_revoke_lops = {
865 .lo_before_commit = revoke_lo_before_commit, 1081 .lo_before_commit = revoke_lo_before_commit,
866 .lo_after_commit = revoke_lo_after_commit, 1082 .lo_after_commit = revoke_lo_after_commit,
867 .lo_before_scan = revoke_lo_before_scan, 1083 .lo_before_scan = revoke_lo_before_scan,
@@ -870,7 +1086,7 @@ const struct gfs2_log_operations gfs2_revoke_lops = {
870 .lo_name = "revoke", 1086 .lo_name = "revoke",
871}; 1087};
872 1088
873const struct gfs2_log_operations gfs2_databuf_lops = { 1089static const struct gfs2_log_operations gfs2_databuf_lops = {
874 .lo_before_commit = databuf_lo_before_commit, 1090 .lo_before_commit = databuf_lo_before_commit,
875 .lo_after_commit = databuf_lo_after_commit, 1091 .lo_after_commit = databuf_lo_after_commit,
876 .lo_scan_elements = databuf_lo_scan_elements, 1092 .lo_scan_elements = databuf_lo_scan_elements,
diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h
index 711c4d89c063..f195ffb435ac 100644
--- a/fs/gfs2/lops.h
+++ b/fs/gfs2/lops.h
@@ -20,18 +20,15 @@
20 ((sizeof(struct gfs2_log_descriptor) + (2 * sizeof(__be64) - 1)) & \ 20 ((sizeof(struct gfs2_log_descriptor) + (2 * sizeof(__be64) - 1)) & \
21 ~(2 * sizeof(__be64) - 1)) 21 ~(2 * sizeof(__be64) - 1))
22 22
23extern const struct gfs2_log_operations gfs2_glock_lops;
24extern const struct gfs2_log_operations gfs2_buf_lops;
25extern const struct gfs2_log_operations gfs2_revoke_lops;
26extern const struct gfs2_log_operations gfs2_databuf_lops;
27
28extern const struct gfs2_log_operations *gfs2_log_ops[]; 23extern const struct gfs2_log_operations *gfs2_log_ops[];
29extern u64 gfs2_log_bmap(struct gfs2_sbd *sdp); 24extern u64 gfs2_log_bmap(struct gfs2_sbd *sdp);
30extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page, 25extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
31 unsigned size, unsigned offset, u64 blkno); 26 unsigned size, unsigned offset, u64 blkno);
32extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page); 27extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page);
33extern void gfs2_log_submit_bio(struct bio **biop, int op, int op_flags); 28extern void gfs2_log_submit_bio(struct bio **biop, int opf);
34extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); 29extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
30extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
31 struct gfs2_log_header_host *head, bool keep_cache);
35 32
36static inline unsigned int buf_limit(struct gfs2_sbd *sdp) 33static inline unsigned int buf_limit(struct gfs2_sbd *sdp)
37{ 34{
@@ -77,7 +74,7 @@ static inline void lops_before_scan(struct gfs2_jdesc *jd,
77 gfs2_log_ops[x]->lo_before_scan(jd, head, pass); 74 gfs2_log_ops[x]->lo_before_scan(jd, head, pass);
78} 75}
79 76
80static inline int lops_scan_elements(struct gfs2_jdesc *jd, unsigned int start, 77static inline int lops_scan_elements(struct gfs2_jdesc *jd, u32 start,
81 struct gfs2_log_descriptor *ld, 78 struct gfs2_log_descriptor *ld,
82 __be64 *ptr, 79 __be64 *ptr,
83 unsigned int pass) 80 unsigned int pass)
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 136484ef35d3..c700738de1f7 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -59,7 +59,6 @@ static void gfs2_init_glock_once(void *foo)
59 INIT_LIST_HEAD(&gl->gl_lru); 59 INIT_LIST_HEAD(&gl->gl_lru);
60 INIT_LIST_HEAD(&gl->gl_ail_list); 60 INIT_LIST_HEAD(&gl->gl_ail_list);
61 atomic_set(&gl->gl_ail_count, 0); 61 atomic_set(&gl->gl_ail_count, 0);
62 atomic_set(&gl->gl_revokes, 0);
63} 62}
64 63
65static void gfs2_init_gl_aspace_once(void *foo) 64static void gfs2_init_gl_aspace_once(void *foo)
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index b041cb8ae383..46f6615eaf12 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -41,6 +41,7 @@
41#include "dir.h" 41#include "dir.h"
42#include "meta_io.h" 42#include "meta_io.h"
43#include "trace_gfs2.h" 43#include "trace_gfs2.h"
44#include "lops.h"
44 45
45#define DO 0 46#define DO 0
46#define UNDO 1 47#define UNDO 1
@@ -117,8 +118,8 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
117 118
118 spin_lock_init(&sdp->sd_log_lock); 119 spin_lock_init(&sdp->sd_log_lock);
119 atomic_set(&sdp->sd_log_pinned, 0); 120 atomic_set(&sdp->sd_log_pinned, 0);
120 INIT_LIST_HEAD(&sdp->sd_log_le_revoke); 121 INIT_LIST_HEAD(&sdp->sd_log_revokes);
121 INIT_LIST_HEAD(&sdp->sd_log_le_ordered); 122 INIT_LIST_HEAD(&sdp->sd_log_ordered);
122 spin_lock_init(&sdp->sd_ordered_lock); 123 spin_lock_init(&sdp->sd_ordered_lock);
123 124
124 init_waitqueue_head(&sdp->sd_log_waitq); 125 init_waitqueue_head(&sdp->sd_log_waitq);
@@ -616,7 +617,7 @@ static int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd)
616 fs_err(sdp, "Error checking journal for spectator mount.\n"); 617 fs_err(sdp, "Error checking journal for spectator mount.\n");
617 goto out_unlock; 618 goto out_unlock;
618 } 619 }
619 error = gfs2_find_jhead(jd, &head); 620 error = gfs2_find_jhead(jd, &head, false);
620 if (error) { 621 if (error) {
621 fs_err(sdp, "Error parsing journal for spectator mount.\n"); 622 fs_err(sdp, "Error parsing journal for spectator mount.\n");
622 goto out_unlock; 623 goto out_unlock;
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index 2dac43065382..389b3ef77e20 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -182,129 +182,6 @@ static int get_log_header(struct gfs2_jdesc *jd, unsigned int blk,
182} 182}
183 183
184/** 184/**
185 * find_good_lh - find a good log header
186 * @jd: the journal
187 * @blk: the segment to start searching from
188 * @lh: the log header to fill in
189 * @forward: if true search forward in the log, else search backward
190 *
191 * Call get_log_header() to get a log header for a segment, but if the
192 * segment is bad, either scan forward or backward until we find a good one.
193 *
194 * Returns: errno
195 */
196
197static int find_good_lh(struct gfs2_jdesc *jd, unsigned int *blk,
198 struct gfs2_log_header_host *head)
199{
200 unsigned int orig_blk = *blk;
201 int error;
202
203 for (;;) {
204 error = get_log_header(jd, *blk, head);
205 if (error <= 0)
206 return error;
207
208 if (++*blk == jd->jd_blocks)
209 *blk = 0;
210
211 if (*blk == orig_blk) {
212 gfs2_consist_inode(GFS2_I(jd->jd_inode));
213 return -EIO;
214 }
215 }
216}
217
218/**
219 * jhead_scan - make sure we've found the head of the log
220 * @jd: the journal
221 * @head: this is filled in with the log descriptor of the head
222 *
223 * At this point, seg and lh should be either the head of the log or just
224 * before. Scan forward until we find the head.
225 *
226 * Returns: errno
227 */
228
229static int jhead_scan(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
230{
231 unsigned int blk = head->lh_blkno;
232 struct gfs2_log_header_host lh;
233 int error;
234
235 for (;;) {
236 if (++blk == jd->jd_blocks)
237 blk = 0;
238
239 error = get_log_header(jd, blk, &lh);
240 if (error < 0)
241 return error;
242 if (error == 1)
243 continue;
244
245 if (lh.lh_sequence == head->lh_sequence) {
246 gfs2_consist_inode(GFS2_I(jd->jd_inode));
247 return -EIO;
248 }
249 if (lh.lh_sequence < head->lh_sequence)
250 break;
251
252 *head = lh;
253 }
254
255 return 0;
256}
257
258/**
259 * gfs2_find_jhead - find the head of a log
260 * @jd: the journal
261 * @head: the log descriptor for the head of the log is returned here
262 *
263 * Do a binary search of a journal and find the valid log entry with the
264 * highest sequence number. (i.e. the log head)
265 *
266 * Returns: errno
267 */
268
269int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
270{
271 struct gfs2_log_header_host lh_1, lh_m;
272 u32 blk_1, blk_2, blk_m;
273 int error;
274
275 blk_1 = 0;
276 blk_2 = jd->jd_blocks - 1;
277
278 for (;;) {
279 blk_m = (blk_1 + blk_2) / 2;
280
281 error = find_good_lh(jd, &blk_1, &lh_1);
282 if (error)
283 return error;
284
285 error = find_good_lh(jd, &blk_m, &lh_m);
286 if (error)
287 return error;
288
289 if (blk_1 == blk_m || blk_m == blk_2)
290 break;
291
292 if (lh_1.lh_sequence <= lh_m.lh_sequence)
293 blk_1 = blk_m;
294 else
295 blk_2 = blk_m;
296 }
297
298 error = jhead_scan(jd, &lh_1);
299 if (error)
300 return error;
301
302 *head = lh_1;
303
304 return error;
305}
306
307/**
308 * foreach_descriptor - go through the active part of the log 185 * foreach_descriptor - go through the active part of the log
309 * @jd: the journal 186 * @jd: the journal
310 * @start: the first log header in the active region 187 * @start: the first log header in the active region
@@ -316,7 +193,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
316 * Returns: errno 193 * Returns: errno
317 */ 194 */
318 195
319static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, 196static int foreach_descriptor(struct gfs2_jdesc *jd, u32 start,
320 unsigned int end, int pass) 197 unsigned int end, int pass)
321{ 198{
322 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); 199 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
@@ -386,10 +263,12 @@ static void clean_journal(struct gfs2_jdesc *jd,
386 struct gfs2_log_header_host *head) 263 struct gfs2_log_header_host *head)
387{ 264{
388 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); 265 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
266 u32 lblock = head->lh_blkno;
389 267
390 sdp->sd_log_flush_head = head->lh_blkno; 268 gfs2_replay_incr_blk(jd, &lblock);
391 gfs2_replay_incr_blk(jd, &sdp->sd_log_flush_head); 269 if (jd->jd_jid == sdp->sd_lockstruct.ls_jid)
392 gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, 270 sdp->sd_log_flush_head = lblock;
271 gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, lblock,
393 GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY, 272 GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY,
394 REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC); 273 REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC);
395} 274}
@@ -467,7 +346,7 @@ void gfs2_recover_func(struct work_struct *work)
467 if (error) 346 if (error)
468 goto fail_gunlock_ji; 347 goto fail_gunlock_ji;
469 348
470 error = gfs2_find_jhead(jd, &head); 349 error = gfs2_find_jhead(jd, &head, true);
471 if (error) 350 if (error)
472 goto fail_gunlock_ji; 351 goto fail_gunlock_ji;
473 t_jhd = ktime_get(); 352 t_jhd = ktime_get();
diff --git a/fs/gfs2/recovery.h b/fs/gfs2/recovery.h
index 11d81248be85..1831a1974c8c 100644
--- a/fs/gfs2/recovery.h
+++ b/fs/gfs2/recovery.h
@@ -14,7 +14,7 @@
14 14
15extern struct workqueue_struct *gfs_recovery_wq; 15extern struct workqueue_struct *gfs_recovery_wq;
16 16
17static inline void gfs2_replay_incr_blk(struct gfs2_jdesc *jd, unsigned int *blk) 17static inline void gfs2_replay_incr_blk(struct gfs2_jdesc *jd, u32 *blk)
18{ 18{
19 if (++*blk == jd->jd_blocks) 19 if (++*blk == jd->jd_blocks)
20 *blk = 0; 20 *blk = 0;
@@ -27,8 +27,6 @@ extern int gfs2_revoke_add(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)
27extern int gfs2_revoke_check(struct gfs2_jdesc *jd, u64 blkno, unsigned int where); 27extern int gfs2_revoke_check(struct gfs2_jdesc *jd, u64 blkno, unsigned int where);
28extern void gfs2_revoke_clean(struct gfs2_jdesc *jd); 28extern void gfs2_revoke_clean(struct gfs2_jdesc *jd);
29 29
30extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
31 struct gfs2_log_header_host *head);
32extern int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd, bool wait); 30extern int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd, bool wait);
33extern void gfs2_recover_func(struct work_struct *work); 31extern void gfs2_recover_func(struct work_struct *work);
34extern int __get_log_header(struct gfs2_sbd *sdp, 32extern int __get_log_header(struct gfs2_sbd *sdp,
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 17a8d3b43990..15d6e32de55f 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1729,25 +1729,22 @@ fail:
1729static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext, 1729static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
1730 const struct gfs2_inode *ip, bool nowrap) 1730 const struct gfs2_inode *ip, bool nowrap)
1731{ 1731{
1732 bool scan_from_start = rbm->bii == 0 && rbm->offset == 0;
1732 struct buffer_head *bh; 1733 struct buffer_head *bh;
1733 int initial_bii; 1734 int last_bii;
1734 u32 initial_offset;
1735 int first_bii = rbm->bii;
1736 u32 first_offset = rbm->offset;
1737 u32 offset; 1735 u32 offset;
1738 u8 *buffer; 1736 u8 *buffer;
1739 int n = 0; 1737 bool wrapped = false;
1740 int iters = rbm->rgd->rd_length;
1741 int ret; 1738 int ret;
1742 struct gfs2_bitmap *bi; 1739 struct gfs2_bitmap *bi;
1743 struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, }; 1740 struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, };
1744 1741
1745 /* If we are not starting at the beginning of a bitmap, then we 1742 /*
1746 * need to add one to the bitmap count to ensure that we search 1743 * Determine the last bitmap to search. If we're not starting at the
1747 * the starting bitmap twice. 1744 * beginning of a bitmap, we need to search that bitmap twice to scan
1745 * the entire resource group.
1748 */ 1746 */
1749 if (rbm->offset != 0) 1747 last_bii = rbm->bii - (rbm->offset == 0);
1750 iters++;
1751 1748
1752 while(1) { 1749 while(1) {
1753 bi = rbm_bi(rbm); 1750 bi = rbm_bi(rbm);
@@ -1761,47 +1758,46 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
1761 WARN_ON(!buffer_uptodate(bh)); 1758 WARN_ON(!buffer_uptodate(bh));
1762 if (state != GFS2_BLKST_UNLINKED && bi->bi_clone) 1759 if (state != GFS2_BLKST_UNLINKED && bi->bi_clone)
1763 buffer = bi->bi_clone + bi->bi_offset; 1760 buffer = bi->bi_clone + bi->bi_offset;
1764 initial_offset = rbm->offset;
1765 offset = gfs2_bitfit(buffer, bi->bi_bytes, rbm->offset, state); 1761 offset = gfs2_bitfit(buffer, bi->bi_bytes, rbm->offset, state);
1766 if (offset == BFITNOENT) 1762 if (offset == BFITNOENT) {
1767 goto bitmap_full; 1763 if (state == GFS2_BLKST_FREE && rbm->offset == 0)
1764 set_bit(GBF_FULL, &bi->bi_flags);
1765 goto next_bitmap;
1766 }
1768 rbm->offset = offset; 1767 rbm->offset = offset;
1769 if (ip == NULL) 1768 if (ip == NULL)
1770 return 0; 1769 return 0;
1771 1770
1772 initial_bii = rbm->bii;
1773 ret = gfs2_reservation_check_and_update(rbm, ip, 1771 ret = gfs2_reservation_check_and_update(rbm, ip,
1774 minext ? *minext : 0, 1772 minext ? *minext : 0,
1775 &maxext); 1773 &maxext);
1776 if (ret == 0) 1774 if (ret == 0)
1777 return 0; 1775 return 0;
1778 if (ret > 0) { 1776 if (ret > 0)
1779 n += (rbm->bii - initial_bii);
1780 goto next_iter; 1777 goto next_iter;
1781 }
1782 if (ret == -E2BIG) { 1778 if (ret == -E2BIG) {
1783 rbm->bii = 0; 1779 rbm->bii = 0;
1784 rbm->offset = 0; 1780 rbm->offset = 0;
1785 n += (rbm->bii - initial_bii);
1786 goto res_covered_end_of_rgrp; 1781 goto res_covered_end_of_rgrp;
1787 } 1782 }
1788 return ret; 1783 return ret;
1789 1784
1790bitmap_full: /* Mark bitmap as full and fall through */
1791 if ((state == GFS2_BLKST_FREE) && initial_offset == 0)
1792 set_bit(GBF_FULL, &bi->bi_flags);
1793
1794next_bitmap: /* Find next bitmap in the rgrp */ 1785next_bitmap: /* Find next bitmap in the rgrp */
1795 rbm->offset = 0; 1786 rbm->offset = 0;
1796 rbm->bii++; 1787 rbm->bii++;
1797 if (rbm->bii == rbm->rgd->rd_length) 1788 if (rbm->bii == rbm->rgd->rd_length)
1798 rbm->bii = 0; 1789 rbm->bii = 0;
1799res_covered_end_of_rgrp: 1790res_covered_end_of_rgrp:
1800 if ((rbm->bii == 0) && nowrap) 1791 if (rbm->bii == 0) {
1801 break; 1792 if (wrapped)
1802 n++; 1793 break;
1794 wrapped = true;
1795 if (nowrap)
1796 break;
1797 }
1803next_iter: 1798next_iter:
1804 if (n >= iters) 1799 /* Have we scanned the entire resource group? */
1800 if (wrapped && rbm->bii > last_bii)
1805 break; 1801 break;
1806 } 1802 }
1807 1803
@@ -1811,8 +1807,8 @@ next_iter:
1811 /* If the extent was too small, and it's smaller than the smallest 1807 /* If the extent was too small, and it's smaller than the smallest
1812 to have failed before, remember for future reference that it's 1808 to have failed before, remember for future reference that it's
1813 useless to search this rgrp again for this amount or more. */ 1809 useless to search this rgrp again for this amount or more. */
1814 if ((first_offset == 0) && (first_bii == 0) && 1810 if (wrapped && (scan_from_start || rbm->bii > last_bii) &&
1815 (*minext < rbm->rgd->rd_extfail_pt)) 1811 *minext < rbm->rgd->rd_extfail_pt)
1816 rbm->rgd->rd_extfail_pt = *minext; 1812 rbm->rgd->rd_extfail_pt = *minext;
1817 1813
1818 /* If the maximum extent we found is big enough to fulfill the 1814 /* If the maximum extent we found is big enough to fulfill the
@@ -2444,7 +2440,7 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
2444 2440
2445 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); 2441 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0);
2446 if (dinode) 2442 if (dinode)
2447 gfs2_trans_add_unrevoke(sdp, block, *nblocks); 2443 gfs2_trans_remove_revoke(sdp, block, *nblocks);
2448 2444
2449 gfs2_quota_change(ip, *nblocks, ip->i_inode.i_uid, ip->i_inode.i_gid); 2445 gfs2_quota_change(ip, *nblocks, ip->i_inode.i_uid, ip->i_inode.i_gid);
2450 2446
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 7b8d2306b3d3..fbf6b1fd330b 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -45,6 +45,7 @@
45#include "util.h" 45#include "util.h"
46#include "sys.h" 46#include "sys.h"
47#include "xattr.h" 47#include "xattr.h"
48#include "lops.h"
48 49
49#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x) 50#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
50 51
@@ -425,7 +426,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
425 426
426 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 427 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
427 428
428 error = gfs2_find_jhead(sdp->sd_jdesc, &head); 429 error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
429 if (error) 430 if (error)
430 goto fail; 431 goto fail;
431 432
@@ -680,7 +681,7 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
680 error = gfs2_jdesc_check(jd); 681 error = gfs2_jdesc_check(jd);
681 if (error) 682 if (error)
682 break; 683 break;
683 error = gfs2_find_jhead(jd, &lh); 684 error = gfs2_find_jhead(jd, &lh, false);
684 if (error) 685 if (error)
685 break; 686 break;
686 if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { 687 if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
@@ -973,8 +974,7 @@ void gfs2_freeze_func(struct work_struct *work)
973 if (error) { 974 if (error) {
974 printk(KERN_INFO "GFS2: couldn't get freeze lock : %d\n", error); 975 printk(KERN_INFO "GFS2: couldn't get freeze lock : %d\n", error);
975 gfs2_assert_withdraw(sdp, 0); 976 gfs2_assert_withdraw(sdp, 0);
976 } 977 } else {
977 else {
978 atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN); 978 atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
979 error = thaw_super(sb); 979 error = thaw_super(sb);
980 if (error) { 980 if (error) {
@@ -987,6 +987,8 @@ void gfs2_freeze_func(struct work_struct *work)
987 gfs2_glock_dq_uninit(&freeze_gh); 987 gfs2_glock_dq_uninit(&freeze_gh);
988 } 988 }
989 deactivate_super(sb); 989 deactivate_super(sb);
990 clear_bit_unlock(SDF_FS_FROZEN, &sdp->sd_flags);
991 wake_up_bit(&sdp->sd_flags, SDF_FS_FROZEN);
990 return; 992 return;
991} 993}
992 994
@@ -1029,6 +1031,7 @@ static int gfs2_freeze(struct super_block *sb)
1029 msleep(1000); 1031 msleep(1000);
1030 } 1032 }
1031 error = 0; 1033 error = 0;
1034 set_bit(SDF_FS_FROZEN, &sdp->sd_flags);
1032out: 1035out:
1033 mutex_unlock(&sdp->sd_freeze_mutex); 1036 mutex_unlock(&sdp->sd_freeze_mutex);
1034 return error; 1037 return error;
@@ -1053,7 +1056,7 @@ static int gfs2_unfreeze(struct super_block *sb)
1053 1056
1054 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); 1057 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
1055 mutex_unlock(&sdp->sd_freeze_mutex); 1058 mutex_unlock(&sdp->sd_freeze_mutex);
1056 return 0; 1059 return wait_on_bit(&sdp->sd_flags, SDF_FS_FROZEN, TASK_INTERRUPTIBLE);
1057} 1060}
1058 1061
1059/** 1062/**
@@ -1474,7 +1477,7 @@ static void gfs2_final_release_pages(struct gfs2_inode *ip)
1474 truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0); 1477 truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0);
1475 truncate_inode_pages(&inode->i_data, 0); 1478 truncate_inode_pages(&inode->i_data, 0);
1476 1479
1477 if (atomic_read(&gl->gl_revokes) == 0) { 1480 if (!test_bit(GLF_REVOKES, &gl->gl_flags)) {
1478 clear_bit(GLF_LFLUSH, &gl->gl_flags); 1481 clear_bit(GLF_LFLUSH, &gl->gl_flags);
1479 clear_bit(GLF_DIRTY, &gl->gl_flags); 1482 clear_bit(GLF_DIRTY, &gl->gl_flags);
1480 } 1483 }
@@ -1630,8 +1633,6 @@ alloc_failed:
1630 goto out_truncate; 1633 goto out_truncate;
1631 } 1634 }
1632 1635
1633 /* Case 1 starts here */
1634
1635 if (S_ISDIR(inode->i_mode) && 1636 if (S_ISDIR(inode->i_mode) &&
1636 (ip->i_diskflags & GFS2_DIF_EXHASH)) { 1637 (ip->i_diskflags & GFS2_DIF_EXHASH)) {
1637 error = gfs2_dir_exhash_dealloc(ip); 1638 error = gfs2_dir_exhash_dealloc(ip);
@@ -1670,7 +1671,6 @@ out_truncate:
1670 write_inode_now(inode, 1); 1671 write_inode_now(inode, 1);
1671 gfs2_ail_flush(ip->i_gl, 0); 1672 gfs2_ail_flush(ip->i_gl, 0);
1672 1673
1673 /* Case 2 starts here */
1674 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); 1674 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
1675 if (error) 1675 if (error)
1676 goto out_unlock; 1676 goto out_unlock;
@@ -1680,7 +1680,6 @@ out_truncate:
1680 gfs2_trans_end(sdp); 1680 gfs2_trans_end(sdp);
1681 1681
1682out_unlock: 1682out_unlock:
1683 /* Error path for case 1 */
1684 if (gfs2_rs_active(&ip->i_res)) 1683 if (gfs2_rs_active(&ip->i_res))
1685 gfs2_rs_deltree(&ip->i_res); 1684 gfs2_rs_deltree(&ip->i_res);
1686 1685
@@ -1699,7 +1698,6 @@ out_unlock:
1699 if (error && error != GLR_TRYFAILED && error != -EROFS) 1698 if (error && error != GLR_TRYFAILED && error != -EROFS)
1700 fs_warn(sdp, "gfs2_evict_inode: %d\n", error); 1699 fs_warn(sdp, "gfs2_evict_inode: %d\n", error);
1701out: 1700out:
1702 /* Case 3 starts here */
1703 truncate_inode_pages_final(&inode->i_data); 1701 truncate_inode_pages_final(&inode->i_data);
1704 gfs2_rsqa_delete(ip, NULL); 1702 gfs2_rsqa_delete(ip, NULL);
1705 gfs2_ordered_del_inode(ip); 1703 gfs2_ordered_del_inode(ip);
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index cd9a94a6b5bb..d328da7cde36 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -253,14 +253,14 @@ void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
253 tr->tr_num_revoke++; 253 tr->tr_num_revoke++;
254} 254}
255 255
256void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len) 256void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len)
257{ 257{
258 struct gfs2_bufdata *bd, *tmp; 258 struct gfs2_bufdata *bd, *tmp;
259 struct gfs2_trans *tr = current->journal_info; 259 struct gfs2_trans *tr = current->journal_info;
260 unsigned int n = len; 260 unsigned int n = len;
261 261
262 gfs2_log_lock(sdp); 262 gfs2_log_lock(sdp);
263 list_for_each_entry_safe(bd, tmp, &sdp->sd_log_le_revoke, bd_list) { 263 list_for_each_entry_safe(bd, tmp, &sdp->sd_log_revokes, bd_list) {
264 if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) { 264 if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) {
265 list_del_init(&bd->bd_list); 265 list_del_init(&bd->bd_list);
266 gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke); 266 gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke);
diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h
index ad70087d0597..1e39f056ccb7 100644
--- a/fs/gfs2/trans.h
+++ b/fs/gfs2/trans.h
@@ -44,6 +44,6 @@ extern void gfs2_trans_end(struct gfs2_sbd *sdp);
44extern void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh); 44extern void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh);
45extern void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh); 45extern void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh);
46extern void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd); 46extern void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd);
47extern void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len); 47extern void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len);
48 48
49#endif /* __TRANS_DOT_H__ */ 49#endif /* __TRANS_DOT_H__ */
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index 996c915a9c97..675e704830df 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -631,7 +631,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
631 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL); 631 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
632 if (error) 632 if (error)
633 return error; 633 return error;
634 gfs2_trans_add_unrevoke(sdp, block, 1); 634 gfs2_trans_remove_revoke(sdp, block, 1);
635 *bhp = gfs2_meta_new(ip->i_gl, block); 635 *bhp = gfs2_meta_new(ip->i_gl, block);
636 gfs2_trans_add_meta(ip->i_gl, *bhp); 636 gfs2_trans_add_meta(ip->i_gl, *bhp);
637 gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA); 637 gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA);
@@ -693,7 +693,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
693 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL); 693 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
694 if (error) 694 if (error)
695 return error; 695 return error;
696 gfs2_trans_add_unrevoke(sdp, block, 1); 696 gfs2_trans_remove_revoke(sdp, block, 1);
697 bh = gfs2_meta_new(ip->i_gl, block); 697 bh = gfs2_meta_new(ip->i_gl, block);
698 gfs2_trans_add_meta(ip->i_gl, bh); 698 gfs2_trans_add_meta(ip->i_gl, bh);
699 gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED); 699 gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED);
@@ -997,7 +997,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
997 error = gfs2_alloc_blocks(ip, &blk, &n, 0, NULL); 997 error = gfs2_alloc_blocks(ip, &blk, &n, 0, NULL);
998 if (error) 998 if (error)
999 return error; 999 return error;
1000 gfs2_trans_add_unrevoke(sdp, blk, 1); 1000 gfs2_trans_remove_revoke(sdp, blk, 1);
1001 indbh = gfs2_meta_new(ip->i_gl, blk); 1001 indbh = gfs2_meta_new(ip->i_gl, blk);
1002 gfs2_trans_add_meta(ip->i_gl, indbh); 1002 gfs2_trans_add_meta(ip->i_gl, indbh);
1003 gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); 1003 gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);