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

Merge tag 'gfs2-v5.16-rc4-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2

Pull gfs2 fixes from Andreas Gruenbacher:

- Since commit 486408d690e1 ("gfs2: Cancel remote delete work
asynchronously"), inode create and lookup-by-number can overlap more
easily and we can end up with temporary duplicate inodes. Fix the
code to prevent that.

- Fix a BUG demoting weak glock holders from a remote node.

* tag 'gfs2-v5.16-rc4-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2:
gfs2: gfs2_create_inode rework
gfs2: gfs2_inode_lookup rework
gfs2: gfs2_inode_lookup cleanup
gfs2: Fix remote demote of weak glock holders

+52 -67
+7 -3
fs/gfs2/glock.c
··· 1857 1857 1858 1858 void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state) 1859 1859 { 1860 - struct gfs2_holder mock_gh = { .gh_gl = gl, .gh_state = state, }; 1861 1860 unsigned long delay = 0; 1862 1861 unsigned long holdtime; 1863 1862 unsigned long now = jiffies; ··· 1889 1890 * keep the glock until the last strong holder is done with it. 1890 1891 */ 1891 1892 if (!find_first_strong_holder(gl)) { 1892 - if (state == LM_ST_UNLOCKED) 1893 - mock_gh.gh_state = LM_ST_EXCLUSIVE; 1893 + struct gfs2_holder mock_gh = { 1894 + .gh_gl = gl, 1895 + .gh_state = (state == LM_ST_UNLOCKED) ? 1896 + LM_ST_EXCLUSIVE : state, 1897 + .gh_iflags = BIT(HIF_HOLDER) 1898 + }; 1899 + 1894 1900 demote_incompat_holders(gl, &mock_gh); 1895 1901 } 1896 1902 handle_callback(gl, state, delay, true);
+45 -64
fs/gfs2/inode.c
··· 40 40 static const struct inode_operations gfs2_dir_iops; 41 41 static const struct inode_operations gfs2_symlink_iops; 42 42 43 - static int iget_test(struct inode *inode, void *opaque) 44 - { 45 - u64 no_addr = *(u64 *)opaque; 46 - 47 - return GFS2_I(inode)->i_no_addr == no_addr; 48 - } 49 - 50 - static int iget_set(struct inode *inode, void *opaque) 51 - { 52 - u64 no_addr = *(u64 *)opaque; 53 - 54 - GFS2_I(inode)->i_no_addr = no_addr; 55 - inode->i_ino = no_addr; 56 - return 0; 57 - } 58 - 59 - static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr) 60 - { 61 - struct inode *inode; 62 - 63 - repeat: 64 - inode = iget5_locked(sb, no_addr, iget_test, iget_set, &no_addr); 65 - if (!inode) 66 - return inode; 67 - if (is_bad_inode(inode)) { 68 - iput(inode); 69 - goto repeat; 70 - } 71 - return inode; 72 - } 73 - 74 43 /** 75 44 * gfs2_set_iop - Sets inode operations 76 45 * @inode: The inode with correct i_mode filled in ··· 73 104 } 74 105 } 75 106 107 + static int iget_test(struct inode *inode, void *opaque) 108 + { 109 + u64 no_addr = *(u64 *)opaque; 110 + 111 + return GFS2_I(inode)->i_no_addr == no_addr; 112 + } 113 + 114 + static int iget_set(struct inode *inode, void *opaque) 115 + { 116 + u64 no_addr = *(u64 *)opaque; 117 + 118 + GFS2_I(inode)->i_no_addr = no_addr; 119 + inode->i_ino = no_addr; 120 + return 0; 121 + } 122 + 76 123 /** 77 124 * gfs2_inode_lookup - Lookup an inode 78 125 * @sb: The super block ··· 117 132 { 118 133 struct inode *inode; 119 134 struct gfs2_inode *ip; 120 - struct gfs2_glock *io_gl = NULL; 121 135 struct gfs2_holder i_gh; 122 136 int error; 123 137 124 138 gfs2_holder_mark_uninitialized(&i_gh); 125 - inode = gfs2_iget(sb, no_addr); 139 + inode = iget5_locked(sb, no_addr, iget_test, iget_set, &no_addr); 126 140 if (!inode) 127 141 return ERR_PTR(-ENOMEM); 128 142 ··· 129 145 130 146 if (inode->i_state & I_NEW) { 131 147 struct gfs2_sbd *sdp = GFS2_SB(inode); 148 + struct gfs2_glock *io_gl; 132 149 133 150 error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); 134 151 if (unlikely(error)) 135 152 goto fail; 136 - flush_delayed_work(&ip->i_gl->gl_work); 137 - 138 - error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); 139 - if (unlikely(error)) 140 - goto fail; 141 - if (blktype != GFS2_BLKST_UNLINKED) 142 - gfs2_cancel_delete_work(io_gl); 143 153 144 154 if (type == DT_UNKNOWN || blktype != GFS2_BLKST_FREE) { 145 155 /* 146 156 * The GL_SKIP flag indicates to skip reading the inode 147 - * block. We read the inode with gfs2_inode_refresh 157 + * block. We read the inode when instantiating it 148 158 * after possibly checking the block type. 149 159 */ 150 160 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, ··· 159 181 } 160 182 } 161 183 162 - glock_set_object(ip->i_gl, ip); 163 184 set_bit(GLF_INSTANTIATE_NEEDED, &ip->i_gl->gl_flags); 164 - error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh); 185 + 186 + error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); 165 187 if (unlikely(error)) 166 188 goto fail; 167 - glock_set_object(ip->i_iopen_gh.gh_gl, ip); 189 + if (blktype != GFS2_BLKST_UNLINKED) 190 + gfs2_cancel_delete_work(io_gl); 191 + error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh); 168 192 gfs2_glock_put(io_gl); 169 - io_gl = NULL; 193 + if (unlikely(error)) 194 + goto fail; 170 195 171 196 /* Lowest possible timestamp; will be overwritten in gfs2_dinode_in. */ 172 197 inode->i_atime.tv_sec = 1LL << (8 * sizeof(inode->i_atime.tv_sec) - 1); 173 198 inode->i_atime.tv_nsec = 0; 174 199 200 + glock_set_object(ip->i_gl, ip); 201 + 175 202 if (type == DT_UNKNOWN) { 176 203 /* Inode glock must be locked already */ 177 204 error = gfs2_instantiate(&i_gh); 178 - if (error) 205 + if (error) { 206 + glock_clear_object(ip->i_gl, ip); 179 207 goto fail; 208 + } 180 209 } else { 181 210 ip->i_no_formal_ino = no_formal_ino; 182 211 inode->i_mode = DT2IF(type); ··· 191 206 192 207 if (gfs2_holder_initialized(&i_gh)) 193 208 gfs2_glock_dq_uninit(&i_gh); 209 + glock_set_object(ip->i_iopen_gh.gh_gl, ip); 194 210 195 211 gfs2_set_iop(inode); 212 + unlock_new_inode(inode); 196 213 } 197 214 198 215 if (no_formal_ino && ip->i_no_formal_ino && 199 216 no_formal_ino != ip->i_no_formal_ino) { 200 - error = -ESTALE; 201 - if (inode->i_state & I_NEW) 202 - goto fail; 203 217 iput(inode); 204 - return ERR_PTR(error); 218 + return ERR_PTR(-ESTALE); 205 219 } 206 - 207 - if (inode->i_state & I_NEW) 208 - unlock_new_inode(inode); 209 220 210 221 return inode; 211 222 212 223 fail: 213 - if (gfs2_holder_initialized(&ip->i_iopen_gh)) { 214 - glock_clear_object(ip->i_iopen_gh.gh_gl, ip); 224 + if (gfs2_holder_initialized(&ip->i_iopen_gh)) 215 225 gfs2_glock_dq_uninit(&ip->i_iopen_gh); 216 - } 217 - if (io_gl) 218 - gfs2_glock_put(io_gl); 219 226 if (gfs2_holder_initialized(&i_gh)) 220 227 gfs2_glock_dq_uninit(&i_gh); 221 228 iget_failed(inode); ··· 707 730 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); 708 731 if (error) 709 732 goto fail_free_inode; 710 - flush_delayed_work(&ip->i_gl->gl_work); 711 733 712 734 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl); 713 735 if (error) 714 736 goto fail_free_inode; 715 737 gfs2_cancel_delete_work(io_gl); 716 738 739 + error = insert_inode_locked4(inode, ip->i_no_addr, iget_test, &ip->i_no_addr); 740 + BUG_ON(error); 741 + 717 742 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1); 718 743 if (error) 719 744 goto fail_gunlock2; 720 745 721 - glock_set_object(ip->i_gl, ip); 722 746 error = gfs2_trans_begin(sdp, blocks, 0); 723 747 if (error) 724 748 goto fail_gunlock2; ··· 735 757 if (error) 736 758 goto fail_gunlock2; 737 759 760 + glock_set_object(ip->i_gl, ip); 738 761 glock_set_object(io_gl, ip); 739 762 gfs2_set_iop(inode); 740 - insert_inode_hash(inode); 741 763 742 764 free_vfs_inode = 0; /* After this point, the inode is no longer 743 765 considered free. Any failures need to undo ··· 779 801 gfs2_glock_dq_uninit(ghs + 1); 780 802 gfs2_glock_put(io_gl); 781 803 gfs2_qa_put(dip); 804 + unlock_new_inode(inode); 782 805 return error; 783 806 784 807 fail_gunlock3: 808 + glock_clear_object(ip->i_gl, ip); 785 809 glock_clear_object(io_gl, ip); 786 810 gfs2_glock_dq_uninit(&ip->i_iopen_gh); 787 811 fail_gunlock2: 788 - glock_clear_object(io_gl, ip); 789 812 gfs2_glock_put(io_gl); 790 813 fail_free_inode: 791 814 if (ip->i_gl) { 792 - glock_clear_object(ip->i_gl, ip); 793 815 if (free_vfs_inode) /* else evict will do the put for us */ 794 816 gfs2_glock_put(ip->i_gl); 795 817 } ··· 807 829 mark_inode_dirty(inode); 808 830 set_bit(free_vfs_inode ? GIF_FREE_VFS_INODE : GIF_ALLOC_FAILED, 809 831 &GFS2_I(inode)->i_flags); 810 - iput(inode); 832 + if (inode->i_state & I_NEW) 833 + iget_failed(inode); 834 + else 835 + iput(inode); 811 836 } 812 837 if (gfs2_holder_initialized(ghs + 1)) 813 838 gfs2_glock_dq_uninit(ghs + 1);