Fix for unlink deadlock
Note the current glock code in the tree is completely busted and will dead lock almost immediately.
I have reverted several changes to glock.c and have tested this patch with the older glock code. dbench will now run through to completion.
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=217356
Signature · 22 lines
Russell Cattelan <[email protected]> -------------- next part -------------- commit 83f2406e817e4964e4d0a25454da54e73005bf43 Author: Russell Cattelan <[email protected]> Date: Mon Jan 29 17:06:06 2007 -0600 [GFS2] Fix unlink deadlocks Move the glock acquisition to outside of the transactions. Lock odering must be preserved in order to prevent ABBA deadlocks. The current gfs2_change_nlink code would tries to grab the glock after having started a transaction and thus is holding the log lock. This is inconsistent with other code paths in gfs that grab the resource group glock prior to staring a tranactions. One problem with this fix is that the resource group lock is always grabbed now even if the inode still has ref count and can not be marked for unlink. Signed-off-by: Russell Cattelan <[email protected]>
fs/gfs2/inode.c +1 -45
@@ -280,50 +280,6 @@ out:return error; } -static int gfs2_change_nlink_i (struct gfs2_inode *ip) -{ -struct gfs2_sbd *sdp = ip->i_inode.i_sb->s_fs_info; -struct gfs2_inode *rindex =GFS2_I (sdp->sd_rindex); -struct gfs2_glock *ri_gl = rindex->i_gl; -struct gfs2_rgrpd *rgd; -struct gfs2_holder ri_gh, rg_gh; -int existing, error; - -/* if we come from rename path, we could have the lock already */ - existing =gfs2_glock_is_locked_by_me (ri_gl); -if (!existing) { - error =gfs2_rindex_hold (sdp, &ri_gh); -if (error) - goto out; - } - -/* find the matching rgd */ - error = -EIO ; - rgd =gfs2_blk2rgrpd (sdp, ip->i_num.no_addr); -if (!rgd) - goto out_norgrp; - -/* -* Eventually we may want to move rgd(s) to a linked list -* and piggyback the free logic into one of gfs2 daemons -* to gain some performance. -*/ -if (!rgd->rd_gl || !gfs2_glock_is_locked_by_me (rgd->rd_gl)) { - error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE ,0 , &rg_gh); -if (error) - goto out_norgrp; - -gfs2_unlink_di (&ip->i_inode);/* mark inode unlinked */ -gfs2_glock_dq_uninit (&rg_gh); - } - -out_norgrp: -if (!existing) -gfs2_glock_dq_uninit (&ri_gh); -out: -return error; -} -/** * gfs2_change_nlink - Change nlink count on inode * @ip: The GFS2 inode
@@ -365,7 +321,7 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff)mark_inode_dirty (&ip->i_inode);if (ip->i_inode.i_nlink ==0 ) - error =gfs2_change_nlink_i (ip); +gfs2_unlink_di (&ip->i_inode);/* mark inode unlinked */ return error; }
fs/gfs2/ops_inode.c +39 -8
98 lines not on this page · raw message
Hi,
Quoted 9 lines · Russell Cattelan
Note the current glock code in the tree is completely busted and will dead lock almost immediately.
I have reverted several changes to
glock.cand have tested this patch with the older glock code. dbench will now run through to completion.
Now applied to the -nmw git tree. I think the way to get around the problem with not knowing whether the link count will hit zero is just to remove the code which changes the link count from gfs2_change_nlink and to turn that into a function which just syncs the current link count to the on-disk inode.
It would also solve the problem of needing to work out whether to use inc_nlink() or dec_nlink() to make the change to the link count. Due to the forthcoming read-only bind mounts work, we must always use the macros to change the link count rather than doing it directly.
Steve.
Quoted 6 lines · Steven Whitehouse
Hi,
Quoted 3 lines · Russell Cattelan
Note the current glock code in the tree is completely busted and will dead lock almost immediately.
Quoted 8 lines
Quoted 6 lines
I have reverted several changes to
glock.cand have tested this patch with the older glock code. dbench will now run through to completion.Now applied to the -nmw git tree.
hmm.. just untar Steve's git tree he sent me this morning few minutes ago and spot this - sorry I should have read this post earlier ... Look to me this will deadlock gfs2_rename() *again* (since it tries to grab rindex lock multiple times). Will test this out tomorrow when I get the connectathon cluster up.
-- Wendy
Quoted 14 lines
I think the way to get around the
problem with not knowing whether the link count will hit zero is just to remove the code which changes the link count fromgfs2_change_nlinkand to turn that into a function which just syncs the current link count to the on-disk inode.It would also solve the problem of needing to work out whether to use
inc_nlink()ordec_nlink()to make the change to the link count. Due to the forthcoming read-only bind mounts work, we must always use the macros to change the link count rather than doing it directly.Steve.
Quoted 14 lines · Wendy Cheng
Quoted 13 lines · Steven Whitehouse
Hi,
Quoted 9 lines · Russell Cattelan
Note the current glock code in the tree is completely busted and will dead lock almost immediately.
I have reverted several changes to
glock.cand have tested this patch with the older glock code. dbench will now run through to completion.
Quoted 9 lines
Quoted 1 line
Now applied to the -nmw git tree.
hmm.. just untar Steve's git tree he sent me this morning few minutes ago and spot this - sorry I should have read this post earlier ... Look to me this will deadlock
gfs2_rename()*again* (since it tries to grab rindex lock multiple times). Will test this out tomorrow when I get the connectathon cluster up.
BTW, Is it too late to NACK this patch ? :) ... Wendy
Quoted 14 lines · Wendy Cheng
Quoted 13 lines · Steven Whitehouse
Hi,
Quoted 9 lines · Russell Cattelan
Note the current glock code in the tree is completely busted and will dead lock almost immediately.
I have reverted several changes to
glock.cand have tested this patch with the older glock code. dbench will now run through to completion.
Quoted 8 lines
Quoted 1 line
Now applied to the -nmw git tree.
hmm.. just untar Steve's git tree he sent me this morning few minutes ago and spot this - sorry I should have read this post earlier ... Look to me this will deadlock
gfs2_rename()*again* (since it tries to grab rindex lock multiple times). Will test this out tomorrow when I get the connectathon cluster up.
I never understood what sequence of events that you found that would cause the recursive locking, but I tried to set it up such that rename will only grab the rsgr lock once and outside log locks.
I tested the touch foo foo1 ; mv foo foo1 scenario and it works.
Quoted 18 lines
-- Wendy
Quoted 14 lines
I think the way to get around the
problem with not knowing whether the link count will hit zero is just to remove the code which changes the link count fromgfs2_change_nlinkand to turn that into a function which just syncs the current link count to the on-disk inode.It would also solve the problem of needing to work out whether to use
inc_nlink()ordec_nlink()to make the change to the link count. Due to the forthcoming read-only bind mounts work, we must always use the macros to change the link count rather than doing it directly.Steve.
Signature · 1 line
Russell Cattelan <[email protected]>