All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] NFS: Fix state owner lock usage
@ 2014-09-03 18:15 Anna Schumaker
  2014-09-03 18:15 ` [PATCH] NFS: Clear up " Anna Schumaker
  0 siblings, 1 reply; 2+ messages in thread
From: Anna Schumaker @ 2014-09-03 18:15 UTC (permalink / raw)
  To: Trond.Myklebust, linux-nfs

The function can_open_cached() is used to determine if we can open a file
using cached information.  It does this by reading values from the state
structure, which I think means we need to be holding the so_lock to get the
right answer.  The current code calls this function twice - once without the
lock, and then a second time with the lock to check the answer.  I think
this is technically correct, since false positives are verified and false
negatives lead to the normal open code.

Even if the code is correct, it's not immediately obvious to me why it works
so I think it's worth taking a second look at.

What do you all think?

Anna


Anna Schumaker (1):
  NFS: Clear up state owner lock usage

 fs/nfs/nfs4proc.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

-- 
2.1.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] NFS: Clear up state owner lock usage
  2014-09-03 18:15 [PATCH] NFS: Fix state owner lock usage Anna Schumaker
@ 2014-09-03 18:15 ` Anna Schumaker
  0 siblings, 0 replies; 2+ messages in thread
From: Anna Schumaker @ 2014-09-03 18:15 UTC (permalink / raw)
  To: Trond.Myklebust, linux-nfs

can_open_cached() reads values out of the state structure, meaning that
we need the so_lock to have a correct return value.  As a bonus, this
helps clear up some potentially confusing code.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 fs/nfs/nfs4proc.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 7dd8aca..18eb31c 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1307,15 +1307,13 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
 	int ret = -EAGAIN;
 
 	for (;;) {
+		spin_lock(&state->owner->so_lock);
 		if (can_open_cached(state, fmode, open_mode)) {
-			spin_lock(&state->owner->so_lock);
-			if (can_open_cached(state, fmode, open_mode)) {
-				update_open_stateflags(state, fmode);
-				spin_unlock(&state->owner->so_lock);
-				goto out_return_state;
-			}
+			update_open_stateflags(state, fmode);
 			spin_unlock(&state->owner->so_lock);
+			goto out_return_state;
 		}
+		spin_unlock(&state->owner->so_lock);
 		rcu_read_lock();
 		delegation = rcu_dereference(nfsi->delegation);
 		if (!can_open_delegated(delegation, fmode)) {
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-03 18:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-03 18:15 [PATCH] NFS: Fix state owner lock usage Anna Schumaker
2014-09-03 18:15 ` [PATCH] NFS: Clear up " Anna Schumaker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.