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

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

Pull gfs2 updates from Andreas Gruenbacher:

- Fix the long-standing warnings in inode_to_wb() when CONFIG_LOCKDEP
is enabled: gfs2 doesn't support cgroup writeback and so inode->i_wb
will never change. This is the counterpart of commit 9e888998ea4d
("writeback: fix false warning in inode_to_wb()")

- Fix a hang introduced by commit 8d391972ae2d ("gfs2: Remove
__gfs2_writepage()"): prevent gfs2_logd from creating transactions
for jdata pages while trying to flush the log

- Fix a race between gfs2_create_inode() and gfs2_evict_inode() by
deallocating partially created inodes on the gfs2_create_inode()
error path

- Fix a bug in the journal head lookup code that could cause mount to
fail after successful recovery

- Various smaller fixes and cleanups from various people

* tag 'gfs2-for-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: (23 commits)
gfs2: No more gfs2_find_jhead caching
gfs2: Get rid of duplicate log head lookup
gfs2: Simplify clean_journal
gfs2: Simplify gfs2_log_pointers_init
gfs2: Move gfs2_log_pointers_init
gfs2: Minor comments fix
gfs2: Don't start unnecessary transactions during log flush
gfs2: Move gfs2_trans_add_databufs
gfs2: Rename jdata_dirty_folio to gfs2_jdata_dirty_folio
gfs2: avoid inefficient use of crc32_le_shift()
gfs2: Do not call iomap_zero_range beyond eof
gfs: don't check for AOP_WRITEPAGE_ACTIVATE in gfs2_write_jdata_batch
gfs2: Fix usage of bio->bi_status in gfs2_end_log_write
gfs2: deallocate inodes in gfs2_create_inode
gfs2: Move GIF_ALLOC_FAILED check out of gfs2_ea_dealloc
gfs2: Move gfs2_dinode_dealloc
gfs2: Don't reread inodes unnecessarily
gfs2: gfs2_create_inode error handling fix
gfs2: Remove unnecessary NULL check before free_percpu()
gfs2: check sb_min_blocksize return value
...

+263 -213
+44 -42
fs/gfs2/aops.c
··· 37 37 #include "aops.h" 38 38 39 39 40 - void gfs2_trans_add_databufs(struct gfs2_inode *ip, struct folio *folio, 41 - size_t from, size_t len) 42 - { 43 - struct buffer_head *head = folio_buffers(folio); 44 - unsigned int bsize = head->b_size; 45 - struct buffer_head *bh; 46 - size_t to = from + len; 47 - size_t start, end; 48 - 49 - for (bh = head, start = 0; bh != head || !start; 50 - bh = bh->b_this_page, start = end) { 51 - end = start + bsize; 52 - if (end <= from) 53 - continue; 54 - if (start >= to) 55 - break; 56 - set_buffer_uptodate(bh); 57 - gfs2_trans_add_data(ip->i_gl, bh); 58 - } 59 - } 60 - 61 40 /** 62 41 * gfs2_get_block_noalloc - Fills in a buffer head with details about a block 63 42 * @inode: The inode ··· 112 133 inode->i_sb->s_blocksize, 113 134 BIT(BH_Dirty)|BIT(BH_Uptodate)); 114 135 } 115 - gfs2_trans_add_databufs(ip, folio, 0, folio_size(folio)); 136 + gfs2_trans_add_databufs(ip->i_gl, folio, 0, folio_size(folio)); 116 137 } 117 138 return gfs2_write_jdata_folio(folio, wbc); 139 + } 140 + 141 + /** 142 + * gfs2_jdata_writeback - Write jdata folios to the log 143 + * @mapping: The mapping to write 144 + * @wbc: The writeback control 145 + * 146 + * Returns: errno 147 + */ 148 + int gfs2_jdata_writeback(struct address_space *mapping, struct writeback_control *wbc) 149 + { 150 + struct inode *inode = mapping->host; 151 + struct gfs2_inode *ip = GFS2_I(inode); 152 + struct gfs2_sbd *sdp = GFS2_SB(mapping->host); 153 + struct folio *folio = NULL; 154 + int error; 155 + 156 + BUG_ON(current->journal_info); 157 + if (gfs2_assert_withdraw(sdp, ip->i_gl->gl_state == LM_ST_EXCLUSIVE)) 158 + return 0; 159 + 160 + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { 161 + if (folio_test_checked(folio)) { 162 + folio_redirty_for_writepage(wbc, folio); 163 + folio_unlock(folio); 164 + continue; 165 + } 166 + error = __gfs2_jdata_write_folio(folio, wbc); 167 + } 168 + 169 + return error; 118 170 } 119 171 120 172 /** ··· 238 228 239 229 ret = __gfs2_jdata_write_folio(folio, wbc); 240 230 if (unlikely(ret)) { 241 - if (ret == AOP_WRITEPAGE_ACTIVATE) { 242 - folio_unlock(folio); 243 - ret = 0; 244 - } else { 245 - 246 - /* 247 - * done_index is set past this page, 248 - * so media errors will not choke 249 - * background writeout for the entire 250 - * file. This has consequences for 251 - * range_cyclic semantics (ie. it may 252 - * not be suitable for data integrity 253 - * writeout). 254 - */ 255 - *done_index = folio_next_index(folio); 256 - ret = 1; 257 - break; 258 - } 231 + /* 232 + * done_index is set past this page, so media errors 233 + * will not choke background writeout for the entire 234 + * file. This has consequences for range_cyclic 235 + * semantics (ie. it may not be suitable for data 236 + * integrity writeout). 237 + */ 238 + *done_index = folio_next_index(folio); 239 + ret = 1; 240 + break; 259 241 } 260 242 261 243 /* ··· 542 540 gfs2_trans_end(sdp); 543 541 } 544 542 545 - static bool jdata_dirty_folio(struct address_space *mapping, 543 + static bool gfs2_jdata_dirty_folio(struct address_space *mapping, 546 544 struct folio *folio) 547 545 { 548 546 if (current->journal_info) ··· 724 722 .writepages = gfs2_jdata_writepages, 725 723 .read_folio = gfs2_read_folio, 726 724 .readahead = gfs2_readahead, 727 - .dirty_folio = jdata_dirty_folio, 725 + .dirty_folio = gfs2_jdata_dirty_folio, 728 726 .bmap = gfs2_bmap, 729 727 .migrate_folio = buffer_migrate_folio, 730 728 .invalidate_folio = gfs2_invalidate_folio,
+1 -2
fs/gfs2/aops.h
··· 9 9 #include "incore.h" 10 10 11 11 void adjust_fs_space(struct inode *inode); 12 - void gfs2_trans_add_databufs(struct gfs2_inode *ip, struct folio *folio, 13 - size_t from, size_t len); 12 + int gfs2_jdata_writeback(struct address_space *mapping, struct writeback_control *wbc); 14 13 15 14 #endif /* __AOPS_DOT_H__ */
+6 -3
fs/gfs2/bmap.c
··· 988 988 struct gfs2_sbd *sdp = GFS2_SB(inode); 989 989 990 990 if (!gfs2_is_stuffed(ip)) 991 - gfs2_trans_add_databufs(ip, folio, offset_in_folio(folio, pos), 991 + gfs2_trans_add_databufs(ip->i_gl, folio, 992 + offset_in_folio(folio, pos), 992 993 copied); 993 994 994 995 folio_unlock(folio); ··· 1297 1296 * uses iomap write to perform its actions, which begin their own transactions 1298 1297 * (iomap_begin, get_folio, etc.) 1299 1298 */ 1300 - static int gfs2_block_zero_range(struct inode *inode, loff_t from, 1301 - unsigned int length) 1299 + static int gfs2_block_zero_range(struct inode *inode, loff_t from, loff_t length) 1302 1300 { 1303 1301 BUG_ON(current->journal_info); 1302 + if (from >= inode->i_size) 1303 + return 0; 1304 + length = min(length, inode->i_size - from); 1304 1305 return iomap_zero_range(inode, from, length, NULL, &gfs2_iomap_ops, 1305 1306 NULL); 1306 1307 }
+1 -2
fs/gfs2/glock.c
··· 1166 1166 const struct gfs2_glock_operations *glops, int create, 1167 1167 struct gfs2_glock **glp) 1168 1168 { 1169 - struct super_block *s = sdp->sd_vfs; 1170 1169 struct lm_lockname name = { .ln_number = number, 1171 1170 .ln_type = glops->go_type, 1172 1171 .ln_sbd = sdp }; ··· 1228 1229 mapping = gfs2_glock2aspace(gl); 1229 1230 if (mapping) { 1230 1231 mapping->a_ops = &gfs2_meta_aops; 1231 - mapping->host = s->s_bdev->bd_mapping->host; 1232 + mapping->host = sdp->sd_inode; 1232 1233 mapping->flags = 0; 1233 1234 mapping_set_gfp_mask(mapping, GFP_NOFS); 1234 1235 mapping->i_private_data = NULL;
+4 -5
fs/gfs2/glops.c
··· 168 168 static int gfs2_rgrp_metasync(struct gfs2_glock *gl) 169 169 { 170 170 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 171 - struct address_space *metamapping = &sdp->sd_aspace; 171 + struct address_space *metamapping = gfs2_aspace(sdp); 172 172 struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl); 173 173 const unsigned bsize = sdp->sd_sb.sb_bsize; 174 174 loff_t start = (rgd->rd_addr * bsize) & PAGE_MASK; ··· 225 225 static void rgrp_go_inval(struct gfs2_glock *gl, int flags) 226 226 { 227 227 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 228 - struct address_space *mapping = &sdp->sd_aspace; 228 + struct address_space *mapping = gfs2_aspace(sdp); 229 229 struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl); 230 230 const unsigned bsize = sdp->sd_sb.sb_bsize; 231 231 loff_t start, end; ··· 601 601 if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { 602 602 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 603 603 604 - error = gfs2_find_jhead(sdp->sd_jdesc, &head, false); 604 + error = gfs2_find_jhead(sdp->sd_jdesc, &head); 605 605 if (gfs2_assert_withdraw_delayed(sdp, !error)) 606 606 return error; 607 607 if (gfs2_assert_withdraw_delayed(sdp, head.lh_flags & 608 608 GFS2_LOG_HEAD_UNMOUNT)) 609 609 return -EIO; 610 - sdp->sd_log_sequence = head.lh_sequence + 1; 611 - gfs2_log_pointers_init(sdp, head.lh_blkno); 610 + gfs2_log_pointers_init(sdp, &head); 612 611 } 613 612 return 0; 614 613 }
+8 -1
fs/gfs2/incore.h
··· 795 795 796 796 /* Log stuff */ 797 797 798 - struct address_space sd_aspace; 798 + struct inode *sd_inode; 799 799 800 800 spinlock_t sd_log_lock; 801 801 ··· 850 850 struct dentry *debugfs_dir; /* debugfs directory */ 851 851 unsigned long sd_glock_dqs_held; 852 852 }; 853 + 854 + #define GFS2_BAD_INO 1 855 + 856 + static inline struct address_space *gfs2_aspace(struct gfs2_sbd *sdp) 857 + { 858 + return sdp->sd_inode->i_mapping; 859 + } 853 860 854 861 static inline void gfs2_glstats_inc(struct gfs2_glock *gl, int which) 855 862 {
+90 -9
fs/gfs2/inode.c
··· 439 439 return error; 440 440 } 441 441 442 + static void gfs2_final_release_pages(struct gfs2_inode *ip) 443 + { 444 + struct inode *inode = &ip->i_inode; 445 + struct gfs2_glock *gl = ip->i_gl; 446 + 447 + if (unlikely(!gl)) { 448 + /* This can only happen during incomplete inode creation. */ 449 + BUG_ON(!test_bit(GIF_ALLOC_FAILED, &ip->i_flags)); 450 + return; 451 + } 452 + 453 + truncate_inode_pages(gfs2_glock2aspace(gl), 0); 454 + truncate_inode_pages(&inode->i_data, 0); 455 + 456 + if (atomic_read(&gl->gl_revokes) == 0) { 457 + clear_bit(GLF_LFLUSH, &gl->gl_flags); 458 + clear_bit(GLF_DIRTY, &gl->gl_flags); 459 + } 460 + } 461 + 462 + int gfs2_dinode_dealloc(struct gfs2_inode *ip) 463 + { 464 + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 465 + struct gfs2_rgrpd *rgd; 466 + struct gfs2_holder gh; 467 + int error; 468 + 469 + if (gfs2_get_inode_blocks(&ip->i_inode) != 1) { 470 + gfs2_consist_inode(ip); 471 + return -EIO; 472 + } 473 + 474 + gfs2_rindex_update(sdp); 475 + 476 + error = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE); 477 + if (error) 478 + return error; 479 + 480 + rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1); 481 + if (!rgd) { 482 + gfs2_consist_inode(ip); 483 + error = -EIO; 484 + goto out_qs; 485 + } 486 + 487 + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 488 + LM_FLAG_NODE_SCOPE, &gh); 489 + if (error) 490 + goto out_qs; 491 + 492 + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 493 + sdp->sd_jdesc->jd_blocks); 494 + if (error) 495 + goto out_rg_gunlock; 496 + 497 + gfs2_free_di(rgd, ip); 498 + 499 + gfs2_final_release_pages(ip); 500 + 501 + gfs2_trans_end(sdp); 502 + 503 + out_rg_gunlock: 504 + gfs2_glock_dq_uninit(&gh); 505 + out_qs: 506 + gfs2_quota_unhold(ip); 507 + return error; 508 + } 509 + 442 510 static void gfs2_init_dir(struct buffer_head *dibh, 443 511 const struct gfs2_inode *parent) 444 512 { ··· 697 629 struct gfs2_inode *dip = GFS2_I(dir), *ip; 698 630 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 699 631 struct gfs2_glock *io_gl; 700 - int error; 632 + int error, dealloc_error; 701 633 u32 aflags = 0; 702 634 unsigned blocks = 1; 703 635 struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, }; 636 + bool xattr_initialized = false; 704 637 705 638 if (!name->len || name->len > GFS2_FNAMESIZE) 706 639 return -ENAMETOOLONG; ··· 728 659 if (!IS_ERR(inode)) { 729 660 if (S_ISDIR(inode->i_mode)) { 730 661 iput(inode); 731 - inode = ERR_PTR(-EISDIR); 662 + inode = NULL; 663 + error = -EISDIR; 732 664 goto fail_gunlock; 733 665 } 734 666 d_instantiate(dentry, inode); ··· 814 744 815 745 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); 816 746 if (error) 817 - goto fail_free_inode; 747 + goto fail_dealloc_inode; 818 748 819 749 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl); 820 750 if (error) 821 - goto fail_free_inode; 751 + goto fail_dealloc_inode; 822 752 gfs2_cancel_delete_work(io_gl); 823 753 io_gl->gl_no_formal_ino = ip->i_no_formal_ino; 824 754 ··· 837 767 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, &gh); 838 768 if (error) 839 769 goto fail_gunlock3; 770 + clear_bit(GLF_INSTANTIATE_NEEDED, &ip->i_gl->gl_flags); 840 771 841 772 error = gfs2_trans_begin(sdp, blocks, 0); 842 773 if (error) 843 774 goto fail_gunlock3; 844 775 845 - if (blocks > 1) 776 + if (blocks > 1) { 846 777 gfs2_init_xattr(ip); 778 + xattr_initialized = true; 779 + } 847 780 init_dinode(dip, ip, symname); 848 781 gfs2_trans_end(sdp); 849 782 ··· 901 828 gfs2_glock_dq_uninit(&ip->i_iopen_gh); 902 829 fail_gunlock2: 903 830 gfs2_glock_put(io_gl); 831 + fail_dealloc_inode: 832 + set_bit(GIF_ALLOC_FAILED, &ip->i_flags); 833 + dealloc_error = 0; 834 + if (ip->i_eattr) 835 + dealloc_error = gfs2_ea_dealloc(ip, xattr_initialized); 836 + clear_nlink(inode); 837 + mark_inode_dirty(inode); 838 + if (!dealloc_error) 839 + dealloc_error = gfs2_dinode_dealloc(ip); 840 + if (dealloc_error) 841 + fs_warn(sdp, "%s: %d\n", __func__, dealloc_error); 842 + ip->i_no_addr = 0; 904 843 fail_free_inode: 905 844 if (ip->i_gl) { 906 845 gfs2_glock_put(ip->i_gl); ··· 927 842 gfs2_dir_no_add(&da); 928 843 gfs2_glock_dq_uninit(&d_gh); 929 844 if (!IS_ERR_OR_NULL(inode)) { 930 - set_bit(GIF_ALLOC_FAILED, &ip->i_flags); 931 - clear_nlink(inode); 932 - if (ip->i_no_addr) 933 - mark_inode_dirty(inode); 934 845 if (inode->i_state & I_NEW) 935 846 iget_failed(inode); 936 847 else
+1
fs/gfs2/inode.h
··· 92 92 struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr, 93 93 u64 no_formal_ino, 94 94 unsigned int blktype); 95 + int gfs2_dinode_dealloc(struct gfs2_inode *ip); 95 96 96 97 struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, 97 98 int is_root);
+8 -3
fs/gfs2/lock_dlm.c
··· 328 328 { 329 329 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 330 330 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 331 + uint32_t flags = 0; 331 332 int error; 332 333 333 334 BUG_ON(!__lockref_is_dead(&gl->gl_lockref)); ··· 353 352 * When the lockspace is released, all remaining glocks will be 354 353 * unlocked automatically. This is more efficient than unlocking them 355 354 * individually, but when the lock is held in DLM_LOCK_EX or 356 - * DLM_LOCK_PW mode, the lock value block (LVB) will be lost. 355 + * DLM_LOCK_PW mode, the lock value block (LVB) would be lost. 357 356 */ 358 357 359 358 if (test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags) && ··· 362 361 return; 363 362 } 364 363 364 + if (gl->gl_lksb.sb_lvbptr) 365 + flags |= DLM_LKF_VALBLK; 366 + 365 367 again: 366 - error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_VALBLK, 368 + error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, flags, 367 369 NULL, gl); 368 370 if (error == -EBUSY) { 369 371 msleep(20); ··· 1000 996 if (sdp->sd_args.ar_spectator) { 1001 997 fs_info(sdp, "Recovery is required. Waiting for a " 1002 998 "non-spectator to mount.\n"); 999 + spin_unlock(&ls->ls_recover_spin); 1003 1000 msleep_interruptible(1000); 1004 1001 } else { 1005 1002 fs_info(sdp, "control_mount wait1 block %u start %u " 1006 1003 "mount %u lvb %u flags %lx\n", block_gen, 1007 1004 start_gen, mount_gen, lvb_gen, 1008 1005 ls->ls_recover_flags); 1006 + spin_unlock(&ls->ls_recover_spin); 1009 1007 } 1010 - spin_unlock(&ls->ls_recover_spin); 1011 1008 goto restart; 1012 1009 } 1013 1010
+6 -1
fs/gfs2/log.c
··· 31 31 #include "dir.h" 32 32 #include "trace_gfs2.h" 33 33 #include "trans.h" 34 + #include "aops.h" 34 35 35 36 static void gfs2_log_shutdown(struct gfs2_sbd *sdp); 36 37 ··· 132 131 if (!mapping) 133 132 continue; 134 133 spin_unlock(&sdp->sd_ail_lock); 135 - ret = mapping->a_ops->writepages(mapping, wbc); 134 + BUG_ON(GFS2_SB(mapping->host) != sdp); 135 + if (gfs2_is_jdata(GFS2_I(mapping->host))) 136 + ret = gfs2_jdata_writeback(mapping, wbc); 137 + else 138 + ret = mapping->a_ops->writepages(mapping, wbc); 136 139 if (need_resched()) { 137 140 blk_finish_plug(plug); 138 141 cond_resched();
-11
fs/gfs2/log.h
··· 44 44 spin_unlock(&sdp->sd_log_lock); 45 45 } 46 46 47 - static inline void gfs2_log_pointers_init(struct gfs2_sbd *sdp, 48 - unsigned int value) 49 - { 50 - if (++value == sdp->sd_jdesc->jd_blocks) { 51 - value = 0; 52 - } 53 - sdp->sd_log_tail = value; 54 - sdp->sd_log_flush_tail = value; 55 - sdp->sd_log_head = value; 56 - } 57 - 58 47 static inline void gfs2_ordered_add_inode(struct gfs2_inode *ip) 59 48 { 60 49 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
+8 -9
fs/gfs2/lops.c
··· 204 204 struct bvec_iter_all iter_all; 205 205 206 206 if (bio->bi_status) { 207 - if (!cmpxchg(&sdp->sd_log_error, 0, (int)bio->bi_status)) 207 + int err = blk_status_to_errno(bio->bi_status); 208 + 209 + if (!cmpxchg(&sdp->sd_log_error, 0, err)) 208 210 fs_err(sdp, "Error %d writing to journal, jid=%u\n", 209 - bio->bi_status, sdp->sd_jdesc->jd_jid); 211 + err, sdp->sd_jdesc->jd_jid); 210 212 gfs2_withdraw_delayed(sdp); 211 213 /* prevent more writes to the journal */ 212 214 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); ··· 451 449 * Find the folio with 'index' in the journal's mapping. Search the folio for 452 450 * the journal head if requested (cleanup == false). Release refs on the 453 451 * folio so the page cache can reclaim it. We grabbed a 454 - * reference on this folio twice, first when we did a grab_cache_page() 452 + * reference on this folio twice, first when we did a filemap_grab_folio() 455 453 * to obtain the folio to add it to the bio and second when we do a 456 454 * filemap_get_folio() here to get the folio to wait on while I/O on it is being 457 455 * completed. ··· 476 474 if (!*done) 477 475 *done = gfs2_jhead_folio_search(jd, head, folio); 478 476 479 - /* filemap_get_folio() and the earlier grab_cache_page() */ 477 + /* filemap_get_folio() and the earlier filemap_grab_folio() */ 480 478 folio_put_refs(folio, 2); 481 479 } 482 480 ··· 496 494 * gfs2_find_jhead - find the head of a log 497 495 * @jd: The journal descriptor 498 496 * @head: The log descriptor for the head of the log is returned here 499 - * @keep_cache: If set inode pages will not be truncated 500 497 * 501 498 * Do a search of a journal by reading it in large chunks using bios and find 502 499 * the valid log entry with the highest sequence number. (i.e. the log head) 503 500 * 504 501 * Returns: 0 on success, errno otherwise 505 502 */ 506 - int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head, 507 - bool keep_cache) 503 + int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head) 508 504 { 509 505 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); 510 506 struct address_space *mapping = jd->jd_inode->i_mapping; ··· 591 591 if (!ret) 592 592 ret = filemap_check_wb_err(mapping, since); 593 593 594 - if (!keep_cache) 595 - truncate_inode_pages(mapping, 0); 594 + truncate_inode_pages(mapping, 0); 596 595 597 596 return ret; 598 597 }
+1 -1
fs/gfs2/lops.h
··· 20 20 void gfs2_log_submit_bio(struct bio **biop, blk_opf_t opf); 21 21 void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); 22 22 int gfs2_find_jhead(struct gfs2_jdesc *jd, 23 - struct gfs2_log_header_host *head, bool keep_cache); 23 + struct gfs2_log_header_host *head); 24 24 void gfs2_drain_revokes(struct gfs2_sbd *sdp); 25 25 26 26 static inline unsigned int buf_limit(struct gfs2_sbd *sdp)
+1 -1
fs/gfs2/meta_io.c
··· 132 132 unsigned int bufnum; 133 133 134 134 if (mapping == NULL) 135 - mapping = &sdp->sd_aspace; 135 + mapping = gfs2_aspace(sdp); 136 136 137 137 shift = PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift; 138 138 index = blkno >> shift; /* convert block to page */
+1 -3
fs/gfs2/meta_io.h
··· 44 44 struct gfs2_glock_aspace *gla = 45 45 container_of(mapping, struct gfs2_glock_aspace, mapping); 46 46 return gla->glock.gl_name.ln_sbd; 47 - } else if (mapping->a_ops == &gfs2_rgrp_aops) 48 - return container_of(mapping, struct gfs2_sbd, sd_aspace); 49 - else 47 + } else 50 48 return inode->i_sb->s_fs_info; 51 49 } 52 50
+25 -16
fs/gfs2/ops_fstype.c
··· 64 64 65 65 void free_sbd(struct gfs2_sbd *sdp) 66 66 { 67 - if (sdp->sd_lkstats) 68 - free_percpu(sdp->sd_lkstats); 67 + free_percpu(sdp->sd_lkstats); 69 68 kfree(sdp); 70 69 } 71 70 72 71 static struct gfs2_sbd *init_sbd(struct super_block *sb) 73 72 { 74 73 struct gfs2_sbd *sdp; 75 - struct address_space *mapping; 76 74 77 75 sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); 78 76 if (!sdp) ··· 106 108 spin_lock_init(&sdp->sd_bitmap_lock); 107 109 108 110 INIT_LIST_HEAD(&sdp->sd_sc_inodes_list); 109 - 110 - mapping = &sdp->sd_aspace; 111 - 112 - address_space_init_once(mapping); 113 - mapping->a_ops = &gfs2_rgrp_aops; 114 - mapping->host = sb->s_bdev->bd_mapping->host; 115 - mapping->flags = 0; 116 - mapping_set_gfp_mask(mapping, GFP_NOFS); 117 - mapping->i_private_data = NULL; 118 - mapping->writeback_index = 0; 119 111 120 112 spin_lock_init(&sdp->sd_log_lock); 121 113 atomic_set(&sdp->sd_log_pinned, 0); ··· 482 494 sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); 483 495 goto out; 484 496 } 485 - sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); 497 + ret = -EINVAL; 498 + if (!sb_set_blocksize(sb, sdp->sd_sb.sb_bsize)) 499 + goto out; 486 500 487 501 /* Get the root inode */ 488 502 no_addr = sdp->sd_sb.sb_root_dir.no_addr; ··· 1119 1129 int silent = fc->sb_flags & SB_SILENT; 1120 1130 struct gfs2_sbd *sdp; 1121 1131 struct gfs2_holder mount_gh; 1132 + struct address_space *mapping; 1122 1133 int error; 1123 1134 1124 1135 sdp = init_sbd(sb); ··· 1141 1150 sb->s_flags |= SB_NOSEC; 1142 1151 sb->s_magic = GFS2_MAGIC; 1143 1152 sb->s_op = &gfs2_super_ops; 1153 + 1144 1154 sb->s_d_op = &gfs2_dops; 1145 1155 sb->s_export_op = &gfs2_export_ops; 1146 1156 sb->s_qcop = &gfs2_quotactl_ops; ··· 1153 1161 /* Set up the buffer cache and fill in some fake block size values 1154 1162 to allow us to read-in the on-disk superblock. */ 1155 1163 sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, 512); 1164 + error = -EINVAL; 1165 + if (!sdp->sd_sb.sb_bsize) 1166 + goto fail_free; 1156 1167 sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; 1157 1168 sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - 9; 1158 1169 sdp->sd_fsb2bb = BIT(sdp->sd_fsb2bb_shift); ··· 1170 1175 sdp->sd_tune.gt_statfs_quantum = 30; 1171 1176 } 1172 1177 1178 + /* Set up an address space for metadata writes */ 1179 + sdp->sd_inode = new_inode(sb); 1180 + error = -ENOMEM; 1181 + if (!sdp->sd_inode) 1182 + goto fail_free; 1183 + sdp->sd_inode->i_ino = GFS2_BAD_INO; 1184 + sdp->sd_inode->i_size = OFFSET_MAX; 1185 + 1186 + mapping = gfs2_aspace(sdp); 1187 + mapping->a_ops = &gfs2_rgrp_aops; 1188 + mapping_set_gfp_mask(mapping, GFP_NOFS); 1189 + 1173 1190 error = init_names(sdp, silent); 1174 1191 if (error) 1175 - goto fail_free; 1192 + goto fail_iput; 1176 1193 1177 1194 snprintf(sdp->sd_fsname, sizeof(sdp->sd_fsname), "%s", sdp->sd_table_name); 1178 1195 ··· 1193 1186 WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_FREEZABLE, 0, 1194 1187 sdp->sd_fsname); 1195 1188 if (!sdp->sd_glock_wq) 1196 - goto fail_free; 1189 + goto fail_iput; 1197 1190 1198 1191 sdp->sd_delete_wq = alloc_workqueue("gfs2-delete/%s", 1199 1192 WQ_MEM_RECLAIM | WQ_FREEZABLE, 0, sdp->sd_fsname); ··· 1310 1303 fail_glock_wq: 1311 1304 if (sdp->sd_glock_wq) 1312 1305 destroy_workqueue(sdp->sd_glock_wq); 1306 + fail_iput: 1307 + iput(sdp->sd_inode); 1313 1308 fail_free: 1314 1309 free_sbd(sdp); 1315 1310 sb->s_fs_info = NULL;
+19 -9
fs/gfs2/recovery.c
··· 118 118 int __get_log_header(struct gfs2_sbd *sdp, const struct gfs2_log_header *lh, 119 119 unsigned int blkno, struct gfs2_log_header_host *head) 120 120 { 121 + const u32 zero = 0; 121 122 u32 hash, crc; 122 123 123 124 if (lh->lh_header.mh_magic != cpu_to_be32(GFS2_MAGIC) || ··· 127 126 return 1; 128 127 129 128 hash = crc32(~0, lh, LH_V1_SIZE - 4); 130 - hash = ~crc32_le_shift(hash, 4); /* assume lh_hash is zero */ 129 + hash = ~crc32(hash, &zero, 4); /* assume lh_hash is zero */ 131 130 132 131 if (be32_to_cpu(lh->lh_hash) != hash) 133 132 return 1; ··· 264 263 struct gfs2_log_header_host *head) 265 264 { 266 265 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); 267 - u32 lblock = head->lh_blkno; 268 266 269 - gfs2_replay_incr_blk(jd, &lblock); 270 - gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, lblock, 267 + gfs2_replay_incr_blk(jd, &head->lh_blkno); 268 + head->lh_sequence++; 269 + gfs2_write_log_header(sdp, jd, head->lh_sequence, 0, head->lh_blkno, 271 270 GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY, 272 271 REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC); 273 - if (jd->jd_jid == sdp->sd_lockstruct.ls_jid) { 274 - sdp->sd_log_flush_head = lblock; 275 - gfs2_log_incr_head(sdp); 276 - } 277 272 } 278 273 279 274 ··· 454 457 if (error) 455 458 goto fail_gunlock_ji; 456 459 457 - error = gfs2_find_jhead(jd, &head, true); 460 + error = gfs2_find_jhead(jd, &head); 458 461 if (error) 459 462 goto fail_gunlock_ji; 460 463 t_jhd = ktime_get(); ··· 530 533 ktime_ms_delta(t_rep, t_tlck)); 531 534 } 532 535 536 + if (jd->jd_jid == sdp->sd_lockstruct.ls_jid) 537 + gfs2_log_pointers_init(sdp, &head); 538 + 533 539 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS); 534 540 535 541 if (jlocked) { ··· 580 580 return wait ? jd->jd_recover_error : 0; 581 581 } 582 582 583 + void gfs2_log_pointers_init(struct gfs2_sbd *sdp, 584 + struct gfs2_log_header_host *head) 585 + { 586 + sdp->sd_log_sequence = head->lh_sequence + 1; 587 + gfs2_replay_incr_blk(sdp->sd_jdesc, &head->lh_blkno); 588 + sdp->sd_log_tail = head->lh_blkno; 589 + sdp->sd_log_flush_head = head->lh_blkno; 590 + sdp->sd_log_flush_tail = head->lh_blkno; 591 + sdp->sd_log_head = head->lh_blkno; 592 + }
+2
fs/gfs2/recovery.h
··· 29 29 int __get_log_header(struct gfs2_sbd *sdp, 30 30 const struct gfs2_log_header *lh, unsigned int blkno, 31 31 struct gfs2_log_header_host *head); 32 + void gfs2_log_pointers_init(struct gfs2_sbd *sdp, 33 + struct gfs2_log_header_host *head); 32 34 33 35 #endif /* __RECOVERY_DOT_H__ */ 34 36
+6 -88
fs/gfs2/super.c
··· 134 134 { 135 135 struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode); 136 136 struct gfs2_glock *j_gl = ip->i_gl; 137 - struct gfs2_log_header_host head; 138 137 int error; 139 138 140 139 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 141 140 if (gfs2_withdrawing_or_withdrawn(sdp)) 142 141 return -EIO; 143 142 144 - error = gfs2_find_jhead(sdp->sd_jdesc, &head, false); 145 - if (error) { 146 - gfs2_consist(sdp); 147 - return error; 148 - } 149 - 150 - if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { 151 - gfs2_consist(sdp); 143 + if (sdp->sd_log_sequence == 0) { 144 + fs_err(sdp, "unknown status of our own journal jid %d", 145 + sdp->sd_lockstruct.ls_jid); 152 146 return -EIO; 153 147 } 154 - 155 - /* Initialize some head of the log stuff */ 156 - sdp->sd_log_sequence = head.lh_sequence + 1; 157 - gfs2_log_pointers_init(sdp, head.lh_blkno); 158 148 159 149 error = gfs2_quota_init(sdp); 160 150 if (!error && gfs2_withdrawing_or_withdrawn(sdp)) ··· 360 370 error = gfs2_jdesc_check(jd); 361 371 if (error) 362 372 break; 363 - error = gfs2_find_jhead(jd, &lh, false); 373 + error = gfs2_find_jhead(jd, &lh); 364 374 if (error) 365 375 break; 366 376 if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { ··· 638 648 gfs2_jindex_free(sdp); 639 649 /* Take apart glock structures and buffer lists */ 640 650 gfs2_gl_hash_clear(sdp); 641 - truncate_inode_pages_final(&sdp->sd_aspace); 651 + iput(sdp->sd_inode); 642 652 gfs2_delete_debugfs_file(sdp); 643 653 644 654 gfs2_sys_fs_del(sdp); ··· 1169 1179 return 0; 1170 1180 } 1171 1181 1172 - static void gfs2_final_release_pages(struct gfs2_inode *ip) 1173 - { 1174 - struct inode *inode = &ip->i_inode; 1175 - struct gfs2_glock *gl = ip->i_gl; 1176 - 1177 - if (unlikely(!gl)) { 1178 - /* This can only happen during incomplete inode creation. */ 1179 - BUG_ON(!test_bit(GIF_ALLOC_FAILED, &ip->i_flags)); 1180 - return; 1181 - } 1182 - 1183 - truncate_inode_pages(gfs2_glock2aspace(gl), 0); 1184 - truncate_inode_pages(&inode->i_data, 0); 1185 - 1186 - if (atomic_read(&gl->gl_revokes) == 0) { 1187 - clear_bit(GLF_LFLUSH, &gl->gl_flags); 1188 - clear_bit(GLF_DIRTY, &gl->gl_flags); 1189 - } 1190 - } 1191 - 1192 - static int gfs2_dinode_dealloc(struct gfs2_inode *ip) 1193 - { 1194 - struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1195 - struct gfs2_rgrpd *rgd; 1196 - struct gfs2_holder gh; 1197 - int error; 1198 - 1199 - if (gfs2_get_inode_blocks(&ip->i_inode) != 1) { 1200 - gfs2_consist_inode(ip); 1201 - return -EIO; 1202 - } 1203 - 1204 - gfs2_rindex_update(sdp); 1205 - 1206 - error = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE); 1207 - if (error) 1208 - return error; 1209 - 1210 - rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1); 1211 - if (!rgd) { 1212 - gfs2_consist_inode(ip); 1213 - error = -EIO; 1214 - goto out_qs; 1215 - } 1216 - 1217 - error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 1218 - LM_FLAG_NODE_SCOPE, &gh); 1219 - if (error) 1220 - goto out_qs; 1221 - 1222 - error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1223 - sdp->sd_jdesc->jd_blocks); 1224 - if (error) 1225 - goto out_rg_gunlock; 1226 - 1227 - gfs2_free_di(rgd, ip); 1228 - 1229 - gfs2_final_release_pages(ip); 1230 - 1231 - gfs2_trans_end(sdp); 1232 - 1233 - out_rg_gunlock: 1234 - gfs2_glock_dq_uninit(&gh); 1235 - out_qs: 1236 - gfs2_quota_unhold(ip); 1237 - return error; 1238 - } 1239 - 1240 1182 /** 1241 1183 * gfs2_glock_put_eventually 1242 1184 * @gl: The glock to put ··· 1254 1332 struct gfs2_sbd *sdp = sb->s_fs_info; 1255 1333 int ret; 1256 1334 1257 - if (unlikely(test_bit(GIF_ALLOC_FAILED, &ip->i_flags))) 1258 - goto should_delete; 1259 - 1260 1335 if (gfs2_holder_initialized(&ip->i_iopen_gh) && 1261 1336 test_bit(GLF_DEFER_DELETE, &ip->i_iopen_gh.gh_gl->gl_flags)) 1262 1337 return EVICT_SHOULD_DEFER_DELETE; ··· 1283 1364 if (inode->i_nlink) 1284 1365 return EVICT_SHOULD_SKIP_DELETE; 1285 1366 1286 - should_delete: 1287 1367 if (gfs2_holder_initialized(&ip->i_iopen_gh) && 1288 1368 test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) 1289 1369 return gfs2_upgrade_iopen_glock(inode); ··· 1306 1388 } 1307 1389 1308 1390 if (ip->i_eattr) { 1309 - ret = gfs2_ea_dealloc(ip); 1391 + ret = gfs2_ea_dealloc(ip, true); 1310 1392 if (ret) 1311 1393 goto out; 1312 1394 }
+21
fs/gfs2/trans.c
··· 226 226 unlock_buffer(bh); 227 227 } 228 228 229 + void gfs2_trans_add_databufs(struct gfs2_glock *gl, struct folio *folio, 230 + size_t from, size_t len) 231 + { 232 + struct buffer_head *head = folio_buffers(folio); 233 + unsigned int bsize = head->b_size; 234 + struct buffer_head *bh; 235 + size_t to = from + len; 236 + size_t start, end; 237 + 238 + for (bh = head, start = 0; bh != head || !start; 239 + bh = bh->b_this_page, start = end) { 240 + end = start + bsize; 241 + if (end <= from) 242 + continue; 243 + if (start >= to) 244 + break; 245 + set_buffer_uptodate(bh); 246 + gfs2_trans_add_data(gl, bh); 247 + } 248 + } 249 + 229 250 void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh) 230 251 { 231 252
+2
fs/gfs2/trans.h
··· 42 42 43 43 void gfs2_trans_end(struct gfs2_sbd *sdp); 44 44 void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh); 45 + void gfs2_trans_add_databufs(struct gfs2_glock *gl, struct folio *folio, 46 + size_t from, size_t len); 45 47 void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh); 46 48 void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd); 47 49 void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len);
+1 -1
fs/gfs2/util.c
··· 73 73 "mount.\n"); 74 74 goto out_unlock; 75 75 } 76 - error = gfs2_find_jhead(jd, &head, false); 76 + error = gfs2_find_jhead(jd, &head); 77 77 if (error) { 78 78 if (verbose) 79 79 fs_err(sdp, "Error parsing journal for spectator "
+6 -5
fs/gfs2/xattr.c
··· 1383 1383 return error; 1384 1384 } 1385 1385 1386 - static int ea_dealloc_block(struct gfs2_inode *ip) 1386 + static int ea_dealloc_block(struct gfs2_inode *ip, bool initialized) 1387 1387 { 1388 1388 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1389 1389 struct gfs2_rgrpd *rgd; ··· 1416 1416 ip->i_eattr = 0; 1417 1417 gfs2_add_inode_blocks(&ip->i_inode, -1); 1418 1418 1419 - if (likely(!test_bit(GIF_ALLOC_FAILED, &ip->i_flags))) { 1419 + if (initialized) { 1420 1420 error = gfs2_meta_inode_buffer(ip, &dibh); 1421 1421 if (!error) { 1422 1422 gfs2_trans_add_meta(ip->i_gl, dibh); ··· 1435 1435 /** 1436 1436 * gfs2_ea_dealloc - deallocate the extended attribute fork 1437 1437 * @ip: the inode 1438 + * @initialized: xattrs have been initialized 1438 1439 * 1439 1440 * Returns: errno 1440 1441 */ 1441 1442 1442 - int gfs2_ea_dealloc(struct gfs2_inode *ip) 1443 + int gfs2_ea_dealloc(struct gfs2_inode *ip, bool initialized) 1443 1444 { 1444 1445 int error; 1445 1446 ··· 1452 1451 if (error) 1453 1452 return error; 1454 1453 1455 - if (likely(!test_bit(GIF_ALLOC_FAILED, &ip->i_flags))) { 1454 + if (initialized) { 1456 1455 error = ea_foreach(ip, ea_dealloc_unstuffed, NULL); 1457 1456 if (error) 1458 1457 goto out_quota; ··· 1464 1463 } 1465 1464 } 1466 1465 1467 - error = ea_dealloc_block(ip); 1466 + error = ea_dealloc_block(ip, initialized); 1468 1467 1469 1468 out_quota: 1470 1469 gfs2_quota_unhold(ip);
+1 -1
fs/gfs2/xattr.h
··· 54 54 const void *value, size_t size, 55 55 int flags, int type); 56 56 ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size); 57 - int gfs2_ea_dealloc(struct gfs2_inode *ip); 57 + int gfs2_ea_dealloc(struct gfs2_inode *ip, bool initialized); 58 58 59 59 /* Exported to acl.c */ 60 60