fs: don't use igrab() while holding i_lock
authorDave Chinner <dchinner@redhat.com>
Tue, 29 Mar 2011 07:08:50 +0000 (18:08 +1100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 29 Mar 2011 14:50:34 +0000 (07:50 -0700)
Fix the incorrect use of igrab() inside the i_lock in NFS and Ceph‥

If we are already holding the i_lock, we have a reference to the
inode so we can safely use ihold() to gain an extra reference. This
avoids hangs due to lock recursion on the i_lock now that the
inode_lock is gone and igrab() uses the i_lock itself.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Cc: Ryan Mallon <ryan@bluewatersys.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ceph/addr.c
fs/ceph/snap.c
fs/nfs/nfs4state.c

index 561438b6a50cd3789b90d54e473562431d528ec8..37368ba2e67c111352287c379c1f7b0235595c1c 100644 (file)
@@ -92,7 +92,7 @@ static int ceph_set_page_dirty(struct page *page)
                ci->i_head_snapc = ceph_get_snap_context(snapc);
        ++ci->i_wrbuffer_ref_head;
        if (ci->i_wrbuffer_ref == 0)
-               igrab(inode);
+               ihold(inode);
        ++ci->i_wrbuffer_ref;
        dout("%p set_page_dirty %p idx %lu head %d/%d -> %d/%d "
             "snapc %p seq %lld (%d snaps)\n",
index f40b9139e43732ea94dc2dad363a7b3d6e910960..0aee66b92af3158ff5ce9055c0a0490068d0a219 100644 (file)
@@ -463,8 +463,8 @@ void ceph_queue_cap_snap(struct ceph_inode_info *ci)
 
                dout("queue_cap_snap %p cap_snap %p queuing under %p\n", inode,
                     capsnap, snapc);
-               igrab(inode);
-               
+               ihold(inode);
+
                atomic_set(&capsnap->nref, 1);
                capsnap->ci = ci;
                INIT_LIST_HEAD(&capsnap->ci_item);
index ab1bf5bb021f55cfaf3c45dcbdb226acfc3da3e0..a6804f704d9d8656868b6492c66232020132fe6d 100644 (file)
@@ -590,7 +590,8 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
                state->owner = owner;
                atomic_inc(&owner->so_count);
                list_add(&state->inode_states, &nfsi->open_states);
-               state->inode = igrab(inode);
+               ihold(inode);
+               state->inode = inode;
                spin_unlock(&inode->i_lock);
                /* Note: The reclaim code dictates that we add stateless
                 * and read-only stateids to the end of the list */