From: Jeff Layton <jlayton@primarydata.com>
To: bfields@fieldses.org
Cc: trond.myklebust@primarydata.com, bhalevy@primarydata.com,
linux-nfs@vger.kernel.org
Subject: [PATCH 3/9] nfsd4: use recall_lock for delegation hashing
Date: Fri, 30 May 2014 09:09:27 -0400 [thread overview]
Message-ID: <1401455373-18207-4-git-send-email-jlayton@primarydata.com> (raw)
In-Reply-To: <1401455373-18207-1-git-send-email-jlayton@primarydata.com>
From: Benny Halevy <bhalevy@primarydata.com>
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>
---
fs/nfsd/nfs4state.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index be6199cc8711..96bdd90b96b1 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -433,12 +433,21 @@ static void unhash_stid(struct nfs4_stid *s)
s->sc_type = 0;
}
+static void
+hash_delegation_locked(struct nfs4_delegation *dp, struct nfs4_file *fp)
+{
+ lockdep_assert_held(&recall_lock);
+
+ list_add(&dp->dl_perfile, &fp->fi_delegations);
+ list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations);
+}
+
/* Called under the state lock. */
static void
unhash_delegation(struct nfs4_delegation *dp)
{
- list_del_init(&dp->dl_perclnt);
spin_lock(&recall_lock);
+ list_del_init(&dp->dl_perclnt);
list_del_init(&dp->dl_perfile);
list_del_init(&dp->dl_recall_lru);
spin_unlock(&recall_lock);
@@ -3053,11 +3062,12 @@ static int nfs4_setlease(struct nfs4_delegation *dp)
status = vfs_setlease(fl->fl_file, fl->fl_type, &fl);
if (status)
goto out_free;
- list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations);
fp->fi_lease = fl;
fp->fi_deleg_file = get_file(fl->fl_file);
atomic_set(&fp->fi_delegees, 1);
- list_add(&dp->dl_perfile, &fp->fi_delegations);
+ spin_lock(&recall_lock);
+ hash_delegation_locked(dp, fp);
+ spin_unlock(&recall_lock);
return 0;
out_free:
locks_free_lock(fl);
@@ -3078,9 +3088,8 @@ static int nfs4_set_delegation(struct nfs4_delegation *dp, struct nfs4_file *fp)
spin_unlock(&recall_lock);
return -EAGAIN;
}
- list_add(&dp->dl_perfile, &fp->fi_delegations);
+ hash_delegation_locked(dp, fp);
spin_unlock(&recall_lock);
- list_add(&dp->dl_perclnt, &dp->dl_stid.sc_client->cl_delegations);
return 0;
}
@@ -4891,6 +4900,7 @@ static u64 nfsd_find_all_delegations(struct nfs4_client *clp, u64 max,
struct nfs4_delegation *dp, *next;
u64 count = 0;
+ lockdep_assert_held(&recall_lock);
list_for_each_entry_safe(dp, next, &clp->cl_delegations, dl_perclnt) {
if (victims)
list_move(&dp->dl_recall_lru, victims);
--
1.9.3
next prev parent reply other threads:[~2014-05-30 13:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-30 13:09 [PATCH 0/9] nfsd: bugfixes and preliminary patches for client_mutex removal Jeff Layton
2014-05-30 13:09 ` [PATCH 1/9] nfsd: make nfsd4_encode_fattr static Jeff Layton
2014-05-30 13:09 ` [PATCH 2/9] nfsd: fix laundromat next-run-time calculation Jeff Layton
2014-05-30 13:09 ` Jeff Layton [this message]
2014-05-30 13:09 ` [PATCH 4/9] nfsd: fix setting of NFS4_OO_CONFIRMED in nfsd4_open Jeff Layton
2014-05-30 13:09 ` [PATCH 5/9] nfsd: remove unneeded zeroing of fields in nfsd4_proc_compound Jeff Layton
2014-05-30 13:09 ` [PATCH 6/9] nfsd4: rename recall_lock to state_lock Jeff Layton
2014-05-30 13:09 ` [PATCH 7/9] nfsd4: hash deleg stateid only on successful nfs4_set_delegation Jeff Layton
2014-05-30 13:09 ` [PATCH 8/9] NFSd: Protect addition to the file_hashtbl Jeff Layton
2014-06-05 16:12 ` J. Bruce Fields
2014-06-05 16:18 ` Trond Myklebust
2014-06-05 16:27 ` Jeff Layton
2014-05-30 13:09 ` [PATCH 9/9] NFSd: protect delegation setup with the i_lock Jeff Layton
2014-06-02 8:46 ` Christoph Hellwig
2014-06-02 14:17 ` Jeff Layton
2014-06-02 18:20 ` Christoph Hellwig
2014-06-02 18:48 ` Jeff Layton
2014-05-30 13:13 ` [PATCH 10/9] nfsd: remove initial assignment of "p" in nfsd4_encode_security_label Jeff Layton
2014-06-04 19:56 ` [PATCH 0/9] nfsd: bugfixes and preliminary patches for client_mutex removal J. Bruce Fields
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=1401455373-18207-4-git-send-email-jlayton@primarydata.com \
--to=jlayton@primarydata.com \
--cc=bfields@fieldses.org \
--cc=bhalevy@primarydata.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@primarydata.com \
/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;
as well as URLs for NNTP newsgroup(s).