mirror of
https://github.com/torvalds/linux.git
synced 2024-11-27 06:31:52 +00:00
NFSv4: Fix races between open and delegreturn
If the server returns the same delegation in an open that we just used in a delegreturn, we need to ensure we don't apply that stateid if the delegreturn has freed it on the server. To do so, we ensure that we do not free the storage for the delegation until either it is replaced by a new one, or we throw the inode out of cache. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
This commit is contained in:
parent
42c304c34e
commit
ee05f45677
@ -229,7 +229,6 @@ static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *
|
|||||||
delegation->cred,
|
delegation->cred,
|
||||||
&delegation->stateid,
|
&delegation->stateid,
|
||||||
issync);
|
issync);
|
||||||
nfs_free_delegation(delegation);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +301,6 @@ nfs_detach_delegation_locked(struct nfs_inode *nfsi,
|
|||||||
spin_unlock(&delegation->lock);
|
spin_unlock(&delegation->lock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
set_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
|
|
||||||
list_del_rcu(&delegation->super_list);
|
list_del_rcu(&delegation->super_list);
|
||||||
delegation->inode = NULL;
|
delegation->inode = NULL;
|
||||||
rcu_assign_pointer(nfsi->delegation, NULL);
|
rcu_assign_pointer(nfsi->delegation, NULL);
|
||||||
@ -329,10 +327,12 @@ nfs_inode_detach_delegation(struct inode *inode)
|
|||||||
struct nfs_server *server = NFS_SERVER(inode);
|
struct nfs_server *server = NFS_SERVER(inode);
|
||||||
struct nfs_delegation *delegation;
|
struct nfs_delegation *delegation;
|
||||||
|
|
||||||
delegation = nfs_start_delegation_return(nfsi);
|
rcu_read_lock();
|
||||||
if (delegation == NULL)
|
delegation = rcu_dereference(nfsi->delegation);
|
||||||
return NULL;
|
if (delegation != NULL)
|
||||||
return nfs_detach_delegation(nfsi, delegation, server);
|
delegation = nfs_detach_delegation(nfsi, delegation, server);
|
||||||
|
rcu_read_unlock();
|
||||||
|
return delegation;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -384,16 +384,18 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,
|
|||||||
spin_lock(&clp->cl_lock);
|
spin_lock(&clp->cl_lock);
|
||||||
old_delegation = rcu_dereference_protected(nfsi->delegation,
|
old_delegation = rcu_dereference_protected(nfsi->delegation,
|
||||||
lockdep_is_held(&clp->cl_lock));
|
lockdep_is_held(&clp->cl_lock));
|
||||||
if (old_delegation != NULL) {
|
if (old_delegation == NULL)
|
||||||
/* Is this an update of the existing delegation? */
|
goto add_new;
|
||||||
if (nfs4_stateid_match_other(&old_delegation->stateid,
|
/* Is this an update of the existing delegation? */
|
||||||
&delegation->stateid)) {
|
if (nfs4_stateid_match_other(&old_delegation->stateid,
|
||||||
spin_lock(&old_delegation->lock);
|
&delegation->stateid)) {
|
||||||
nfs_update_inplace_delegation(old_delegation,
|
spin_lock(&old_delegation->lock);
|
||||||
delegation);
|
nfs_update_inplace_delegation(old_delegation,
|
||||||
spin_unlock(&old_delegation->lock);
|
delegation);
|
||||||
goto out;
|
spin_unlock(&old_delegation->lock);
|
||||||
}
|
goto out;
|
||||||
|
}
|
||||||
|
if (!test_bit(NFS_DELEGATION_REVOKED, &old_delegation->flags)) {
|
||||||
/*
|
/*
|
||||||
* Deal with broken servers that hand out two
|
* Deal with broken servers that hand out two
|
||||||
* delegations for the same file.
|
* delegations for the same file.
|
||||||
@ -412,11 +414,11 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,
|
|||||||
if (test_and_set_bit(NFS_DELEGATION_RETURNING,
|
if (test_and_set_bit(NFS_DELEGATION_RETURNING,
|
||||||
&old_delegation->flags))
|
&old_delegation->flags))
|
||||||
goto out;
|
goto out;
|
||||||
freeme = nfs_detach_delegation_locked(nfsi,
|
|
||||||
old_delegation, clp);
|
|
||||||
if (freeme == NULL)
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
freeme = nfs_detach_delegation_locked(nfsi, old_delegation, clp);
|
||||||
|
if (freeme == NULL)
|
||||||
|
goto out;
|
||||||
|
add_new:
|
||||||
list_add_tail_rcu(&delegation->super_list, &server->delegations);
|
list_add_tail_rcu(&delegation->super_list, &server->delegations);
|
||||||
rcu_assign_pointer(nfsi->delegation, delegation);
|
rcu_assign_pointer(nfsi->delegation, delegation);
|
||||||
delegation = NULL;
|
delegation = NULL;
|
||||||
@ -431,8 +433,10 @@ out:
|
|||||||
spin_unlock(&clp->cl_lock);
|
spin_unlock(&clp->cl_lock);
|
||||||
if (delegation != NULL)
|
if (delegation != NULL)
|
||||||
nfs_free_delegation(delegation);
|
nfs_free_delegation(delegation);
|
||||||
if (freeme != NULL)
|
if (freeme != NULL) {
|
||||||
nfs_do_return_delegation(inode, freeme, 0);
|
nfs_do_return_delegation(inode, freeme, 0);
|
||||||
|
nfs_free_delegation(freeme);
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,7 +446,6 @@ out:
|
|||||||
static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation *delegation, int issync)
|
static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation *delegation, int issync)
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (delegation == NULL)
|
if (delegation == NULL)
|
||||||
@ -464,8 +467,6 @@ static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation
|
|||||||
nfs_abort_delegation_return(delegation, clp);
|
nfs_abort_delegation_return(delegation, clp);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (!nfs_detach_delegation(nfsi, delegation, NFS_SERVER(inode)))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
err = nfs_do_return_delegation(inode, delegation, issync);
|
err = nfs_do_return_delegation(inode, delegation, issync);
|
||||||
out:
|
out:
|
||||||
@ -608,6 +609,7 @@ void nfs_inode_evict_delegation(struct inode *inode)
|
|||||||
if (delegation != NULL) {
|
if (delegation != NULL) {
|
||||||
set_bit(NFS_DELEGATION_INODE_FREEING, &delegation->flags);
|
set_bit(NFS_DELEGATION_INODE_FREEING, &delegation->flags);
|
||||||
nfs_do_return_delegation(inode, delegation, 1);
|
nfs_do_return_delegation(inode, delegation, 1);
|
||||||
|
nfs_free_delegation(delegation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,10 +765,9 @@ static void nfs_mark_delegation_revoked(struct nfs_server *server,
|
|||||||
{
|
{
|
||||||
set_bit(NFS_DELEGATION_REVOKED, &delegation->flags);
|
set_bit(NFS_DELEGATION_REVOKED, &delegation->flags);
|
||||||
delegation->stateid.type = NFS4_INVALID_STATEID_TYPE;
|
delegation->stateid.type = NFS4_INVALID_STATEID_TYPE;
|
||||||
nfs_mark_return_delegation(server, delegation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool nfs_revoke_delegation(struct inode *inode,
|
static void nfs_revoke_delegation(struct inode *inode,
|
||||||
const nfs4_stateid *stateid)
|
const nfs4_stateid *stateid)
|
||||||
{
|
{
|
||||||
struct nfs_delegation *delegation;
|
struct nfs_delegation *delegation;
|
||||||
@ -799,19 +800,12 @@ out:
|
|||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
if (ret)
|
if (ret)
|
||||||
nfs_inode_find_state_and_recover(inode, stateid);
|
nfs_inode_find_state_and_recover(inode, stateid);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void nfs_remove_bad_delegation(struct inode *inode,
|
void nfs_remove_bad_delegation(struct inode *inode,
|
||||||
const nfs4_stateid *stateid)
|
const nfs4_stateid *stateid)
|
||||||
{
|
{
|
||||||
struct nfs_delegation *delegation;
|
nfs_revoke_delegation(inode, stateid);
|
||||||
|
|
||||||
if (!nfs_revoke_delegation(inode, stateid))
|
|
||||||
return;
|
|
||||||
delegation = nfs_inode_detach_delegation(inode);
|
|
||||||
if (delegation)
|
|
||||||
nfs_free_delegation(delegation);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nfs_remove_bad_delegation);
|
EXPORT_SYMBOL_GPL(nfs_remove_bad_delegation);
|
||||||
|
|
||||||
@ -839,7 +833,7 @@ void nfs_delegation_mark_returned(struct inode *inode,
|
|||||||
delegation->stateid.seqid = stateid->seqid;
|
delegation->stateid.seqid = stateid->seqid;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bit(NFS_DELEGATION_REVOKED, &delegation->flags);
|
nfs_mark_delegation_revoked(NFS_SERVER(inode), delegation);
|
||||||
|
|
||||||
out_clear_returning:
|
out_clear_returning:
|
||||||
clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
|
clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user