1 From 0c5c5bf6b39c5fededcbc2d66e072bb6d5e58bc5 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 26 Sep 2022 14:41:01 -0400
4 Subject: nfsd: make nfsd4_run_cb a bool return function
6 From: Jeff Layton <jlayton@kernel.org>
8 [ Upstream commit b95239ca4954a0d48b19c09ce7e8f31b453b4216 ]
10 queue_work can return false and not queue anything, if the work is
11 already queued. If that happens in the case of a CB_RECALL, we'll have
12 taken an extra reference to the stid that will never be put. Ensure we
13 throw a warning in that case.
15 Signed-off-by: Jeff Layton <jlayton@kernel.org>
16 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
18 fs/nfsd/nfs4callback.c | 14 ++++++++++++--
19 fs/nfsd/nfs4state.c | 5 ++---
20 fs/nfsd/state.h | 2 +-
21 3 files changed, 15 insertions(+), 6 deletions(-)
23 diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
24 index face8908a40b1..39989c14c8a1e 100644
25 --- a/fs/nfsd/nfs4callback.c
26 +++ b/fs/nfsd/nfs4callback.c
27 @@ -1373,11 +1373,21 @@ void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
28 cb->cb_holds_slot = false;
31 -void nfsd4_run_cb(struct nfsd4_callback *cb)
33 + * nfsd4_run_cb - queue up a callback job to run
34 + * @cb: callback to queue
36 + * Kick off a callback to do its thing. Returns false if it was already
37 + * on a queue, true otherwise.
39 +bool nfsd4_run_cb(struct nfsd4_callback *cb)
41 struct nfs4_client *clp = cb->cb_clp;
44 nfsd41_cb_inflight_begin(clp);
45 - if (!nfsd4_queue_cb(cb))
46 + queued = nfsd4_queue_cb(cb);
48 nfsd41_cb_inflight_end(clp);
51 diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
52 index e98306c69f424..61978ad43a0f7 100644
53 --- a/fs/nfsd/nfs4state.c
54 +++ b/fs/nfsd/nfs4state.c
55 @@ -4874,14 +4874,13 @@ static void nfsd_break_one_deleg(struct nfs4_delegation *dp)
56 * we know it's safe to take a reference.
58 refcount_inc(&dp->dl_stid.sc_count);
59 - nfsd4_run_cb(&dp->dl_recall);
60 + WARN_ON_ONCE(!nfsd4_run_cb(&dp->dl_recall));
63 /* Called from break_lease() with flc_lock held. */
65 nfsd_break_deleg_cb(struct file_lock *fl)
68 struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner;
69 struct nfs4_file *fp = dp->dl_stid.sc_file;
70 struct nfs4_client *clp = dp->dl_stid.sc_client;
71 @@ -4907,7 +4906,7 @@ nfsd_break_deleg_cb(struct file_lock *fl)
72 fp->fi_had_conflict = true;
73 nfsd_break_one_deleg(dp);
74 spin_unlock(&fp->fi_lock);
80 diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
81 index b3477087a9fc3..e2daef3cc0034 100644
84 @@ -692,7 +692,7 @@ extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
85 extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
86 extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
87 const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op);
88 -extern void nfsd4_run_cb(struct nfsd4_callback *cb);
89 +extern bool nfsd4_run_cb(struct nfsd4_callback *cb);
90 extern int nfsd4_create_callback_queue(void);
91 extern void nfsd4_destroy_callback_queue(void);
92 extern void nfsd4_shutdown_callback(struct nfs4_client *);