diff options
author | Benny Halevy <bhalevy@primarydata.com> | 2014-05-30 09:09:27 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2014-06-04 15:41:52 -0400 |
commit | 931ee56c67573eb4e51c8a4e78598d965b8b059e (patch) | |
tree | c9a2dd61a536acd1110ee611c1996cd6b57783ac /fs/nfsd | |
parent | a832e7ae8b4f71fc522089d83fd445693aa7dbc5 (diff) |
nfsd4: use recall_lock for delegation hashing
This fixes a bug in the handling of the fi_delegations list.
nfs4_setlease does not hold the recall_lock when adding to it. The
client_mutex is held, which prevents against concurrent list changes,
but nfsd_break_deleg_cb does not hold while walking it. New delegations
could theoretically creep onto the list while we're walking it there.
Signed-off-by: Benny Halevy <bhalevy@primarydata.com>
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Cc: stable@vger.kernel.org
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd')
-rw-r--r-- | fs/nfsd/nfs4state.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 01a0e4384500..05ca64c4599d 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c | |||
@@ -433,12 +433,21 @@ static void unhash_stid(struct nfs4_stid *s) | |||
433 | s->sc_type = 0; | 433 | s->sc_type = 0; |
434 | } | 434 | } |
435 | 435 | ||
436 | static void | ||
437 | hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp) | ||
438 | { | ||
439 | lockdep_assert_held(&recall_lock); | ||
440 | |||
441 | list_add(&dp->dl_perfile, &fp->fi_delegations); | ||
442 | list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); | ||
443 | } | ||
444 | |||
436 | /* Called under the state lock. */ | 445 | /* Called under the state lock. */ |
437 | static void | 446 | static void |
438 | unhash_delegation(struct nfs4_delegation *dp) | 447 | unhash_delegation(struct nfs4_delegation *dp) |
439 | { | 448 | { |
440 | list_del_init(&dp->dl_perclnt); | ||
441 | spin_lock(&recall_lock); | 449 | spin_lock(&recall_lock); |
450 | list_del_init(&dp->dl_perclnt); | ||
442 | list_del_init(&dp->dl_perfile); | 451 | list_del_init(&dp->dl_perfile); |
443 | list_del_init(&dp->dl_recall_lru); | 452 | list_del_init(&dp->dl_recall_lru); |
444 | spin_unlock(&recall_lock); | 453 | spin_unlock(&recall_lock); |
@@ -3065,11 +3074,12 @@ static int nfs4_setlease(struct nfs4_delegation *dp) | |||
3065 | status = vfs_setlease(fl->fl_file, fl->fl_type, &fl); | 3074 | status = vfs_setlease(fl->fl_file, fl->fl_type, &fl); |
3066 | if (status) | 3075 | if (status) |
3067 | goto out_free; | 3076 | goto out_free; |
3068 | list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); | ||
3069 | fp->fi_lease = fl; | 3077 | fp->fi_lease = fl; |
3070 | fp->fi_deleg_file = get_file(fl->fl_file); | 3078 | fp->fi_deleg_file = get_file(fl->fl_file); |
3071 | atomic_set(&fp->fi_delegees, 1); | 3079 | atomic_set(&fp->fi_delegees, 1); |
3072 | list_add(&dp->dl_perfile, &fp->fi_delegations); | 3080 | spin_lock(&recall_lock); |
3081 | hash_delegation_locked(dp, fp); | ||
3082 | spin_unlock(&recall_lock); | ||
3073 | return 0; | 3083 | return 0; |
3074 | out_free: | 3084 | out_free: |
3075 | locks_free_lock(fl); | 3085 | locks_free_lock(fl); |
@@ -3090,9 +3100,8 @@ static int nfs4_set_delegation(struct nfs4_delegation *dp, struct nfs4_file *fp) | |||
3090 | spin_unlock(&recall_lock); | 3100 | spin_unlock(&recall_lock); |
3091 | return -EAGAIN; | 3101 | return -EAGAIN; |
3092 | } | 3102 | } |
3093 | list_add(&dp->dl_perfile, &fp->fi_delegations); | 3103 | hash_delegation_locked(dp, fp); |
3094 | spin_unlock(&recall_lock); | 3104 | spin_unlock(&recall_lock); |
3095 | list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations); | ||
3096 | return 0; | 3105 | return 0; |
3097 | } | 3106 | } |
3098 | 3107 | ||
@@ -4903,6 +4912,7 @@ static u64 nfsd_find_all_delegations(struct nfs4_client *clp, u64 max, | |||
4903 | struct nfs4_delegation *dp, *next; | 4912 | struct nfs4_delegation *dp, *next; |
4904 | u64 count = 0; | 4913 | u64 count = 0; |
4905 | 4914 | ||
4915 | lockdep_assert_held(&recall_lock); | ||
4906 | list_for_each_entry_safe(dp, next, &clp->cl_delegations, dl_perclnt) { | 4916 | list_for_each_entry_safe(dp, next, &clp->cl_delegations, dl_perclnt) { |
4907 | if (victims) | 4917 | if (victims) |
4908 | list_move(&dp->dl_recall_lru, victims); | 4918 | list_move(&dp->dl_recall_lru, victims); |