public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: David Howells <dhowells@redhat.com>
Cc: Trond.Myklebust@netapp.com, linux-nfs@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] NFSv4: Fix the locking in nfs_inode_reclaim_delegation()
Date: Tue, 20 Apr 2010 15:21:40 -0700	[thread overview]
Message-ID: <20100420222140.GN2628@linux.vnet.ibm.com> (raw)
In-Reply-To: <20100420102608.31956.93404.stgit@warthog.procyon.org.uk>

On Tue, Apr 20, 2010 at 11:26:08AM +0100, David Howells wrote:
> From: Trond Myklebust <Trond.Myklebust@netapp.com>
> 
> Ensure that we correctly rcu-dereference the delegation itself, and that we
> protect against removal while we're changing the contents.

I queued both of these, thank you Trond and David!

Trond, if you would rather carry these in your tree, please let me know.

							Thanx, Paul

> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
> 
>  fs/nfs/delegation.c |   42 ++++++++++++++++++++++++++++--------------
>  1 files changed, 28 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
> index 1567124..8d9ec49 100644
> --- a/fs/nfs/delegation.c
> +++ b/fs/nfs/delegation.c
> @@ -129,21 +129,35 @@ again:
>   */
>  void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
>  {
> -	struct nfs_delegation *delegation = NFS_I(inode)->delegation;
> -	struct rpc_cred *oldcred;
> +	struct nfs_delegation *delegation;
> +	struct rpc_cred *oldcred = NULL;
> 
> -	if (delegation == NULL)
> -		return;
> -	memcpy(delegation->stateid.data, res->delegation.data,
> -			sizeof(delegation->stateid.data));
> -	delegation->type = res->delegation_type;
> -	delegation->maxsize = res->maxsize;
> -	oldcred = delegation->cred;
> -	delegation->cred = get_rpccred(cred);
> -	clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
> -	NFS_I(inode)->delegation_state = delegation->type;
> -	smp_wmb();
> -	put_rpccred(oldcred);
> +	rcu_read_lock();
> +	delegation = rcu_dereference(NFS_I(inode)->delegation);
> +	if (delegation != NULL) {
> +		spin_lock(&delegation->lock);
> +		if (delegation->inode != NULL) {
> +			memcpy(delegation->stateid.data, res->delegation.data,
> +			       sizeof(delegation->stateid.data));
> +			delegation->type = res->delegation_type;
> +			delegation->maxsize = res->maxsize;
> +			oldcred = delegation->cred;
> +			delegation->cred = get_rpccred(cred);
> +			clear_bit(NFS_DELEGATION_NEED_RECLAIM,
> +				  &delegation->flags);
> +			NFS_I(inode)->delegation_state = delegation->type;
> +			spin_unlock(&delegation->lock);
> +			put_rpccred(oldcred);
> +			rcu_read_unlock();
> +		} else {
> +			/* We appear to have raced with a delegation return. */
> +			spin_unlock(&delegation->lock);
> +			rcu_read_unlock();
> +			nfs_inode_set_delegation(inode, cred, res);
> +		}
> +	} else {
> +		rcu_read_unlock();
> +	}
>  }
> 
>  static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
> 

  parent reply	other threads:[~2010-04-20 22:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-20 10:26 [PATCH 1/2] NFSv4: Fix the locking in nfs_inode_reclaim_delegation() David Howells
2010-04-20 10:26 ` [PATCH 2/2] NFS: Fix RCU issues in the NFSv4 delegation code David Howells
2010-04-20 22:21 ` Paul E. McKenney [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-05-01  0:31 [PATCH] fix RCU-lockdep splats in NFS Paul E. McKenney
2010-05-01  0:32 ` [PATCH 1/2] NFSv4: Fix the locking in nfs_inode_reclaim_delegation() Paul E. McKenney

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=20100420222140.GN2628@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --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