]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/nfsd-add-support-for-lock-conflict-to-courteous-serv.patch
Fixes for 5.15
[thirdparty/kernel/stable-queue.git] / queue-5.15 / nfsd-add-support-for-lock-conflict-to-courteous-serv.patch
1 From ff37a4d344eca7f819cb5977b8aaafc566459af4 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 2 May 2022 14:19:26 -0700
4 Subject: NFSD: add support for lock conflict to courteous server
5
6 From: Dai Ngo <dai.ngo@oracle.com>
7
8 [ Upstream commit 27431affb0dbc259ac6ffe6071243a576c8f38f1 ]
9
10 This patch allows expired client with lock state to be in COURTESY
11 state. Lock conflict with COURTESY client is resolved by the fs/lock
12 code using the lm_lock_expirable and lm_expire_lock callback in the
13 struct lock_manager_operations.
14
15 If conflict client is in COURTESY state, set it to EXPIRABLE and
16 schedule the laundromat to run immediately to expire the client. The
17 callback lm_expire_lock waits for the laundromat to flush its work
18 queue before returning to caller.
19
20 Reviewed-by: J. Bruce Fields <bfields@fieldses.org>
21 Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
22 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
23 ---
24 fs/nfsd/nfs4state.c | 70 ++++++++++++++++++++++++++++++++++-----------
25 1 file changed, 54 insertions(+), 16 deletions(-)
26
27 diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
28 index 582c9c7ba60a8..447faa4348227 100644
29 --- a/fs/nfsd/nfs4state.c
30 +++ b/fs/nfsd/nfs4state.c
31 @@ -5731,39 +5731,51 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
32 }
33 #endif
34
35 +/* Check if any lock belonging to this lockowner has any blockers */
36 static bool
37 -nfs4_has_any_locks(struct nfs4_client *clp)
38 +nfs4_lockowner_has_blockers(struct nfs4_lockowner *lo)
39 +{
40 + struct file_lock_context *ctx;
41 + struct nfs4_ol_stateid *stp;
42 + struct nfs4_file *nf;
43 +
44 + list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) {
45 + nf = stp->st_stid.sc_file;
46 + ctx = nf->fi_inode->i_flctx;
47 + if (!ctx)
48 + continue;
49 + if (locks_owner_has_blockers(ctx, lo))
50 + return true;
51 + }
52 + return false;
53 +}
54 +
55 +static bool
56 +nfs4_anylock_blockers(struct nfs4_client *clp)
57 {
58 int i;
59 struct nfs4_stateowner *so;
60 + struct nfs4_lockowner *lo;
61
62 + if (atomic_read(&clp->cl_delegs_in_recall))
63 + return true;
64 spin_lock(&clp->cl_lock);
65 for (i = 0; i < OWNER_HASH_SIZE; i++) {
66 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[i],
67 so_strhash) {
68 if (so->so_is_open_owner)
69 continue;
70 - spin_unlock(&clp->cl_lock);
71 - return true;
72 + lo = lockowner(so);
73 + if (nfs4_lockowner_has_blockers(lo)) {
74 + spin_unlock(&clp->cl_lock);
75 + return true;
76 + }
77 }
78 }
79 spin_unlock(&clp->cl_lock);
80 return false;
81 }
82
83 -/*
84 - * place holder for now, no check for lock blockers yet
85 - */
86 -static bool
87 -nfs4_anylock_blockers(struct nfs4_client *clp)
88 -{
89 - if (atomic_read(&clp->cl_delegs_in_recall) ||
90 - !list_empty(&clp->async_copies) ||
91 - nfs4_has_any_locks(clp))
92 - return true;
93 - return false;
94 -}
95 -
96 static void
97 nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist,
98 struct laundry_time *lt)
99 @@ -6729,6 +6741,29 @@ nfsd4_lm_put_owner(fl_owner_t owner)
100 nfs4_put_stateowner(&lo->lo_owner);
101 }
102
103 +/* return pointer to struct nfs4_client if client is expirable */
104 +static bool
105 +nfsd4_lm_lock_expirable(struct file_lock *cfl)
106 +{
107 + struct nfs4_lockowner *lo = (struct nfs4_lockowner *)cfl->fl_owner;
108 + struct nfs4_client *clp = lo->lo_owner.so_client;
109 + struct nfsd_net *nn;
110 +
111 + if (try_to_expire_client(clp)) {
112 + nn = net_generic(clp->net, nfsd_net_id);
113 + mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
114 + return true;
115 + }
116 + return false;
117 +}
118 +
119 +/* schedule laundromat to run immediately and wait for it to complete */
120 +static void
121 +nfsd4_lm_expire_lock(void)
122 +{
123 + flush_workqueue(laundry_wq);
124 +}
125 +
126 static void
127 nfsd4_lm_notify(struct file_lock *fl)
128 {
129 @@ -6755,9 +6790,12 @@ nfsd4_lm_notify(struct file_lock *fl)
130 }
131
132 static const struct lock_manager_operations nfsd_posix_mng_ops = {
133 + .lm_mod_owner = THIS_MODULE,
134 .lm_notify = nfsd4_lm_notify,
135 .lm_get_owner = nfsd4_lm_get_owner,
136 .lm_put_owner = nfsd4_lm_put_owner,
137 + .lm_lock_expirable = nfsd4_lm_lock_expirable,
138 + .lm_expire_lock = nfsd4_lm_expire_lock,
139 };
140
141 static inline void
142 --
143 2.43.0
144