Skip to content

Commit b66648a

Browse files
committed
gfs2: Move inode generation number check into gfs2_inode_lookup
Move the inode generation number check from gfs2_lookup_by_inum into gfs2_inode_lookup: gfs2_inode_lookup may be able to decide that an inode with the given inode generation number cannot exist without having to verify the block type or reading the inode from disk. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent 6bdcade commit b66648a

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

‎fs/gfs2/inode.c‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ static void gfs2_set_iop(struct inode *inode)
114114
* placeholder because it doesn't otherwise make sense), the on-disk block type
115115
* is verified to be @blktype.
116116
*
117+
* When @no_formal_ino is non-zero, this function will return ERR_PTR(-ESTALE)
118+
* if it detects that @no_formal_ino doesn't match the actual inode generation
119+
* number. However, it doesn't always know unless @type is DT_UNKNOWN.
120+
*
117121
* Returns: A VFS inode, or an error
118122
*/
119123

@@ -157,6 +161,11 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
157161
if (error)
158162
goto fail;
159163

164+
error = -ESTALE;
165+
if (no_formal_ino &&
166+
gfs2_inode_already_deleted(ip->i_gl, no_formal_ino))
167+
goto fail;
168+
160169
if (blktype != GFS2_BLKST_FREE) {
161170
error = gfs2_check_blk_type(sdp, no_addr,
162171
blktype);
@@ -189,13 +198,23 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
189198
inode->i_mode = DT2IF(type);
190199
}
191200

201+
if (gfs2_holder_initialized(&i_gh))
202+
gfs2_glock_dq_uninit(&i_gh);
203+
192204
gfs2_set_iop(inode);
205+
}
193206

194-
unlock_new_inode(inode);
207+
if (no_formal_ino && ip->i_no_formal_ino &&
208+
no_formal_ino != ip->i_no_formal_ino) {
209+
if (inode->i_state & I_NEW)
210+
goto fail;
211+
iput(inode);
212+
return ERR_PTR(-ESTALE);
195213
}
196214

197-
if (gfs2_holder_initialized(&i_gh))
198-
gfs2_glock_dq_uninit(&i_gh);
215+
if (inode->i_state & I_NEW)
216+
unlock_new_inode(inode);
217+
199218
return inode;
200219

201220
fail:
@@ -221,16 +240,12 @@ struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
221240
struct inode *inode;
222241
int error;
223242

224-
inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0, blktype);
243+
inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, no_formal_ino,
244+
blktype);
225245
if (IS_ERR(inode))
226246
return inode;
227247

228-
/* Two extra checks for NFS only */
229248
if (no_formal_ino) {
230-
error = -ESTALE;
231-
if (GFS2_I(inode)->i_no_formal_ino != no_formal_ino)
232-
goto fail_iput;
233-
234249
error = -EIO;
235250
if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM)
236251
goto fail_iput;

0 commit comments

Comments
 (0)