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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'gfs2-for-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2

Pull gfs2 updates from Andreas Gruenbacher:

- Fix possible data loss during inode evict

- Fix a race during bufdata allocation

- More careful cleaning up during a withdraw

- Prevent excessive log flushing under memory pressure

- Various other minor fixes and cleanups

* tag 'gfs2-for-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2:
gfs2: prevent NULL pointer dereference during unmount
gfs2: hide error messages after withdraw
gfs2: wait for withdraw earlier during unmount
gfs2: inode directory consistency checks
gfs2: gfs2_log_flush withdraw fixes
gfs2: add some missing log locking
gfs2: fix address space truncation during withdraw
gfs2: drain ail under sd_log_flush_lock
gfs2: bufdata allocation race
gfs2: Remove trans_drain code duplication
gfs2: Move gfs2_remove_from_journal to log.c
gfs2: Get rid of gfs2_log_[un]lock helpers
gfs2: less aggressive low-memory log flushing
gfs2: Fix data loss during inode evict
gfs2: minor evict_[un]linked_inode cleanup
gfs2: Avoid unnecessary transactions in evict_linked_inode
gfs2: Remove unnecessary check in gfs2_evict_inode
gfs2: Call unlock_new_inode before d_instantiate

+237 -170
+8 -7
fs/gfs2/aops.c
··· 158 158 struct writeback_control *wbc) 159 159 { 160 160 struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping); 161 + long initial_nr_to_write = wbc->nr_to_write; 161 162 struct iomap_writepage_ctx wpc = { 162 163 .inode = mapping->host, 163 164 .wbc = wbc, ··· 167 166 int ret; 168 167 169 168 /* 170 - * Even if we didn't write enough pages here, we might still be holding 169 + * Even if we didn't write any pages here, we might still be holding 171 170 * dirty pages in the ail. We forcibly flush the ail because we don't 172 171 * want balance_dirty_pages() to loop indefinitely trying to write out 173 172 * pages held in the ail that it can't find. 174 173 */ 175 174 ret = iomap_writepages(&wpc); 176 - if (ret == 0 && wbc->nr_to_write > 0) 175 + if (ret == 0 && wbc->nr_to_write == initial_nr_to_write) 177 176 set_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags); 178 177 return ret; 179 178 } ··· 583 582 struct gfs2_bufdata *bd; 584 583 585 584 lock_buffer(bh); 586 - gfs2_log_lock(sdp); 585 + spin_lock(&sdp->sd_log_lock); 587 586 clear_buffer_dirty(bh); 588 587 bd = bh->b_private; 589 588 if (bd) { ··· 599 598 clear_buffer_mapped(bh); 600 599 clear_buffer_req(bh); 601 600 clear_buffer_new(bh); 602 - gfs2_log_unlock(sdp); 601 + spin_unlock(&sdp->sd_log_lock); 603 602 unlock_buffer(bh); 604 603 } 605 604 ··· 667 666 * again. 668 667 */ 669 668 670 - gfs2_log_lock(sdp); 669 + spin_lock(&sdp->sd_log_lock); 671 670 bh = head; 672 671 do { 673 672 if (atomic_read(&bh->b_count)) ··· 699 698 700 699 bh = bh->b_this_page; 701 700 } while (bh != head); 702 - gfs2_log_unlock(sdp); 701 + spin_unlock(&sdp->sd_log_lock); 703 702 704 703 return try_to_free_buffers(folio); 705 704 706 705 cannot_release: 707 - gfs2_log_unlock(sdp); 706 + spin_unlock(&sdp->sd_log_lock); 708 707 return false; 709 708 } 710 709
+1 -1
fs/gfs2/bmap.c
··· 1539 1539 revokes = jblocks_rqsted; 1540 1540 if (meta) 1541 1541 revokes += end - start; 1542 - else if (ip->i_depth) 1542 + else if (ip->i_diskflags & GFS2_DIF_EXHASH) 1543 1543 revokes += sdp->sd_inptrs; 1544 1544 ret = gfs2_trans_begin(sdp, jblocks_rqsted, revokes); 1545 1545 if (ret)
+9 -4
fs/gfs2/glops.c
··· 64 64 struct buffer_head *bh; 65 65 const unsigned long b_state = (1UL << BH_Dirty)|(1UL << BH_Pinned)|(1UL << BH_Lock); 66 66 67 - gfs2_log_lock(sdp); 67 + spin_lock(&sdp->sd_log_lock); 68 68 spin_lock(&sdp->sd_ail_lock); 69 69 list_for_each_entry_safe_reverse(bd, tmp, head, bd_ail_gl_list) { 70 70 if (nr_revokes == 0) ··· 80 80 } 81 81 GLOCK_BUG_ON(gl, !fsync && atomic_read(&gl->gl_ail_count)); 82 82 spin_unlock(&sdp->sd_ail_lock); 83 - gfs2_log_unlock(sdp); 83 + spin_unlock(&sdp->sd_log_lock); 84 84 } 85 85 86 86 ··· 109 109 * If none of these conditions are true, our revokes are all 110 110 * flushed and we can return. 111 111 */ 112 - gfs2_log_lock(sdp); 112 + spin_lock(&sdp->sd_log_lock); 113 113 have_revokes = !list_empty(&sdp->sd_log_revokes); 114 114 log_in_flight = atomic_read(&sdp->sd_log_in_flight); 115 - gfs2_log_unlock(sdp); 115 + spin_unlock(&sdp->sd_log_lock); 116 116 if (have_revokes) 117 117 goto flush; 118 118 if (log_in_flight) ··· 456 456 } 457 457 ip->i_depth = (u8)depth; 458 458 ip->i_entries = be32_to_cpu(str->di_entries); 459 + 460 + if (!S_ISDIR(inode->i_mode) && (ip->i_diskflags & GFS2_DIF_EXHASH)) { 461 + gfs2_consist_inode(ip); 462 + return -EIO; 463 + } 459 464 460 465 if (gfs2_is_stuffed(ip) && inode->i_size > gfs2_max_stuffed_size(ip)) { 461 466 gfs2_consist_inode(ip);
+1 -2
fs/gfs2/inode.c
··· 892 892 goto fail_gunlock4; 893 893 894 894 mark_inode_dirty(inode); 895 - d_instantiate(dentry, inode); 895 + d_instantiate_new(dentry, inode); 896 896 /* After instantiate, errors should result in evict which will destroy 897 897 * both inode and iopen glocks properly. */ 898 898 if (file) { ··· 904 904 gfs2_glock_dq_uninit(&gh); 905 905 gfs2_glock_put(io_gl); 906 906 gfs2_qa_put(dip); 907 - unlock_new_inode(inode); 908 907 return error; 909 908 910 909 fail_gunlock4:
+92 -35
fs/gfs2/log.c
··· 72 72 * 73 73 */ 74 74 75 - void gfs2_remove_from_ail(struct gfs2_bufdata *bd) 75 + static void gfs2_remove_from_ail(struct gfs2_bufdata *bd) 76 76 { 77 77 bd->bd_tr = NULL; 78 78 list_del_init(&bd->bd_ail_st_list); ··· 467 467 { 468 468 atomic_add(blks, &sdp->sd_log_blks_free); 469 469 trace_gfs2_log_blocks(sdp, blks); 470 - gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= 471 - sdp->sd_jdesc->jd_blocks); 470 + gfs2_assert_withdraw(sdp, !sdp->sd_jdesc || 471 + atomic_read(&sdp->sd_log_blks_free) <= 472 + sdp->sd_jdesc->jd_blocks); 472 473 if (atomic_read(&sdp->sd_log_blks_needed)) 473 474 wake_up(&sdp->sd_log_waitq); 474 475 } ··· 801 800 /* number of revokes we still have room for */ 802 801 unsigned int max_revokes = atomic_read(&sdp->sd_log_revokes_available); 803 802 804 - gfs2_log_lock(sdp); 803 + spin_lock(&sdp->sd_log_lock); 805 804 gfs2_ail1_empty(sdp, max_revokes); 806 - gfs2_log_unlock(sdp); 805 + spin_unlock(&sdp->sd_log_lock); 807 806 } 808 807 809 808 /** ··· 984 983 } 985 984 } 986 985 986 + static void gfs2_trans_drain_list(struct gfs2_sbd *sdp, struct list_head *list) 987 + { 988 + struct gfs2_bufdata *bd; 989 + 990 + while (!list_empty(list)) { 991 + bd = list_first_entry(list, struct gfs2_bufdata, bd_list); 992 + struct buffer_head *bh = bd->bd_bh; 993 + 994 + WARN_ON_ONCE(!buffer_pinned(bh)); 995 + clear_buffer_pinned(bh); 996 + trace_gfs2_pin(bd, 0); 997 + atomic_dec(&sdp->sd_log_pinned); 998 + list_del_init(&bd->bd_list); 999 + brelse(bh); 1000 + } 1001 + } 1002 + 987 1003 /** 988 - * trans_drain - drain the buf and databuf queue for a failed transaction 1004 + * gfs2_trans_drain - drain the buf and databuf queue for a failed transaction 1005 + * @sdp: the filesystem 989 1006 * @tr: the transaction to drain 990 1007 * 991 1008 * When this is called, we're taking an error exit for a log write that failed 992 1009 * but since we bypassed the after_commit functions, we need to remove the 993 1010 * items from the buf and databuf queue. 994 1011 */ 995 - static void trans_drain(struct gfs2_trans *tr) 1012 + static void gfs2_trans_drain(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 996 1013 { 997 - struct gfs2_bufdata *bd; 998 - struct list_head *head; 999 - 1000 1014 if (!tr) 1001 1015 return; 1016 + gfs2_trans_drain_list(sdp, &tr->tr_buf); 1017 + gfs2_trans_drain_list(sdp, &tr->tr_databuf); 1018 + } 1002 1019 1003 - head = &tr->tr_buf; 1004 - while (!list_empty(head)) { 1005 - bd = list_first_entry(head, struct gfs2_bufdata, bd_list); 1020 + void gfs2_remove_from_journal(struct buffer_head *bh, int meta) 1021 + { 1022 + struct address_space *mapping = bh->b_folio->mapping; 1023 + struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping); 1024 + struct gfs2_bufdata *bd = bh->b_private; 1025 + struct gfs2_trans *tr = current->journal_info; 1026 + int was_pinned = 0; 1027 + 1028 + if (test_clear_buffer_pinned(bh)) { 1029 + trace_gfs2_pin(bd, 0); 1030 + atomic_dec(&sdp->sd_log_pinned); 1006 1031 list_del_init(&bd->bd_list); 1007 - if (!list_empty(&bd->bd_ail_st_list)) 1008 - gfs2_remove_from_ail(bd); 1009 - kmem_cache_free(gfs2_bufdata_cachep, bd); 1032 + if (tr) { 1033 + if (meta == REMOVE_META) 1034 + tr->tr_num_buf_rm++; 1035 + else 1036 + tr->tr_num_databuf_rm++; 1037 + set_bit(TR_TOUCHED, &tr->tr_flags); 1038 + } 1039 + was_pinned = 1; 1040 + brelse(bh); 1010 1041 } 1011 - head = &tr->tr_databuf; 1012 - while (!list_empty(head)) { 1013 - bd = list_first_entry(head, struct gfs2_bufdata, bd_list); 1014 - list_del_init(&bd->bd_list); 1015 - if (!list_empty(&bd->bd_ail_st_list)) 1042 + if (bd) { 1043 + if (bd->bd_tr) { 1044 + if (tr) 1045 + gfs2_trans_add_revoke(sdp, bd); 1046 + else 1047 + gfs2_remove_from_ail(bd); 1048 + } else if (was_pinned) { 1049 + bh->b_private = NULL; 1050 + kmem_cache_free(gfs2_bufdata_cachep, bd); 1051 + } else if (!list_empty(&bd->bd_ail_st_list) && 1052 + !list_empty(&bd->bd_ail_gl_list)) { 1016 1053 gfs2_remove_from_ail(bd); 1017 - kmem_cache_free(gfs2_bufdata_cachep, bd); 1054 + } 1018 1055 } 1056 + clear_buffer_dirty(bh); 1057 + clear_buffer_uptodate(bh); 1019 1058 } 1020 1059 1021 1060 /** 1022 - * gfs2_log_flush - flush incore transaction(s) 1061 + * __gfs2_log_flush - flush incore transaction(s) 1023 1062 * @sdp: The filesystem 1024 1063 * @gl: The glock structure to flush. If NULL, flush the whole incore log 1025 1064 * @flags: The log header flags: GFS2_LOG_HEAD_FLUSH_* and debug flags 1026 1065 * 1027 1066 */ 1028 1067 1029 - void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) 1068 + static void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, 1069 + u32 flags) 1030 1070 { 1031 1071 struct gfs2_trans *tr = NULL; 1032 1072 unsigned int reserved_blocks = 0, used_blocks = 0; ··· 1075 1033 unsigned int first_log_head; 1076 1034 unsigned int reserved_revokes = 0; 1077 1035 1078 - down_write(&sdp->sd_log_flush_lock); 1079 1036 trace_gfs2_log_flush(sdp, 1, flags); 1080 1037 1081 1038 repeat: ··· 1151 1110 goto out_withdraw; 1152 1111 lops_after_commit(sdp, tr); 1153 1112 1154 - gfs2_log_lock(sdp); 1113 + spin_lock(&sdp->sd_log_lock); 1155 1114 sdp->sd_log_blks_reserved = 0; 1156 1115 1157 1116 spin_lock(&sdp->sd_ail_lock); ··· 1160 1119 tr = NULL; 1161 1120 } 1162 1121 spin_unlock(&sdp->sd_ail_lock); 1163 - gfs2_log_unlock(sdp); 1122 + spin_unlock(&sdp->sd_log_lock); 1164 1123 1165 1124 if (!(flags & GFS2_LOG_HEAD_FLUSH_NORMAL)) { 1166 1125 if (!sdp->sd_log_idle) { ··· 1186 1145 gfs2_assert_withdraw(sdp, used_blocks < reserved_blocks); 1187 1146 gfs2_log_release(sdp, reserved_blocks - used_blocks); 1188 1147 } 1189 - up_write(&sdp->sd_log_flush_lock); 1190 1148 gfs2_trans_free(sdp, tr); 1191 1149 trace_gfs2_log_flush(sdp, 0, flags); 1192 1150 return; 1193 1151 1194 1152 out_withdraw: 1195 - trans_drain(tr); 1153 + if (sdp->sd_jdesc->jd_log_bio) { 1154 + bio_io_error(sdp->sd_jdesc->jd_log_bio); 1155 + sdp->sd_jdesc->jd_log_bio = NULL; 1156 + } 1157 + gfs2_trans_drain(sdp, tr); 1196 1158 /** 1197 1159 * If the tr_list is empty, we're withdrawing during a log 1198 1160 * flush that targets a transaction, but the transaction was ··· 1208 1164 spin_unlock(&sdp->sd_ail_lock); 1209 1165 tr = NULL; 1210 1166 goto out_end; 1167 + } 1168 + 1169 + void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) 1170 + { 1171 + down_write(&sdp->sd_log_flush_lock); 1172 + __gfs2_log_flush(sdp, gl, flags); 1173 + up_write(&sdp->sd_log_flush_lock); 1211 1174 } 1212 1175 1213 1176 /** ··· 1251 1200 unsigned int unused; 1252 1201 unsigned int maxres; 1253 1202 1254 - gfs2_log_lock(sdp); 1203 + spin_lock(&sdp->sd_log_lock); 1255 1204 1256 1205 if (sdp->sd_log_tr) { 1257 1206 gfs2_merge_trans(sdp, tr); ··· 1269 1218 gfs2_log_release(sdp, unused); 1270 1219 sdp->sd_log_blks_reserved = reserved; 1271 1220 1272 - gfs2_log_unlock(sdp); 1221 + spin_unlock(&sdp->sd_log_lock); 1273 1222 } 1274 1223 1275 1224 static inline int gfs2_jrnl_flush_reqd(struct gfs2_sbd *sdp) ··· 1348 1297 break; 1349 1298 1350 1299 if (gfs2_jrnl_flush_reqd(sdp) || t == 0) { 1300 + down_write(&sdp->sd_log_flush_lock); 1351 1301 gfs2_ail1_empty(sdp, 0); 1352 - gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL | 1353 - GFS2_LFC_LOGD_JFLUSH_REQD); 1302 + __gfs2_log_flush(sdp, NULL, 1303 + GFS2_LOG_HEAD_FLUSH_NORMAL | 1304 + GFS2_LFC_LOGD_JFLUSH_REQD); 1305 + up_write(&sdp->sd_log_flush_lock); 1354 1306 } 1355 1307 1356 1308 if (test_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags) || 1357 1309 gfs2_ail_flush_reqd(sdp)) { 1358 1310 clear_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags); 1311 + down_write(&sdp->sd_log_flush_lock); 1359 1312 gfs2_ail1_start(sdp); 1360 1313 gfs2_ail1_wait(sdp); 1361 1314 gfs2_ail1_empty(sdp, 0); 1362 - gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL | 1363 - GFS2_LFC_LOGD_AIL_FLUSH_REQD); 1315 + __gfs2_log_flush(sdp, NULL, 1316 + GFS2_LOG_HEAD_FLUSH_NORMAL | 1317 + GFS2_LFC_LOGD_AIL_FLUSH_REQD); 1318 + up_write(&sdp->sd_log_flush_lock); 1364 1319 } 1365 1320 1366 1321 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
+1 -25
fs/gfs2/log.h
··· 20 20 */ 21 21 #define GFS2_LOG_FLUSH_MIN_BLOCKS 4 22 22 23 - /** 24 - * gfs2_log_lock - acquire the right to mess with the log manager 25 - * @sdp: the filesystem 26 - * 27 - */ 28 - 29 - static inline void gfs2_log_lock(struct gfs2_sbd *sdp) 30 - __acquires(&sdp->sd_log_lock) 31 - { 32 - spin_lock(&sdp->sd_log_lock); 33 - } 34 - 35 - /** 36 - * gfs2_log_unlock - release the right to mess with the log manager 37 - * @sdp: the filesystem 38 - * 39 - */ 40 - 41 - static inline void gfs2_log_unlock(struct gfs2_sbd *sdp) 42 - __releases(&sdp->sd_log_lock) 43 - { 44 - spin_unlock(&sdp->sd_log_lock); 45 - } 46 - 47 23 static inline void gfs2_ordered_add_inode(struct gfs2_inode *ip) 48 24 { 49 25 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); ··· 37 61 38 62 void gfs2_ordered_del_inode(struct gfs2_inode *ip); 39 63 unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct); 40 - void gfs2_remove_from_ail(struct gfs2_bufdata *bd); 41 64 bool gfs2_log_is_empty(struct gfs2_sbd *sdp); 42 65 void gfs2_log_release_revokes(struct gfs2_sbd *sdp, unsigned int revokes); 43 66 void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks); ··· 47 72 void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, 48 73 u64 seq, u32 tail, u32 lblock, u32 flags, 49 74 blk_opf_t op_flags); 75 + void gfs2_remove_from_journal(struct buffer_head *bh, int meta); 50 76 void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, 51 77 u32 type); 52 78 void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
+8 -8
fs/gfs2/lops.c
··· 648 648 unsigned n; 649 649 __be64 *ptr; 650 650 651 - gfs2_log_lock(sdp); 651 + spin_lock(&sdp->sd_log_lock); 652 652 list_sort(NULL, blist, blocknr_cmp); 653 653 bd1 = bd2 = list_prepare_entry(bd1, blist, bd_list); 654 654 while(total) { 655 655 num = total; 656 656 if (total > limit) 657 657 num = limit; 658 - gfs2_log_unlock(sdp); 658 + spin_unlock(&sdp->sd_log_lock); 659 659 page = gfs2_get_log_desc(sdp, 660 660 is_databuf ? GFS2_LOG_DESC_JDATA : 661 661 GFS2_LOG_DESC_METADATA, num + 1, num); 662 662 ld = page_address(page); 663 - gfs2_log_lock(sdp); 663 + spin_lock(&sdp->sd_log_lock); 664 664 ptr = (__be64 *)(ld + 1); 665 665 666 666 n = 0; ··· 674 674 break; 675 675 } 676 676 677 - gfs2_log_unlock(sdp); 677 + spin_unlock(&sdp->sd_log_lock); 678 678 gfs2_log_write_page(sdp, page); 679 - gfs2_log_lock(sdp); 679 + spin_lock(&sdp->sd_log_lock); 680 680 681 681 n = 0; 682 682 list_for_each_entry_continue(bd2, blist, bd_list) { 683 683 get_bh(bd2->bd_bh); 684 - gfs2_log_unlock(sdp); 684 + spin_unlock(&sdp->sd_log_lock); 685 685 lock_buffer(bd2->bd_bh); 686 686 687 687 if (buffer_escaped(bd2->bd_bh)) { ··· 698 698 } else { 699 699 gfs2_log_write_bh(sdp, bd2->bd_bh); 700 700 } 701 - gfs2_log_lock(sdp); 701 + spin_lock(&sdp->sd_log_lock); 702 702 if (++n >= num) 703 703 break; 704 704 } ··· 706 706 BUG_ON(total < num); 707 707 total -= num; 708 708 } 709 - gfs2_log_unlock(sdp); 709 + spin_unlock(&sdp->sd_log_lock); 710 710 } 711 711 712 712 static void buf_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
+4 -39
fs/gfs2/meta_io.c
··· 338 338 return 0; 339 339 } 340 340 341 - void gfs2_remove_from_journal(struct buffer_head *bh, int meta) 342 - { 343 - struct address_space *mapping = bh->b_folio->mapping; 344 - struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping); 345 - struct gfs2_bufdata *bd = bh->b_private; 346 - struct gfs2_trans *tr = current->journal_info; 347 - int was_pinned = 0; 348 - 349 - if (test_clear_buffer_pinned(bh)) { 350 - trace_gfs2_pin(bd, 0); 351 - atomic_dec(&sdp->sd_log_pinned); 352 - list_del_init(&bd->bd_list); 353 - if (meta == REMOVE_META) 354 - tr->tr_num_buf_rm++; 355 - else 356 - tr->tr_num_databuf_rm++; 357 - set_bit(TR_TOUCHED, &tr->tr_flags); 358 - was_pinned = 1; 359 - brelse(bh); 360 - } 361 - if (bd) { 362 - if (bd->bd_tr) { 363 - gfs2_trans_add_revoke(sdp, bd); 364 - } else if (was_pinned) { 365 - bh->b_private = NULL; 366 - kmem_cache_free(gfs2_bufdata_cachep, bd); 367 - } else if (!list_empty(&bd->bd_ail_st_list) && 368 - !list_empty(&bd->bd_ail_gl_list)) { 369 - gfs2_remove_from_ail(bd); 370 - } 371 - } 372 - clear_buffer_dirty(bh); 373 - clear_buffer_uptodate(bh); 374 - } 375 - 376 341 /** 377 342 * gfs2_ail1_wipe - remove deleted/freed buffers from the ail1 list 378 343 * @sdp: superblock ··· 356 391 struct buffer_head *bh; 357 392 u64 end = bstart + blen; 358 393 359 - gfs2_log_lock(sdp); 394 + spin_lock(&sdp->sd_log_lock); 360 395 spin_lock(&sdp->sd_ail_lock); 361 396 list_for_each_entry_safe(tr, s, &sdp->sd_ail1_list, tr_list) { 362 397 list_for_each_entry_safe(bd, bs, &tr->tr_ail1_list, ··· 369 404 } 370 405 } 371 406 spin_unlock(&sdp->sd_ail_lock); 372 - gfs2_log_unlock(sdp); 407 + spin_unlock(&sdp->sd_log_lock); 373 408 } 374 409 375 410 static struct buffer_head *gfs2_getjdatabuf(struct gfs2_inode *ip, u64 blkno) ··· 421 456 } 422 457 if (bh) { 423 458 lock_buffer(bh); 424 - gfs2_log_lock(sdp); 459 + spin_lock(&sdp->sd_log_lock); 425 460 spin_lock(&sdp->sd_ail_lock); 426 461 gfs2_remove_from_journal(bh, ty); 427 462 spin_unlock(&sdp->sd_ail_lock); 428 - gfs2_log_unlock(sdp); 463 + spin_unlock(&sdp->sd_log_lock); 429 464 unlock_buffer(bh); 430 465 brelse(bh); 431 466 }
-1
fs/gfs2/meta_io.h
··· 59 59 REMOVE_META = 1, 60 60 }; 61 61 62 - void gfs2_remove_from_journal(struct buffer_head *bh, int meta); 63 62 void gfs2_journal_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen); 64 63 int gfs2_meta_buffer(struct gfs2_inode *ip, u32 mtype, u64 num, 65 64 struct buffer_head **bhp);
+1 -1
fs/gfs2/rgrp.c
··· 2529 2529 rgrp_unlock_local(rgd); 2530 2530 2531 2531 /* Directories keep their data in the metadata address space */ 2532 - if (meta || ip->i_depth || gfs2_is_jdata(ip)) 2532 + if (meta || (ip->i_diskflags & GFS2_DIF_EXHASH) || gfs2_is_jdata(ip)) 2533 2533 gfs2_journal_wipe(ip, bstart, blen); 2534 2534 } 2535 2535
+87 -24
fs/gfs2/super.c
··· 596 596 } 597 597 spin_unlock(&sdp->sd_jindex_spin); 598 598 599 + /* Wait for withdraw to complete */ 600 + flush_work(&sdp->sd_withdraw_work); 601 + 599 602 if (!sb_rdonly(sb)) 600 603 gfs2_make_fs_ro(sdp); 601 604 else { ··· 607 604 608 605 gfs2_quota_cleanup(sdp); 609 606 } 610 - 611 - flush_work(&sdp->sd_withdraw_work); 612 607 613 608 /* At this point, we're through modifying the disk */ 614 609 ··· 1242 1241 struct gfs2_sbd *sdp = sb->s_fs_info; 1243 1242 int ret; 1244 1243 1244 + if (inode->i_nlink) 1245 + return EVICT_SHOULD_SKIP_DELETE; 1246 + 1245 1247 if (gfs2_holder_initialized(&ip->i_iopen_gh) && 1246 1248 test_bit(GLF_DEFER_DELETE, &ip->i_iopen_gh.gh_gl->gl_flags)) 1247 1249 return EVICT_SHOULD_DEFER_DELETE; ··· 1283 1279 /** 1284 1280 * evict_unlinked_inode - delete the pieces of an unlinked evicted inode 1285 1281 * @inode: The inode to evict 1282 + * @gh: The glock holder structure 1286 1283 */ 1287 - static int evict_unlinked_inode(struct inode *inode) 1284 + static int evict_unlinked_inode(struct inode *inode, struct gfs2_holder *gh) 1288 1285 { 1289 1286 struct gfs2_inode *ip = GFS2_I(inode); 1287 + struct gfs2_glock *gl = ip->i_gl; 1290 1288 int ret; 1289 + 1290 + /* The inode glock must be held exclusively and be instantiated. */ 1291 + BUG_ON(!gfs2_holder_initialized(gh) || 1292 + test_bit(GLF_INSTANTIATE_NEEDED, &gl->gl_flags)); 1291 1293 1292 1294 if (S_ISDIR(inode->i_mode) && 1293 1295 (ip->i_diskflags & GFS2_DIF_EXHASH)) { ··· 1327 1317 */ 1328 1318 1329 1319 ret = gfs2_dinode_dealloc(ip); 1330 - if (!ret && ip->i_gl) 1331 - gfs2_inode_remember_delete(ip->i_gl, ip->i_no_formal_ino); 1320 + if (!ret) 1321 + gfs2_inode_remember_delete(gl, ip->i_no_formal_ino); 1332 1322 1333 1323 out: 1334 1324 return ret; 1335 1325 } 1336 1326 1327 + static int gfs2_truncate_inode_pages(struct inode *inode) 1328 + { 1329 + struct gfs2_inode *ip = GFS2_I(inode); 1330 + struct gfs2_sbd *sdp = GFS2_SB(inode); 1331 + struct address_space *mapping = &inode->i_data; 1332 + bool need_trans = gfs2_is_jdata(ip) && mapping->nrpages; 1333 + int ret = 0; 1334 + 1335 + /* 1336 + * Truncating a jdata inode address space may create revokes in 1337 + * truncate_inode_pages() -> gfs2_invalidate_folio() -> ... -> 1338 + * gfs2_remove_from_journal(), so we need a transaction here. 1339 + * 1340 + * During a withdraw, no new transactions can be created. We still 1341 + * take the log flush lock to prevent truncate from racing with 1342 + * gfs2_log_flush(). 1343 + */ 1344 + if (need_trans) { 1345 + ret = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); 1346 + if (ret) 1347 + down_read(&sdp->sd_log_flush_lock); 1348 + } 1349 + truncate_inode_pages(mapping, 0); 1350 + if (need_trans) { 1351 + if (ret) 1352 + up_read(&sdp->sd_log_flush_lock); 1353 + else 1354 + gfs2_trans_end(sdp); 1355 + } 1356 + return ret; 1357 + } 1358 + 1359 + static void gfs2_truncate_inode_pages_final(struct inode *inode) 1360 + { 1361 + struct gfs2_inode *ip = GFS2_I(inode); 1362 + struct gfs2_sbd *sdp = GFS2_SB(inode); 1363 + struct address_space *mapping = &inode->i_data; 1364 + bool need_lock = gfs2_is_jdata(ip) && mapping->nrpages; 1365 + 1366 + if (need_lock) 1367 + down_read(&sdp->sd_log_flush_lock); 1368 + truncate_inode_pages_final(mapping); 1369 + if (need_lock) 1370 + up_read(&sdp->sd_log_flush_lock); 1371 + } 1372 + 1337 1373 /* 1338 1374 * evict_linked_inode - evict an inode whose dinode has not been unlinked 1339 1375 * @inode: The inode to evict 1376 + * @gh: The glock holder structure 1340 1377 */ 1341 - static int evict_linked_inode(struct inode *inode) 1378 + static int evict_linked_inode(struct inode *inode, struct gfs2_holder *gh) 1342 1379 { 1343 1380 struct super_block *sb = inode->i_sb; 1344 1381 struct gfs2_sbd *sdp = sb->s_fs_info; 1345 1382 struct gfs2_inode *ip = GFS2_I(inode); 1346 - struct address_space *metamapping; 1383 + struct gfs2_glock *gl = ip->i_gl; 1384 + struct address_space *metamapping = gfs2_glock2aspace(gl); 1347 1385 int ret; 1348 1386 1349 - gfs2_log_flush(sdp, ip->i_gl, GFS2_LOG_HEAD_FLUSH_NORMAL | 1387 + if (!(test_bit(GLF_DIRTY, &gl->gl_flags) || inode->i_flags & I_DIRTY)) 1388 + goto clean; 1389 + 1390 + /* The inode glock must be held exclusively and be instantiated. */ 1391 + if (!gfs2_holder_initialized(gh)) 1392 + ret = gfs2_glock_nq_init(gl, LM_ST_EXCLUSIVE, 0, gh); 1393 + else 1394 + ret = gfs2_instantiate(gh); 1395 + if (ret) 1396 + return ret; 1397 + 1398 + gfs2_log_flush(sdp, gl, GFS2_LOG_HEAD_FLUSH_NORMAL | 1350 1399 GFS2_LFC_EVICT_INODE); 1351 - metamapping = gfs2_glock2aspace(ip->i_gl); 1352 - if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) { 1400 + if (test_bit(GLF_DIRTY, &gl->gl_flags)) { 1353 1401 filemap_fdatawrite(metamapping); 1354 1402 filemap_fdatawait(metamapping); 1355 1403 } 1356 1404 write_inode_now(inode, 1); 1357 - gfs2_ail_flush(ip->i_gl, 0); 1405 + gfs2_ail_flush(gl, 0); 1358 1406 1359 - ret = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); 1360 - if (ret) 1361 - return ret; 1362 - 1363 - /* Needs to be done before glock release & also in a transaction */ 1364 - truncate_inode_pages(&inode->i_data, 0); 1407 + clean: 1408 + ret = gfs2_truncate_inode_pages(inode); 1365 1409 truncate_inode_pages(metamapping, 0); 1366 - gfs2_trans_end(sdp); 1367 - return 0; 1410 + return ret; 1368 1411 } 1369 1412 1370 1413 /** ··· 1451 1388 int ret; 1452 1389 1453 1390 gfs2_holder_mark_uninitialized(&gh); 1454 - if (inode->i_nlink || sb_rdonly(sb) || !ip->i_no_addr) 1391 + if (sb_rdonly(sb) || !ip->i_no_addr || !ip->i_gl) 1455 1392 goto out; 1456 1393 1457 1394 /* ··· 1476 1413 behavior = EVICT_SHOULD_SKIP_DELETE; 1477 1414 } 1478 1415 if (behavior == EVICT_SHOULD_DELETE) 1479 - ret = evict_unlinked_inode(inode); 1416 + ret = evict_unlinked_inode(inode, &gh); 1480 1417 else 1481 - ret = evict_linked_inode(inode); 1418 + ret = evict_linked_inode(inode, &gh); 1482 1419 1483 1420 if (gfs2_rs_active(&ip->i_res)) 1484 1421 gfs2_rs_deltree(&ip->i_res); 1485 1422 1486 - if (ret && ret != GLR_TRYFAILED && ret != -EROFS) 1423 + if (ret && !gfs2_withdrawn(sdp) && ret != -EROFS) 1487 1424 fs_warn(sdp, "gfs2_evict_inode: %d\n", ret); 1488 1425 out: 1489 1426 if (gfs2_holder_initialized(&gh)) 1490 1427 gfs2_glock_dq_uninit(&gh); 1491 - truncate_inode_pages_final(&inode->i_data); 1428 + gfs2_truncate_inode_pages_final(inode); 1492 1429 if (ip->i_qadata) 1493 1430 gfs2_assert_warn(sdp, ip->i_qadata->qa_ref == 0); 1494 1431 gfs2_rs_deltree(&ip->i_res);
+24 -21
fs/gfs2/trans.c
··· 176 176 INIT_LIST_HEAD(&bd->bd_list); 177 177 INIT_LIST_HEAD(&bd->bd_ail_st_list); 178 178 INIT_LIST_HEAD(&bd->bd_ail_gl_list); 179 - bh->b_private = bd; 180 179 return bd; 181 180 } 182 181 ··· 204 205 set_bit(TR_TOUCHED, &tr->tr_flags); 205 206 goto out; 206 207 } 207 - gfs2_log_lock(sdp); 208 + spin_lock(&sdp->sd_log_lock); 208 209 bd = bh->b_private; 209 210 if (bd == NULL) { 210 - gfs2_log_unlock(sdp); 211 + spin_unlock(&sdp->sd_log_lock); 211 212 unlock_buffer(bh); 212 - if (bh->b_private == NULL) 213 - bd = gfs2_alloc_bufdata(gl, bh); 214 - else 215 - bd = bh->b_private; 213 + bd = gfs2_alloc_bufdata(gl, bh); 216 214 lock_buffer(bh); 217 - gfs2_log_lock(sdp); 215 + spin_lock(&sdp->sd_log_lock); 216 + if (bh->b_private) { 217 + kmem_cache_free(gfs2_bufdata_cachep, bd); 218 + bd = bh->b_private; 219 + } else { 220 + bh->b_private = bd; 221 + } 218 222 } 219 223 gfs2_assert(sdp, bd->bd_gl == gl); 220 224 set_bit(TR_TOUCHED, &tr->tr_flags); ··· 228 226 tr->tr_num_databuf_new++; 229 227 list_add_tail(&bd->bd_list, &tr->tr_databuf); 230 228 } 231 - gfs2_log_unlock(sdp); 229 + spin_unlock(&sdp->sd_log_lock); 232 230 out: 233 231 unlock_buffer(bh); 234 232 } ··· 268 266 set_bit(TR_TOUCHED, &tr->tr_flags); 269 267 goto out; 270 268 } 271 - gfs2_log_lock(sdp); 269 + spin_lock(&sdp->sd_log_lock); 272 270 bd = bh->b_private; 273 271 if (bd == NULL) { 274 - gfs2_log_unlock(sdp); 272 + spin_unlock(&sdp->sd_log_lock); 275 273 unlock_buffer(bh); 276 - folio_lock(bh->b_folio); 277 - if (bh->b_private == NULL) 278 - bd = gfs2_alloc_bufdata(gl, bh); 279 - else 280 - bd = bh->b_private; 281 - folio_unlock(bh->b_folio); 274 + bd = gfs2_alloc_bufdata(gl, bh); 282 275 lock_buffer(bh); 283 - gfs2_log_lock(sdp); 276 + spin_lock(&sdp->sd_log_lock); 277 + if (bh->b_private) { 278 + kmem_cache_free(gfs2_bufdata_cachep, bd); 279 + bd = bh->b_private; 280 + } else { 281 + bh->b_private = bd; 282 + } 284 283 } 285 284 gfs2_assert(sdp, bd->bd_gl == gl); 286 285 set_bit(TR_TOUCHED, &tr->tr_flags); ··· 312 309 list_add(&bd->bd_list, &tr->tr_buf); 313 310 tr->tr_num_buf_new++; 314 311 out_unlock: 315 - gfs2_log_unlock(sdp); 312 + spin_unlock(&sdp->sd_log_lock); 316 313 out: 317 314 unlock_buffer(bh); 318 315 } ··· 332 329 struct gfs2_bufdata *bd, *tmp; 333 330 unsigned int n = len; 334 331 335 - gfs2_log_lock(sdp); 332 + spin_lock(&sdp->sd_log_lock); 336 333 list_for_each_entry_safe(bd, tmp, &sdp->sd_log_revokes, bd_list) { 337 334 if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) { 338 335 list_del_init(&bd->bd_list); ··· 346 343 break; 347 344 } 348 345 } 349 - gfs2_log_unlock(sdp); 346 + spin_unlock(&sdp->sd_log_lock); 350 347 } 351 348 352 349 void gfs2_trans_free(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
+1 -2
fs/gfs2/util.c
··· 123 123 return; 124 124 } 125 125 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); 126 - up_write(&sdp->sd_log_flush_lock); 127 - 128 126 gfs2_ail_drain(sdp); /* frees all transactions */ 127 + up_write(&sdp->sd_log_flush_lock); 129 128 130 129 wake_up(&sdp->sd_logd_waitq); 131 130 wake_up(&sdp->sd_quota_wait);