GFS2 filesystem hang caused by incorrect lock order
A message that is not in the archive (sent off-list or not yet received): 334680118.494431.1300393075765.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com
PATCH 1/1 GFS2 filesystem hang caused by incorrect lock order
Hi,
This patch fixes a deadlock in GFS2 where two processes are trying to reclaim an unlinked dinode:
One holds the inode glock and calls gfs2_lookup_by_inum trying to look up the inode, which it can't, due to I_FREEING. The other has set I_FREEING from vfs and is at the beginning of gfs2_delete_inode waiting for the glock, which is held by the first. The solution is to add a new non_block parameter to the gfs2_iget function that causes it to return -ENOENT if the inode is being freed.
Regards,
Bob Peterson
Red Hat File Systems
--
fs/gfs2/dir.c | 2 +- fs/gfs2/export.c | 10 +++++--- fs/gfs2/inode.c | 56 ++++++++++++++++++++++++++++++++++++------------- fs/gfs2/inode.h | 3 +- fs/gfs2/ops_fstype.c | 2 +- fs/gfs2/rgrp.c | 4 +- fs/gfs2/super.c | 9 +++++++- 7 files changed, 61 insertions(+), 25 deletions(-)
fs/gfs2/dir.c +1 -1
@@ -1506,7 +1506,7 @@ struct inode *gfs2_dir_search(struct inode *dir, const struct qstr *name) inode =gfs2_inode_lookup (dir->i_sb,be16_to_cpu (dent->de_type),be64_to_cpu (dent->de_inum.no_addr), -be64_to_cpu (dent->de_inum.no_formal_ino)); +be64_to_cpu (dent->de_inum.no_formal_ino),0 );brelse (bh);return inode; }
fs/gfs2/export.c +6 -4
@@ -145,15 +145,17 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,iput (inode);return ERR_PTR (-ESTALE ); } - goto out_inode; + }else { + inode =gfs2_lookup_by_inum (sdp, inum->no_addr, + &inum->no_formal_ino, +GFS2_BLKST_DINODE ); +if (inode ==ERR_PTR (-ENOENT )) + inode =gfs2_ilookup (sb, inum->no_addr); } - inode =gfs2_lookup_by_inum (sdp, inum->no_addr, &inum->no_formal_ino, -GFS2_BLKST_DINODE );if (IS_ERR (inode))return ERR_CAST (inode); -out_inode:return d_obtain_alias (inode); }
fs/gfs2/inode.c +41 -15
122 lines not on this page · raw message
fs/gfs2/inode.h +2 -1
@@ -97,7 +97,8 @@ err: }extern struct inode *gfs2_inode_lookup (struct super_block *sb,unsigned type, -u64 no_addr,u64 no_formal_ino); +u64 no_addr,u64 no_formal_ino, +int non_block);extern struct inode *gfs2_lookup_by_inum (struct gfs2_sbd *sdp,u64 no_addr,u64 *no_formal_ino,unsigned int blktype);
fs/gfs2/ops_fstype.c +1 -1
@@ -430,7 +430,7 @@ static int gfs2_lookup_root(struct super_block *sb, struct dentry **dptr,struct dentry *dentry;struct inode *inode; - inode =gfs2_inode_lookup (sb,DT_DIR , no_addr,0 ); + inode =gfs2_inode_lookup (sb,DT_DIR , no_addr,0 ,0 );if (IS_ERR (inode)) {fs_err (sdp,"can't read in %s inode: %ld\n" , name,PTR_ERR (inode));return PTR_ERR (inode);
fs/gfs2/rgrp.c +2 -2
@@ -945,7 +945,7 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip/* rgblk_search can return a block < goal, so we need to keep it marching forward. */ no_addr = block + rgd->rd_data0; - goal++; + goal =max (block +1 , goal +1 );if (*last_unlinked !=NO_BLOCK && no_addr <= *last_unlinked)continue ;if (no_addr == skip)
@@ -971,7 +971,7 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip found++;/* Limit reclaim to sensible number of tasks */ -if (found >2 *NR_CPUS ) +if (found >NR_CPUS )return ; }
fs/gfs2/super.c +8 -1
@@ -1326,7 +1326,8 @@ static void gfs2_evict_inode(struct inode *inode)if (inode->i_nlink) goto out; - error =gfs2_glock_nq_init (ip->i_gl,LM_ST_EXCLUSIVE ,0 , &gh); +/* Must not read inode block until block type has been verified */ + error =gfs2_glock_nq_init (ip->i_gl,LM_ST_EXCLUSIVE ,GL_SKIP , &gh);if (unlikely (error)) {gfs2_glock_dq_uninit (&ip->i_iopen_gh); goto out;
@@ -1336,6 +1337,12 @@ static void gfs2_evict_inode(struct inode *inode)if (error) goto out_truncate; +if (test_bit (GIF_INVALID , &ip->i_flags)) { + error =gfs2_inode_refresh (ip); +if (error) + goto out_truncate; + } + ip->i_iopen_gh.gh_flags |=GL_NOCACHE ;gfs2_glock_dq_wait (&ip->i_iopen_gh);gfs2_holder_reinit (LM_ST_EXCLUSIVE ,LM_FLAG_TRY_1CB |GL_NOCACHE , &ip->i_iopen_gh);