Skip to content

Commit 40e7e86

Browse files
Andreas GruenbacherAstralBob
authored andcommitted
gfs2: Clean up inode initialization and teardown
When allocating a new inode, mark the iopen glock holder as uninitialized to make sure gfs2_evict_inode won't fail after an incomplete create or lookup. In gfs2_evict_inode, allow the inode glock to be NULL and remove the duplicate iopen glock teardown code. In gfs2_inode_lookup, don't tear down things that gfs2_evict_inode will already tear down. Signed-off-by: Andreas Gruenbacher <[email protected]> Signed-off-by: Bob Peterson <[email protected]>
1 parent 4900312 commit 40e7e86

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

fs/gfs2/inode.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
144144

145145
error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
146146
if (unlikely(error))
147-
goto fail_put;
147+
goto fail;
148148

149149
if (type == DT_UNKNOWN || blktype != GFS2_BLKST_FREE) {
150150
/*
@@ -155,21 +155,21 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
155155
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE,
156156
GL_SKIP, &i_gh);
157157
if (error)
158-
goto fail_put;
158+
goto fail;
159159

160160
if (blktype != GFS2_BLKST_FREE) {
161161
error = gfs2_check_blk_type(sdp, no_addr,
162162
blktype);
163163
if (error)
164-
goto fail_put;
164+
goto fail;
165165
}
166166
}
167167

168168
glock_set_object(ip->i_gl, ip);
169169
set_bit(GIF_INVALID, &ip->i_flags);
170170
error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
171171
if (unlikely(error))
172-
goto fail_put;
172+
goto fail;
173173
glock_set_object(ip->i_iopen_gh.gh_gl, ip);
174174
gfs2_glock_put(io_gl);
175175
io_gl = NULL;
@@ -182,7 +182,7 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
182182
/* Inode glock must be locked already */
183183
error = gfs2_inode_refresh(GFS2_I(inode));
184184
if (error)
185-
goto fail_refresh;
185+
goto fail;
186186
} else {
187187
ip->i_no_formal_ino = no_formal_ino;
188188
inode->i_mode = DT2IF(type);
@@ -197,17 +197,11 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
197197
gfs2_glock_dq_uninit(&i_gh);
198198
return inode;
199199

200-
fail_refresh:
201-
ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
202-
glock_clear_object(ip->i_iopen_gh.gh_gl, ip);
203-
gfs2_glock_dq_uninit(&ip->i_iopen_gh);
204-
fail_put:
200+
fail:
205201
if (io_gl)
206202
gfs2_glock_put(io_gl);
207-
glock_clear_object(ip->i_gl, ip);
208203
if (gfs2_holder_initialized(&i_gh))
209204
gfs2_glock_dq_uninit(&i_gh);
210-
fail:
211205
iget_failed(inode);
212206
return ERR_PTR(error);
213207
}

fs/gfs2/super.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,14 +1393,6 @@ static void gfs2_evict_inode(struct inode *inode)
13931393
if (gfs2_rs_active(&ip->i_res))
13941394
gfs2_rs_deltree(&ip->i_res);
13951395

1396-
if (gfs2_holder_initialized(&ip->i_iopen_gh)) {
1397-
glock_clear_object(ip->i_iopen_gh.gh_gl, ip);
1398-
if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
1399-
ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
1400-
gfs2_glock_dq(&ip->i_iopen_gh);
1401-
}
1402-
gfs2_holder_uninit(&ip->i_iopen_gh);
1403-
}
14041396
if (gfs2_holder_initialized(&gh)) {
14051397
glock_clear_object(ip->i_gl, ip);
14061398
gfs2_glock_dq_uninit(&gh);
@@ -1413,18 +1405,23 @@ static void gfs2_evict_inode(struct inode *inode)
14131405
gfs2_ordered_del_inode(ip);
14141406
clear_inode(inode);
14151407
gfs2_dir_hash_inval(ip);
1416-
glock_clear_object(ip->i_gl, ip);
1417-
wait_on_bit_io(&ip->i_flags, GIF_GLOP_PENDING, TASK_UNINTERRUPTIBLE);
1418-
gfs2_glock_add_to_lru(ip->i_gl);
1419-
gfs2_glock_put_eventually(ip->i_gl);
1420-
ip->i_gl = NULL;
1408+
if (ip->i_gl) {
1409+
glock_clear_object(ip->i_gl, ip);
1410+
wait_on_bit_io(&ip->i_flags, GIF_GLOP_PENDING, TASK_UNINTERRUPTIBLE);
1411+
gfs2_glock_add_to_lru(ip->i_gl);
1412+
gfs2_glock_put_eventually(ip->i_gl);
1413+
ip->i_gl = NULL;
1414+
}
14211415
if (gfs2_holder_initialized(&ip->i_iopen_gh)) {
14221416
struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
14231417

14241418
glock_clear_object(gl, ip);
1425-
ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
1419+
if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
1420+
ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
1421+
gfs2_glock_dq(&ip->i_iopen_gh);
1422+
}
14261423
gfs2_glock_hold(gl);
1427-
gfs2_glock_dq_uninit(&ip->i_iopen_gh);
1424+
gfs2_holder_uninit(&ip->i_iopen_gh);
14281425
gfs2_glock_put_eventually(gl);
14291426
}
14301427
}
@@ -1438,6 +1435,7 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb)
14381435
return NULL;
14391436
ip->i_flags = 0;
14401437
ip->i_gl = NULL;
1438+
gfs2_holder_mark_uninitialized(&ip->i_iopen_gh);
14411439
memset(&ip->i_res, 0, sizeof(ip->i_res));
14421440
RB_CLEAR_NODE(&ip->i_res.rs_node);
14431441
ip->i_rahead = 0;

0 commit comments

Comments
 (0)