Commit 91677467 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'bugfixes' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6

* 'bugfixes' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6:
  NFS: Fix RCU issues in the NFSv4 delegation code
  NFSv4: Fix the locking in nfs_inode_reclaim_delegation()
parents 4a225331 17d2c0a0
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
static void nfs_do_free_delegation(struct nfs_delegation *delegation) static void nfs_do_free_delegation(struct nfs_delegation *delegation)
{ {
if (delegation->cred)
put_rpccred(delegation->cred);
kfree(delegation); kfree(delegation);
} }
...@@ -36,13 +38,7 @@ static void nfs_free_delegation_callback(struct rcu_head *head) ...@@ -36,13 +38,7 @@ static void nfs_free_delegation_callback(struct rcu_head *head)
static void nfs_free_delegation(struct nfs_delegation *delegation) static void nfs_free_delegation(struct nfs_delegation *delegation)
{ {
struct rpc_cred *cred;
cred = rcu_dereference(delegation->cred);
rcu_assign_pointer(delegation->cred, NULL);
call_rcu(&delegation->rcu, nfs_free_delegation_callback); call_rcu(&delegation->rcu, nfs_free_delegation_callback);
if (cred)
put_rpccred(cred);
} }
void nfs_mark_delegation_referenced(struct nfs_delegation *delegation) void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)
...@@ -129,21 +125,35 @@ static int nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *s ...@@ -129,21 +125,35 @@ static int nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *s
*/ */
void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res) 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 nfs_delegation *delegation;
struct rpc_cred *oldcred; struct rpc_cred *oldcred = NULL;
if (delegation == NULL) rcu_read_lock();
return; delegation = rcu_dereference(NFS_I(inode)->delegation);
memcpy(delegation->stateid.data, res->delegation.data, if (delegation != NULL) {
sizeof(delegation->stateid.data)); spin_lock(&delegation->lock);
delegation->type = res->delegation_type; if (delegation->inode != NULL) {
delegation->maxsize = res->maxsize; memcpy(delegation->stateid.data, res->delegation.data,
oldcred = delegation->cred; sizeof(delegation->stateid.data));
delegation->cred = get_rpccred(cred); delegation->type = res->delegation_type;
clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); delegation->maxsize = res->maxsize;
NFS_I(inode)->delegation_state = delegation->type; oldcred = delegation->cred;
smp_wmb(); delegation->cred = get_rpccred(cred);
put_rpccred(oldcred); 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) static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
...@@ -166,9 +176,13 @@ static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation ...@@ -166,9 +176,13 @@ static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation
return inode; return inode;
} }
static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsi, const nfs4_stateid *stateid) static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsi,
const nfs4_stateid *stateid,
struct nfs_client *clp)
{ {
struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation); struct nfs_delegation *delegation =
rcu_dereference_protected(nfsi->delegation,
lockdep_is_held(&clp->cl_lock));
if (delegation == NULL) if (delegation == NULL)
goto nomatch; goto nomatch;
...@@ -195,7 +209,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct ...@@ -195,7 +209,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
{ {
struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
struct nfs_inode *nfsi = NFS_I(inode); struct nfs_inode *nfsi = NFS_I(inode);
struct nfs_delegation *delegation; struct nfs_delegation *delegation, *old_delegation;
struct nfs_delegation *freeme = NULL; struct nfs_delegation *freeme = NULL;
int status = 0; int status = 0;
...@@ -213,10 +227,12 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct ...@@ -213,10 +227,12 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
spin_lock_init(&delegation->lock); spin_lock_init(&delegation->lock);
spin_lock(&clp->cl_lock); spin_lock(&clp->cl_lock);
if (rcu_dereference(nfsi->delegation) != NULL) { old_delegation = rcu_dereference_protected(nfsi->delegation,
if (memcmp(&delegation->stateid, &nfsi->delegation->stateid, lockdep_is_held(&clp->cl_lock));
sizeof(delegation->stateid)) == 0 && if (old_delegation != NULL) {
delegation->type == nfsi->delegation->type) { if (memcmp(&delegation->stateid, &old_delegation->stateid,
sizeof(old_delegation->stateid)) == 0 &&
delegation->type == old_delegation->type) {
goto out; goto out;
} }
/* /*
...@@ -226,12 +242,12 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct ...@@ -226,12 +242,12 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
dfprintk(FILE, "%s: server %s handed out " dfprintk(FILE, "%s: server %s handed out "
"a duplicate delegation!\n", "a duplicate delegation!\n",
__func__, clp->cl_hostname); __func__, clp->cl_hostname);
if (delegation->type <= nfsi->delegation->type) { if (delegation->type <= old_delegation->type) {
freeme = delegation; freeme = delegation;
delegation = NULL; delegation = NULL;
goto out; goto out;
} }
freeme = nfs_detach_delegation_locked(nfsi, NULL); freeme = nfs_detach_delegation_locked(nfsi, NULL, clp);
} }
list_add_rcu(&delegation->super_list, &clp->cl_delegations); list_add_rcu(&delegation->super_list, &clp->cl_delegations);
nfsi->delegation_state = delegation->type; nfsi->delegation_state = delegation->type;
...@@ -301,7 +317,7 @@ int nfs_client_return_marked_delegations(struct nfs_client *clp) ...@@ -301,7 +317,7 @@ int nfs_client_return_marked_delegations(struct nfs_client *clp)
if (inode == NULL) if (inode == NULL)
continue; continue;
spin_lock(&clp->cl_lock); spin_lock(&clp->cl_lock);
delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL); delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL, clp);
spin_unlock(&clp->cl_lock); spin_unlock(&clp->cl_lock);
rcu_read_unlock(); rcu_read_unlock();
if (delegation != NULL) { if (delegation != NULL) {
...@@ -330,9 +346,9 @@ void nfs_inode_return_delegation_noreclaim(struct inode *inode) ...@@ -330,9 +346,9 @@ void nfs_inode_return_delegation_noreclaim(struct inode *inode)
struct nfs_inode *nfsi = NFS_I(inode); struct nfs_inode *nfsi = NFS_I(inode);
struct nfs_delegation *delegation; struct nfs_delegation *delegation;
if (rcu_dereference(nfsi->delegation) != NULL) { if (rcu_access_pointer(nfsi->delegation) != NULL) {
spin_lock(&clp->cl_lock); spin_lock(&clp->cl_lock);
delegation = nfs_detach_delegation_locked(nfsi, NULL); delegation = nfs_detach_delegation_locked(nfsi, NULL, clp);
spin_unlock(&clp->cl_lock); spin_unlock(&clp->cl_lock);
if (delegation != NULL) if (delegation != NULL)
nfs_do_return_delegation(inode, delegation, 0); nfs_do_return_delegation(inode, delegation, 0);
...@@ -346,9 +362,9 @@ int nfs_inode_return_delegation(struct inode *inode) ...@@ -346,9 +362,9 @@ int nfs_inode_return_delegation(struct inode *inode)
struct nfs_delegation *delegation; struct nfs_delegation *delegation;
int err = 0; int err = 0;
if (rcu_dereference(nfsi->delegation) != NULL) { if (rcu_access_pointer(nfsi->delegation) != NULL) {
spin_lock(&clp->cl_lock); spin_lock(&clp->cl_lock);
delegation = nfs_detach_delegation_locked(nfsi, NULL); delegation = nfs_detach_delegation_locked(nfsi, NULL, clp);
spin_unlock(&clp->cl_lock); spin_unlock(&clp->cl_lock);
if (delegation != NULL) { if (delegation != NULL) {
nfs_msync_inode(inode); nfs_msync_inode(inode);
...@@ -526,7 +542,7 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp) ...@@ -526,7 +542,7 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
if (inode == NULL) if (inode == NULL)
continue; continue;
spin_lock(&clp->cl_lock); spin_lock(&clp->cl_lock);
delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL); delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL, clp);
spin_unlock(&clp->cl_lock); spin_unlock(&clp->cl_lock);
rcu_read_unlock(); rcu_read_unlock();
if (delegation != NULL) if (delegation != NULL)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment