Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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)

+438 -294
+10 -4
fs/gfs2/aops.c
··· 649 649 */ 650 650 void 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 653 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); 654 654 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); 655 655 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; ··· 657 657 struct buffer_head *m_bh, *l_bh; 658 658 u64 fs_total, new_free; 659 659 660 + if (gfs2_trans_begin(sdp, 2 * RES_STATFS, 0) != 0) 661 + return; 662 + 660 663 /* Total up the file system space, according to the latest rindex. */ 661 664 fs_total = gfs2_ri_total(sdp); 662 665 if (gfs2_meta_inode_buffer(m_ip, &m_bh) != 0) 663 - return; 666 + goto out; 664 667 665 668 spin_lock(&sdp->sd_statfs_spin); 666 669 gfs2_statfs_change_in(m_sc, m_bh->b_data + ··· 678 675 gfs2_statfs_change(sdp, new_free, new_free, 0); 679 676 680 677 if (gfs2_meta_inode_buffer(l_ip, &l_bh) != 0) 681 - goto out; 678 + goto out2; 682 679 update_statfs(sdp, m_bh, l_bh); 683 680 brelse(l_bh); 684 - out: 681 + out2: 685 682 brelse(m_bh); 683 + out: 684 + sdp->sd_rindex_uptodate = 0; 685 + gfs2_trans_end(sdp); 686 686 } 687 687 688 688 /**
+76 -42
fs/gfs2/bmap.c
··· 142 142 if (error) 143 143 goto out_brelse; 144 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 146 error = gfs2_dir_get_new_buffer(ip, block, &bh); 147 147 if (error) 148 148 goto out_brelse; ··· 676 676 goto out; 677 677 alloced += n; 678 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 680 switch (state) { 681 681 /* Growing height of tree */ 682 682 case ALLOC_GROW_HEIGHT: ··· 925 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 + */ 939 + int 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 + 928 954 static int gfs2_write_lock(struct inode *inode) 929 955 { 930 956 struct gfs2_inode *ip = GFS2_I(inode); ··· 991 965 gfs2_glock_dq_uninit(&ip->i_gh); 992 966 } 993 967 968 + static int gfs2_iomap_page_prepare(struct inode *inode, loff_t pos, 969 + unsigned len, struct iomap *iomap) 970 + { 971 + struct gfs2_sbd *sdp = GFS2_SB(inode); 972 + 973 + return gfs2_trans_begin(sdp, RES_DINODE + (len >> inode->i_blkbits), 0); 974 + } 975 + 994 976 static void gfs2_iomap_page_done(struct inode *inode, loff_t pos, 995 977 unsigned copied, struct page *page, 996 978 struct iomap *iomap) 997 979 { 998 980 struct gfs2_inode *ip = GFS2_I(inode); 981 + struct gfs2_sbd *sdp = GFS2_SB(inode); 999 982 1000 - if (page) 983 + if (page && !gfs2_is_stuffed(ip)) 1001 984 gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied); 985 + gfs2_trans_end(sdp); 1002 986 } 1003 987 1004 988 static const struct iomap_page_ops gfs2_iomap_page_ops = { 989 + .page_prepare = gfs2_iomap_page_prepare, 1005 990 .page_done = gfs2_iomap_page_done, 1006 991 }; 1007 992 ··· 1068 1031 if (alloc_required) 1069 1032 rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); 1070 1033 1071 - ret = gfs2_trans_begin(sdp, rblocks, iomap->length >> inode->i_blkbits); 1072 - if (ret) 1073 - goto out_trans_fail; 1034 + if (unstuff || iomap->type == IOMAP_HOLE) { 1035 + struct gfs2_trans *tr; 1074 1036 1075 - if (unstuff) { 1076 - ret = gfs2_unstuff_dinode(ip, NULL); 1037 + ret = gfs2_trans_begin(sdp, rblocks, 1038 + iomap->length >> inode->i_blkbits); 1077 1039 if (ret) 1078 - goto out_trans_end; 1079 - release_metapath(mp); 1080 - ret = gfs2_iomap_get(inode, iomap->offset, iomap->length, 1081 - flags, iomap, mp); 1082 - if (ret) 1083 - goto out_trans_end; 1084 - } 1040 + goto out_trans_fail; 1085 1041 1086 - if (iomap->type == IOMAP_HOLE) { 1087 - ret = gfs2_iomap_alloc(inode, iomap, flags, mp); 1088 - if (ret) { 1089 - gfs2_trans_end(sdp); 1090 - gfs2_inplace_release(ip); 1091 - punch_hole(ip, iomap->offset, iomap->length); 1092 - goto out_qunlock; 1042 + if (unstuff) { 1043 + ret = gfs2_unstuff_dinode(ip, NULL); 1044 + if (ret) 1045 + goto out_trans_end; 1046 + release_metapath(mp); 1047 + ret = gfs2_iomap_get(inode, iomap->offset, 1048 + iomap->length, flags, iomap, mp); 1049 + if (ret) 1050 + goto out_trans_end; 1093 1051 } 1052 + 1053 + if (iomap->type == IOMAP_HOLE) { 1054 + ret = gfs2_iomap_alloc(inode, iomap, flags, mp); 1055 + if (ret) { 1056 + gfs2_trans_end(sdp); 1057 + gfs2_inplace_release(ip); 1058 + punch_hole(ip, iomap->offset, iomap->length); 1059 + goto out_qunlock; 1060 + } 1061 + } 1062 + 1063 + tr = current->journal_info; 1064 + if (tr->tr_num_buf_new) 1065 + __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 1066 + else 1067 + gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[0]); 1068 + 1069 + gfs2_trans_end(sdp); 1094 1070 } 1095 - if (!gfs2_is_stuffed(ip) && gfs2_is_jdata(ip)) 1071 + 1072 + if (gfs2_is_stuffed(ip) || gfs2_is_jdata(ip)) 1096 1073 iomap->page_ops = &gfs2_iomap_page_ops; 1097 1074 return 0; 1098 1075 ··· 1146 1095 iomap->type != IOMAP_MAPPED) 1147 1096 ret = -ENOTBLK; 1148 1097 } 1149 - if (!ret) { 1150 - get_bh(mp.mp_bh[0]); 1151 - iomap->private = mp.mp_bh[0]; 1152 - } 1153 1098 release_metapath(&mp); 1154 1099 trace_gfs2_iomap_end(ip, iomap, ret); 1155 1100 return ret; ··· 1156 1109 { 1157 1110 struct gfs2_inode *ip = GFS2_I(inode); 1158 1111 struct gfs2_sbd *sdp = GFS2_SB(inode); 1159 - struct gfs2_trans *tr = current->journal_info; 1160 - struct buffer_head *dibh = iomap->private; 1161 1112 1162 1113 if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE) 1163 1114 goto out; 1164 1115 1165 - if (iomap->type != IOMAP_INLINE) { 1116 + if (!gfs2_is_stuffed(ip)) 1166 1117 gfs2_ordered_add_inode(ip); 1167 1118 1168 - if (tr->tr_num_buf_new) 1169 - __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 1170 - else 1171 - gfs2_trans_add_meta(ip->i_gl, dibh); 1172 - } 1173 - 1174 - if (inode == sdp->sd_rindex) { 1119 + if (inode == sdp->sd_rindex) 1175 1120 adjust_fs_space(inode); 1176 - sdp->sd_rindex_uptodate = 0; 1177 - } 1178 1121 1179 - gfs2_trans_end(sdp); 1180 1122 gfs2_inplace_release(ip); 1181 1123 1182 1124 if (length != written && (iomap->flags & IOMAP_F_NEW)) { ··· 1185 1149 gfs2_write_unlock(inode); 1186 1150 1187 1151 out: 1188 - if (dibh) 1189 - brelse(dibh); 1190 1152 return 0; 1191 1153 } 1192 1154
+1
fs/gfs2/bmap.h
··· 64 64 extern int gfs2_map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd); 65 65 extern void gfs2_free_journal_extents(struct gfs2_jdesc *jd); 66 66 extern int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length); 67 + extern int gfs2_lblk_to_dblk(struct inode *inode, u32 lblock, u64 *dblock); 67 68 68 69 #endif /* __BMAP_DOT_H__ */
+1 -1
fs/gfs2/dir.c
··· 883 883 if (!bh) 884 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 887 gfs2_trans_add_meta(ip->i_gl, bh); 888 888 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); 889 889 leaf = (struct gfs2_leaf *)bh->b_data;
+16 -11
fs/gfs2/glock.c
··· 140 140 { 141 141 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 142 142 143 + BUG_ON(test_bit(GLF_REVOKES, &gl->gl_flags)); 143 144 rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms); 144 145 smp_mb(); 145 146 wake_up_glock(gl); ··· 184 183 185 184 void gfs2_glock_add_to_lru(struct gfs2_glock *gl) 186 185 { 186 + if (!(gl->gl_ops->go_flags & GLOF_LRU)) 187 + return; 188 + 187 189 spin_lock(&lru_lock); 188 190 189 - if (!list_empty(&gl->gl_lru)) 190 - list_del_init(&gl->gl_lru); 191 - else 192 - atomic_inc(&lru_count); 193 - 191 + list_del(&gl->gl_lru); 194 192 list_add_tail(&gl->gl_lru, &lru_list); 195 - set_bit(GLF_LRU, &gl->gl_flags); 193 + 194 + if (!test_bit(GLF_LRU, &gl->gl_flags)) { 195 + set_bit(GLF_LRU, &gl->gl_flags); 196 + atomic_inc(&lru_count); 197 + } 198 + 196 199 spin_unlock(&lru_lock); 197 200 } 198 201 ··· 206 201 return; 207 202 208 203 spin_lock(&lru_lock); 209 - if (!list_empty(&gl->gl_lru)) { 204 + if (test_bit(GLF_LRU, &gl->gl_flags)) { 210 205 list_del_init(&gl->gl_lru); 211 206 atomic_dec(&lru_count); 212 207 clear_bit(GLF_LRU, &gl->gl_flags); ··· 1164 1159 !test_bit(GLF_DEMOTE, &gl->gl_flags)) 1165 1160 fast_path = 1; 1166 1161 } 1167 - if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl) && 1168 - (glops->go_flags & GLOF_LRU)) 1162 + if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl)) 1169 1163 gfs2_glock_add_to_lru(gl); 1170 1164 1171 1165 trace_gfs2_glock_queue(gh, 0); ··· 1460 1456 if (!spin_trylock(&gl->gl_lockref.lock)) { 1461 1457 add_back_to_lru: 1462 1458 list_add(&gl->gl_lru, &lru_list); 1459 + set_bit(GLF_LRU, &gl->gl_flags); 1463 1460 atomic_inc(&lru_count); 1464 1461 continue; 1465 1462 } ··· 1468 1463 spin_unlock(&gl->gl_lockref.lock); 1469 1464 goto add_back_to_lru; 1470 1465 } 1471 - clear_bit(GLF_LRU, &gl->gl_flags); 1472 1466 gl->gl_lockref.count++; 1473 1467 if (demote_ok(gl)) 1474 1468 handle_callback(gl, LM_ST_UNLOCKED, 0, false); ··· 1502 1498 if (!test_bit(GLF_LOCK, &gl->gl_flags)) { 1503 1499 list_move(&gl->gl_lru, &dispose); 1504 1500 atomic_dec(&lru_count); 1501 + clear_bit(GLF_LRU, &gl->gl_flags); 1505 1502 freed++; 1506 1503 continue; 1507 1504 } ··· 1801 1796 state2str(gl->gl_target), 1802 1797 state2str(gl->gl_demote_state), dtime, 1803 1798 atomic_read(&gl->gl_ail_count), 1804 - atomic_read(&gl->gl_revokes), 1799 + test_bit(GLF_REVOKES, &gl->gl_flags) ? 1 : 0, 1805 1800 (int)gl->gl_lockref.count, gl->gl_hold_time); 1806 1801 1807 1802 list_for_each_entry(gh, &gl->gl_holders, gh_list)
+2 -1
fs/gfs2/glops.c
··· 28 28 #include "util.h" 29 29 #include "trans.h" 30 30 #include "dir.h" 31 + #include "lops.h" 31 32 32 33 struct workqueue_struct *gfs2_freeze_wq; 33 34 ··· 532 531 if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { 533 532 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 534 533 535 - error = gfs2_find_jhead(sdp->sd_jdesc, &head); 534 + error = gfs2_find_jhead(sdp->sd_jdesc, &head, false); 536 535 if (error) 537 536 gfs2_consist(sdp); 538 537 if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT))
+5 -4
fs/gfs2/incore.h
··· 345 345 GLF_OBJECT = 14, /* Used only for tracing */ 346 346 GLF_BLOCKING = 15, 347 347 GLF_INODE_CREATING = 16, /* Inode creation occurring */ 348 + GLF_REVOKES = 17, /* Glock has revokes in queue */ 348 349 }; 349 350 350 351 struct gfs2_glock { ··· 375 374 struct list_head gl_lru; 376 375 struct list_head gl_ail_list; 377 376 atomic_t gl_ail_count; 378 - atomic_t gl_revokes; 379 377 struct delayed_work gl_work; 380 378 union { 381 379 /* For inode and iopen glocks only */ ··· 535 535 unsigned long jd_flags; 536 536 #define JDF_RECOVERY 1 537 537 unsigned int jd_jid; 538 - unsigned int jd_blocks; 538 + u32 jd_blocks; 539 539 int jd_recover_error; 540 540 /* Replay stuff */ 541 541 ··· 621 621 SDF_SKIP_DLM_UNLOCK = 8, 622 622 SDF_FORCE_AIL_FLUSH = 9, 623 623 SDF_AIL1_IO_ERROR = 10, 624 + SDF_FS_FROZEN = 11, 624 625 }; 625 626 626 627 enum gfs2_freeze_state { ··· 810 809 atomic_t sd_log_pinned; 811 810 unsigned int sd_log_num_revoke; 812 811 813 - struct list_head sd_log_le_revoke; 814 - struct list_head sd_log_le_ordered; 812 + struct list_head sd_log_revokes; 813 + struct list_head sd_log_ordered; 815 814 spinlock_t sd_ordered_lock; 816 815 817 816 atomic_t sd_log_thresh1;
+29 -18
fs/gfs2/log.c
··· 551 551 LIST_HEAD(written); 552 552 553 553 spin_lock(&sdp->sd_ordered_lock); 554 - list_sort(NULL, &sdp->sd_log_le_ordered, &ip_cmp); 555 - while (!list_empty(&sdp->sd_log_le_ordered)) { 556 - ip = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_inode, i_ordered); 554 + list_sort(NULL, &sdp->sd_log_ordered, &ip_cmp); 555 + while (!list_empty(&sdp->sd_log_ordered)) { 556 + ip = list_entry(sdp->sd_log_ordered.next, struct gfs2_inode, i_ordered); 557 557 if (ip->i_inode.i_mapping->nrpages == 0) { 558 558 test_and_clear_bit(GIF_ORDERED, &ip->i_flags); 559 559 list_del(&ip->i_ordered); ··· 564 564 filemap_fdatawrite(ip->i_inode.i_mapping); 565 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 568 spin_unlock(&sdp->sd_ordered_lock); 569 569 } 570 570 ··· 573 573 struct gfs2_inode *ip; 574 574 575 575 spin_lock(&sdp->sd_ordered_lock); 576 - while (!list_empty(&sdp->sd_log_le_ordered)) { 577 - ip = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_inode, i_ordered); 576 + while (!list_empty(&sdp->sd_log_ordered)) { 577 + ip = list_entry(sdp->sd_log_ordered.next, struct gfs2_inode, i_ordered); 578 578 list_del(&ip->i_ordered); 579 579 WARN_ON(!test_and_clear_bit(GIF_ORDERED, &ip->i_flags)); 580 580 if (ip->i_inode.i_mapping->nrpages == 0) ··· 606 606 gfs2_remove_from_ail(bd); /* drops ref on bh */ 607 607 bd->bd_bh = NULL; 608 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 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 614 617 void gfs2_write_revokes(struct gfs2_sbd *sdp) ··· 669 666 } 670 667 671 668 /** 672 - * write_log_header - Write a journal log header buffer at sd_log_flush_head 669 + * gfs2_write_log_header - Write a journal log header buffer at lblock 673 670 * @sdp: The GFS2 superblock 674 671 * @jd: journal descriptor of the journal to which we are writing 675 672 * @seq: sequence number 676 673 * @tail: tail of the log 674 + * @lblock: value for lh_blkno (block number relative to start of journal) 677 675 * @flags: log header flags GFS2_LOG_HEAD_* 678 676 * @op_flags: flags to pass to the bio 679 677 * ··· 682 678 */ 683 679 684 680 void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, 685 - u64 seq, u32 tail, u32 flags, int op_flags) 681 + u64 seq, u32 tail, u32 lblock, u32 flags, 682 + int op_flags) 686 683 { 687 684 struct gfs2_log_header *lh; 688 685 u32 hash, crc; ··· 691 686 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; 692 687 struct timespec64 tv; 693 688 struct super_block *sb = sdp->sd_vfs; 694 - u64 addr; 689 + u64 dblock; 695 690 696 691 lh = page_address(page); 697 692 clear_page(lh); ··· 704 699 lh->lh_sequence = cpu_to_be64(seq); 705 700 lh->lh_flags = cpu_to_be32(flags); 706 701 lh->lh_tail = cpu_to_be32(tail); 707 - lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head); 702 + lh->lh_blkno = cpu_to_be32(lblock); 708 703 hash = ~crc32(~0, lh, LH_V1_SIZE); 709 704 lh->lh_hash = cpu_to_be32(hash); 710 705 711 706 ktime_get_coarse_real_ts64(&tv); 712 707 lh->lh_nsec = cpu_to_be32(tv.tv_nsec); 713 708 lh->lh_sec = cpu_to_be64(tv.tv_sec); 714 - addr = gfs2_log_bmap(sdp); 715 - lh->lh_addr = cpu_to_be64(addr); 709 + if (!list_empty(&jd->extent_list)) 710 + dblock = gfs2_log_bmap(sdp); 711 + else { 712 + int ret = gfs2_lblk_to_dblk(jd->jd_inode, lblock, &dblock); 713 + if (gfs2_assert_withdraw(sdp, ret == 0)) 714 + return; 715 + } 716 + lh->lh_addr = cpu_to_be64(dblock); 716 717 lh->lh_jinode = cpu_to_be64(GFS2_I(jd->jd_inode)->i_no_addr); 717 718 718 719 /* We may only write local statfs, quota, etc., when writing to our ··· 743 732 sb->s_blocksize - LH_V1_SIZE - 4); 744 733 lh->lh_crc = cpu_to_be32(crc); 745 734 746 - gfs2_log_write(sdp, page, sb->s_blocksize, 0, addr); 747 - gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE, op_flags); 735 + gfs2_log_write(sdp, page, sb->s_blocksize, 0, dblock); 736 + gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE | op_flags); 748 737 log_flush_wait(sdp); 749 738 } 750 739 ··· 772 761 } 773 762 sdp->sd_log_idle = (tail == sdp->sd_log_flush_head); 774 763 gfs2_write_log_header(sdp, sdp->sd_jdesc, sdp->sd_log_sequence++, tail, 775 - flags, op_flags); 764 + sdp->sd_log_flush_head, flags, op_flags); 776 765 777 766 if (sdp->sd_log_tail != tail) 778 767 log_pull_tail(sdp, tail); ··· 821 810 822 811 gfs2_ordered_write(sdp); 823 812 lops_before_commit(sdp, tr); 824 - gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE, 0); 813 + gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE); 825 814 826 815 if (sdp->sd_log_head != sdp->sd_log_flush_head) { 827 816 log_flush_wait(sdp);
+3 -2
fs/gfs2/log.h
··· 59 59 if (!test_bit(GIF_ORDERED, &ip->i_flags)) { 60 60 spin_lock(&sdp->sd_ordered_lock); 61 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 63 spin_unlock(&sdp->sd_ordered_lock); 64 64 } 65 65 } ··· 70 70 extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks); 71 71 extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks); 72 72 extern 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); 74 75 extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, 75 76 u32 type); 76 77 extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
+238 -22
fs/gfs2/lops.c
··· 17 17 #include <linux/bio.h> 18 18 #include <linux/fs.h> 19 19 #include <linux/list_sort.h> 20 + #include <linux/blkdev.h> 20 21 22 + #include "bmap.h" 21 23 #include "dir.h" 22 24 #include "gfs2.h" 23 25 #include "incore.h" ··· 196 194 /** 197 195 * gfs2_end_log_write - end of i/o to the log 198 196 * @bio: The bio 199 - * @error: Status of i/o request 200 197 * 201 198 * Each bio_vec contains either data from the pagecache or data 202 199 * relating to the log itself. Here we iterate over the bio_vec ··· 232 231 /** 233 232 * gfs2_log_submit_bio - Submit any pending log bio 234 233 * @biop: Address of the bio pointer 235 - * @op: REQ_OP 236 - * @op_flags: req_flag_bits 234 + * @opf: REQ_OP | op_flags 237 235 * 238 236 * Submit any pending part-built or full bio to the block device. If 239 237 * there is no pending bio, then this is a no-op. 240 238 */ 241 239 242 - void gfs2_log_submit_bio(struct bio **biop, int op, int op_flags) 240 + void gfs2_log_submit_bio(struct bio **biop, int opf) 243 241 { 244 242 struct bio *bio = *biop; 245 243 if (bio) { 246 244 struct gfs2_sbd *sdp = bio->bi_private; 247 245 atomic_inc(&sdp->sd_log_in_flight); 248 - bio_set_op_attrs(bio, op, op_flags); 246 + bio->bi_opf = opf; 249 247 submit_bio(bio); 250 248 *biop = NULL; 251 249 } ··· 305 305 nblk >>= sdp->sd_fsb2bb_shift; 306 306 if (blkno == nblk && !flush) 307 307 return bio; 308 - gfs2_log_submit_bio(biop, op, 0); 308 + gfs2_log_submit_bio(biop, op); 309 309 } 310 310 311 311 *biop = gfs2_log_alloc_bio(sdp, blkno, end_io); ··· 374 374 struct super_block *sb = sdp->sd_vfs; 375 375 gfs2_log_write(sdp, page, sb->s_blocksize, 0, 376 376 gfs2_log_bmap(sdp)); 377 + } 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 + 387 + static 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 + 415 + static 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 + 458 + static 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 + */ 487 + int 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 + 548 + page_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 + 561 + out: 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; 377 576 } 378 577 379 578 static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type, ··· 728 529 jd->jd_replayed_blocks = 0; 729 530 } 730 531 731 - static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, 532 + static int buf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start, 732 533 struct gfs2_log_descriptor *ld, __be64 *ptr, 733 534 int pass) 734 535 { ··· 821 622 { 822 623 struct gfs2_meta_header *mh; 823 624 unsigned int offset; 824 - struct list_head *head = &sdp->sd_log_le_revoke; 625 + struct list_head *head = &sdp->sd_log_revokes; 825 626 struct gfs2_bufdata *bd; 826 627 struct page *page; 827 628 unsigned int length; ··· 859 660 860 661 static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 861 662 { 862 - struct list_head *head = &sdp->sd_log_le_revoke; 863 - struct gfs2_bufdata *bd; 864 - struct gfs2_glock *gl; 663 + struct list_head *head = &sdp->sd_log_revokes; 664 + struct gfs2_bufdata *bd, *tmp; 865 665 866 - while (!list_empty(head)) { 867 - bd = list_entry(head->next, struct gfs2_bufdata, bd_list); 868 - list_del_init(&bd->bd_list); 869 - gl = bd->bd_gl; 870 - atomic_dec(&gl->gl_revokes); 871 - clear_bit(GLF_LFLUSH, &gl->gl_flags); 666 + /* 667 + * Glocks can be referenced repeatedly on the revoke list, but the list 668 + * only holds one reference. All glocks on the list will have the 669 + * GLF_REVOKES flag set initially. 670 + */ 671 + 672 + list_for_each_entry_safe(bd, tmp, head, bd_list) { 673 + struct gfs2_glock *gl = bd->bd_gl; 674 + 675 + if (test_bit(GLF_REVOKES, &gl->gl_flags)) { 676 + /* Keep each glock on the list exactly once. */ 677 + clear_bit(GLF_REVOKES, &gl->gl_flags); 678 + continue; 679 + } 680 + list_del(&bd->bd_list); 872 681 kmem_cache_free(gfs2_bufdata_cachep, bd); 873 682 } 683 + list_for_each_entry_safe(bd, tmp, head, bd_list) { 684 + struct gfs2_glock *gl = bd->bd_gl; 685 + 686 + list_del(&bd->bd_list); 687 + kmem_cache_free(gfs2_bufdata_cachep, bd); 688 + clear_bit(GLF_LFLUSH, &gl->gl_flags); 689 + gfs2_glock_queue_put(gl); 690 + } 691 + /* the list is empty now */ 874 692 } 875 693 876 694 static void revoke_lo_before_scan(struct gfs2_jdesc *jd, ··· 900 684 jd->jd_replay_tail = head->lh_tail; 901 685 } 902 686 903 - static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, 687 + static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, u32 start, 904 688 struct gfs2_log_descriptor *ld, __be64 *ptr, 905 689 int pass) 906 690 { ··· 982 766 gfs2_before_commit(sdp, limit, nbuf, &tr->tr_databuf, 1); 983 767 } 984 768 985 - static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, 769 + static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start, 986 770 struct gfs2_log_descriptor *ld, 987 771 __be64 *ptr, int pass) 988 772 { ··· 1068 852 } 1069 853 1070 854 1071 - const struct gfs2_log_operations gfs2_buf_lops = { 855 + static const struct gfs2_log_operations gfs2_buf_lops = { 1072 856 .lo_before_commit = buf_lo_before_commit, 1073 857 .lo_after_commit = buf_lo_after_commit, 1074 858 .lo_before_scan = buf_lo_before_scan, ··· 1077 861 .lo_name = "buf", 1078 862 }; 1079 863 1080 - const struct gfs2_log_operations gfs2_revoke_lops = { 864 + static const struct gfs2_log_operations gfs2_revoke_lops = { 1081 865 .lo_before_commit = revoke_lo_before_commit, 1082 866 .lo_after_commit = revoke_lo_after_commit, 1083 867 .lo_before_scan = revoke_lo_before_scan, ··· 1086 870 .lo_name = "revoke", 1087 871 }; 1088 872 1089 - const struct gfs2_log_operations gfs2_databuf_lops = { 873 + static const struct gfs2_log_operations gfs2_databuf_lops = { 1090 874 .lo_before_commit = databuf_lo_before_commit, 1091 875 .lo_after_commit = databuf_lo_after_commit, 1092 876 .lo_scan_elements = databuf_lo_scan_elements,
+4 -7
fs/gfs2/lops.h
··· 20 20 ((sizeof(struct gfs2_log_descriptor) + (2 * sizeof(__be64) - 1)) & \ 21 21 ~(2 * sizeof(__be64) - 1)) 22 22 23 - extern const struct gfs2_log_operations gfs2_glock_lops; 24 - extern const struct gfs2_log_operations gfs2_buf_lops; 25 - extern const struct gfs2_log_operations gfs2_revoke_lops; 26 - extern const struct gfs2_log_operations gfs2_databuf_lops; 27 - 28 23 extern const struct gfs2_log_operations *gfs2_log_ops[]; 29 24 extern u64 gfs2_log_bmap(struct gfs2_sbd *sdp); 30 25 extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page, 31 26 unsigned size, unsigned offset, u64 blkno); 32 27 extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page); 33 - extern void gfs2_log_submit_bio(struct bio **biop, int op, int op_flags); 28 + extern void gfs2_log_submit_bio(struct bio **biop, int opf); 34 29 extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); 30 + extern int gfs2_find_jhead(struct gfs2_jdesc *jd, 31 + struct gfs2_log_header_host *head, bool keep_cache); 35 32 36 33 static inline unsigned int buf_limit(struct gfs2_sbd *sdp) 37 34 { ··· 74 77 gfs2_log_ops[x]->lo_before_scan(jd, head, pass); 75 78 } 76 79 77 - static inline int lops_scan_elements(struct gfs2_jdesc *jd, unsigned int start, 80 + static inline int lops_scan_elements(struct gfs2_jdesc *jd, u32 start, 78 81 struct gfs2_log_descriptor *ld, 79 82 __be64 *ptr, 80 83 unsigned int pass)
-1
fs/gfs2/main.c
··· 59 59 INIT_LIST_HEAD(&gl->gl_lru); 60 60 INIT_LIST_HEAD(&gl->gl_ail_list); 61 61 atomic_set(&gl->gl_ail_count, 0); 62 - atomic_set(&gl->gl_revokes, 0); 63 62 } 64 63 65 64 static void gfs2_init_gl_aspace_once(void *foo)
+4 -3
fs/gfs2/ops_fstype.c
··· 41 41 #include "dir.h" 42 42 #include "meta_io.h" 43 43 #include "trace_gfs2.h" 44 + #include "lops.h" 44 45 45 46 #define DO 0 46 47 #define UNDO 1 ··· 118 117 119 118 spin_lock_init(&sdp->sd_log_lock); 120 119 atomic_set(&sdp->sd_log_pinned, 0); 121 - INIT_LIST_HEAD(&sdp->sd_log_le_revoke); 122 - INIT_LIST_HEAD(&sdp->sd_log_le_ordered); 120 + INIT_LIST_HEAD(&sdp->sd_log_revokes); 121 + INIT_LIST_HEAD(&sdp->sd_log_ordered); 123 122 spin_lock_init(&sdp->sd_ordered_lock); 124 123 125 124 init_waitqueue_head(&sdp->sd_log_waitq); ··· 617 616 fs_err(sdp, "Error checking journal for spectator mount.\n"); 618 617 goto out_unlock; 619 618 } 620 - error = gfs2_find_jhead(jd, &head); 619 + error = gfs2_find_jhead(jd, &head, false); 621 620 if (error) { 622 621 fs_err(sdp, "Error parsing journal for spectator mount.\n"); 623 622 goto out_unlock;
+7 -128
fs/gfs2/recovery.c
··· 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 - 197 - static 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 - 229 - static 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 - 269 - int 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 185 * foreach_descriptor - go through the active part of the log 309 186 * @jd: the journal 310 187 * @start: the first log header in the active region ··· 193 316 * Returns: errno 194 317 */ 195 318 196 - static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, 319 + static int foreach_descriptor(struct gfs2_jdesc *jd, u32 start, 197 320 unsigned int end, int pass) 198 321 { 199 322 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); ··· 263 386 struct gfs2_log_header_host *head) 264 387 { 265 388 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); 389 + u32 lblock = head->lh_blkno; 266 390 267 - sdp->sd_log_flush_head = head->lh_blkno; 268 - gfs2_replay_incr_blk(jd, &sdp->sd_log_flush_head); 269 - gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, 391 + gfs2_replay_incr_blk(jd, &lblock); 392 + if (jd->jd_jid == sdp->sd_lockstruct.ls_jid) 393 + sdp->sd_log_flush_head = lblock; 394 + gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, lblock, 270 395 GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY, 271 396 REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC); 272 397 } ··· 346 467 if (error) 347 468 goto fail_gunlock_ji; 348 469 349 - error = gfs2_find_jhead(jd, &head); 470 + error = gfs2_find_jhead(jd, &head, true); 350 471 if (error) 351 472 goto fail_gunlock_ji; 352 473 t_jhd = ktime_get();
+1 -3
fs/gfs2/recovery.h
··· 14 14 15 15 extern struct workqueue_struct *gfs_recovery_wq; 16 16 17 - static inline void gfs2_replay_incr_blk(struct gfs2_jdesc *jd, unsigned int *blk) 17 + static inline void gfs2_replay_incr_blk(struct gfs2_jdesc *jd, u32 *blk) 18 18 { 19 19 if (++*blk == jd->jd_blocks) 20 20 *blk = 0; ··· 27 27 extern int gfs2_revoke_check(struct gfs2_jdesc *jd, u64 blkno, unsigned int where); 28 28 extern void gfs2_revoke_clean(struct gfs2_jdesc *jd); 29 29 30 - extern int gfs2_find_jhead(struct gfs2_jdesc *jd, 31 - struct gfs2_log_header_host *head); 32 30 extern int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd, bool wait); 33 31 extern void gfs2_recover_func(struct work_struct *work); 34 32 extern int __get_log_header(struct gfs2_sbd *sdp,
+26 -30
fs/gfs2/rgrp.c
··· 1729 1729 static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext, 1730 1730 const struct gfs2_inode *ip, bool nowrap) 1731 1731 { 1732 + bool scan_from_start = rbm->bii == 0 && rbm->offset == 0; 1732 1733 struct buffer_head *bh; 1733 - int initial_bii; 1734 - u32 initial_offset; 1735 - int first_bii = rbm->bii; 1736 - u32 first_offset = rbm->offset; 1734 + int last_bii; 1737 1735 u32 offset; 1738 1736 u8 *buffer; 1739 - int n = 0; 1740 - int iters = rbm->rgd->rd_length; 1737 + bool wrapped = false; 1741 1738 int ret; 1742 1739 struct gfs2_bitmap *bi; 1743 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 1746 - * need to add one to the bitmap count to ensure that we search 1747 - * the starting bitmap twice. 1742 + /* 1743 + * Determine the last bitmap to search. If we're not starting at the 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) 1750 - iters++; 1747 + last_bii = rbm->bii - (rbm->offset == 0); 1751 1748 1752 1749 while(1) { 1753 1750 bi = rbm_bi(rbm); ··· 1758 1761 WARN_ON(!buffer_uptodate(bh)); 1759 1762 if (state != GFS2_BLKST_UNLINKED && bi->bi_clone) 1760 1763 buffer = bi->bi_clone + bi->bi_offset; 1761 - initial_offset = rbm->offset; 1762 1764 offset = gfs2_bitfit(buffer, bi->bi_bytes, rbm->offset, state); 1763 - if (offset == BFITNOENT) 1764 - goto bitmap_full; 1765 + if (offset == BFITNOENT) { 1766 + if (state == GFS2_BLKST_FREE && rbm->offset == 0) 1767 + set_bit(GBF_FULL, &bi->bi_flags); 1768 + goto next_bitmap; 1769 + } 1765 1770 rbm->offset = offset; 1766 1771 if (ip == NULL) 1767 1772 return 0; 1768 1773 1769 - initial_bii = rbm->bii; 1770 1774 ret = gfs2_reservation_check_and_update(rbm, ip, 1771 1775 minext ? *minext : 0, 1772 1776 &maxext); 1773 1777 if (ret == 0) 1774 1778 return 0; 1775 - if (ret > 0) { 1776 - n += (rbm->bii - initial_bii); 1779 + if (ret > 0) 1777 1780 goto next_iter; 1778 - } 1779 1781 if (ret == -E2BIG) { 1780 1782 rbm->bii = 0; 1781 1783 rbm->offset = 0; 1782 - n += (rbm->bii - initial_bii); 1783 1784 goto res_covered_end_of_rgrp; 1784 1785 } 1785 1786 return ret; 1786 - 1787 - bitmap_full: /* Mark bitmap as full and fall through */ 1788 - if ((state == GFS2_BLKST_FREE) && initial_offset == 0) 1789 - set_bit(GBF_FULL, &bi->bi_flags); 1790 1787 1791 1788 next_bitmap: /* Find next bitmap in the rgrp */ 1792 1789 rbm->offset = 0; ··· 1788 1797 if (rbm->bii == rbm->rgd->rd_length) 1789 1798 rbm->bii = 0; 1790 1799 res_covered_end_of_rgrp: 1791 - if ((rbm->bii == 0) && nowrap) 1792 - break; 1793 - n++; 1800 + if (rbm->bii == 0) { 1801 + if (wrapped) 1802 + break; 1803 + wrapped = true; 1804 + if (nowrap) 1805 + break; 1806 + } 1794 1807 next_iter: 1795 - if (n >= iters) 1808 + /* Have we scanned the entire resource group? */ 1809 + if (wrapped && rbm->bii > last_bii) 1796 1810 break; 1797 1811 } 1798 1812 ··· 1807 1811 /* If the extent was too small, and it's smaller than the smallest 1808 1812 to have failed before, remember for future reference that it's 1809 1813 useless to search this rgrp again for this amount or more. */ 1810 - if ((first_offset == 0) && (first_bii == 0) && 1811 - (*minext < rbm->rgd->rd_extfail_pt)) 1814 + if (wrapped && (scan_from_start || rbm->bii > last_bii) && 1815 + *minext < rbm->rgd->rd_extfail_pt) 1812 1816 rbm->rgd->rd_extfail_pt = *minext; 1813 1817 1814 1818 /* If the maximum extent we found is big enough to fulfill the ··· 2440 2444 2441 2445 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); 2442 2446 if (dinode) 2443 - gfs2_trans_add_unrevoke(sdp, block, *nblocks); 2447 + gfs2_trans_remove_revoke(sdp, block, *nblocks); 2444 2448 2445 2449 gfs2_quota_change(ip, *nblocks, ip->i_inode.i_uid, ip->i_inode.i_gid); 2446 2450
+9 -11
fs/gfs2/super.c
··· 45 45 #include "util.h" 46 46 #include "sys.h" 47 47 #include "xattr.h" 48 + #include "lops.h" 48 49 49 50 #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x) 50 51 ··· 426 425 427 426 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 428 427 429 - error = gfs2_find_jhead(sdp->sd_jdesc, &head); 428 + error = gfs2_find_jhead(sdp->sd_jdesc, &head, false); 430 429 if (error) 431 430 goto fail; 432 431 ··· 681 680 error = gfs2_jdesc_check(jd); 682 681 if (error) 683 682 break; 684 - error = gfs2_find_jhead(jd, &lh); 683 + error = gfs2_find_jhead(jd, &lh, false); 685 684 if (error) 686 685 break; 687 686 if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { ··· 974 973 if (error) { 975 974 printk(KERN_INFO "GFS2: couldn't get freeze lock : %d\n", error); 976 975 gfs2_assert_withdraw(sdp, 0); 977 - } 978 - else { 976 + } else { 979 977 atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN); 980 978 error = thaw_super(sb); 981 979 if (error) { ··· 987 987 gfs2_glock_dq_uninit(&freeze_gh); 988 988 } 989 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 992 return; 991 993 } 992 994 ··· 1031 1029 msleep(1000); 1032 1030 } 1033 1031 error = 0; 1032 + set_bit(SDF_FS_FROZEN, &sdp->sd_flags); 1034 1033 out: 1035 1034 mutex_unlock(&sdp->sd_freeze_mutex); 1036 1035 return error; ··· 1056 1053 1057 1054 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); 1058 1055 mutex_unlock(&sdp->sd_freeze_mutex); 1059 - return 0; 1056 + return wait_on_bit(&sdp->sd_flags, SDF_FS_FROZEN, TASK_INTERRUPTIBLE); 1060 1057 } 1061 1058 1062 1059 /** ··· 1477 1474 truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0); 1478 1475 truncate_inode_pages(&inode->i_data, 0); 1479 1476 1480 - if (atomic_read(&gl->gl_revokes) == 0) { 1477 + if (!test_bit(GLF_REVOKES, &gl->gl_flags)) { 1481 1478 clear_bit(GLF_LFLUSH, &gl->gl_flags); 1482 1479 clear_bit(GLF_DIRTY, &gl->gl_flags); 1483 1480 } ··· 1633 1630 goto out_truncate; 1634 1631 } 1635 1632 1636 - /* Case 1 starts here */ 1637 - 1638 1633 if (S_ISDIR(inode->i_mode) && 1639 1634 (ip->i_diskflags & GFS2_DIF_EXHASH)) { 1640 1635 error = gfs2_dir_exhash_dealloc(ip); ··· 1671 1670 write_inode_now(inode, 1); 1672 1671 gfs2_ail_flush(ip->i_gl, 0); 1673 1672 1674 - /* Case 2 starts here */ 1675 1673 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); 1676 1674 if (error) 1677 1675 goto out_unlock; ··· 1680 1680 gfs2_trans_end(sdp); 1681 1681 1682 1682 out_unlock: 1683 - /* Error path for case 1 */ 1684 1683 if (gfs2_rs_active(&ip->i_res)) 1685 1684 gfs2_rs_deltree(&ip->i_res); 1686 1685 ··· 1698 1699 if (error && error != GLR_TRYFAILED && error != -EROFS) 1699 1700 fs_warn(sdp, "gfs2_evict_inode: %d\n", error); 1700 1701 out: 1701 - /* Case 3 starts here */ 1702 1702 truncate_inode_pages_final(&inode->i_data); 1703 1703 gfs2_rsqa_delete(ip, NULL); 1704 1704 gfs2_ordered_del_inode(ip);
+2 -2
fs/gfs2/trans.c
··· 253 253 tr->tr_num_revoke++; 254 254 } 255 255 256 - void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len) 256 + void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len) 257 257 { 258 258 struct gfs2_bufdata *bd, *tmp; 259 259 struct gfs2_trans *tr = current->journal_info; 260 260 unsigned int n = len; 261 261 262 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 264 if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) { 265 265 list_del_init(&bd->bd_list); 266 266 gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke);
+1 -1
fs/gfs2/trans.h
··· 44 44 extern void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh); 45 45 extern void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh); 46 46 extern void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd); 47 - extern void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len); 47 + extern void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len); 48 48 49 49 #endif /* __TRANS_DOT_H__ */
+3 -3
fs/gfs2/xattr.c
··· 631 631 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL); 632 632 if (error) 633 633 return error; 634 - gfs2_trans_add_unrevoke(sdp, block, 1); 634 + gfs2_trans_remove_revoke(sdp, block, 1); 635 635 *bhp = gfs2_meta_new(ip->i_gl, block); 636 636 gfs2_trans_add_meta(ip->i_gl, *bhp); 637 637 gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA); ··· 693 693 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL); 694 694 if (error) 695 695 return error; 696 - gfs2_trans_add_unrevoke(sdp, block, 1); 696 + gfs2_trans_remove_revoke(sdp, block, 1); 697 697 bh = gfs2_meta_new(ip->i_gl, block); 698 698 gfs2_trans_add_meta(ip->i_gl, bh); 699 699 gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED); ··· 997 997 error = gfs2_alloc_blocks(ip, &blk, &n, 0, NULL); 998 998 if (error) 999 999 return error; 1000 - gfs2_trans_add_unrevoke(sdp, blk, 1); 1000 + gfs2_trans_remove_revoke(sdp, blk, 1); 1001 1001 indbh = gfs2_meta_new(ip->i_gl, blk); 1002 1002 gfs2_trans_add_meta(ip->i_gl, indbh); 1003 1003 gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);