Commit d8be0289 authored by Jeff Layton's avatar Jeff Layton Committed by Kamal Mostafa

nfsd: ensure that delegation stateid hash references are only put once

commit 3fcbbd24 upstream.

It's possible that a DELEGRETURN could race with (e.g.) client expiry,
in which case we could end up putting the delegation hash reference more
than once.

Have unhash_delegation_locked return a bool that indicates whether it
was already unhashed. In the case of destroy_delegation we only
conditionally put the hash reference if that returns true.

The other callers of unhash_delegation_locked call it while walking
list_heads that shouldn't yet be detached. If we find that it doesn't
return true in those cases, then throw a WARN_ON as that indicates that
we have a partially hashed delegation, and that something is likely very
wrong.
Tested-by: default avatarAndrew W Elble <aweits@rit.edu>
Tested-by: default avatarAnna Schumaker <Anna.Schumaker@netapp.com>
Signed-off-by: default avatarJeff Layton <jeff.layton@primarydata.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
[ kamal: backport to 3.19-stable: context ]
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent 89ed88d0
...@@ -715,13 +715,16 @@ hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp) ...@@ -715,13 +715,16 @@ hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp)
list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations);
} }
static void static bool
unhash_delegation_locked(struct nfs4_delegation *dp) unhash_delegation_locked(struct nfs4_delegation *dp)
{ {
struct nfs4_file *fp = dp->dl_stid.sc_file; struct nfs4_file *fp = dp->dl_stid.sc_file;
lockdep_assert_held(&state_lock); lockdep_assert_held(&state_lock);
if (list_empty(&dp->dl_perfile))
return false;
dp->dl_stid.sc_type = NFS4_CLOSED_DELEG_STID; dp->dl_stid.sc_type = NFS4_CLOSED_DELEG_STID;
/* Ensure that deleg break won't try to requeue it */ /* Ensure that deleg break won't try to requeue it */
++dp->dl_time; ++dp->dl_time;
...@@ -730,15 +733,20 @@ unhash_delegation_locked(struct nfs4_delegation *dp) ...@@ -730,15 +733,20 @@ unhash_delegation_locked(struct nfs4_delegation *dp)
list_del_init(&dp->dl_recall_lru); list_del_init(&dp->dl_recall_lru);
list_del_init(&dp->dl_perfile); list_del_init(&dp->dl_perfile);
spin_unlock(&fp->fi_lock); spin_unlock(&fp->fi_lock);
return true;
} }
static void destroy_delegation(struct nfs4_delegation *dp) static void destroy_delegation(struct nfs4_delegation *dp)
{ {
bool unhashed;
spin_lock(&state_lock); spin_lock(&state_lock);
unhash_delegation_locked(dp); unhashed = unhash_delegation_locked(dp);
spin_unlock(&state_lock); spin_unlock(&state_lock);
nfs4_put_deleg_lease(dp->dl_stid.sc_file); if (unhashed) {
nfs4_put_stid(&dp->dl_stid); nfs4_put_deleg_lease(dp->dl_stid.sc_file);
nfs4_put_stid(&dp->dl_stid);
}
} }
static void revoke_delegation(struct nfs4_delegation *dp) static void revoke_delegation(struct nfs4_delegation *dp)
...@@ -1653,7 +1661,7 @@ __destroy_client(struct nfs4_client *clp) ...@@ -1653,7 +1661,7 @@ __destroy_client(struct nfs4_client *clp)
spin_lock(&state_lock); spin_lock(&state_lock);
while (!list_empty(&clp->cl_delegations)) { while (!list_empty(&clp->cl_delegations)) {
dp = list_entry(clp->cl_delegations.next, struct nfs4_delegation, dl_perclnt); dp = list_entry(clp->cl_delegations.next, struct nfs4_delegation, dl_perclnt);
unhash_delegation_locked(dp); WARN_ON(!unhash_delegation_locked(dp));
list_add(&dp->dl_recall_lru, &reaplist); list_add(&dp->dl_recall_lru, &reaplist);
} }
spin_unlock(&state_lock); spin_unlock(&state_lock);
...@@ -4252,7 +4260,7 @@ nfs4_laundromat(struct nfsd_net *nn) ...@@ -4252,7 +4260,7 @@ nfs4_laundromat(struct nfsd_net *nn)
new_timeo = min(new_timeo, t); new_timeo = min(new_timeo, t);
break; break;
} }
unhash_delegation_locked(dp); WARN_ON(!unhash_delegation_locked(dp));
list_add(&dp->dl_recall_lru, &reaplist); list_add(&dp->dl_recall_lru, &reaplist);
} }
spin_unlock(&state_lock); spin_unlock(&state_lock);
...@@ -6164,7 +6172,7 @@ static u64 nfsd_find_all_delegations(struct nfs4_client *clp, u64 max, ...@@ -6164,7 +6172,7 @@ static u64 nfsd_find_all_delegations(struct nfs4_client *clp, u64 max,
continue; continue;
atomic_inc(&clp->cl_refcount); atomic_inc(&clp->cl_refcount);
unhash_delegation_locked(dp); WARN_ON(!unhash_delegation_locked(dp));
list_add(&dp->dl_recall_lru, victims); list_add(&dp->dl_recall_lru, victims);
} }
++count; ++count;
...@@ -6494,7 +6502,7 @@ nfs4_state_shutdown_net(struct net *net) ...@@ -6494,7 +6502,7 @@ nfs4_state_shutdown_net(struct net *net)
spin_lock(&state_lock); spin_lock(&state_lock);
list_for_each_safe(pos, next, &nn->del_recall_lru) { list_for_each_safe(pos, next, &nn->del_recall_lru) {
dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
unhash_delegation_locked(dp); WARN_ON(!unhash_delegation_locked(dp));
list_add(&dp->dl_recall_lru, &reaplist); list_add(&dp->dl_recall_lru, &reaplist);
} }
spin_unlock(&state_lock); spin_unlock(&state_lock);
......
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