History

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

Linus Torvalds committed 4 years ago

Commit 5c623c32 parents 12119cf 3d36e572 files · +52 −67Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t