From: Bian Naimeng <biannm@cn.fujitsu.com>
To: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 1/2] Make lock inode before lock nfs4_state_owner
Date: Wed, 04 Aug 2010 17:15:27 +0800 [thread overview]
Message-ID: <4C592FAF.5090700@cn.fujitsu.com> (raw)
In-Reply-To: <4C592F85.8070308@cn.fujitsu.com>
We should lock inode before lock nfs4_state_owner, sometimes, we want scan
nfsi->open_states, and modify once state, so we need lock state->owner.
Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com>
---
fs/nfs/nfs4state.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 34acf59..fe34c41 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -498,8 +498,8 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
if (state)
goto out;
new = nfs4_alloc_open_state();
- spin_lock(&owner->so_lock);
spin_lock(&inode->i_lock);
+ spin_lock(&owner->so_lock);
state = __nfs4_find_state_byowner(inode, owner);
if (state == NULL && new != NULL) {
state = new;
@@ -507,14 +507,14 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
atomic_inc(&owner->so_count);
list_add(&state->inode_states, &nfsi->open_states);
state->inode = igrab(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 */
list_add_tail(&state->open_states, &owner->so_states);
spin_unlock(&owner->so_lock);
- } else {
spin_unlock(&inode->i_lock);
+ } else {
spin_unlock(&owner->so_lock);
+ spin_unlock(&inode->i_lock);
if (new)
nfs4_free_open_state(new);
}
@@ -527,13 +527,15 @@ void nfs4_put_open_state(struct nfs4_state *state)
struct inode *inode = state->inode;
struct nfs4_state_owner *owner = state->owner;
- if (!atomic_dec_and_lock(&state->count, &owner->so_lock))
- return;
spin_lock(&inode->i_lock);
- list_del(&state->inode_states);
+ if (!atomic_dec_and_lock(&state->count, &owner->so_lock)) {
+ spin_unlock(&inode->i_lock);
+ return;
+ }
list_del(&state->open_states);
- spin_unlock(&inode->i_lock);
spin_unlock(&owner->so_lock);
+ list_del(&state->inode_states);
+ spin_unlock(&inode->i_lock);
iput(inode);
nfs4_free_open_state(state);
nfs4_put_state_owner(owner);
--
1.6.5.2
--
Regards
Bian Naimeng
next prev parent reply other threads:[~2010-08-04 9:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-04 9:14 [PATCH 0/2] Fix bug that client use a invaild delegation Bian Naimeng
2010-08-04 9:15 ` Bian Naimeng [this message]
2010-08-04 9:18 ` [PATCH 2/2] We should clear NFS_DELEGATED_STATE after return delegation Bian Naimeng
2010-08-04 12:45 ` Trond Myklebust
2010-08-05 2:26 ` Bian Naimeng
2010-08-05 13:03 ` Trond Myklebust
2010-08-06 4:10 ` Bian Naimeng
2010-08-06 13:30 ` Trond Myklebust
2010-08-16 7:50 ` Bian Naimeng
2010-08-17 23:16 ` Trond Myklebust
2010-08-18 3:17 ` Bian Naimeng
2010-08-23 7:43 ` Bian Naimeng
2010-09-01 6:40 ` Bian Naimeng
2010-09-07 22:04 ` Trond Myklebust
2010-09-08 1:33 ` Bian Naimeng
2010-09-08 1:57 ` Trond Myklebust
2010-09-08 2:37 ` Bian Naimeng
2010-09-08 3:11 ` Bian Naimeng
2010-09-08 20:37 ` Trond Myklebust
2010-09-09 1:29 ` Bian Naimeng
2010-11-24 6:27 ` Bian Naimeng
[not found] ` <1283978245.2905.23.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2010-12-02 8:32 ` Li Yewang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C592FAF.5090700@cn.fujitsu.com \
--to=biannm@cn.fujitsu.com \
--cc=Trond.Myklebust@netapp.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).